Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Zabbix automatically discovers host, port, and custom script key values

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Autodiscover host rules

Start by creating an AutoDiscovery host:

Configure AutoDiscovery Rules:

After completion of the automatic discovery in the action to create a discovery action:

custom scripts

zabbix custom monitoring key value automatic discovery automatic execution of remote scripts

For example:

Monitoring whether a process exists:

mkdir /etc/zabbix/alertscripts/

vim check_badvp.sh

#!/ bin/bash

result=`ps -ef | grep badvp-udpgw | grep -v grep`

if [ -n "$result" ]

then

echo '1'

else

echo '0'

fi

Through the script to determine whether this process exists returns 1 does not exist returns 0, we customize this script to the above directory

Configure the script path and key value in zabbix_agent.conf

UnsafeUserParameters=1

UserParameter=check_badvp,/bin/bash /etc/zabbix/alertscripts/check_badvp.sh

Modify timeout

Timeout = 8

Set timeout to avoid script execution failure

Set the script to start the service/opt/autorestart.sh

Finally, modify the sudoers file and add zabiix user's startup permissions visudo in the following line

root ALL=(ALL) ALL

zabbix ALL=(root) NOPASSWD:/opt/autorestart.sh

Finally restart the agent.

interface settings

Create a monitoring item:

Create Trigger:

Last conditional action notification:

Finally realize alarm:

zabbix port auto-discovery

After many experiments, due to the large number and irregular business ports on the company server, a large number of useless ports will be found by using the automatic port discovery rule (netstat) method on the Internet, and it is not friendly to only display ports when alarming. Finally, a solution has been found.

Python scripts and pyadmin scripts

Use zabbix custom key to call the company server existing process management tool pyadmin

Python script:

#!/ usr/bin/python

import os,json

#command = "sudo /usr/skymobi/admin/PYsanpadmin |awk -F'_' {'print $2'} | awk '{print $1}' | sort|uniq"

command = "sudo /usr/skymobi/admin/PYsanpadmin"

lines = os.popen(command).readlines()

resultLi = []

for line in lines:

lineLi = line.split()

newLineLi = lineLi[0].split("_")

resDic = {"{#SERVICES}":newLineLi[0],"{#TCP_PORT}":newLineLi[1]}

resultLi.append(resDic)

data = {"data":resultLi}

jsonStr = json.dumps(data, sort_keys=True, indent=4)

jsonStr=jsonStr.replace(r"\u001b[1;32;40m","").replace(r"\u001b[1;31;40m","").replace(r"\u001b[1;33;40m","")

print jsonStr

Replace in the script is to filter me PY output color green red No in the print json format will have color code

PYadmin Output Results

The principle is to use python script to separate the output of pyadmin management tool, filter out the process name and port, and pass it to zabbix automatic discovery rules.

vim zabbix-agentd.conf

UserParameter=nettcpservice,/usr/bin/python /etc/zabbix/alertscripts/discover_tcpport.py "$1" "$2"

Restart agent.

Configure AutoDiscovery Rules

Key value corresponds to key value in our configuration file, here type is active, in order to reduce the number of client server connections caused by server detection.

Finally bind to our server ~

zabbix agent Value should be a JSON object Troubleshooting

Consider script execution permissions first

chmod 755 discovery script

Second visudo, last line added

zabbix ALL=(ALL) NOPASSWD: ALL

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report