Nagios: SMS notification

    Nagios: notification via SMS

    Due to the increase in the number of servers, it became necessary to monitor them with the ability to alert when problems arise. The choice fell on Nagios, since a couple of years ago, working in the telecom operator company, he worked with him.
    One of the conditions was the ability to alert via SMS messages.
    So, what do we have and how to make it all work together:
    - Linux (Debian 5) server with Nagios installed (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 necessary hosts.

    Next, we configure the system for working with a mobile phone. I will describe this step as I implemented, since there are many ways to do this :)
    First, install the gammu
    apt-get install gammu program.
    The next step is to configure gammu to work with a mobile phone. You can use the
    gammu-config utility for this .
    After configuring gammu, the .gammurc file should appear in the home directory with the following contents:
    ~ # cat ~ / .gammurc
    [gammu]
    port = / dev / ttyACM0
    connection = at115200
    name = Nokia 3110c
    model = nauto

    In order to check the operation, we will use the following commands:
    ~ # echo "test msg" | gammu sendsms TEXT + your_phone_number
    so we send an SMS with the text "test msg" to the phone "+ your_phone_number" - it is better to indicate the phone number in international format.

    if SMS has arrived, then we read on, otherwise, we return to the gammu setup (I think by googling on this topic, you can find a bunch of documentation).

    The next step is to configure Nagios to send SMS.

    We look at the file / etc / passwd to find out where the home directory for the nagios user is located (in my case: / var / run / nagios3). We copy the .gammurc file there and change the permissions for the nagios user:
    ~ # chown nagios: ./.gammurc
    Next, I had to change the permissions on the / usr / bin / gammu file - assign the UID on execution, 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 commands.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 go on to configure the file with contacts (in my case contacts_nagios2.cfg in the directory /etc/nagios3/conf.d).
    We need to add the address1 parameter, in which we indicate the mobile number in the international format, as well as add commands for notifications when changing the status of services or hosts.
    Here's how I had it 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 what happened 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, we restart Nagios and begin to enjoy the incoming messages :)
    Although it is better when there are fewer :)

    PS: please do not kick much, because this is my first post :) if you have questions, ask, I will try to answer :)

    UPD: I noticed one more nuance, at least for me. Since for the nagios user the home directory is specified in / var / run / nagio3, after rebooting the .gammurc file disappears from there. I decided simply, in /etc/rc.local I registered it to copy this file to the / var / run / nagios3 directory and change the owner to nagios, after which restart the service:

    / bin / cp /root/.gammurc / var / run / nagios3
    / bin / chown -R nagios: / var / run / nagios3
    /etc/init.d/nagios3 restart

    Also popular now: