Free sending SMS notifications to Zabbix

    Everyone realizes the need for continuous monitoring of a large distributed network and there are many monitoring systems for this. I’ll immediately notice that I work with a large provider and my, so to speak, shoulders are in control of the state of a large number of access nodes, which are often very far away from me.

    Now I am actively using the Zabbix 2.0 branch: I managed to fasten the constant control of ADSL subscriber line parameters on all access nodes, about 200,000 parameters. Descriptions of how this was done are enough for a separate article. I’ll tell you how to make a notification of any events via SMS in a simple and affordable way, and not use specific iron for this.

    I’ll tell you how to make a notification of any events via SMS in a simple and affordable way, and not use specific iron for this.

    Alert option using the free features of email2sms sms.ru service


    UPD: In connection with the change of the corporate telecom operator, the email2sms method from the beeline is no longer acceptable to me. I found a rather interesting offer in the form of the sms.ru web service . What attracted me to it? Firstly, when registering as a programmer, we get the following buns:

    • Advanced API - you can send messages, check their status, find out the cost, check the balance through simple HTTP requests.
    • Ability to replace the sender - as the sender, the Latin name of your site or company can be used
    • Messages to your own number
    • Free up to 60 SMS per day, then paid at standard rates
    • SMS to your number is free only if the text fits into 1 SMS message
    • e-mail2sms


    Registration is simple, confirmation will be sent to the phone in the form of SMS. I registered as a programmer.
    Actually, in order not to go beyond the limits of free SMS, it is enough to observe the following conditions

    1. No more than 10 SMS to numbers different from the one used at registration. The limit, cost, status of the message can be checked with simple requests.
    2. No more than 160 characters in Latin letters in SMS.
    3. No more than 60 SMS to your number


    By default, the sender will be your number specified during registration, it seemed to me not beautiful and I sent an application to the sender zabbix from the control panel, the application was not considered for a long time, maybe 2 hours and I began to receive messages from the sender zabbix.

    Email2sms setup


    Select the menu item Applications - Mail @ sms.ru. Something similar to this will open:


    Click edit and see the following picture: I


    ’ll go through the points
    1. The first is your address of the form xxx @ sms.ru to which you need to send notification letters
    2. Uncheck
    3. Uncheck (I don’t need the name of the action)
    4. Put a tick
    5. We put a tick otherwise SMS will be paid
    6. We choose from which sender the message will come (I already have the name zabbix)
    7. Put a tick
    8. Then we can enter additional phone numbers where SMS will be duplicated. those. By sending a letter to one SMS box, several clients with different phones can receive at once.
    9. Enter the addresses of the boxes from which letters will go to the email2sms box. If you leave the field blank, then the letters will be paid.


    Click save and it should turn out like this The


    setup on the sms.ru service is finished.

    There are two ways to send messages.
    • Using smtp service server
    • Using your mail server


    Configure zabbix using smtp service server


    Create a notification method for the first method. Administration - Alert methods .

    As the outgoing email we indicate our emai2sms which was issued by sms.ru

    Now you need to assign a notification method to the user. Administration - Users We select the user and select the alert tab. Next add.




    If necessary, adjust the levels and time for the notification.

    Configure zabbix using your mail server


    For the second method, using our mail server that requires authorization, we will make another notification method of the "script" type.


    The script is in AlertScriptsPath (specified in the zabbix configuration files). In my case, this is / usr / local / share / zabbix / alertscripts /
    The script itself

    #!/bin/bash
    export smtpemailfrom=ss@cbx.ru
    export zabbixemailto=$1
    export zabbixsubject=$2
    export zabbixbody=$3
    export smtpserver=хххх.хххx.ru
    export smtplogin=ххххх@ххххх.ru
    export smtppass=password
    /usr/bin/sendEmail -f $smtpemailfrom -t $zabbixemailto -u $zabbixsubject -m "$zabbixbody" -s $smtpserver:25 -xu $smtplogin -xp $smtppass -o message-format=raw
    


    Do not forget to give 755 permissions to the zabbix_sendemai file .

    Now you need to assign a notification method to the user. Administration - Users Select user and select alert tab. Next add


    Create a zabbix action sending an alert via sms


    Set the action on the trigger that has worked. For example, I took the trigger for the drop in the port fa 0/5 of the d-link switch. Go to Settings - Actions - Create an action (event source - trigger)

    On the action tab, set it up so


    on the condition tab set the trigger to the condition value problem


    On the operation tab, make the operation type send a message add the user and select the send_email or email type from the user sms.ru in "send only" and do not forget to click the update button and then save .


    If you do everything, a new action will appear.


    Check sending sms


    Put the port handles on the long. When viewing an event, you can see a successful reaction to the event: text, sending address, sending time.


    Photo of the screen of the phone to which sms arrived with a delay of less than a minute.



    Old solutions email2sms


    The solution comes out completely free when using Beeline mobile phones. (I have not studied other operators, but I will be glad if you tell me).
    There is a site beonline.ru where you can learn how to enable receiving emails from e-mail in the form of SMS messages. This is done either by calling the toll free number 06849909 or by sending the following command to number 784: SIM ON-POSTCHANASMS YES .
    The response will be SMS SIM> ON-POSTCHANASMS YES (your phone has a mailing address: 79031234567@sms.beemail.ru). <p> - in more detail.

    We remember this address, although what is there to remember?

    All probably guessed that it was necessary to configure notifications by e-mail to the address received above, but not so simple. Zabbix does not allow standard means to send e-mail notifications if the smtp server requires authentication.
    There is a way out - using scripts that can be found on the Zabbix forum . I used the option with sendEmail .

    Create a zabbix_sendemail script with 755 permissions

    #!/bin/sh
    export smtpemailfrom=zabbix@yourdomain.com
    export zabbixemailto=$1
    export zabbixsubject=$2
    export zabbixbody=$3
    export smtpserver=yoursmtpserver.com
    export smtplogin=smtpuser
    export smtppass=smtppassword
    /usr/bin/sendEmail -f $smtpemailfrom -t $zabbixemailto -u $zabbixsubject -m $zabbixbody -s $smtpserver:25 -xu $smtplogin -xp $smtppass
    


    Substituting the necessary data and save it in the directory that is specified as AlertScriptsPath in the configuration file /etc/zabbix/zabbix_server.conf
    ### Option: AlertScriptsPath
    #       Location of custom alert scripts
    #                                       
    # Mandatory: no                         
    # Default:                              
    AlertScriptsPath=/home/zabbix/bin/
    


    The next step is to create a new Media Type in the Administration - Media Types menu .
    In the description we write for example send email
    type select the script
    Name of the script write zabbix_sendemail
    Save.

    We set the transmission medium for the user to whom we will send SMS. This is done in the Administration - Users menu . Select the desired user, click add transfer medium .
    Type - select send email
    Send - enter the received e-mail from Beeline
    Further at will (you can better leave it by default).

    Now you need to create an action on the trigger that will send us an SMS.
    This is done in the Settings - Action menu .

    Create an effect on the inaccessibility of iron. SMS

    name Event Trigger Default theme {TRIGGER.NAME}: {STATUS} (it doesn’t really matter since SMS will come without a theme) Default message {HOSTNAME} unreachable {STATUS} We set the recovery message if necessary, and fill it out with analogies with the above written Next, select the conditions of action






    I did so, you can write the conditions that you need.
    Calculation type (A) and (B) and and (D) and (E)
    (A) Host group = “especially important”
    (B) Trigger description contains “not available”
    Trigger importance = “Emergency”
    (D) Trigger value = “PROBLEM”
    (E) The time period in “1-7.08: 00-23: 59”


    When all conditions are met, a message is sent.

    We configure the operation for the action.
    Operation type Send message
    Send message Single user
    Only send send email
    The default message is kryzhik.
    Save.

    The message will come if there is a triggered trigger containing in the description “unavailable” in the group of network nodes “especially important” and on all days of the week from 8 a.m. to 12 p.m.
    And so we got a notification system via SMS without using any complex or paid solutions.

    UPD Second article “Automatic renaming of hosts in Zabbix, according to snmp sysName”

    Also popular now: