1.下载MegaCLI
- #mkdir -p /opt/build/
- #cd /opt/build/
- 在http://www.lsi.com 网站下载MegaCLI - 5.3
- #unzip 8.04.07_MegaCLI.zip
- 解压出来安装里面linux(这两个文件见附件)
#rpm -ivh Lib_Utils-1.00-09.noarch.rpm
#rpm -ivh MegaCli-8.04.07-1.noarch.rpm
2.编写插件
- #vim /usr/lib64/nagios/plugins/check_raid
- #!/bin/bash
- STATE_OK=0
- STATE_WARNING=1
- STATE_CRITICAL=2
- STATE_UNKNOWN=3
- Optimal=" Optimal"
- VDSTATE=$(/opt/MegaRAID/MegaCli/MegaCli64 -cfgdsply -aALL | /bin/grep "^State")
- STATE=$(/opt/MegaRAID/MegaCli/MegaCli64 -cfgdsply -aALL | /bin/grep "^State" | /bin/awk -F\: '{print $2}')
- #echo $? >> /tmp/vdiskstatus.log
- #echo $STATE >> /tmp/vdiskstatus.log
- if [ $STATE = $Optimal ];then
- echo OK -- "Virtual Disk : $STATE"
- exit $STATE_OK
- else
- echo CRITICAL -- "Virtual Disk : $STATE"
- exit $STATE_CRITICAL
- fi
3.更改插件的权限
- #chown nagios.nagios /usr/lib64/nagios/plugins/check_raid
- #chmod 755 /usr/lib64/nagios/plugins/check_raid
4.测试插件是否正常工作
#/usr/lib64/nagios/plugins/check_raid
OK -- Virtual Disk : Optimal
5.给nagios用户增加sudo权限
由于MegaCli命令执行时需要root权限,所以我们需要为nagios用户创建一个sudo使nagios用户可以执行check_raid。
#visudo
增加以下行:
- # Allow nagios to run certain plugins as root
- nagios ALL=(ALL) NOPASSWD: /usr/lib64/nagios/plugins/
注释以下行:
- #Defaults requiretty
启用以下行:
- %wheel ALL=(ALL) NOPASSWD: ALL
由于nrpe在传输的过程中也要用到root权限所以把nrpe加入到wheel组中
- #usermod -a -G wheel nrpe
6.编辑被监控服务器的nrpe.cfg
增加一个新的命令:
- #vim /etc/nagios/nrpe.cfg
- command[check_raid]=/usr/bin/sudo /usr/lib64/nagios/plugins/check_raid
重启nrpe:
- #/etc/init.d/nrpe restart
7.在nagios服务器端添加服务
- define service{
- host_name test
- service_description raid_status
- check_period 24x7
- normal_check_interval 5
- retry_check_interval 2
- max_check_attempts 5
- notification_period 24x7
- contact_groups admins
- check_command check_nrpe!check_raid
- }
验证配置文件并重启服务。
- #nagios -v /etc/nagios/nagios.cfg
- #/etc/init.d/nagios restart
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。