Created
September 4, 2012 23:45
-
-
Save kazad/3628157 to your computer and use it in GitHub Desktop.
Leftronic API Access
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#Which | |
Grep="`/usr/bin/which grep`" | |
Awk="`/usr/bin/which awk`" | |
Cat="`/usr/bin/which cat`" | |
Sed="`/usr/bin/which sed`" | |
Curl="`/usr/bin/which curl`" | |
# Scrape Nagios | |
$Curl -s --user thebaws:S3cuR3p@55wdBr@ "https://monitoring.example.com/nagios/cgi-bin/status.cgi?host=all&servicestatustypes=28" > data/nagios-count.html | |
# Get host status stats | |
$Cat data/nagios-count.html |$Sed -n "43,46p" > data/hosts | |
$Sed 's/>/ /g;s/</ /g' data/hosts |$Awk {'print $3'} > data/hostnumbers | |
# Extract the numbers | |
HostUp="`$Awk 'NR == 1' data/hostnumbers`" | |
HostDown="`$Awk 'NR == 2' data/hostnumbers`" | |
HostUn="`$Awk 'NR == 3' data/hostnumbers`" | |
HostPend="`$Awk 'NR == 4' data/hostnumbers`" | |
# Send Host Stats to Leftronic | |
$Curl -i -X POST -k -d '{"accessKey": "000000000000000000000000000000000", "streamName": "000000", "point": '"$HostUp"'}' https://www.leftronic.com/customSend/ | |
$Curl -i -X POST -k -d '{"accessKey": "000000000000000000000000000000000", "streamName": "000000", "point": '"$HostDown"'}' https://www.leftronic.com/customSend/ | |
$Curl -i -X POST -k -d '{"accessKey": "000000000000000000000000000000000", "streamName": "000000", "point": '"$HostUn"'}' https://www.leftronic.com/customSend/ | |
$Curl -i -X POST -k -d '{"accessKey": "000000000000000000000000000000000", "streamName": "000000", "point": '"$HostPend"'}' https://www.leftronic.com/customSend/ | |
####################### | |
# Get Service status stats | |
$Cat data/nagios-count.html |$Sed -n "77,79p" > data/service | |
$Sed 's/>/ /g;s/</ /g' data/service |$Awk {'print $3'} > data/servicenumbers | |
# Extract the numbers | |
ServiceWarn="`$Awk 'NR == 1' data/servicenumbers`" | |
ServiceCrit="`$Awk 'NR == 3' data/servicenumbers`" | |
# Send Host Stats to Leftronic | |
$Curl -i -X POST -k -d '{"accessKey": "000000000000000000000000000000000", "streamName": "00000000", "point": '"$ServiceWarn"'}' https://www.leftronic.com/customSend/ | |
$Curl -i -X POST -k -d '{"accessKey": "000000000000000000000000000000000", "streamName": "00000000", "point": '"$ServiceCrit"'}' https://www.leftronic.com/customSend/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment