User Tools

Site Tools


public:doku:nagios_sms

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

public:doku:nagios_sms [2011/03/20 01:45]
ello
public:doku:nagios_sms [2014/10/25 18:12]
Line 1: Line 1:
-===== Wie man SMS mit Nagios verschicken kann ===== 
  
-==== SMS-Provider ==== 
-Ich nutze [[http://​www.smstrade.de]]. Die haben eine recht einfache http-Schnittstelle. 
-Prinzipiell geht jeder, der eine http-Schnittstelle bietet. 
- 
- 
-==== Schnittstelle zum Gateway ==== 
-https://​gateway.smstrade.de/?​key=$GATEWAY_KEY&​to=$NUMBER&​route=basic&​concat=1&​cost=1&​message_id=1&​count=1&​message=$SMS_MESSAGE 
- 
-==== Script ==== 
-Das ganze in ein Script gegossen: 
- 
-<​file|/​usr/​local/​bin/​send_nagios_sms.sh>​ 
-#!/bin/bash 
- 
-GATEWAY_KEY=<​key vom provider>​ 
-MESSAGE=$1 
-SMS_MESSAGE=`php -r "echo urlencode('​$MESSAGE'​);"​` 
-NUMBER=$2 
-LOGFILE=/​var/​log/​nagios.sms.log 
- 
-date >> $LOGFILE 
-echo $SMS_MESSAGE >> $LOGFILE 
-wget -q -O - --no-check-certificate "​https://​gateway.smstrade.de/?​key=$GATEWAY_KEY&​to=$NUMBER&​route=basic&​concat=1&​cost=1&​message_id=1&​count=1&​message=$SMS_MESSAGE"​ >> $LOGFILE 
-</​file>​ 
- 
-Das script hat 2 Parameter: 
-  - Nachricht 
-  - Nummer an die die SMS gehen soll 
- 
-Da die Nachricht url-encodiert werden muss und die Bash das nicht selbst kann, wird hier php dazu bemüht. Da auf dem Nagios-Server eh php für die Weboberfläche von Nagios installiert ist, sollte das kein Problem darstellen. ​ 
-Die Ausgaben, werden in ein Logfile geschrieben:​ 
-  - Datum 
-  - url-encodierte Nachricht 
-  - Status-Code von SMS-Trade siehe [[http://​www.smstrade.de/​pdf/​SMS-Gateway_HTTP_API_v2_de.pdf]] 
-  - Message-ID 
-  - Kosten 
-  - Anzahl der versendeten Nachrichten 
- 
-==== Aufruf von Nagios ==== 
-<​file|/​etc/​nagios3/​commands.cfg>​ 
-define command{ 
-        command_name ​   notify-service-by-sms 
-        command_line ​   /​usr/​local/​bin/​send_nagios_sms.sh "​$NOTIFICATIONTYPE$ for $SERVICEDESC$ at host $HOSTALIAS$/​$HOSTADDRESS$:​ $SERVICESTATE$"​ $CONTACTPAGER$ 
-        } 
- 
-define command{ 
-        command_name ​   notify-host-by-sms 
-        command_line ​   /​usr/​local/​bin/​send_nagios_sms.sh "​$NOTIFICATIONTYPE$ for $HOSTNAME$/​$HOSTADDRESS$:​ $HOSTSTATE$"​ $CONTACTPAGER$ 
-        } 
-</​file>​ 
- 
-Aufgrund von "​concat=1"​ beim SMS-Versand kann die Nachricht bis zu 1530 Zeichen lang sein. Es werden entsprechend mehrere SMS versendet. 
- 
-<​file|/​etc/​nagios3/​conf.d/​contacts.cfg>​ 
-define contact{ 
-        contact_name ​                   ello-sms 
-        alias                           ​ello-sms 
-        service_notification_period ​    24x7 
-        host_notification_period ​       24x7 
-        service_notification_options ​   c,r 
-        host_notification_options ​      d,r,u 
-        service_notification_commands ​  ​notify-service-by-sms 
-        host_notification_commands ​     notify-host-by-sms 
-        pager                           ​+49xxxxxx 
-        } 
-        ​ 
-        ​ 
-        ​ 
-        ​ 
-define contactgroup{ 
-        contactgroup_name ​      ​admins 
-        alias                   ​Nagios Administrators 
-        members ​                ​ello,​ello-sms 
-        } 
-</​file>​ 
- 
-Ich hab für den SMS-Versand einen extra Kontakt definiert, dann ist man flexibeler. Man kann auch mehrere Kontakte definieren, die auch für unterschiedliche Dinge Nachrichten bekommen sollen. 
public/doku/nagios_sms.txt · Last modified: 2014/10/25 18:12 (external edit)