today, because of the need for work, it is not possible to use Zabbix's own functionality to detect network availability on an offer machine (Windows system) that is connected to the Web. So start by thinking about using the Python script to tune the system's ping command to detect
You can then use Zabbix to monitor and complete the task.
Online check, found that using subprocess and Shlex can complete the detection, and then refer to the entire small script
#!/usr/bin/env python#-*-coding:utf-8-*-#author: qingmiaoimport subprocessimport shlexcmd = "Ping-n 1 127.0.0.1" args = Shlex.split (cmd) try:subprocess.check_call (args, stdout=subprocess. PIPE, Stderr=subprocess. PIPE) print "1" except subprocess. Calledprocesserror:print "0"
After execution as shown, the detection returns 1 successfully, otherwise 0
Later found that this method did not land into documents, not easy to track. Tried a lot of ways, and finally found that the use of Windows comes with the bat script can be easily implemented, pleasantly surprised!
Redirect execution results to a timestamp-named file that is split in time to facilitate tracking results.
@echo offset Thisdate=%date:~0,4%%date:~5,2%%date:~8,2%set Ip=10.10.83.131echo%time:~0,8% >>D:\test\ping_ Result_%thisdate%.txt (Ping%ip%-N 1 | find "TTL" >>d:\test\ping_result_%thisdate%.txt) && echo 1 | | Echo 0
The execution results are as follows, and you can also use Zabbix to invoke the script
BINGO
Using Python and the batch bat script ping to detect host connectivity