📜 ⬆️ ⬇️

Zabbix. Sending a trigger with a comment

Greetings
I decided to share a small scratch (slightly modified original) by sending notifications in Zabbix with user comments.
The essence of the problem: at work, Zabbix is ​​used mainly for monitoring remote networks (availability, some quality). In the absence of communication with the remote network, we must notify certain departments of this by job descriptions. It was not difficult to set up a regular mail dispatch, but with such dispatch, the departments lacked clarity - for what reason the “network” was disconnected, how long it would not be. Therefore, I set out to insert a comment in the dashboard that was sent to the dashboard when the trigger was confirmed.
In essence, this is the same script that lies in the official Zabbix documentation with one small insert:

#! /bin/bash to=$1 #  subject=$2 #  body=$3 #  status="$(echo $body | cut -d\; -f3)" # ,   if text0='   ,  : ' text1='   30 .' text2=':' text3=':' text4=':' text5='    :' text6='        : ' text7='Original event ID:' text8='  :' text9='    :' ack=`echo "select message FROM acknowledges WHERE eventid='$(echo $body | cut -d\; -f1)'" | mysql -uuser -ppassword -Dzabbix` #     if [[ $status = "PROBLEM" ]]; then #if- ,               cat <<EOF | mail -s "$subject" "$to" $text0 $(echo $body | cut -d\; -f2) $text1 $text2 $(echo $body | cut -d\; -f3) $text3 $(echo $body | cut -d\; -f4) $text4 $text5 $(echo $body | cut -d\; -f5) $(echo $body | cut -d\; -f6) $text6 $text8 $ack $text7 $(echo $body | cut -d\; -f1) EOF else cat <<EOF | mail -s "$subject" "$to" $text0 $(echo $body | cut -d\; -f2) $text1 $text2 $(echo $body | cut -d\; -f3) $text3 $(echo $body | cut -d\; -f4) $text4 $text9 $(echo $body | cut -d\; -f5) $(echo $body | cut -d\; -f6) $text6 $text8 $ack $text7 $(echo $body | cut -d\; -f1) EOF fi 


Now about setting up actions:




In my case, sending a message occurs 30 minutes later, after a trigger occurs, due to the fact that it takes time to clarify information about the causes of network unavailability and its elimination. After 30 minutes, if the problem is not resolved, users who are in the notification group will be notified.
')
Script flaws:
1) The script does not understand multi-line comments. In this case, it sends the text in an attachment. Who knows how to fix - share the thought.
2) Since I can say the only one who interacts with the zabbiks front end — I did not insert the author of the comment. But it is in principle feasible:
 userid=`echo "select userid FROM acknowledges WHERE eventid='$(echo $body | cut -d\; -f1)'" | mysql -uuser -ppassword -Dzabbix` user=`echo "select alias [   name  surname -     ] FROM users WHERE userid=$userid" | mysql -uuser -ppassword -Dzabbix` 

3) Made through standard mail, you can redo it through mutt to add html and make everything beautiful.

Now about the features. The location of the host is taken from “Inventory data” - “Location”
Separator - ";"
Text written in action:
{EVENT.ID}; {INVENTORY.LOCATION1}; {TRIGGER.STATUS}; {TRIGGER.SEVERITY}; {EVENT.DATE}; {EVENT.TIME}


In principle, you can change anything, the main thing is to find the corresponding macro, which can be viewed here.

I understand that this is too small a fix, but maybe someone will come in handy.

UPD: Here on the forum, a week later it was suggested that I invented the bicycle, and it was enough to add {EVENT.ACK.HISTORY} to the standard output method.

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


All Articles