Problem with multiple devices telegraf nagios plugin - telegraf

I am trying to add some hosts (UPSs) for monitoring battery charge, invertor status, input voltage, etc. I've been trying to get this working for hours. So, the Nagios scripts seem to work ok and at least some data is logged in influxdb. However, when trying to view the data from the Data Explorer on influx web page, it doesn't appear to keep the details of the individual hosts. I have also separate configs same as below but with just one host in each config file, but it does not appear to make a difference. All config files are storing data in the same bucket. Took a screenshot of the query and the returned data as I could not copy/paste and still be legible.
Query selections
Displayed data
This is my config:
[[inputs.exec]]
timeout = "5s"
commands = [
"/usr/local/nagios/libexec/custom-plugins/check_ups_temperature -H 192.168.x.x -o 1.3.6.1.2.1.33.1.2.7.0 -v1 -C public -w 28 -c 31",
"/usr/local/nagios/libexec/custom-plugins/check_ups_temperature -H 192.168.x.x -o 1.3.6.1.2.1.33.1.2.7.0 -v1 -C public -w 28 -c 31",
"/usr/local/nagios/libexec/custom-plugins/check_ups_temperature -H 192.168.x.x -o 1.3.6.1.2.1.33.1.2.7.0 -v1 -C public -w 28 -c 31",
"/usr/local/nagios/libexec/custom-plugins/check_ups_temperature -H 192.168.x.x -o 1.3.6.1.2.1.33.1.2.7.0 -v1 -C public -w 28 -c 31"
]
name_suffix = "_ups_temp"
data_format = "nagios"
[[outputs.influxdb_v2]]
urls = ["http://192.168.x.x:8086"]
token = "--token--"
organization = "--org--"
bucket = "UPS"
Any pointers would be greatly appreciated.

I would try making multiple [[inputs.exec]] configuration with different name_suffix = "_ups_tempXX" where XX something what could identify source device. It will put data in different measurement.
Another way to go is to add tag keys in your telegraf exec configuration.
List of tag names to extract from top-level of JSON server response:
tag_keys = [
"my_tag_1",
"my_tag_2"
]
But in this case you will need to update your exec response by sending also values of tag keys. As a tag key you may use device IP or something what will let you easily filter data from all sources. I found some old docs, It may be helpful for you: https://archive.docs.influxdata.com/telegraf/v1.3/concepts/data_formats_input/

Related

bash: output/write/append a csv file with timestamp and public IP

I have an R script that gets the public IP by
system("curl ifconfig.me",intern = T )
and then
writes/appends it in a CSV file
write.table(data.frame(start.script=start.time, runtime=round(Sys.time()-start.time,4), ip=myip), append = T, file = "/home/eic/ip.report.csv", row.names = F,sep = ",", col.names = !file.exists("/home/eic/ip.report.csv"))
the script runs with cron every minute.
However, i will be running it in an small raspberry Zero and the installation of R is almost 500MB
is it possible to do this with bash?
The output should create or append a CSV file with (time and public IP as strings). If the internet is not reachable , "Internet not reachable" should be output. It doesn't necessarily have to do curl ifconfig.me to check for internet connectivity . Checking for ping at 8.8.8.8 would be also an option. However it should output the public IP.
Thanks
msg=$(curl -s --max-time 3 icanhazip.com) ||
msg='Internet unreachable'
echo "$(date '+%Y-%m-%d %T %Z'),${msg:-Unkown}" >> /home/eic/ip.report.csv
Each line will look like:
2022-02-21 14:59:59,12.123.123.12 UTC
Obviously, "Internet unreachable" means "icanhazip.com unreachable". Failing to ifconfig.me, and/or ping -c 1 -W 3 google.com to log connectivity, but not IP, may be worthwhile to reduce maintenance of an embedded device.
I might even use a 5 second time out (instead of 3), for very slow connections, like bad satellite, proxies, etc.
${msg:-Unkown} replaces an empty response with Unkown.
You can change the date format: man date.
Add 2>/dev/null to curl if you don't want cron to log errors it may produce (eg if internet is down).
More info on checking internet connectivity from the shell: https://unix.stackexchange.com/questions/190513/shell-scripting-proper-way-to-check-for-internet-connectivity
#!/bin/bash
ip=$(curl --max-time 2 ifconfig.me 2>/dev/null) #Curl outputs some data on stderr. 2>/dev/null will remove that
hasInternet=$? #will be 0 if there was no error, make sure this line is directly after the curl line
curdate=$(date)
csvfile="file.csv" #right now this is a relative path to your working directory. For cron maybe better to use a absolute path
if [ $hasInternet -eq 0 ]; then
echo "${curdate},${ip}" >> $csvfile #>> will add a new line to the file
else
echo "${curdate},No internet" >> $csvfile
fi
I think this is a good start for your script. Might not be exactly as your original was, but I think you should be able to make the necessary changes.

