自制python脚本监控EMC VNXe 3200存储硬盘

发布时间:2020-07-19 21:54:34 作者:normanjin
来源:网络 阅读:305

自制python脚本监控EMC VNXe 3200存储硬盘
[root@localhost libexec]# vi vnxe.py
#!/usr/bin/env python
import commands
import os
#0 ok; 1 warning; 2 critical; 3 unknown
os.chdir("/usr/local/nagios/libexec/")
(status, output) = commands.getstatusoutput("uemcli -d 10.10.1.11 -u admin -p Password /env/ps show | grep 'Health state'| awk '{print $4}' | wc -l")
if int(output) == 2:
print "VNXe 3200 harddisk ok"
else:
print "VNXe 3200 harddisk fail"

测试运行结果
[root@localhost libexec]# ./vnxe.py
VNXe 3200 harddisk ok

先在commands.cfg中添加命令。
[root@localhost libexec]# vi /usr/local/nagios/etc/objects/commands.cfg
define command {
command_name vnxe
command_line $USER1$/vnxe.py
}

在nagios.cfg中添加以下内容
[root@localhost libexec]# vi /usr/local/nagios/etc/nagios.cfg
cfg_file=/usr/local/nagios/etc/objects/VNXe.cfg

定义主机和服务:在/usr/local/nagios/etc/objects中新建VNXe.cfg
[root@localhost libexec]# vi /usr/local/nagios/etc/objects/VNXe.cfg
define host{
use EMC VNXe 3200
host_name EMC VNXe 3200
alias EMC VNXe 3200
address 10.10.1.11
}

define service{
use generic-service
host_name EMC VNXe 3200
service_description EMC VNXe 3200
check_command vnxe
notifications_enabled 1
}

然后必须在templates.cfg中添加以下内容
[root@localhost libexec]# vi /usr/local/nagios/etc/objects/templates.cfg
define host{
name EMC VNXe 3200 ; The name of this host template
use generic-host ; This template inherits other values from the generic-host template
check_period 24x7 ; By default, EMC VNXe 3200 hosts are checked round the clock
check_interval 5 ; Actively check the host every 10 minutes
retry_interval 1 ; Schedule host check retries at 10 minute intervals
max_check_attempts 10 ; Check each EMC VNXe 3200 host 10 times (max)
check_command check-host-alive ; Default command to check EMC VNXe 3200 hosts
notification_period workhours ; EMC VNXe 3200 admins hate to be woken up, so we only notify during the day
; Note that the notification_period variable is being overridden from
; the value that is inherited from the generic-host template!
notification_interval 120 ; Resend notifications every 2 hours
notification_options d,u,r ; Only send notifications for specific host states
contact_groups admins ; Notifications get sent to the admins by default
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!
}

放入Nagios测试后,结果出错,(没有任何报错信息)始终找不到问题。原因是Nagios中的 command_line $USER1$/vnxe.py是以nagios账号来运行脚本vnxe.py,抓取不到正确的python脚本结果(前面我们是用root来运行,所以才能得到正确的结果)。以下解决问题。
[root@localhost libexec]# visudo
nagios ALL=(ALL) NOPASSWD:/usr/local/nagios/libexec/vnxe.py
#Defaults requiretty

在commands.cfg中修改命令。
[root@localhost libexec]# vi /usr/local/nagios/etc/objects/commands.cfg
define command {
command_name vnxe
command_line sudo $USER1$/vnxe.py

重启 Nagios生效
[root@localhost libexec]# systemctl restart nagios.service

推荐阅读:
  1. android 横屏 竖屏切换
  2. 更改python中pip默认安装路径的方法

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

自制python脚本监控emc vnxe vn 200

上一篇:StartDT AI Lab | 视觉智能引擎——从Face ID说起,浅析顾客数字化

下一篇:pipenv—不可不知的python包管理利器

相关阅读

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

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