自制python脚本监控EMC VNXe 3200存储硬盘
admin
2023-02-26 22:21:53
0

自制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

相关内容

热门资讯

这个“中国首次”,很有看点 刚刚,韩国釜山,第48届世界遗产大会传来好消息:“景德镇手工瓷业遗存”成功列入《世界遗产名录》!这是...
85岁剑桥教授,为何成了中国年... ·2026年6月,艾伦·麦克法兰在英国剑桥大学国王学院。(Muye.G/摄)(本文图片均由剑桥康河出...
西安造12英寸硅片月产销突破1... 12英寸电子级硅片是当前全球半导体产业链的紧缺关键材料。近日,记者从位于西安高新区的西安奕斯伟材料科...
把防人的墙筑太高,困住的可能是... 据新华社消息,近日OpenAI公司的两款大模型联合进行内部评估时失控,突破隔离测试环境,侵入了美国A...
三星Galaxy S27 Pr... IT之家 7 月 25 日消息,科技媒体 WinFuture 昨日(7 月 24 日)发布博文,分享...
郑丽文颁卢秀燕一等奖章,两人热... 中国国民党第22届第二次全代会25日上午登场,党主席郑丽文颁发实践一等奖章给即将卸任的党籍县市长,台...
AI、信息服务激活广东产业增长... 佛山市美的库卡智能制造科技园工业机器人产线车间。 掌握PCB钻针关键技术的广东鼎泰高科技术股份有限...
固态电池技术对汽车产业的影响有... 当前新能源汽车市场正处于快速变革期,消费者对于续航里程和安全性的要求日益严苛。传统液态锂离子电池在能...
台风“红霞”即将登陆,广东多地... 今年第12号台风“红霞”已于今天(25日)早晨由强热带风暴级加强为台风级。预计,该台风将于今天夜间至...
日本皇室恐上演养子夺嫡,麻生太... 澎湃新闻记者 陈沁涵日本政府7月24日正式公布修订后的《皇室典范》,核心在于确保足够的皇族人数。这是...