📜 ⬆️ ⬇️

We fasten SMS to cacti

For monitoring servers, I use cacti with thold plugin. The plugin is wonderful, it allows you to monitor both the availability of the entire server and the output of any parameter outside the specified limits. When an event occurs, an e-mail is sent. But I want to receive not only e-mail, but also sms messages. There are several ways to do this:
  1. e-mail2sms gateway provided by the mobile operator. The method is not very reliable and not all operators have this service.
  2. Use an iron phone bolted to the monitoring server. The most reliable and sophisticated way.
  3. Teach thold to send messages via SMS service.


I chose the third method. There are several reasons for this. First, the monitoring server is “far away” and there is no physical ability to connect a hardware phone. Secondly, one of the areas of my business is SMS service. Therefore, it is interesting to expand the service and to work with cacti . I must say that this method is not suitable for those who need 100% performance. It is clear that if the monitoring server lost access to the Internet, then you will not receive any messages. But for those who are satisfied and 99% is a good method. So let's get started.

First, we need to install and configure the cacti itself and the thold module. Configuring cacti is not the topic of this article, so we believe that everything is set up and working. Go to the settings of cacti Console-> Settings-> Thresholds and put the checkmark Send Alerts as Text , we do not need the HTML code in the messages.
image
Next you must have a working account on the SMS service vesms.ru . If not, register. After downloading the PHP class to work with the service. Unpack and put the VESMS.class.php file into the folder with the thold module, usually / usr / local / share / cacti / plugins / thold .

Next, edit the code of the file / usr / local / share / cacti / plugins / thold /thold_functions.php . Looking for the line function thold_mail ($ to, $ from, $ subject, $ message, $ filename, $ headers = '') {
We need to add to the code of this function work with SMS. Initially, the code looks like this.
... function thold_mail($to, $from, $subject, $message, $filename, $headers = '') { global $config; thold_debug('Preparing to send email'); include_once($config['base_path'] . '/plugins/settings/include/mailer.php'); include_once($config['base_path'] . '/plugins/thold/setup.php'); $subject = trim($subject); $message = str_replace('<SUBJECT>', $subject, $message); ... 

Change to
 ... function thold_mail($to, $from, $subject, $message, $filename, $headers = '') { global $config; thold_debug('Preparing to send email'); include_once($config['base_path'] . '/plugins/settings/include/mailer.php'); include_once($config['base_path'] . '/plugins/thold/setup.php'); require_once($config['base_path'] . '/plugins/thold/VESMS.class.php'); $subject = trim($subject); $message = str_replace('<SUBJECT>', $subject, $message); $user = 'USERNAME'; //API       (    ) $key = 'APIKEY'; //API ,    http://client.vesms.ru/settings/api $sms = new VESMS($user, $key); $recipients='NUMBER'; //     $sender='cacti'; //  ,    ,             $sms->messageSend($recipients, $subject, $sender); ... 

')
That's all. In this configuration, all e-mail messages will be duplicated SMS. Only the subject of an e-mail without the body of the letter comes to sms. This is more than enough, all the necessary information is contained there.
Ideally, of course, I want a separate module for SMS with more flexible settings. Maybe this will reach hands. But in the current version, everything works fine and allows you to quickly respond to abnormal situations.

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


All Articles