Zabbix monitoring (eight): Automatic monitoring of Windows ports

Source: Internet
Author: User

Description: Zabbix itself comes with two autodiscover templates, disk discovery mounted filesystem discovery and network card Discovery network Interface discovery I made the automatic Port Discovery template and the automatic Service discovery template with reference to these two templates.


1. About Custom Key

(1) Refer to the official documentation:

Https://www.zabbix.com/documentation/2.4/manual/config/items/userparameters

(2) Key custom syntax format

Userparameter=<key>,<command>

(3) Example: View Linux system version

#vi zabbix_agentd.confunsafeuserparameters=1userparameter=get.os.type,head-1/etc/issue#service Zabbix_agentd Restart#zabbix_get-s 127.0.0.1-k Get.os.type

(4) Example: the use of transfer parameters

#vi zabbix_agentd.confunsafeuserparameters=1userparameter=wc[*],grep-c "$" $1# here means to pass $2,$1 to key, test the following #service Zabbix_agentd restart#zabbix_get-s 127.0.0.1-k Wc[/etc/passwd,root]

Description:/ETC/PASSWD is $1,root for $, then key is finally run with the command grep-croot/etc/passwd

(5) Example: View the number of lines in a passwd file

#vi zabbix_agentd.confunsafeuserparameters=1userparameter=count.line.passwd,wc-l/etc/passwd|awk ' {print $} ' # Service Zabbix_agentd restart#zabbix_get-s 127.0.0.1-k count.line.passwd

2. Create a script file

Create a new Discovertcpport.bat file on the client and place it in the C:\zabbix\ directory with the following contents:

