Configurando Zabbix SMS Script
Leandro Campos

Leandro Campos

Share on facebook
Share on twitter
Share on linkedin
Share on whatsapp
Share on pinterest
Share on reddit
Share on email

How configure Zabbix SMS API

In this article, I will teach you, with a step-by-step tutorial, how to set up an SMS sending script in Zabbix via the Nvoip API.

What is Zabbix?

Zabbix is one of the best known and most widely used open source tools in the world for monitoring networks, servers and services. It provides monitoring metrics, history and also allows you to perform actions on monitored services.

A monitoring tool is indispensable in the life of any team, IT professional or company that operates with technology as the foundation of their business. But keeping track of Zabbix charts day and night can be a daunting and almost impossible task for a human being, so Zabbix natively offers media types, which are channels where the user can be notified if any problems occur.

What media types can I use on Zabbix?

By default, you can set up an SMTP server and receive email if an incident happens. The problem is that if you don’t have your email open, you probably won’t see it in time to resolve the incident in the shortest possible time.

There is also a function of using a GSM gateway in Zabbix, but nowadays, many Zabbix servers are installed in the clouds, which would prevent the use of a GSM Gateway. Also, setting up a GSM gateway takes longer than setting up an SMS API.

Why use SMS on Zabbix?

SMS is an alert that will draw more attention than an email. You can be at a party or sleeping, which, when the SMS arrives, will ring or vibrate your phone, catching your eye.

What do I need to set up SMS sending in Zabbix?

In this tutorial you will need the following items to configure SMS Alert on Zabbix:

  • Zabbix Server (In this tutorial we use a CentOS 7 Linux Server running Zabbix 4.2).
  • Basic knowledge in Linux to access your server and enter the script.
  • Token Nvoip (If you don’t have a Nvoip account yet, create a free account and earn BRL5 in credits, click here)

Instructions

Knowledge: Basic

Estimated time: 10 minutes

Access our Zabbix repository on GitHub by clicking here to get the updated send_sms_nvoip_zabbix.sh script.

Let’s understand the script. The code is commented for ease.

The $1, $2, $3 and $4 variables will be passed by Zabbix, and the $1 variable must be the cell phone that will receive the SMS.

The script will be executed by Zabbix every time an incident is triggered, firing the data to our API.

Attention: You only need to change the token_auth variable with your Nvoip token.

#!/bin/bash

#Nvoip - SMS

#Copyright (C) 2020 Nvoip Plataforma Telefonia Ltda
#Leandro Campos <https://www.linkedin.com/in/leandro-campos/>
#License https://www.gnu.org/licenses/gpl-3.0.html

#This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by #the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

#This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.

#You should have received a copy of the GNU General Public License along with this program.  If not, see <https://www.gnu.org/licenses/>.

###Inicio do Script###
# Seu Token da Nvoip. Acesse https://www.nvoip.com.br, crie sua para ter acesso ao seu Token.
# English: Your Nvoip Token. Visit https://www.nvoip.com.br, create yours to have access to your Token.

token_auth="TOKEN NVOIP"

#$1, $2, $3 e $4 são os parâmetros, em ordem, que você define no seu Servidor Zabbix. O $1 é o número que irá receber a chamada. Você pode reduzir, alterar a ordem ou acrescentar mais parâmetros.
#English: $1, $2, $3 and $4 are parameters, in order, that you set in your Zabbix Server. $ 1 is the number that will receive the call. You can reduce, change the order or add more parameters.

curl --include 
     --request POST 
     --header "Content-Type: application/json" 
     --header "token_auth: $token_auth" 
     --data-binary "{
    "celular":"$1",
    "msg":"$2 $3 $4"
}" 
'https://api.nvoip.com.br/v1/sms'

Refer to the path of your Zabbix installation where scripts should be placed in the zabbix_server.conf file. This file is usually in /etc/zabbix/zabbix_server.conf.

Copy the send_sms_nvoip_zabbix.sh file into the script directory. (In our case, the script directory is /usr/lib/zabbix /alertscripts).

Set file permissions:

chown zabbix:zabbix send_sms_nvoip_zabbix.sh (Verifique qual usuário você usou no se Zabbix)
chmod 777 send_sms_nvoip_zabbix.sh

Go to your Zabbix and go to Administration> Media Types and click create media type. Use the information below:

Configuração Nova Mídia Envio SMS Zabbix pela Nvoip.
Name: SMS Nvoip
Type: Script
Script Name: send_sms_nvoip_zabbix.sh
Script parameters:
{ALERT.SENDTO}
{ALERT.SUBJECT}
{ALERT.MESSAGE}
{HOST.NAME1}
Enabled: Yes

Note: See the image that I marked the fields that are the variables that Zabbix sends to the SMS Send Script. With the exception of the $1 variable in the first field, you can send other variables, see your Zabbix version documentation for possible variables. Just remember the 160 character limit per SMS.

Go to Administration > Users and select the user who will receive SMS. Click on Media and then Add. Configure with the data below:

Configuração Mídia SMS Usuário Zabbix.
Type: SMS Nvoip
Send To: (Enter here the cell phone that will receive the SMS (Currently only Brazilian cell phones.) Format: DDD + Number. Example: 11911112222.
When Active: 1-7,00:00-24:00 (Or according to your preference)
Use if severity: Check the trigger severity options that will trigger SMS.
Enabled: Sim

Ready. To test you can go back to Administration> Media Types and fire or trigger an incident.

If you prefer, access the video of this tutorial on our Youtube Channel by clicking here or see below:

Liked? Share. Encourage us to put more content like this on our social networks.

Share on facebook
Facebook
Share on twitter
Twitter
Share on linkedin
LinkedIn
Share on whatsapp
WhatsApp
Share on email
Email