S
S
Sergey_A_R2016-04-26 11:24:10
linux
Sergey_A_R, 2016-04-26 11:24:10

Why doesn't Zabbix 3.0 pass parameters $1,$2,$3 to the script?

There is Zabbix 3.0 on Ubuntu 14.04. Got an API from SMS.RU to send SMS.
Created a script in /usr/local/share/zabbix/alertscripts. Here is the content of the script:

#!/bin/bash
# SMS.RU sender for zabbix
api="133C1FB3-8D01-DD1C-90BA-********"
to="$1"
subject="$2"
body="$3"
curl -d "text=$body" http://sms.ru/sms/send\?api_id=$api\&to=$to

Added execution rights to the script (chmod +x /usr/local/share/zabbix/alertscripts/zabbix-sms).
In zabbix itself, I set up all the alerts and added the {ALERT.SENDTO}, {ALERT.SUBJECT}, {ALERT.MESSAGE} parameters to my script. When the trigger fires, Zabbix reports that the notification has been sent, but nothing comes up.
When executing the script from the console, it gives 203 alert - no message text. Replacing the values ​​of $1, $2, $3 with their own (I wrote hello in the body of the letter), SMS began to arrive. How would I do it now, so that I would receive trigger values, and not hello ))
I ask for your help, because I have little experience with the work of Zabbix, as well as with programming.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
S
Sergey_A_R, 2016-04-26
@Sergey_A_R

8ec1b262c16f4fbdbf7388f20bcec7d0.JPG9a697a62b902406f83ef9fe3b0392bff.JPG
Problem solved! The problem was that I ran the script from under the bash and, accordingly, it did not receive parameters from Zabbix (because I used the bash standard input / output stream). For performance, it was necessary to initiate the execution of the script by Zabbix or add variables when executing the script in the bash. For Zabbix 3.0 it was easy to add {ALERT.SENDTO}, {ALERT.SUBJECT}, {ALERT.MESSAGE} values ​​in Media Types to your script.

V
Vladimir Kuts, 2016-04-26
@fox_12

And why did you put the parameters in quotation marks?
to="$1" => to=$1

N
Nicholas, 2016-05-05
@VR4

Maybe someone will need my version of the script for sending through the site sms.ru

#!/bin/bash
# SMS.RU
#Задаём переменные
api="Тут должен быть API"
phone="$1"
text="$2"
body="$3"
LOG="/var/log/zabbix/SMS.log"

# Делаем запись даты в лог
echo >> $LOG
echo -e "                             \e[1;32m --=START=--\e[m" >> $LOG
echo >> $LOG
echo -e "                   \e[1;33m -=`date`=-\e[0m" >> $LOG
echo >> $LOG
#Записываем в лог, что передаёт ZABBIX в скрипт.
echo " Заголовок сообщения" >> $LOG
echo -e "\e[1;36m $body\e[0m" >> $LOG
echo " Текст сообщения" >> $LOG
echo -e "\e[1;36m $text\e[0m" >> $LOG
echo " Телефон получателя" >> $LOG
echo -e "\e[1;36m $phone\e[0m" >> $LOG
echo >> $LOG
#Посылаем СМС
curl -d "text=$body" http://sms.ru/sms/send\?api_id=$api\&to=$phone >> $LOG
echo -e "\e[1;34m <-ответ от СМС шлюза\e[0m" >> $LOG
echo >> $LOG
echo -e "                             \e[1;31m --=FINISH=--\e[m" >> $LOG
echo"===================================================================================================================" >> $LOG
#Смотреть логи в цветном виде можно командой вида : tail -n 19  *Путь к файлу*.log

The response from the server is also written to the Log, which will help to diagnose malfunctions faster
. Here is an example of a log output
44c828ca4e404a07b6bd9f8cee09f356.JPG

T
Tan Chatn, 2016-04-26
@DUKAEV

Use ${1} instead of $1

K
ky0, 2016-04-27
@ky0

In the server config, does the path to the directory with the alert scripts exactly match your /usr/local/share/zabbix/alertscripts?
Well, this ... try to remove the extra quotes, yes. Or use single ones in curl.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question