一.准备好被监控机器上面执行脚本,以备服务端发现和监控
脚本的内容:
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文件如下:
- "1.0" encoding="UTF-8"?>
- <zabbix_export>
- <version>6.0version>
- <date>2023-08-14T06:54:29Zdate>
- <groups>
- <group>
- <uuid>7df96b18c230490a9a0a9e2307226338uuid>
- <name>Templatesname>
- group>
- groups>
- <templates>
- <template>
- <uuid>d506374c76194ef2a89f16a5a1a2bdd0uuid>
- <template>zabbixtest-Template-naschktemplate>
- <name>zabbix-Template-naschkname>
- <groups>
- <group>
- <name>Templatesname>
- group>
- groups>
- <discovery_rules>
- <discovery_rule>
- <uuid>65640ddbe5274e79966964e0acdbc503uuid>
- <name>findnasname>
- <key>nas.discoverykey>
- <delay>60mdelay>
- <item_prototypes>
- <item_prototype>
- <uuid>98d3e0de995246b8ab905e11c39c774duuid>
- <name>chknas write on {#NASNAME}name>
- <key>nas.checkwrite[{#NASNAME}]key>
- <delay>60mdelay>
- <trigger_prototypes>
- <trigger_prototype>
- <uuid>bc3fd41f548f4c93b697d01d1af5c3d8uuid>
- <expression>last(/zabbixtest-Template-naschk/nas.checkwrite[{#NASNAME}])<>0expression>
- <name>NAS盘write{#NASNAME}状态异常name>
- <event_name>NAS盘write{#NASNAME}状态异常event_name>
- <status>DISABLEDstatus>
- <priority>HIGHpriority>
- trigger_prototype>
- trigger_prototypes>
- item_prototype>
- <item_prototype>
- <uuid>0c70897bc30446c5a07c1ecaa863c11duuid>
三.导入模板,在被监控的主机上执行脚本和应用监控模板,实现对被监控主机NAS盘读写情况的监控
并根据实际的需求启用/禁用触发器