温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

CentOS 7 中自定义nagios 插件脚本

发布时间:2020-06-27 01:35:50 来源:网络 阅读:699 作者:niyoudeyuliujun 栏目:移动开发

一、 系统环境

       操作系统:CentOS 7

      nagios 服务器端版本:nagios-4.0.8-2.el7.x86_64

      nrpe  客户端版本:nrpe-2.15-7.el7.x86_64

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

三、定义插件,将插件放在 /usr/lib64/nagios/plugins

(1)脚本需要具有执行权限

   -rwxrwxrwx 1 nagios nagios 281 May 24 13:35 check_zfstatus.sh

  (2)定义监控命令,在被监控端  /etc/nagios/nrpe.cfg 中,

     command[check_zfs]= /usr/bin/sudo  /usr/lib64/nagios/plugins/check_zfstatus.sh

  (3)  在nagios 服务器端定义 service 及command

    define command{
          command_name check_nrpe
          command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
         }

      define service{
            use         local-service
            host_name          test
            service_description      zfs_status
            check_command        check_nrpe!check_zfs
           }

四、重启进程,在可以在监控界面看到定义的服务了

PS:  在安装过程中遇到的问题及解决办法

 附上脚本代码:

  #! /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
脚本说明:

(1)因为zpool 只有root用户有权限,nrpe 无法调用,所以需要编辑 /etc/sudoers 文件,给予

   nrpe 权限。添加   nrpe  ALL=(ALL)   NOPASSWD:ALL

   Defaults    requiretty,修改为 #Defaults    requiretty,表示不需要控制终端。

(2)[[ "$device" == "$status" ]]     因为device变量有时会为空值,故需要在判断时候写两个中括号

(3)如遇到监控状态输出与 脚本执行结果不一致时,调错,切换到nagios 用户
 /usr/lib64/nagios/plugins/check_nrpe -H IP地址 -c check_zfs





向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI