自制python脚本监控Esxi底层DELL硬盘(利用python自带模块 paramiko)
admin
2023-02-26 11:41:39
0

自制python脚本监控Esxi底层DELL硬盘(利用python自带模块 paramiko)
[root@localhost libexec]# cd /usr/local/nagios/libexec
[root@localhost libexec]# vi datadomain.py
#!/usr/bin/env python
import paramiko
import re
import sys
#0 ok; 1 warning; 2 critical; 3 unknown
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ip = "10.10.254.11"
user = "sysadmin"
passwd = "11111111111111"
ssh.connect(ip,22,user,passwd)
stdin,stdout,stderr = ssh.exec_command("disk status")
outmsg,errmsg = stdout.read(),stderr.read()
keyvalue=outmsg.find('7')
if int(keyvalue) <> -1:
print "Disk ok !"
sys.exit(0)
else:
print "Disk goes wrong!"
sys.exit(2)
ssh.close()
脚本注解:当keyvalue等于-1,说明数量没有7,也就是硬盘有问题了。

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

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

cfg_file=/usr/local/nagios/etc/objects/datadomain.cfg

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

define service{
use generic-service
host_name EMC DataDomain 2200
service_description EMC DataDomain 2200
check_command datadomain
notifications_enabled 1
}

然后必须在templates.cfg中添加以下内容
[root@localhost libexec]# vi /usr/local/nagios/etc/objects/templates.cfg

define host{
name EMC DataDomain 2200 ; 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 DataDomain 2200 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 DataDomain 2200 host 10 times (max)
check_command check-host-alive ; Default command to check EMC DataDomain 2200 hosts
notification_period workhours ; EMC DataDomain 2200 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!
}

添加sudo权限
[root@localhost libexec]# visudo
nagios ALL=(ALL) NOPASSWD:/usr/local/nagios/libexec/datadomain.py

相关内容

热门资讯

特朗普对美伊达成协议再表乐观 ... 新华社华盛顿5月6日电 美国总统特朗普6日接受美国公共广播公司电话采访时,对美国同伊朗达成协议的前景...
美对伊战事或为白宫记协晚宴枪手... 当地时间5月6日,总台记者获悉,美国国土安全部在一份情报评估中指出,美国对伊朗发起的军事行动可能是白...
权威数读丨尽显中国活力!五一假... 全社会跨区域人员流动量超15亿人次,消费相关行业销售收入同比增长14.3%,电影票房突破7.5亿元…...
“最美婚姻登记点”长啥样 郑州市金水区民政局婚姻登记处为新人举行户外颁证仪式。 受访者供图三门峡市天鹅湖婚姻登记处设置的创意路...
消息人士称伊朗预计将于7日回应... △伊朗首都德黑兰(资料图)当地时间5月6日,据一位地区消息人士表示,伊朗预计将于5月7日向调解人提交...
大数据透视“五一”假期消费亮点 刚刚过去的“五一”假期,国内消费市场活力十足。5月1日至4日,商务部重点监测的78个步行街(商圈)客...
河南超有品 第十个“中国品牌日... 4月30日,走进位于新县的羚锐制药贴膏剂生产基地,没有印象中传统药材加工的浓郁气味,也没有传统车间的...
假日出游正当时 文旅市场活力涌 “五一”假期,全省接待国内游客6611.7万人次,实现旅游收入381.1亿元假日出游正当时 文旅市场...
坚定不移沿着习近平总书记指引的... 大风起兮风车转。支撑这个“追风巨人”不停转动的“芯”,主要产自洛阳。5月6日,在洛阳轴承集团股份有限...
燃气灶为什么换了感应针还是熄灭 问题:燃气灶为什么换了感应针还是熄灭回答:原因是电池有没有电,这是平时容易碰见的问题,发现点不着火时...