溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

數(shù)以千計的服務(wù)器存活狀態(tài)檢查

發(fā)布時間:2020-07-11 20:26:55 來源:網(wǎng)絡(luò) 閱讀:209 作者:lyq314 欄目:系統(tǒng)運維

# !/usr/bin/python
# -*- coding: UTF-8 -*-
import commands
import sys
import time

class server_unreache(object):
    def __init__(self, ip_list):
        self.ip_list = ip_list
#第一次獲取無法ping通的服務(wù)器列表
    def unreachable_ip_list(self):
        global unreachable_iplist_one_time
        unreachable_iplist_one_time=[]
        get_un_iplist_str = "/sbin/fping -u  -f  {}".format(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

# 對第一次獲取無法ping通的服務(wù)器列表,在進行3次ping操作,每次操作時間間隔為10秒
    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(j+1,unreache_3times[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 <= 2:
                print("do_reboot_ip:{},\n do_reboot_cmd:{}".format(unreache_3times[i],do_reboot_cmd.format(unreache_3times[i].replace('172.','10.'))))
                #print("do_reboot_ip", unreache_3times[i])

if __name__ == '__main__':
    ip_list = sys.argv[1]
    ds=server_unreache(ip_list)
    ds.unreachable_ip_list()
    ds.do_3times_fping_unreachable()
    ds.do_reboot()
向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI