Last active
December 26, 2017 10:27
-
-
Save solarkennedy/7713642 to your computer and use it in GitHub Desktop.
A script to report on the failed checks from sensu. Great for putting in the motd: sensu_report -s my_sensu_server > /etc/motd
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
#!/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) | |
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." | |
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
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