Zabbix Monitoring (12): Automatic monitoring of Linux ports

Source: Internet
Author: User
Tags server port egrep

1. Client New script

[[email protected] ~]# vi /usr/local/zabbix_agent/sbin/discovertcpport.sh #!/bin/ bashportarray= (' netstat -tnlp|egrep -i  ' $ "|awk {' print $4 '}|awk -F ': '   ' {if   ($NF ~/^[0-9]*$/)  print  $NF} ' |sort|uniq ') #namearray = (' netstat -tnlp|egrep -i  ') "|awk {' print $7 '}|awk -f '/'   ' {if  ($NF  != " Address ")  print  $NF} ' | Uniq ') length=${#portarray [@]}printf  "{\ n" printf   ' \ t ' "\" data\ ": [" for  (i=0;i< $length; i+ +))   do     printf  ' \n\t\t{'      printf  "\" {#TCP_PORT}\ ": \" ${portarray[$i]}\ "}" #     printf  "\" {#TCP_NAME}\ ": \" ${ namearray[$i]}\ "}"      if [  $i  -lt $[$length -1] ];then                 printf  ', '      fi  doneprintf   "\n\t]\n" printf  "}\n"  [[email protected] ~]#  cd /usr/local/zabbix_agent/sbin[[email protected] sbin]# chmod +x  discovertcpport.sh

Script Description:

Use the netstat command to output the port number,-TNLP=TCP protocol + do not display alias +listen status + Display program name, $1~$9 represents the first parameter of the output; awk {' Print $4 '} represents the output of the 4th parameter (such as 0.0.0.0:80); Awk-f ' : ' {if ($NF ~/^[0-9]*$/) print $NF} means that the value after the colon is intercepted and can only be a 0~9 number; |sort|uniq indicates sorting and de-weight.

The two lines that are commented out in the script are used to monitor the service, and simply replace the line on it with a scan service script.


2, the client added discovery key

[Email protected] sbin]#

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


3. Restart ZABBIX_AGENTD Service

[Email protected] sbin]#


4. Testing

The client runs the script test:

[Email protected] ~]# Cd/usr/local/zabbix_agent/sbin[[email protected] sbin]#./discovertcpport.sh

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/53/AE/wKioL1Rtn1-x5AssAACqMO37y4I155.jpg "title=" Qq20141120155713.png "alt=" Wkiol1rtn1-x5assaacqmo37y4i155.jpg "/>

Client test Scan Port command:

[[email protected] ~]# netstat-tnlp|egrep-i "$" |awk {' Print $4 '}|awk-f ': ' {if ($NF ~/^[0-9]*$/) print $NF} '

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/53/AE/wKioL1RtnGrjUFqRAACv3V0hXBY852.jpg "style=" float: none; "title=" Image 58.png "alt=" Wkiol1rtngrjufqraacv3v0hxby852.jpg "/>

Client Test Scan Service command:

[Email protected] ~]# netstat-tnlp|egrep-i "$" |awk {' Print $7 '}|awk-f '/' {print $NF} '

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/53/B0/wKiom1Rtm_LwbcOXAADKGEqKudg795.jpg "style=" float: none; "title=" Image 59.png "alt=" Wkiom1rtm_lwbcoxaadkgeqkudg795.jpg "/>

You can see that the above two command outputs have duplicates.

The following is a script created on the Zabbix server, followed by a local zabbix_get test:

[Email protected] ~]#/usr/local/zabbix_agent/bin/zabbix_get-s 127.0.0.1-k Tcpportlisten

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/53/AE/wKioL1RtnGuSi1nMAAFofnueeHg376.jpg "style=" float: none; "title=" Image 60.png "alt=" Wkiol1rtngusi1nmaafofnueehg376.jpg "/>


5. Create a port Autodiscover rule in a Linux template

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/53/B0/wKiom1Rtm_KhgRzbAAQA_74md6U667.jpg "style=" float: none; "title=" Image 61.png "alt=" Wkiom1rtm_khgrzbaaqa_74md6u667.jpg "/>


Set automatic discovery rule name and key:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/53/AE/wKioL1RtnGvQ9AI6AAKR1YeqXIM213.jpg "style=" float: none; "title=" Image 62.png "alt=" Wkiol1rtngvq9ai6aakr1yeqxim213.jpg "/>


To create the item prototype:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/53/B0/wKiom1Rtm_OBB6tHAAKnkyFHixc202.jpg "style=" float: none; "title=" Image 63.png "alt=" Wkiom1rtm_obb6thaaknkyfhixc202.jpg "/>


To create a trigger prototype:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/53/AE/wKioL1RtnGuRjIC3AANYXMa_zPg425.jpg "style=" float: none; "title=" Image 64.png "alt=" Wkiol1rtngurjic3aanyxma_zpg425.jpg "/>


Create Image prototypes (can be ignored):

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/53/B0/wKiom1Rtm_PhoJ87AAN3TSdgJnE978.jpg "style=" float: none; "title=" Image 65.png "alt=" Wkiom1rtm_phoj87aan3tsdgjne978.jpg "/>


6. View Autodiscover Results

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/53/AE/wKioL1RtnGzhNaPuAAc9X6YwjvU797.jpg "style=" float: none; "title=" Image 66.png "alt=" Wkiol1rtngzhnapuaac9x6ywjvu797.jpg "/>


View Last value: 1 indicates that the port is listening

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/53/B0/wKiom1Rtm_ShD7Z4AAPSURtRXPg073.jpg "style=" float: none; "title=" Image 67.png "alt=" Wkiom1rtm_shd7z4aapsurtrxpg073.jpg "/>


To view the Autodiscover image:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/53/AE/wKioL1RtnGzCZIlUAAPJlGJgxz8483.jpg "style=" float: none; "title=" Image 68.png "alt=" Wkiol1rtngzcziluaapjlgjgxz8483.jpg "/>

Conclusion: Auto-discovery can monitor the server port very well, when the new port is opened, it will scan itself, do not need to care for the person, it is recommended to disable the non-important trigger, otherwise it will be alerted frequently, and some ports will be in a meeting.

About the automatic monitoring service, the reader can go to try, the command has been written on it, it should not be a problem.

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

Zabbix Monitoring (12): Automatic monitoring of Linux ports

Related Article

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.