欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

nagios自定义脚插件开发

程序员文章站 2022-04-10 13:58:47
...
假设我们开发一个监听远程服务器硬盘空间大小的插件
1.在nagios目录libexec下添加可执行脚本check_remote_disk.sh:

out=`ssh [email protected]$1 '/opt/nagios/check_disk -w 10% -c 5% -p / -w 10% -c 5% -p /home -w 10% -c 5% -p /opt -w 10% -c 5% -p /var/log'`
result=`echo $out | grep "DISK OK"`
if [ "$result" = "" ]; then
echo $out
exit 2
else
echo $out
exit 0
fi

2.将nagios下面的libexec拷贝至远程服务器/opt/nagios,并设置免密码登录至该远程服务器上;
3.etc/objetcs/commands.cfg添加:

define command{
command_name remote_disk_check
command_line $USER1$/check_remote_disk.sh $HOSTADDRESS$
}

4.etc/objects/自定义.cfg添加:

define service{
use generic-service
hostgroup_name server1 #我自己定义的host-group
service_description remote_disk_check
check_command remote_disk_check
normal_check_interval 5
retry_check_interval 5
}

5.重启nagios.

PS:
nagios自定义插件返回码:
Return Code Service State Host State
0 OK UP
1 WARNING UP or DOWN/UNREACHABLE*
2 CRITICAL DOWN/UNREACHABLE
3 UNKNOWN DOWN/UNREACHABLE

nagios脚本排错:
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg