Saturday, July 14, 2012

Sending custom Nagios notification emails with coffeescript

Lets imagine for a second that you are using Nagios to monitor systems and services.  Nagios can send you notifications upon events, but the default email notification command is kind of boring.

Lets spice it up with coffeescript!


Nagios


define contact{
        contact_name                    mike
        alias                           Mike Kunze
        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-with-nodejs
        host_notification_commands      notify-host-by-email
        email                          
}


define command {
    command_name    notify-service-with-nodejs
    command_line    /opt/bin/notify-service.coffee "$HOSTNAME$" "$SERVICEDESC$" "$HOSTADDRESS$" "$NOTIFICATIONTYPE$" "$SERVICESTATE$" "$LONGDATETIME$" "$SERVICEOUTPUT$"
}



CoffeeScript



This script will be executed by nagios and will contain the macros provided by the nagios command.

No comments:

Post a Comment