Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A script to report on the failed checks from sensu. Great for putting in the motd: sensu_report -s my_sensu_server > /etc/motd
#!/usr/bin/env python2
import json,sys,urllib2,socket
GREEN = '\033[92m'
RED = '\033[91m'
CLEAR = '\033[0m'
from optparse import OptionParser
parser = OptionParser()
parser.add_option("-s", "--server", dest="server",
help="sensu api server hostname", default='sensu')
parser.add_option("-p", "--port", dest="port",
help="sensu server api port", default='4567')
(options, args) = parser.parse_args()
response = urllib2.urlopen('http://' + options.server + ':' + options.port + '/events/' + socket.getfqdn())
data = json.load(response)
print
if len(data) > 0:
print "Failed Sensu checks on this host:"
for entry in data:
sys.stdout.write(" " + RED + entry['check'] + ': ' + entry['output'] + CLEAR )
else:
print "All Sensu checks " + GREEN + "green " + CLEAR + "for this host."
print
file { '/usr/bin/sensu_report':
mode => '0555',
source => 'puppet:///files/sensu/sensu_report',
} ->
cron { 'sensu_report':
command => "/usr/bin/sensu_report -s $sensu_api_server > /etc/motd",
minute => fqdn_rand(60),
} ->
sensu::check { "sensu_report":
handlers => 'default',
command => '/usr/lib/nagios/plugins/check_file_age -w 7200 -c 21600 -f /etc/motd',
subscribers => 'sensu-test'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.