📜 ⬆️ ⬇️

Nagios: SMS Notification without Google Calendar

I read the topic of the SMS-notification from Nagios with little blood and wondered why the author calls it “little” blood ...
I want to tell you about my method of notification using SMS, at which the time of receiving the message is at least less and, at most, the ubiquitous Google does not recognize your mobile phone number .

Theory


All the recommendations below are based on the assumption that you can activate such a service of mobile operators as email-to-SMS / SMS-to-email. The service works as follows: you send an e-mail to a special e-mail address that the mobile operator issues to you, and receive a message in the form of an SMS to your mobile phone.

In Belarus, such services have
Mts
Velcom .
life :) still has this service

In Russia
MTS has: http://www.mts.ru/services/internet/e-mail/ , the service is called a little wrong, but it allows you to receive mail from rambler.ru and mail.ru.
They also have the E-mail to SMS service, but it all depends on the region.
I did not find such a service on Beeline’s website, but people who know have suggested how to turn it on (see below).
')
I don’t know anything about Ukrainian telecoms at all.

Beeline


We activate the service "SMS to email": dial the number 06849909, wait for SMS about the result of connecting a new service.
Turn on the gluing of long messages: dial 06849908.
As a result, in the first SMS we will receive an email from which all emails will be broadcast as SMS.
Beeline does not take money for anything.

Important!
In Beeline, when sending a message to such an email, the message text is sent before the first character of the line feed, so we delete all \ n from command_line command directives (see below).

Customization


So, you activated the service, the operator took the money from you, you sent a test letter to the specified email and made sure that “everything works”. Next, as usual, the configuration process begins.

Add a new command to the Nagios configuration to send notifications via SMS, let's call it notify-by-epager:

 define command {
         command_name notify-by-epager
         command_line / usr / bin / printf "% b" "\ n \ nType: $ NOTIFICATIONTYPE $ \ n $ SERVICEOUTPUT $ \ nTime: $ SHORTDATETIME $" |  / bin / mail -s "$ HOSTALIAS $ / $ SERVICEDESC $" $ CONTACTPAGER $
 }


In fact, this is the same notification command as by e-mail with the only difference being that the amount of information transmitted is reduced (SMS can be only 76 characters) and the $ CONTACTPAGER $ macro is used as the recipient, and not $ CONTACTEMAIL $ ( more about macros in Nagios ).

Next, create a contact to which we will send SMS:
 define contact {
         contact_name <USER_NAME>
         alias <USER_ALIAS>
         contactgroups <CONTACT_GROUPS>
         host_notification_period <HOST_NOTIFICATION_PERIODS>
         service_notification_period <SERVICE_NOTIFICATION_PERIODS>
         host_notification_options <HOST_NOTOFICATIONS_OPTIONS>
         service_notification_options <SERVICE_NOTOFICATIONS_OPTIONS>
         host_notification_commands host-notify-by-email, host-notify-by-epager
         service_notification_commands notify-by-email, notify-by-epager
         email <USER_EMAIL>
         pager <PAGER_EMAIL>
 }


In order for a contact to add an alert via SMS, add the line to it:
         pager <PAGER_EMAIL>


and in the service_notification_options and host_notification_options options add a comma separated notify-by-epager (see example).

Well, that's all, theoretically, you can now restart Nagios and try to “break” something, you should receive an SMS message describing the problem.

Source: https://habr.com/ru/post/96249/


All Articles