Tested On Fedora 14
And Gsm Nokia X-05
Needed Packages:
yum install gammu.i686 wammu.noarch python-gammu.i686 gammu-libs.i686 gammu-devel.i686
#####################################################################################
First Config file
vi /etc/gammurc
[gammu]
port=/dev/ttyACM0
connection=at
name=Nokia X-05
synchronizetime = no
use_locking = no
:wq!
##########################
execute the following :
gammu --identify
Manufacturer : Nokia
Model : unknown (Nokia X5-01)
Firmware : V ICPR82_10w18.7.7,18-10-10
IMEI : 555555555555
SIM IMSI : 8888888888
####################
Now we will be able to send sms with the following
echo "Test message" | gammu --sendsms TEXT
############################################
next create a script for send sms from nagios
vi /usr/local/nagios/sendsms.sh
#!/bin/bash
# Location of the logfile
# check the file is been created and updating (permission also check checkmod)
LOGFILE=/var/log/sms.log
# Determine the type of message.
case "$1" in
'host')
case "$NAGIOS_NOTIFICATIONTYPE" in
'ACKNOWLEDGEMENT')
MESSAGE="$NAGIOS_NOTIFICATIONTYPE \nHost '$NAGIOS_HOSTALIAS' is $NAGIOS_HOSTSTATE\nI: $NAGIOS_HOSTOUTPUT\nT: $NAGIOS_SHORTDATETIME\nA: $NAGIOS_HOSTACKAUTHOR R: $NAGIOS_HOSTACKCOMMENT"
;;
'PROBLEM')
MESSAGE="$NAGIOS_NOTIFICATIONTYPE \nHost '$NAGIOS_HOSTALIAS' is $NAGIOS_HOSTSTATE\nI: $NAGIOS_HOSTOUTPUT\nT: $NAGIOS_SHORTDATETIME\nR: "
;;
'FLAPPINGSTART')
MESSAGE="$NAGIOS_NOTIFICATIONTYPE \nHost '$NAGIOS_HOSTALIAS' is $NAGIOS_HOSTSTATE\nI: $NAGIOS_HOSTOUTPUT\nT: $NAGIOS_SHORTDATETIME\nR: "
;;
'FLAPPINGSTOP')
MESSAGE="$NAGIOS_NOTIFICATIONTYPE \nHost '$NAGIOS_HOSTALIAS' is $NAGIOS_HOSTSTATE\nI: $NAGIOS_HOSTOUTPUT\nT: $NAGIOS_SHORTDATETIME"
;;
'RECOVERY')
MESSAGE="$NAGIOS_NOTIFICATIONTYPE \nHost '$NAGIOS_HOSTALIAS' is $NAGIOS_HOSTSTATE\nI: $NAGIOS_HOSTOUTPUT\nT: $NAGIOS_SHORTDATETIME"
;;
esac
;;
'service')
case "$NAGIOS_NOTIFICATIONTYPE" in
'ACKNOWLEDGEMENT')
MESSAGE="$NAGIOS_NOTIFICATIONTYPE \nH: $NAGIOS_HOSTNAME\nS: $NAGIOS_SERVICEDESC\nST: $NAGIOS_SERVICESTATE\nI: $NAGIOS_SERVICEOUTPUT\nT: $NAGIOS_SHORTDATETIME\nA: $NAGIOS_SERVICEACKAUTHOR R: $NAGIOS_SERVICEACKCOMMENT"
;;
'PROBLEM')
MESSAGE="$NAGIOS_NOTIFICATIONTYPE \nH: $NAGIOS_HOSTNAME\nS: $NAGIOS_SERVICEDESC\nST: $NAGIOS_SERVICESTATE\nI: $NAGIOS_SERVICEOUTPUT\nT: $NAGIOS_SHORTDATETIME\nR: "
;;
'FLAPPINGSTART')
MESSAGE="$NAGIOS_NOTIFICATIONTYPE \nH: $NAGIOS_HOSTNAME\nS: $NAGIOS_SERVICEDESC\nST: $NAGIOS_SERVICESTATE\nI: $NAGIOS_SERVICEOUTPUT\nT: $NAGIOS_SHORTDATETIME\nR: "
;;
'FLAPPINGSTOP')
MESSAGE="$NAGIOS_NOTIFICATIONTYPE \nH: $NAGIOS_HOSTNAME\nS: $NAGIOS_SERVICEDESC\nST: $NAGIOS_SERVICESTATE\nI: $NAGIOS_SERVICEOUTPUT\nT: $NAGIOS_SHORTDATETIME"
;;
'RECOVERY')
MESSAGE="$NAGIOS_NOTIFICATIONTYPE \nH: $NAGIOS_HOSTNAME\nS: $NAGIOS_SERVICEDESC\nST: $NAGIOS_SERVICESTATE\nI: $NAGIOS_SERVICEOUTPUT\nT: $NAGIOS_SHORTDATETIME"
;;
esac
;;
esac
# Write to log file.
echo "*********************************************************" >> $LOGFILE
echo -e $MESSAGE >> $LOGFILE
echo "*********************************************************" >> $LOGFILE
echo -e "\n" >> $LOGFILE
# Send the alert.
echo -e $MESSAGE | /usr/bin/gammu --sendsms TEXT $NAGIOS_CONTACTPAGER
# Unset the variables used.
unset $MESSAGE
# Exit the program.
exit
:wq!
##########################
now add the command in nagios
##############################
vi /etc/nagios/objects/commands.cfg
define command {
command_name notify-service-by-sms
command_line /usr/local/nagios/sendsms.sh service
}
:wq!
####################
then in the contact file also
#################################
vi /etc/nagios/objects/contacts.cfg
service_notification_commands notify-service-by-sms
pager +91
:wq!
####################
I'm assuming that you already configured the contact details so not mentioning all those.
#######################################################################
Try to send a service test notification.
And Gsm Nokia X-05
Needed Packages:
yum install gammu.i686 wammu.noarch python-gammu.i686 gammu-libs.i686 gammu-devel.i686
#####################################################################################
First Config file
vi /etc/gammurc
[gammu]
port=/dev/ttyACM0
connection=at
name=Nokia X-05
synchronizetime = no
use_locking = no
:wq!
##########################
execute the following :
gammu --identify
Manufacturer : Nokia
Model : unknown (Nokia X5-01)
Firmware : V ICPR82_10w18.7.7,18-10-10
IMEI : 555555555555
SIM IMSI : 8888888888
####################
Now we will be able to send sms with the following
echo "Test message" | gammu --sendsms TEXT
############################################
next create a script for send sms from nagios
vi /usr/local/nagios/sendsms.sh
#!/bin/bash
# Location of the logfile
# check the file is been created and updating (permission also check checkmod)
LOGFILE=/var/log/sms.log
# Determine the type of message.
case "$1" in
'host')
case "$NAGIOS_NOTIFICATIONTYPE" in
'ACKNOWLEDGEMENT')
MESSAGE="$NAGIOS_NOTIFICATIONTYPE \nHost '$NAGIOS_HOSTALIAS' is $NAGIOS_HOSTSTATE\nI: $NAGIOS_HOSTOUTPUT\nT: $NAGIOS_SHORTDATETIME\nA: $NAGIOS_HOSTACKAUTHOR R: $NAGIOS_HOSTACKCOMMENT"
;;
'PROBLEM')
MESSAGE="$NAGIOS_NOTIFICATIONTYPE \nHost '$NAGIOS_HOSTALIAS' is $NAGIOS_HOSTSTATE\nI: $NAGIOS_HOSTOUTPUT\nT: $NAGIOS_SHORTDATETIME\nR: "
;;
'FLAPPINGSTART')
MESSAGE="$NAGIOS_NOTIFICATIONTYPE \nHost '$NAGIOS_HOSTALIAS' is $NAGIOS_HOSTSTATE\nI: $NAGIOS_HOSTOUTPUT\nT: $NAGIOS_SHORTDATETIME\nR: "
;;
'FLAPPINGSTOP')
MESSAGE="$NAGIOS_NOTIFICATIONTYPE \nHost '$NAGIOS_HOSTALIAS' is $NAGIOS_HOSTSTATE\nI: $NAGIOS_HOSTOUTPUT\nT: $NAGIOS_SHORTDATETIME"
;;
'RECOVERY')
MESSAGE="$NAGIOS_NOTIFICATIONTYPE \nHost '$NAGIOS_HOSTALIAS' is $NAGIOS_HOSTSTATE\nI: $NAGIOS_HOSTOUTPUT\nT: $NAGIOS_SHORTDATETIME"
;;
esac
;;
'service')
case "$NAGIOS_NOTIFICATIONTYPE" in
'ACKNOWLEDGEMENT')
MESSAGE="$NAGIOS_NOTIFICATIONTYPE \nH: $NAGIOS_HOSTNAME\nS: $NAGIOS_SERVICEDESC\nST: $NAGIOS_SERVICESTATE\nI: $NAGIOS_SERVICEOUTPUT\nT: $NAGIOS_SHORTDATETIME\nA: $NAGIOS_SERVICEACKAUTHOR R: $NAGIOS_SERVICEACKCOMMENT"
;;
'PROBLEM')
MESSAGE="$NAGIOS_NOTIFICATIONTYPE \nH: $NAGIOS_HOSTNAME\nS: $NAGIOS_SERVICEDESC\nST: $NAGIOS_SERVICESTATE\nI: $NAGIOS_SERVICEOUTPUT\nT: $NAGIOS_SHORTDATETIME\nR: "
;;
'FLAPPINGSTART')
MESSAGE="$NAGIOS_NOTIFICATIONTYPE \nH: $NAGIOS_HOSTNAME\nS: $NAGIOS_SERVICEDESC\nST: $NAGIOS_SERVICESTATE\nI: $NAGIOS_SERVICEOUTPUT\nT: $NAGIOS_SHORTDATETIME\nR: "
;;
'FLAPPINGSTOP')
MESSAGE="$NAGIOS_NOTIFICATIONTYPE \nH: $NAGIOS_HOSTNAME\nS: $NAGIOS_SERVICEDESC\nST: $NAGIOS_SERVICESTATE\nI: $NAGIOS_SERVICEOUTPUT\nT: $NAGIOS_SHORTDATETIME"
;;
'RECOVERY')
MESSAGE="$NAGIOS_NOTIFICATIONTYPE \nH: $NAGIOS_HOSTNAME\nS: $NAGIOS_SERVICEDESC\nST: $NAGIOS_SERVICESTATE\nI: $NAGIOS_SERVICEOUTPUT\nT: $NAGIOS_SHORTDATETIME"
;;
esac
;;
esac
# Write to log file.
echo "*********************************************************" >> $LOGFILE
echo -e $MESSAGE >> $LOGFILE
echo "*********************************************************" >> $LOGFILE
echo -e "\n" >> $LOGFILE
# Send the alert.
echo -e $MESSAGE | /usr/bin/gammu --sendsms TEXT $NAGIOS_CONTACTPAGER
# Unset the variables used.
unset $MESSAGE
# Exit the program.
exit
:wq!
##########################
now add the command in nagios
##############################
vi /etc/nagios/objects/commands.cfg
define command {
command_name notify-service-by-sms
command_line /usr/local/nagios/sendsms.sh service
}
:wq!
####################
then in the contact file also
#################################
vi /etc/nagios/objects/contacts.cfg
service_notification_commands notify-service-by-sms
pager +91
:wq!
####################
I'm assuming that you already configured the contact details so not mentioning all those.
#######################################################################
Try to send a service test notification.
No comments:
Post a Comment