First, the system environment
Operating system: CentOS 7
Nagios server-side version: nagios-4.0.8-2.el7.x86_64
Nrpe Client version: nrpe-2.15-7.el7.x86_64
Two, Nagios custom plugin return code:
Return Code Service State Host State
0 OK up
1 WARNING up or down/unreachable*
2 CRITICAL down/unreachable
3 UNKNOWN down/unreachable
Third, define the plug-in, put the plug-in/usr/lib64/nagios/plugins
(1) Scripts need to have Execute permission
-RWXRWXRWX 1 Nagios Nagios 281 may 13:35 check_zfstatus.sh
(2) Define the monitoring command, in the monitored end/etc/nagios/nrpe.cfg,
command[check_zfs]=/usr/bin/sudo/usr/lib64/nagios/plugins/check_zfstatus.sh
(3) define Service and command on Nagios server side
Define Command{
Command_name Check_nrpe
Command_line $USER 1$/check_nrpe-h $HOSTADDRESS $-C $ARG 1$
}
Define Service{
Use Local-service
HOST_NAME test
Service_description Zfs_status
Check_command CHECK_NRPE!CHECK_ZFS
}
Four, restart the process, in the monitoring interface can see the definition of the service
PS: In the installation process encountered problems and solutions
Attach the script code:
#! /bin/bash
Sudo/usr/sbin/zpool Scrub Myzpool
Device= ' Sudo/usr/sbin/zpool status | Grep-o UNAVAIL | Uniq '
Status=unavail
if [["$device" = = "$status"]]; Then
echo "Device wrong!"
Exit 2
Else
echo "Device all right;"
Exit 0
Fi
Script Description:
(1) Because Zpool only root user has permission, Nrpe cannot call, so need to edit/etc/sudoers file, give
Nrpe permissions. Add Nrpe all= (All) Nopasswd:all
(2) [["$device" = = "$status"]] because the device variable is sometimes null, it is necessary to write two brackets in the judgment
(3) If the monitoring status output is inconsistent with the script execution results, the error is switched to the Nagios user
/usr/lib64/nagios/plugins/check_nrpe-h IP address-c CHECK_ZFS
This article is from the Linux tours blog, so be sure to keep this source http://bluefei.blog.51cto.com/3921428/1782527
Custom Nagios plugin script in CentOS 7