zabbix自动发现linux系统挂载的nas盘,并实现读写故障的监控告警

一.准备好被监控机器上面执行脚本,以备服务端发现和监控

脚本的内容:

ZABBI安装路径可执行文件及配置文件根据实际部署的路径更改

#!/bin/bash >/zabbixconfpath/zbx_nas.conf >/zabbixscriptspath/findnas.sh >/zabbixscriptspath/checknas.sh >/zabbixscriptspath/checknaswrite.sh ( cat <<EOF UserParameter=nas.discovery,/zabbixscriptspath/findnas.sh UserParameter=nas.check[*],/zabbixscriptspath/checknas.sh \$1 UserParameter=nas.checkwrite[*],/zabbixscriptspath/checknaswrite.sh \$1 EOF )>>/zabbixconfpath/zbx_nas.conf ( cat <<EOF #!/bin/bash mount_discovery () { mount | grep "type nfs" | grep -v "nfsd" | awk '{print \$3}' > /zabbixscriptspath/naslists.txt chown zabbixuser:zabbixuser /zabbixscriptspath/naslists.txt NAS_LIST=(\$(cat /zabbixscriptspath/naslists.txt)) printf '{\n' printf '\t"data":[\n' for((i=0;i<\${#NAS_LIST[@]};++i)) { num=\$(echo \$((\${#NAS_LIST[@]}-1))) if [ "\$i" != \${num} ]; then printf "\t\t{ \n" printf "\t\t\t\"{#NASNAME}\":\"\${NAS_LIST[\$i]}\"},\n" else printf "\t\t{ \n" printf "\t\t\t\"{#NASNAME}\":\"\${NAS_LIST[\$num]}\"}]}\n" fi } } mount_discovery EOF )>>/zabbixscriptspath/findnas.sh ( cat <<EOF #!/bin/bash timeout 3 df -h \$1 > /dev/null if [ \$? -ne 0 ]; then echo 1 else echo 0 fi EOF )>>/zabbixscriptspath/checknas.sh ( cat <<EOF #!/bin/bash timeout 3 touch \$1/zabbixtestfiles.txt.txt.txt > /dev/null if [ \$? -ne 0 ]; then echo 1 else echo 0 fi EOF )>>/zabbixscriptspath/checknaswrite.sh chmod a+x /zabbixscriptspath/findnas.sh /zabbixscriptspath/checknas.sh /zabbixscriptspath/checknaswrite.sh systemctl restart zabbix-agent.service || ps -ef | grep zabbix-agent | grep -v grep | awk '{print $2}' | xargs -I {} kill {};sleep 1;su - zabbixuser -c "/zabbixpath/sbin/zabbix_agentd -c /zabbixpath/conf/zabbix_agentd.conf" 

二.ZABBIX监控模板导出的XML文件如下:

<?xml version="1.0" encoding="UTF-8"?> <zabbix_export> <version>6.0</version> <date>2023-08-14T06:54:29Z</date> <groups> <group> <uuid>7df96b18c230490a9a0a9e2307226338</uuid> <name>Templates</name> </group> </groups> <templates> <template> <uuid>d506374c76194ef2a89f16a5a1a2bdd0</uuid> <template>zabbixtest-Template-naschk</template> <name>zabbix-Template-naschk</name> <groups> <group> <name>Templates</name> </group> </groups> <discovery_rules> <discovery_rule> <uuid>65640ddbe5274e79966964e0acdbc503</uuid> <name>findnas</name> <key>nas.discovery</key> <delay>60m</delay> <item_prototypes> <item_prototype> <uuid>98d3e0de995246b8ab905e11c39c774d</uuid> <name>chknas write on {#NASNAME}</name> <key>nas.checkwrite[{#NASNAME}]</key> <delay>60m</delay> <trigger_prototypes> <trigger_prototype> <uuid>bc3fd41f548f4c93b697d01d1af5c3d8</uuid> <expression>last(/zabbixtest-Template-naschk/nas.checkwrite[{#NASNAME}])&lt;&gt;0</expression> <name>NAS盘write{#NASNAME}状态异常</name> <event_name>NAS盘write{#NASNAME}状态异常</event_name> <status>DISABLED</status> <priority>HIGH</priority> </trigger_prototype> </trigger_prototypes> </item_prototype> <item_prototype> <uuid>0c70897bc30446c5a07c1ecaa863c11d</uuid>

三.导入模板,在被监控的主机上执行脚本和应用监控模板,实现对被监控主机NAS盘读写情况的监控

并根据实际的需求启用/禁用触发器

原文链接:https://blog.csdn.net/lsysafe/article/details/132287188?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522171836984116800180651264%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=171836984116800180651264&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~times_rank-4-132287188-null-null.nonecase&utm_term=NAS%E7%A1%AC%E7%9B%98

© 版权声明
THE END
喜欢就支持一下吧
点赞10 分享