From bd69166795ae92b72a1d3eccb3e21217a2353350 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Wed, 13 Feb 2013 16:19:08 -0500 Subject: [PATCH] Make the Nagios integration configurable, available, and documented. (imported from commit 1208fc08ed366a892763c3b29b9aeafa90b29981) --- integrations/nagios/humbug_nagios.cfg | 21 +++++++++++++++++++ integrations/nagios/humbugrc.example | 5 +++++ .../nagios/nagios-notify-humbug | 14 ++++++------- setup.py | 1 + 4 files changed, 33 insertions(+), 8 deletions(-) create mode 100644 integrations/nagios/humbug_nagios.cfg create mode 100644 integrations/nagios/humbugrc.example rename bots/send-nagios-notification => integrations/nagios/nagios-notify-humbug (84%) diff --git a/integrations/nagios/humbug_nagios.cfg b/integrations/nagios/humbug_nagios.cfg new file mode 100644 index 0000000..8a06c11 --- /dev/null +++ b/integrations/nagios/humbug_nagios.cfg @@ -0,0 +1,21 @@ +define contact{ + contact_name humbug + alias humbug + service_notification_period 24x7 + host_notification_period 24x7 + service_notification_options w,u,c,r + host_notification_options d,r + service_notification_commands notify-service-by-humbug + host_notification_commands notify-host-by-humbug + } + +# Humbug commands +define command { + command_name notify-host-by-humbug + command_line /usr/local/share/humbug/integrations/nagios/nagios-notify-humbug --stream=nagios --type="$NOTIFICATIONTYPE$" --host="$HOSTADDRESS$" --state="$HOSTSTATE$" --output="$HOSTOUTPUT$" --long-output="$LONGHOSTOUTPUT$" +} + +define command { + command_name notify-service-by-humbug + command_line /usr/local/share/humbug/integrations/nagios/nagios-notify-humbug --stream=nagios --type="$NOTIFICATIONTYPE$" --host="$HOSTADDRESS$" --service="$SERVICEDESC$" --state="$SERVICESTATE$" --output="$SERVICEOUTPUT$" --long-output="$LONGSERVICEOUTPUT$" +} diff --git a/integrations/nagios/humbugrc.example b/integrations/nagios/humbugrc.example new file mode 100644 index 0000000..9cbd1ba --- /dev/null +++ b/integrations/nagios/humbugrc.example @@ -0,0 +1,5 @@ +# Fill these values in with the appropriate values for your realm, and +# then install this value at /etc/nagios3/humbugrc +[api] +email = nagios@example.com +key = 0123456789abcdef0123456789abcdef diff --git a/bots/send-nagios-notification b/integrations/nagios/nagios-notify-humbug similarity index 84% rename from bots/send-nagios-notification rename to integrations/nagios/nagios-notify-humbug index 0efc71d..2f64f78 100755 --- a/bots/send-nagios-notification +++ b/integrations/nagios/nagios-notify-humbug @@ -1,9 +1,7 @@ #!/usr/bin/env python import sys import optparse -from os import path - -sys.path.append(path.join(path.dirname(__file__), '../api')) +import os.path import humbug # Nagios passes the notification details as command line options. @@ -12,11 +10,15 @@ import humbug parser = optparse.OptionParser() parser.add_option('--output', default='') parser.add_option('--long-output', default='') +parser.add_option('--stream', default='nagios') +parser.add_option('--config', default='/etc/nagios3/humbugrc') for opt in ('type', 'host', 'service', 'state'): parser.add_option('--' + opt) (opts, args) = parser.parse_args() -msg = dict(type='stream', to='nagios') +client = humbug.Client(config_file=opts.config) + +msg = dict(type='stream', to=opts.stream) # Set a subject based on the host or service in question. This enables # threaded discussion of multiple concurrent issues, and provides useful @@ -43,8 +45,4 @@ if output: # Put any command output in a code block. msg['content'] += ('\n\n~~~~\n' + output + "\n~~~~\n") -client = humbug.Client( - email = 'humbug+nagios@humbughq.com', - api_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', - site = 'https://staging.humbughq.com') client.send_message(msg) diff --git a/setup.py b/setup.py index ba7a4bd..17ee2f7 100644 --- a/setup.py +++ b/setup.py @@ -22,6 +22,7 @@ setup(name='humbug', packages=['humbug'], data_files=[('share/humbug/examples', ["examples/humbugrc", "examples/send-message"]), ('share/humbug/integrations/trac', glob.glob('integrations/trac/*')), + ('share/humbug/integrations/nagios', glob.glob('integrations/nagios/*')), ], scripts=["bin/humbug-send"], )