Realize Zabbix voice alarm at zero cost

1. Scenario simulation
Company A, a well-known large domestic securities company, found that Zabbix can only generate corresponding sound notifications according to the alarm level when using the open source Zabbix monitoring platform, but cannot broadcast the alarm information by voice. To this end, Xiaodong, an operation and maintenance colleague, volunteered to create a set of "the simplest Zabbix voice alarm at zero cost" solution for the company, realizing the alarm docking with Zabbix, saving the company 10W+ in operation and maintenance costs.

2. Implementation principle
1. Software and hardware preparation

1) A computer with Windows operating system with sound, as a tool for displaying Zabbix system alarms on a large screen

2) A zabbix_agent installation package

3) A bat script (call the voice assistant built-in tool that comes with the window system)

4) Bat_To_Exe_Converter.exe. A tool to convert bat scripts to exe. This tool is mainly to solve the problem that there will be pop-up windows when the bat script is called (even if there are commands on the Internet that can put the bat script in the background for execution, but the window will flash for a moment when calling the bat, so you need to use this software to put the script into Background process)

2. Implementation principle

1) Voice play bat, read the alarm title pushed by zabbix_server, call the voice assistant built in the system, and then the bat parameter receives a parameter for the alarm title transmitted when zabbix_server generates an alarm.

2) Add the voice alarm playback bat script to the scheduled task of the window. Note: Some commands of the key value of zabbix_agent cannot be called. In this case, you can consider adding the script to the scheduled task, and then the agent defines the key value to call the corresponding scheduled task. The specific reason may be caused by some security restrictions of the window operating system, and some operations may be intercepted as viruses

3) Install zabbix_agent. Customize a key-value command to call the scheduled task of window's voice alarm playback to play the received alarm voice.

4) Configure the alarm action. When the zabbix_server generates an alarm, the command to execute the client is specifically, zabbix_get -s client's ip -k 'key value of voice alarm'. In this way, after the alarm is generated, the scheduled task of the window that displays the alarm on the large screen can be called, and then the scheduled task will play the received alarm title voice.

Note: Generally, it is enough to pass the alarm title parameter, and many alarm titles can determine the specific alarm, which is concise and clear

3. Experimental process
1. Prepare the bat script (33.bat is the voice playback bat script).
The script content is as follows:
insert image description here
@echo off

for /f %%i in (‘type “G:\alert_mess.txt”‘) do (

set “alert_mess=%%i”

)

Script description: The above command is required. G:\alert_mess.txt is a file that temporarily stores the title of the alarm after each alarm is generated. The specific path can be customized. The reason why this file exists is that it cannot be transferred when the scheduled task is called by cmd. Input parameters, so for flexible calls. When zabbix generates an alarm in the future, it will do two operations. The first is to store the alarm title in the G:\alert_mess.txt directory, and then call the bat script above to get the alarm title in the text, play the voice, and play After finishing, clear the content of alert_mess.txt, and wait for the new content of the next alarm.

mshta vbscript:createobject(“sapi.spvoice”).speak(%alert_mess%)(window.close)

Script description: The above command calls the voice assistant that comes with the window for voice broadcast. The content of alert_mess is the content of the alarm title, what is the received alarm title, and what will be played in the voice broadcast

2. Convert the above bat script into an exe tool
and open the software.
insert image description here
Note: If the above conversion is unsuccessful, it may be intercepted by the system or anti-virus software. You can temporarily close it for conversion.
insert image description here
3. Add
the shortcut key of the scheduled task, win+r, enter taskschd.msc opens the scheduled task
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
4, configures custom key values ​​for the agent, and enables remote call parameters
insert image description here
Enable remote call parameters for the agent. If the Agent version is 3.X or 4.X, the command to enable remote configuration parameters is EnbaleRemoteCommands=1. When this parameter is turned on, it is used to receive the alarm title generated by Zabbix.
insert image description here
5. Configure Zabbix alarm actions and scripts
Note that the environment I configured below is based on Zabbix6.0, and there may be differences in the configuration of Zabbix3-5 versions.
insert image description here
Add the following command

/itops/zabbix/bin/zabbix_get -s 192.168.74.1 -k 'system.run[echo "[Generate alert] {TRIGGER.NAME} of {HOST.IP}">G:\alert_mess.txt]'

Note: The path of this file should be consistent with the path of the file read by 33.exe

/itops/zabbix/bin/zabbix_get -s 192.168.74.1 -k ‘run’

Note: This key value should be consistent with the custom key value
insert image description here
. Adding a recovery alarm is mainly to distinguish whether the alarm is generated or restored when the voice alarm is issued.

Generate an alarm
insert image description here
Resume an alarm
insert image description here
insert image description here
insert image description here
4. Verification results
insert image description here
You can view the effect of voice playback and video through the link below, and the voice playback is about 37-44s. Others are triggers that have not been updated

Link: https://pan.baidu.com/s/1gd87dc02XtrfdUuW8KzyHw

Extraction code: 26pt

V. Supplement
The above script can adjust the speech rate and volume, and can also replace the voice package by itself.

The above is the knowledge sharing of Zabbix operation and maintenance in this issue. Hello everyone, I am Lele, focusing on the research and sharing of operation and maintenance technology, follow me to learn Zabbix and other usage skills, and for more operation and maintenance questions, you can also leave a message in the Lewei community https://forum.lwops.cn/ to ask questions~

Guess you like

Origin blog.csdn.net/weixin_43631631/article/details/132103890