@echo Offecho {echo "data": [for/f "tokens=2 delims="%%i in (' Netstat-anp tcp^|find/i ' LISTENING "') do for/f "tokens=2 delims=:"%%j in ("%%i") do echo {"{#TCP_PORT}": "%%j"},echo {"{#TCP_PORT}": "1005 0 "}echo]echo}

Script Description:

Command NETSTAT-ANP TCP ^|find/i "LISTENING" To view the TCP port of the listening state;

for/f "Tokens=2 delims=" represents the intercept value of the loop output, which is the 2nd (token=2) value separated by a space (delims=) in each line, with a variable%%i output;

After that, the port number is intercepted and the output is formatted with the same loop.

The output format must be output in JSON object format, otherwise the error "Value should be a JSON object";

In particular, note that the last line has no commas, so add a single line of echo {"{#TCP_PORT}": "10050" to meet the JSON object format.


3. Modify Client Configuration

Add the following to the client's zabbix_agentd.conf:

Unsafeuserparameters=1userparameter=tcpportlisten,c:\zabbix\discovertcpport.bat

Note: The first article is allowed to use user-defined parameters, the second set user parameters, the name Tcpportlisten is a custom key name, followed by key to execute the command or script file.

Restart Zabbix AGENTD Service


Tip: The script and configuration of the client can be done in advance at the time of installation, referencing my installation documentation:

http://ywzhou.blog.51cto.com/2785388/1579165


4. Client Testing

Run the CMD,CD to C:\zabbix directory as Administrator, enter the script file name, carriage return:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/53/A8/wKiom1RtQWqwf-0NAAHaghGKIIo667.jpg "title=" Picture 12.png "alt=" Wkiom1rtqwqwf-0naahaghgkiio667.jpg "/>

Note: It was tested on my notes, the scanned port is not the monitor host 10.188.1.44.

JSON format Description: #TCP_PORT是变量名称, the following values are the values of the variables.


5. Service-Side testing

[Email protected] ~]#/usr/local/zabbix/bin/zabbix_get-s 10.188.1.44-k Tcpportlisten

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/53/A6/wKioL1RtQfSRFwdAAAHwlLm0gEU429.jpg "style=" float: none; "title=" Image 13.png "alt=" Wkiol1rtqfsrfwdaaahwllm0geu429.jpg "/>

Note: You can see that the monitoring host scanned out of the port has 10050, and I added a 10050 later, do not matter, then look down.


6. Create a port Autodiscover rule

You can create a template individually, or you can create it directly in a Windows template:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/53/A8/wKiom1RtQXyTks-tAANeNsV4EtI936.jpg "style=" float: none; "title=" Image 14.png "alt=" Wkiom1rtqxytks-taanensv4eti936.jpg "/>



7. Set the port Autodiscover rule

The key used is the custom tcpportlisten650 in the client configuration file) this.width=650; "Src=" http://s3.51cto.com/wyfs02/M02/53/A6/ Wkiol1rtqfthkwmzaai2wwsubhy489.jpg "style=" Float:none; "title=" Image 15.png "alt=" />


8. Create an item prototype for the Autodiscover template

Use ntp.tcp.listen[] to monitor the port status, [] the value in [] is taken from the value of the variable #tcp_port, and the title is also taken from the value of the variable #tcp_port.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/53/A8/wKiom1RtQXzQdq1EAAFekOleplA919.jpg "style=" float: none; "title=" Image 16.png "alt=" Wkiom1rtqxzqdq1eaafekolepla919.jpg "/>



9. Create a trigger prototype for the Autodiscover template

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/53/A6/wKioL1RtQfXAXByDAAIWIqTyyoo503.jpg "style=" float: none; "title=" Image 17.png "alt=" Wkiol1rtqfxaxbydaaiwiqtyyoo503.jpg "/>

Click Select Prototype to choose the item prototype for the trigger:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/53/A8/wKiom1RtQX3QPdjtAADp9RSSxTw261.jpg "style=" float: none; "title=" Image 18.png "alt=" Wkiom1rtqx3qpdjtaadp9rssxtw261.jpg "/>


10. Create an image prototype for the Autodiscover template

Image prototypes can also not be created, meaning, the return value is not 0 is 1, it does not matter to see the graph, but it is necessary to monitor the performance of such a curve.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/53/A6/wKioL1RtQfXyOZkrAAJvgwIEgiM957.jpg "style=" float: none; "title=" Image 19.png "alt=" Wkiol1rtqfxyozkraajvgwiegim957.jpg "/>


11, repeated monitoring problems

If you have manually created port monitoring using Net.tcp.listen, the following error will be reported, but it does not matter.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/53/A8/wKiom1RtQX2RER0TAAS9HGlZjgw873.jpg "style=" float: none; "title=" Image 20.png "alt=" Wkiom1rtqx2rer0taas9hglzjgw873.jpg "/>


12, check the port automatic monitoring results

Since I am adding the Autodiscover rule to the Windows module, the monitoring host will add the port monitoring itself, if it is created in a template created separately, link to the monitoring host.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/53/A6/wKioL1RtQfbD1n4bAAbbCgpQDoY650.jpg "style=" float: none; "title=" Image 21.png "alt=" Wkiol1rtqfbd1n4baabbcgpqdoy650.jpg "/>


13. View recently returned values

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/53/A6/wKioL1RtQfbhaAVyAAROhAIz8HA277.jpg "style=" float: none; "title=" Image 22.png "alt=" Wkiol1rtqfbhaavyaarohaiz8ha277.jpg "/>



Conclusion: Although the automatic monitoring port is convenient, but a lot of listening ports do not understand, I do not know what the program is enabled, can be used with the previous port template, first create a port template to listen to the important service port, and then use automatic monitoring port to monitor other listening ports.

Modifying the script can be used to monitor other content, such as monitoring the started service net start, monitoring the connected client netstat established status, etc., you can also add several port-related items on the basis of the port monitoring script, such as whether you can connect, How the connection is performing.

Disable the triggers for some unimportant ports, or you will be bothered to receive email alerts.

This article is from the "Moon Ching Xing Fei" blog, please be sure to keep this source http://ywzhou.blog.51cto.com/2785388/1579936

Zabbix monitoring (eight): Automatic monitoring of Windows ports

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.