We fasten the SMS notification to cacti

To monitor servers, I use cacti with the thold plugin . The plugin is wonderful, it allows you to track both the availability of the entire server and the exit of any parameter beyond the specified limits. When an event occurs, an e-mail message 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 telephone screwed to the monitoring server. The most reliable and difficult way.
  3. Teach thold to send messages via SMS service.


I chose the third method. There are several reasons for this. Firstly, the monitoring server is “far” 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 for working with cacti . I must say right away that this method will not work for those who need 100% working capacity. It is clear that if the Internet connection is lost at the monitoring server, you will not receive any messages. But for those who are satisfied and 99% is a good method. So let's get started.

First, cacti and the thold module must be installed and configured . Configuring cacti is not the topic of this article, so we believe that everything is configured and working. Go to cacti settingsConsole-> Settings-> Thresholds and tick Send Alerts as Text , we don’t need HTML code in messages.
image
Next, you should 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 in the folder with the thold module , usually it is / usr / local / share / cacti / plugins / thold .

Next, edit the code for the file / usr / local / share / cacti / plugins / thold /thold_functions.php . We are looking for the string function thold_mail ($ to, $ from, $ subject, $ message, $ filename, $ headers = '') {
We need to add work with SMS to the code of this function. The code initially 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, $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, $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 by SMS. Only the subject of e-mail comes to SMS without the body of the letter. 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 the hands. But in the current version, everything works fine and allows you to quickly respond to emergency situations.

Also popular now: