paging helper script

Skip Montanaro skip at pobox.com
Fri Nov 21 22:42:37 CET 2003


Most of our system engineers (all but me I think) use Cingular cell phones
provided by the University which have a very small maximum length for text
messages, 100 characters total, I think.  Since the $OUTPUT$ from some of
the plugins can be a bit verbose, they often spill over into two messages,
sometimes more.  I hacked and hacked at the notify-by-epager and
host-notify-by-epager commands to try and shorten things up, but some
messages still overflowed.

I finally realized I had no choice but to trim $OUTPUT$, at which point it
became more practical to write a shell script instead of fiddling with
unmaintainable shell pipelines containing if/then/else stuff, awk commands,
shell output capturing and so forth.  In addition, since I use NagMIN and it
doesn't properly quote input ` characters, I wound up making these edits at
the MySQL prompt.  Not a lot of fun.  Appended is my pager-helper.sh file.
My pager commands now look like this:


    define command {
        command_name    notify-by-epager
        command_line    /usr/local/nagios/bin/pager-helper $HOSTNAME$ "$SERVICEDESC$" "$OUTPUT$" "$SERVICESTATE$" "$DATETIME$" "$NOTIFICATIONTYPE$" "$CONTACTPAGER$"
    }

    define command {
        command_name    host-notify-by-epager
        command_line    /usr/local/nagios/bin/pager-helper $HOSTNAME$ "" "$OUTPUT$" "$SERVICESTATE$" "$DATETIME$" "$NOTIFICATIONTYPE$" "$CONTACTPAGER$"
    }

The only difference being that the service description is empty for the host
version of the command.

Maybe this is something which could be included in a future version of
Nagios.  In any case, feel free to use/hack the little script below if it
looks potentially useful to you.

-- 
Skip Montanaro
Got gigs? http://www.musi-cal.com/
          http://www.mojam.com/
Got spam? http://spambayes.sf.net/


#!/bin/bash

HOSTNAME=$1
SERVICE=$2
OUTPUT=$3
STATE=$4
DATETIME=$5
NOTIFICATIONTYPE=$6
CONTACTPAGER=$7
OUTPUTLEN=$(echo $OUTPUT | awk '{print length($0)}')

if [ "$OUTPUTLEN" -gt 30 ] ; then
    OUTPUT=$(echo $OUTPUT | cut -b 1-30)...
fi

if [ "x$SERVICE" = x ] ; then
    # host notification
    /usr/bin/printf "%b" "$HOSTNAME is $STATE
Info: $OUTPUT
Time: $DATETIME"
else
    # service notification
    /usr/bin/printf "%b" "$HOSTNAME:$SERVICE is $STATE
Info: $OUTPUT
Time: $DATETIME"
fi | /usr/bin/mailx -s "$NOTIFICATIONTYPE" $CONTACTPAGER


-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?  SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null





More information about the Users mailing list