Thousands of server survival status checks
#! / usr/bin/python#-*-coding: UTF-8-*-import commandsimport sysimport timeclass server_unreache (object): def _ _ init__ (self Ip_list): self.ip_list = ip_list# gets the list of servers that cannot be ping for the first time def unreachable_ip_list (self): global unreachable_iplist_one_time unreachable_iplist_one_time= [] get_un_iplist_str = "/ sbin/fping-u-f {}" .fo rmat (ip_list) (status) Get_un_iplist) = commands.getstatusoutput (get_un_iplist_str) for unreach in get_un_iplist.split ('\ n'): unreachable_iplist_one_time.append (unreach) # return unreachable_iplist_one_time pass# to get the list of servers that cannot ping for the first time Performing 3 ping operations The interval between each operation is 10 seconds def do_3times_fping_unreachable (self): global unreache_3times unreache_3times= [] for j in range (3): for i in range (len (unreachable_iplist_one_time)): get_3times_un_iplist_str = "/ sbin/fping-u {}" .format (unreachable_iplist_one_ time [I]) Time.sleep (10) (status Get_3times_un_iplist) = commands.getstatusoutput (get_3times_un_iplist_str) print (time.strftime ("% Y-%m-%d% H:%M:%S", time.localtime () if status! = 0 and get_3times_un_iplist not in unreache_3times: unreache_3times.append (get_3times_un_iplist) print ("{} times" Unreache_3times {} ".format (unreache3times [I]) print (unreache_3times) pass def do_reboot (self) Count=0): global do_reboot_cmd do_reboot_cmd= "ipmitool-I lanplus-H {}-U UserNmae-P PassWord chassis power status" for i in range (len (unreache_3times)): count= count + 1 # print (count) if count