📜 ⬆️ ⬇️

Alerts from Nagios phone call

It still seems incredible that the server can call me in case of problems, but in reality the implementation was even simpler than I thought. I want to share my decision.

All actions are performed on Ubuntu, sipnet.ru is a sip-provider

Load and build pjsip :

wget http://www.pjsip.org/release/1.10/pjproject-1.10.tar.bz2 tar xfv pjproject-1.10.tar.bz2 cd pjproject-1.10 ./configure --disable-sound make dep make 

From all that I have gathered, only pjsua will be needed :
')
 sudo cp pjsip-apps/bin/pjsua-x86_64-unknown-linux-gnu /usr/bin/pjsua 

Create the / etc / pjsuarc file with the following content:

 --duration=1 #  ,      --null-audio # pjsua       --id sip:SIPID@sipnet.ru #  sipnet.ru --registrar sip:sipnet.ru --realm etc.tario.ru --username SIPID --password PASSWORD 

Now it's time to check the configuration and make a test call:

 pjsua --config-file=/etc/pjsuarc sip:+12345678901@sipnet.ru 

In the case of sipnet, if the Caller ID service is not included in the Premium Services section (I don’t know why premium, the service is free), or the same number that the call is made to, the number will be determined +74993462198 (at least for Russia ), it does not allow to identify what our server is calling.
Therefore, I did the following: I registered my second number in sipnet and indicated it as the displayed number. In the phone he saved it under the name of Nagios and set him a pleasant loud melody.

Next, change the permissions on / etc / pjsuarc, so that only root and nagios can see the password:

 sudo chmod 640 /etc/pjsuarc sudo chown root:nagios /etc/pjsuarc 

Add the following lines to /etc/nagios3/commands.cfg:

 # 'notify-host-by-sip' command definition define command{ command_name notify-host-by-sip command_line (sleep 120 && echo q) | /usr/bin/pjsua --config-file=/etc/pjsuarc sip:$CONTACTEMAIL$ } # 'notify-service-by-sip' command definition define command{ command_name notify-service-by-sip command_line (sleep 120 && echo q) | /usr/bin/pjsua --config-file=/etc/pjsuarc sip:$CONTACTEMAIL$ } 

Add the contact to /etc/nagios3/conf.d/contacts_nagios2.cfg:

 define contact{ contact_name user_sip alias useralias service_notification_period 24x7 host_notification_period 24x7 service_notification_options c host_notification_options d service_notification_commands notify-service-by-sip host_notification_commands notify-host-by-sip email +12345678901@sipnet.ru } 

Nagios will call at any time, but only in critical cases.

And do not forget to add a new contact in the same config to the desired group:

 define contactgroup{ contactgroup_name admins alias Nagios Administrators members root,user_email,user_sip } 

Just in case, we are convinced that in a critical case, the server really calls us, for example, by correcting the password for accessing MySQL to the wrong one in /etc/nagios3/conf.d/services_nagios2.cfg

Restart Nagios:

 sudo service nagios3 restart 

And waiting for a call.

If you wish, you can go ahead and add text-to-speech, but it turned out to be enough for me to call from a certain number to see that there was a problem, and you can find out the details by checking the mail.

Pjsu manual

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


All Articles