Created
May 17, 2015 09:22
-
-
Save russss/6c5329fd18e321b95abc to your computer and use it in GitHub Desktop.
Icinga plugin for IRCCat
This file contains hidden or 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
define command { | |
command_name notify-host-by-irccat | |
command_line /usr/local/share/nagios-plugins/icinga-irccat.py $HOSTNAME$ $HOSTSTATE$ | /bin/nc -q0 irccat-host 12345 | |
} | |
define command { | |
command_name notify-service-by-irccat | |
command_line /usr/local/share/nagios-plugins/icinga-irccat.py -s "$SERVICEDESC$" -o "$SERVICEOUTPUT$" $HOSTNAME$ $SERVICESTATE$ | /bin/nc -q0 irccat-host 12345 | |
} |
This file contains hidden or 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 python | |
from __future__ import division, absolute_import, print_function, unicode_literals | |
import argparse | |
parser = argparse.ArgumentParser(description='Format icinga messages for display through irccat') | |
parser.add_argument('host', metavar='HOSTNAME') | |
parser.add_argument('state', metavar='STATE') | |
parser.add_argument('-s', metavar='SERVICENAME') | |
parser.add_argument('-o', metavar='OUTPUT') | |
args = parser.parse_args() | |
def colour(string, colour): | |
return "%%%s%s%%NORMAL" % (colour, string) | |
def colour_state(state): | |
if state in ('UP', 'OK'): | |
return colour(state, 'GREEN') | |
elif state in ('CRITICAL', 'DOWN'): | |
return colour(state, 'RED') | |
elif state == 'WARNING': | |
return colour(state, 'YELLOW') | |
return state | |
PREFIX = "[%s]" % colour('icinga', 'BOLD') | |
if args.s: | |
print("%s Service %s / %s is %s (%s)" % (PREFIX, colour(args.host, 'BOLD'), colour(args.s, 'BOLD'), | |
colour_state(args.state), args.o)) | |
else: | |
print("%s Host %s is %s" % (PREFIX, colour(args.host, 'BOLD'), colour_state(args.state))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment