一.准备好被监控机器上面执行脚本,以备服务端发现和监控
脚本的内容:
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
)>>/zabbixscriptspath/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}])<>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://www.toymoban.com/news/detail-693921.html
并根据实际的需求启用/禁用触发器文章来源地址https://www.toymoban.com/news/detail-693921.html
到了这里,关于zabbix自动发现linux系统挂载的nas盘,并实现读写故障的监控告警的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!