Some basics related to this topic:
- Nagios accepts only an "one-liner" command to send notifications (command_line parameter of command object). Note that ; means comment here.
- Kannel has a web interface which expects the text to be sent urlencoded
- curl is a very nice tool to connect to http interfaces, but it is too smart in this case. It means that it has a very useful argument --data-urlencode which URLencodes the text given to this parameter preceeding an "&".
That "&" causes problem. Kannel expets the message in "text=messagetobesent" format in the url, but data-urlencode encodes "text=" to "text%3D" which kannel does not understand.
#!/bin/bash # ZsZs 2014 trap cleanup EXIT cleanup() { rm -F $TMP 2>/dev/null } MSISDN=$1 MSG="$2" TMP=$(mktemp) printf '%b' "$MSG" >$TMP MSGU=$( perl -p -e 's/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg' $TMP ) curl -G -s "http://localhost:13131/cgi-bin/sendsms?username=KANNELUSER&password=KANNELPW&validity=60&to=$MSISDN&text=$MSGU"
Nagios configuration should look like this:
define command{ command_name notify-host-by-sms command_line /usr/local/bin/smssend $CONTACTPAGER$ 'Host: $HOSTNAME$\nState: $HOSTSTATE$\nInfo: $HOSTOUTPUT$\nTime: $LONGDATETIME$' } define command{ command_name notify-service-by-sms command_line /usr/local/bin/smssend $CONTACTPAGER$ 'Service: $SERVICEDESC$\nHost: $HOSTNAME$\nState: $SERVICESTATE$\nInfo: $SERVICEOUTPUT$\nTime: $LONGDATETIME$' }
man, you saved my day, tried to integrate Nagios with Kannel for weeks until i find this how to, thank you for sharing.
ReplyDelete