How to in salt find host when specific package installed

I have hundreds of servers connected to the salt-master.
I need to find all servers when specific package installed or service is running.
How I can write a query (minion target) to find these minions and run a single command (service restart for example).
Ad-hoc Commands Against Target Minions
First, find the best way to target your minions by referencing the Targeting Minions Salt documentation, or the Getting Started: Targeting guide.
For example, if it is checking all minions running CentOS, you could just target with a query focused on the os grain:
salt -G 'os:centos' test.ping
If you wanted each one of them that had the vim-enhanced package installed, modify the query with the pkg execution module:
salt -G 'os:centos' pkg.version vim-enhanced
Then you can use a simple bash script to loop through the results with the command you want to run after, but use the --out txt argument to simplify the output for use in a bash script.
A simple bash script example that uses the service execution module:
PKG_INSTALLED=`salt -G 'os:centos' pkg.version vim-enhanced --out txt | cut -d':' -f1`
for PKG in "$PKG_INSTALLED"; do
salt "$PKG" service.start <target-service>
done
This can be simplified further with the -L argument:
TARGETS=`salt -G 'os:centos' pkg.version vim-enhanced --out txt | cut -d':' -f1`
salt -L "$TARGETS" service.start <service>
Info on the -L arg:
-L, --list Instead of using shell globs to evaluate the target
servers, take a comma or whitespace delimited list
of servers.
That command can technically be reduced down to a one-liner, but it is a long one:
salt -L "$(salt -G 'os:centos' pkg.version vim-enhanced --out txt | cut -d':' -f1)" service.start <service>
Using Salt States
If not wanting merely ad-hoc targeting, it would be advisable to use Salt States.
Resources
The following should be good resources:
Getting Started: Fundamentals: This includes targeting, basic states, and applying states to targets.
Getting Started: Configuration Management: This includes more in-depth information, including a deeper look at states.

Display Network Encryption Type in Tshark?

I've been using tshark to gather some basic information on networks near where I live. I've got tshark to display the bssid, ssid, and rssi but I was wondering if there was also a way to display the networks encryption type as well. I'm using the following command:
tshark -i wlan1mon -l -T fields -e wlan.bssid -e wlan.ssid -e radiotap.dbm_antsignal -Y 'wlan.ssid' | grep -v "ff:ff:ff"
and this is and example of the output I get:
00:11:22:33:44:55 Bell Wireless -74,-74
66:77:88:99:00:22 Dlink -83,-83
33:44:55:66:77:88 NetflixNChill -68,-83
Ideally I'd want the output to look more like this:
00:11:22:33:44:55 Bell Wireless WPA -74,-74
66:77:88:99:00:22 Dlink WPA2 -83,-83
33:44:55:66:77:88 NetflixNChill Open -68,-83
Any help would be greatly appreciated!
Maybe -e wlan.rsn.pcs.type and -e wlan.rsn.gcs.type are what you're looking for? Those are for the Pairwise Cipher Suite type" and "Group Cipher Suite type", respectively.
In case those aren't the fields you're interested in, or in case you want to include additional fields, you can find a complete list of display filters, including wlan filters, online at the Wireshark Display Filter Reference page.
You can also get this information from:
Wireshark itself via "View -> Internals -> Supported Protocols -> ...", but unfortunately the sorting leaves much to be desired there.
tshark using the tshark -G fields command, but this output isn't very user-friendly either.

snmpwalk doesnt work on net-snmp altho snmpget works

I am trying to monitor a system with net-snmp, and I am using my own MIB.
i added the needed files in the path and snmpget works
snmpget -v 2c -c public IP MY-MIB::myField.0
the thing is that when i run snmpwalk it doesnt show the results in the output.
I tried:
snmpwalk -v 2c -c public IP -m MY-MIB
Of course i run it with the IP of the machine i want to probe
i also tried adding MY-MIB to MIBS and then export it.
but it still doesnt appear in the log.
thanks in advance.

Multiple WEP keys which can be retrieved from the Pcap file

Ok, i have this Cap file that i captured with Wireshark. There are multiple WEP keys which can be retrieved from the file.
Is there a way, using Wireshark or aircrack-ng, to know exactly how many wep keys that are available in that Pcap file ?
Edit: not the Wep passwords, just the number of Wep keys available.
Wireshark has a display/filter field named wlan.wep.key.
So: Using tshark with a display filter and wc as follows might give you the desired result (altho i haven't tried it):
tshark -R wlan.wep.key -r <filename> | wc -l
Note: I don't know if there can be more than 1 WEP key in a frame. If so then the above won't give the right count.
tshark -R wlan.wep.key -Tfields -eframe.number -r <filename> should show just the frame numbers of all the frames with WEP keys.
tshark -R wlan.wep.key -Tfields -eframe.number -ewlan.wep.key -r <filename> will print out all the keys (even if more than 1 per frame).

Resources