Annotation of nagios/alert/alert, Revision 1.5
1.1 andrew 1: #!/bin/sh
1.5 ! andrew 2: # $AFresh1: alert,v 1.4 2010/02/16 17:58:35 andrew Exp $
1.1 andrew 3: local _type=$1
4: local _method=$2
5: local _contact=$3
6:
7: if [ X"" == X"$_type" -o $"" == X"$_method" -o X"" == X"$_contact" ]; then
8: echo "Usage: $0: <type> <method> <contact>"
9: echo " type is HOST or SERVICE"
10: echo " method is mail, qpage or jabber"
11: echo " contact is the identifier to send to"
12: exit 2
13: fi
14:
15:
1.4 andrew 16: local _notification=$NAGIOS_NOTIFICATIONTYPE
17: if [ X"" != X"$NAGIOS_NOTIFICATIONCOMMENT" ]; then
18: _notification="$_notification $NAGIOS_NOTIFICATIONCOMMENT"
19: fi
20: if [ X"" != X"$NAGIOS_NOTIFICATIONAUTHOR" ]; then
21: _notification="$_notification ($NAGIOS_NOTIFICATIONAUTHOR)"
22: fi
23:
1.1 andrew 24: ### HOST Descriptions ###
25:
1.2 andrew 26: local _short_host="$NAGIOS_HOSTNAME"
1.1 andrew 27: local _long_host="Date/Time: $NAGIOS_LONGDATETIME
1.4 andrew 28: $_notification
1.1 andrew 29:
1.4 andrew 30: Host: $NAGIOS_HOSTALIAS [$NAGIOS_HOSTADDRESS]
1.1 andrew 31: State: $NAGIOS_HOSTSTATE (for $NAGIOS_HOSTDURATION)
1.4 andrew 32: $NAGIOS_HOSTOUTPUT
1.1 andrew 33:
34: https://stats.redrivernet.com/CGi-bin/nagios/extinfo.cgi?type=1&host=$NAGIOS_HOSTNAME
35: "
36:
37: ### SERVICE Descriptions ###
38:
1.3 andrew 39: local _short_svc="$NAGIOS_HOSTNAME $NAGIOS_SERVICEDESC"
1.1 andrew 40: local _long_svc="Date/Time: $NAGIOS_LONGDATETIME
1.4 andrew 41: $_notification
1.1 andrew 42:
1.4 andrew 43: Service: $NAGIOS_SERVICEDESC
1.1 andrew 44: Host: $NAGIOS_HOSTALIAS ($NAGIOS_HOSTADDRESS)
1.4 andrew 45: State: $NAGIOS_SERVICESTATE (for $NAGIOS_SERVICEDURATION)
46: $NAGIOS_SERVICEOUTPUT
1.1 andrew 47:
48: https://stats.redrivernet.com/cgi-bin/nagios/extinfo.cgi?type=2&host=$NAGIOS_HOSTNAME&service=`echo $NAGIOS_SERVICEDESC | sed -e 's/ /+/g'`
49: "
50:
51: ### Actions ###
52:
1.2 andrew 53: local _state
1.1 andrew 54: local _short
55: local _long
1.4 andrew 56:
1.1 andrew 57: case $_type in
58: HOST)
1.2 andrew 59: _state=$NAGIOS_HOSTSTATE
1.1 andrew 60: _short=$_short_host
61: _long=$_long_host
62: ;;
63: SERVICE)
1.2 andrew 64: _state=$NAGIOS_SERVICESTATE
1.1 andrew 65: _short=$_short_svc
66: _long=$_long_svc
67: ;;
68: *)
69: echo "Unknown type $_type"
70: exit 3
71: ;;
72: esac
73:
1.2 andrew 74: if [ X"$NAGIOS_NOTIFICATIONTYPE" == X"ACKNOWLEDGEMENT" ]; then
1.5 ! andrew 75: _state=ACK
1.1 andrew 76: fi
77:
1.5 ! andrew 78: _short="`echo $_state | cut -c 1-4`: $_short"
1.4 andrew 79: _long=`echo "$_long" | awk '{ gsub(/<br *\/?>/,"\n") }1'`
1.1 andrew 80:
81: case $_method in
82: mail)
83: echo "$_long" | /usr/bin/mail -s "$_short" $_contact
84: ;;
85: qpage)
86: echo "$_short" | /usr/local/bin/page_somehow $_contact
87: ;;
88: jabber)
89: echo "$_long" | /usr/local/libexec/nagios/eventhandlers/alert_jabber $_contact
90: ;;
91: *)
92: echo "Unknown method $_method"
93: exit 3
94: ;;
95: esac
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>