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

相关内容

热门资讯

终于了解“快乐打筒子.怎么装挂... 有 亲,根据资深记者爆料快乐打筒子是可以开挂的,确实有挂(咨询软件无需打...
玩家最新攻略“琼戏互娱.究竟有... 您好:琼戏互娱这款游戏可以开挂,确实是有挂的,需要了解加客服微信【4282891】很多玩家在这款游戏...
终于了解“新九方炸金花.开挂器... 有 亲,根据资深记者爆料新九方炸金花是可以开挂的,确实有挂(咨询软件无需...
最新引进“新蓝鲸.到底有挂吗?... 有 亲,根据资深记者爆料新蓝鲸是可以开挂的,确实有挂(咨询软件无需打开直...
玩家攻略科普“中至上饶麻将.真... 您好:中至上饶麻将这款游戏可以开挂,确实是有挂的,需要了解加客服微信【9784099】很多玩家在这款...
【今日要闻】“花城牌舍.可以开... 有 亲,根据资深记者爆料花城牌舍是可以开挂的,确实有挂(咨询软件无需打开...
乌代表团与美欧举行系列会议,美... 当地时间12月21日,美国总统特使威特科夫表示,过去三天,乌克兰代表团在美国佛罗里达州与美国和欧洲伙...
终于懂了“新青鸟牛牛.怎么装挂... 您好:新青鸟牛牛这款游戏可以开挂,确实是有挂的,需要了解加客服微信【9752949】很多玩家在这款游...
今日重磅消息“圣盛宜昌花牌.真... 今日重磅消息“圣盛宜昌花牌.真的有挂吗?”其实是有挂您好,圣盛宜昌花牌这个游戏其实有挂的,确实是有挂...
开发者破1000万,华为鸿蒙迈... 据心声社区公众号 12 月 19 日分享,鸿蒙迈过了生死线 —— 搭载 HarmonyOS 5、Ha...