Package: zmpe
zabbix-monitoring-programs-executionThe program controls the execution of any programs, scripts or commands OS and sends the execution result to zabbix, and in case of an execution error, it additionally can notify via telegram.NOTE: Any programs, scripts or commands OS that is controlled by zm.py in the future, I will call - process.Work logicLogging is done in stdout.All zm.py settings are performed through environment variables.Telegram notifications can be turned off withZM_TELEGRAM_NOTIF=False. In this case, you will only receive alerts from Zabbix in which you can also set up Telegram alerts, but zm.py has more informative alerts.Send data to can be turned off with ZabbixZM_ZABBIX_SEND=False. In this case, you will only receive alerts to Telegram.
Send process time execution to can be turned off with ZabbixZM_ZABBIX_SEND_TIME=False.
Only error messages are sent to Telegram. Messages about the successful completion of the process are not sent to Telegram (so that there is no flood).In case of successful completion of the process, the process execution time and the successful result are sent to Zabbix. The value of successful result is set to ZM_ZABBIX_OK.In case of the process execution error, execution time = 0 and the unsuccessful result are sent to Zabbix. The value of unsuccessful result is set to ZM_ZABBIX_NOT_OK.
You can run zm.py in a Docker container.SettingsENVDefaultDescriptionZM_DEBUGFalseEnable DEBUG mode? (True or False).HOSTNAMEUnknownFor Telegram message to see which host this message is from. In Linux, such a variable is usually already set.Zabbix settingsZM_ZABBIX_SENDTrueShould app send data to Zabbix? (True or False).ZM_ZABBIX_SEND_TIMETrueShould app send execution time to Zabbix? (True or False).ZM_ZABBIX_OK0OK value for Zabbix.ZM_ZABBIX_NOT_OK1Not OK value for Zabbix.ZM_ZABBIX_IPNoneZabbix server ip address.ZM_ZABBIX_HOST_NAMENoneZabbix "Host name". How is the host named in Zabbix. (See picture after table).ZM_ZABBIX_ITEM_NAMENoneHow is the trapped item key named in Zabbix.ZM_ZABBIX_ITEM_TIME_NAMENoneHow is the trapped item for execution time key named in Zabbix.Telegram settingsZM_TELEGRAM_NOTIFTrueShould app send telegram alerts? or log messages only to stdout. (True or False).ZM_TELEGRAM_TIMEOUT10Telegram connection timeout.ZM_TELEGRAM_BOT_TOKENNoneTelegram bot token. It usually looks like this1470616475:AAHFSvznxxLTDedQBSiRVrYVP49ixkghpRT. You need to create a bot in Telegram usingBotFatherand you can also get a bot token there.ZM_TELEGRAM_CHATNoneTelegram chat (ID) to which the bot will send messages. If this is a private chat, then usually the ID looks like a positive number. If it is a channel or group then ID is a negative number.NOTE: ParameterZM_ZABBIX_HOST_NAMEyou can see hereInstall and runInstall Python3Python DownloadCustomize ZabbixIn this example,ZM_ZABBIX_ITEM_NAMEwill be calleddocker-rmi-shandZM_ZABBIX_ITEM_TIME_NAME-docker-rmi-sh-time. This name will be written in theKeyfield.Create trapped itemsZM_ZABBIX_ITEM_NAMEand if you needZM_ZABBIX_ITEM_TIME_NAME.Create trigger forZM_ZABBIX_ITEM_NAMEwith that Expression:{172.26.12.168:docker-rmi-sh.last()}=1 or {172.26.12.168:docker-rmi-sh.nodata(25h)}<>0The trigger fires when there was an error while executing the process or when the process has not run for more than 25 hours.You can see Graphs for items: menuMonitoring-Latest data-Filter.Hostschoose desired host - there isGraphin the item line.Or you cat create your own graphs.SettingsYou must set environment variables on the computer where the zm.py will run and under the account under which zm.py will run.There are many ways to define environment variables.RunIn this example, I write all the necessary variables in file.bash_profile.export ZM_ZABBIX_IP="172.26.12.86"
export ZM_ZABBIX_HOST_NAME="172.26.12.168"
export ZM_ZABBIX_ITEM_NAME="docker-rmi-sh"
export ZM_ZABBIX_ITEM_TIME_NAME="docker-rmi-sh-time"
export ZM_TELEGRAM_BOT_TOKEN="1470616475:AAHFSvznxxLTDedQBSiRVrYVP49ixkghpRT"
export ZM_TELEGRAM_CHAT="123456789"1) As scriptmkdir /usr/share/zabbix-monitoring-programs-execution
cd /usr/share/zabbix-monitoring-programs-execution
git clone https://github.com/MinistrBob/zabbix-monitoring-programs-execution.git .
pip3 install -r requirements.txt
python3 /usr/share/zabbix-monitoring-programs-execution/zm.py <process>2) As cronjob (or if you use sudo -s or su)If you use cronjob or if you use sudo -s or su you will needsourcecommandMAILTO=""
0 3 * * * source /home/user/.bash_profile; python3 /usr/share/zabbix-monitoring-programs-execution/zm.py /usr/share/local/docker-rmi.sh 2>&1For developersGet and install requirements (requirements.txt)c:\MyGit\zabbix-monitoring-programs-execution\venv\Scripts\pip.exe freeze | Out-File -Encoding UTF8 c:\MyGit\zabbix-monitoring-programs-execution\requirements.txtpip install -r c:\MyGit\zabbix-monitoring-programs-execution\requirements.txtPublish the package on pypi.orgpython setup.py sdist
twine upload dist/*TelegramsendMessagehttps://api.telegram.org/bot{token}/sendMessageExample message (html):MESSAGE: вќЊ Test<b>bold</b>,<strong>bold</strong><i>italic</i>,<em>italic</em><ahref="URL">inline URL</a><code>inline fixed-width code</code><pre>pre-formatted fixed-width code block</pre>