Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Self-made python script to monitor Esxi underlying DELL hard disk (using python with its own module paramiko)

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Self-made python script to monitor Esxi underlying DELL hard disk (using python with its own module 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 = "1111111111111111"

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 ()

Script note: when keyvalue is equal to-1, the quantity is not 7, that is, there is a problem with the hard drive.

Add commands to commands.cfg first.

[root@localhost libexec] # vi / usr/local/nagios/etc/objects/commands.cfg

Define command {

Command_name datadomain

Command_line sudo $USER1 $/ datadomain.py

}

Add the following to nagios.cfg

[root@localhost libexec] # vi / usr/local/nagios/etc/nagios.cfg

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

Define hosts and services: create a new datadomain.cfg in / usr/local/nagios/etc/objects

[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

}

Then you must add the following to the 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 djingheng 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!

}

Add sudo permissions

[root@localhost libexec] # visudo

Nagios ALL= (ALL) NOPASSWD:/usr/local/nagios/libexec/datadomain.py

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report