The first is to write a script that outputs the TCP port that the current Windows machine listens on
check_port.py
#!/usr/bin/python
__author__ = ' Yan '
Import OS
Import JSON
data = {}
Tcp_list = []
Port_list = []
Command = ' netstat-ano-p tcp| Find "Listening" '
lines = Os.popen (command). ReadLines ()
For line in lines:
Port = Line.split () [1].split (': ') [1]
Port_list.append (Port)
For port in list (set (Port_list)):
Port_dict = {}
port_dict[' {#TCP_PORT} '] = PORT
Tcp_list.append (port_dict)
data[' data '] = Tcp_list
JSONSTR = json.dumps (data, sort_keys=true, indent=4)
Print Jsonstr
This script is currently only used under Windows, Linux need to use, you can write their own, as long as the results of the script output the following format is OK. The results of this script run are as follows:
{
"Data": [
{
' {#TCP_PORT} ': ' 1025 '
},
{
' {#TCP_PORT} ': ' 25 '
},
{
' {#TCP_PORT} ': ' 1028 '
}
]
}
Modify the Zabbix_agent configuration file under Win zabbix_agentd.win.conf
Unsafeuserparameters=1
Userparameter=tcpportlisten,python C:\zabbix-2.2.2_agent\check_port.py
Restart the Zabbix_agent service after the modification is complete.
At this time at the Zabbix_server end can use Zabbix_get to test whether it is normal.
Zabbix_get-s ip-k Tcpportlisten
The results returned are consistent with the results returned by running the script on the agent to indicate normal.
Add Discover to Page
Click Discovery on the template or host page (explore), then click Create Discovery rule in the upper right corner (create discovery rules)
Then create an item in this new TCP port discover
Finally create the alarm trigger
Notice the expression of this place
{xxxxx:net.tcp.listen[{#TCP_PORT}].count (#3, 0,eq)}>1
If you are added on a single machine, here xxxxx should be the specific name of a machine, if it is a template, here is the name of the template
. Count (#3, 0,eq)}>1
Indicates that the last three values are equal to 0, and the alarm is more than once.
If you are added on the host, this time you will be able to see a lot of monitoring items in the port, if the template added, you need to the template to be associated with the response of the host to see a monitoring port.
The ports monitored below
Valve value of the port