Nagios: SMS notification
In connection with the increase in the number of servers, it became necessary to monitor them with the possibility of notifying you if problems arise. The choice fell on Nagios, as a couple of years ago, working in a telecom operator company worked with him.
One of the conditions was the possibility of notification via SMS messages.
So, what we have and how to make it all work together:
- Linux (Debian 5) server with installed Nagios (I will not describe the process of initial installation and configuration of Nagios itself in this article)
- Mobile phone (in this case, Nokia 3110), connected via USB cable
- The desire to make this whole thing work together :)
First, install Nagios and configure it to monitor the required hosts.
')
Next, set up the system to work with a mobile phone. I will describe this step as I implemented, since there are many ways to do this :)
First, install the program gammu
apt-get install gammu
The next step is to configure gammu to work with a mobile phone. To do this, you can use the utility
gammu-config.
After configuring gammu, a .gammurc file of the following format should appear in your home directory:
~ # cat ~ / .gammurc
[gammu]
port = / dev / ttyACM0
connection = at115200
name = Nokia 3110c
model = nauto
In order to check the performance, use the following commands:
~ # echo "test msg" | gammu sendsms TEXT + your_phone_number
Thus, we send an SMS with the text “test msg” to the telephone "+ your_phone_number" - the telephone number should be indicated in the international format.
if the SMS has arrived, then we read further, otherwise we return to the gammu setup (I think, by Google on this topic, you can find a bunch of documentation).
The next step is to configure Nagios to send SMS.
Check the / etc / passwd file to find out where the home directory for the user nagios is located (in my case: / var / run / nagios3). Copy the .gammurc file there and change the permissions for the user nagios:
~ # chown nagios: ./.gammurc
Next, I had to change the permissions on the / usr / bin / gammu file — assign the UID at runtime, so they became:
/ usr / bin # ls -la ./gammu
-rwsr-xr-x 1 root root 360088 May 11 2008 ./gammu
Next, configure Nagios. To begin, add new commands. This is done in the settings.cfg settings file in the Nagios configuration directory (for me / etc / nagios3). Add the following lines:
# 'notify-host-by-sms' command definition
define command {
command_name notify-host-by-sms
command_line / usr / bin / printf "% b" "***** Nagios ***** \ n \ nNotification Type: $ NOTIFICATIONTYPE $ \ nHost: $ HOSTNAME $ \ nState: $ HOSTSTATE $ \ nAdd
ress: $ HOSTADDRESS $ \ nInfo: $ HOSTOUTPUT $ \ n \ nDate / Time: $ LONGDATETIME $ \ n "| / usr / bin / gammu sendsms TEXT $ CONTACTADDRESS1 $
}
# 'notify-service-by-sms' command definition
define command {
command_name notify-service-by-sms
command_line / usr / bin / printf "% b" "***** Nagios ***** \ n \ nNotification Type: $ NOTIFICATIONTYPE $ \ n \ nService: $ SERVICEDESC $ \ nHost: $ HOSTALIA
S $ \ nAddress: $ HOSTADDRESS $ \ nState: $ SERVICESTATE $ \ n \ nDate / Time: $ LONGDATETIME $ \ n \ nAdditional Info: \ n \ n $ SERVICEOUTPUT $ "| / usr / bin / gammu sendsms TEXT
$ CONTACTADDRESS1 $
}
Then we proceed to the configuration of the file with contacts (in my case contacts_nagios2.cfg in the /etc/nagios3/conf.d directory).
We need to add the address1 parameter in which we specify the mobile number in the international format, as well as add commands to notify when the status of services or hosts changes.
Here is how I had before:
define contact {
contact_name vano
alias Vano
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w, u, c, r
host_notification_options d, r
service_notification_commands notify-service-by-email
host_notification_commands notify-host-by-email
email vano@gde-to.tam
}
And as it became after:
define contact {
contact_name vano
alias Vano
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w, u, c, r
host_notification_options d, r
service_notification_commands notify-service-by-email, notify-service-by-sms
host_notification_commands notify-host-by-email, notify-host-by-sms
email vano@gde-to.tam
address1 +700000000000
}
Next, restart Nagios and start enjoying incoming messages :)
Although it is better when there are fewer :)
PS: please do not kick with your feet, as this is my first post :) if you have questions - ask, try to answer :)
UPD: noticed another nuance, at least for me. Since the nagios user has a home directory specified in / var / run / nagio3, after rebooting, the .gammurc file disappears from there. I decided simply, in /etc/rc.local I registered that I copied this file to the / var / run / nagios3 directory and changed the owner to nagios, then restart the service:
/ bin / cp /root/.gammurc / var / run / nagios3
/ bin / chown -R nagios: / var / run / nagios3
/etc/init.d/nagios3 restart