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

相关内容

热门资讯

终于了解“鱼扑克.辅助器?”详... 您好:鱼扑克这款游戏可以开挂,确实是有挂的,需要了解加客服微信【9784099】很多玩家在这款游戏中...
终于懂了“天天乐棋牌.到底有挂... 家人们!今天小编来为大家解答天天乐棋牌透视挂怎么安装这个问题咨询软件客服徽4282891的挂在哪里买...
【第一消息】“情怀古诗词.到底... 【第一消息】“情怀古诗词.到底有挂吗?”必胜开挂神器您好,情怀古诗词这个游戏其实有挂的,确实是有挂的...
【第一消息】“新皇豪牛牛.是不... 【第一消息】“新皇豪牛牛.是不是有挂?”透视曝光猫腻您好,新皇豪牛牛这个游戏其实有挂的,确实是有挂的...
【第一消息】“战皇炸金花.有挂... 有 亲,根据资深记者爆料战皇炸金花是可以开挂的,确实有挂(咨询软件无需打...
玩家最新攻略“咸宁晃晃麻将.到... 有 亲,根据资深记者爆料咸宁晃晃麻将是可以开挂的,确实有挂(咨询软件无需...
烤鸡少年承认用“肉宝王”来调味... 极目新闻记者 丁伟近日,深圳烤鸡少年小陈被曝使用“肉宝王”来调味,引发争议。12月22日,小陈发布视...
我来教教您“先锋大厅.有挂吗?... 家人们!今天小编来为大家解答先锋大厅透视挂怎么安装这个问题咨询软件客服徽9752949的挂在哪里买很...
香港通报10亿日元大劫案:11... 12月18日约9时香港上环永乐街发生劫案,4名持刀匪徒在皇后大道中181号新纪元广场附近劫走约10亿...
最新引进“九九牌游十三水.究竟... 网上科普关于“九九牌游十三水有没有挂”话题很是火热,小编也是针对九九牌游十三水作*弊开挂的方法以及开...