数以千计的服务器存活状态检查
admin
2023-02-25 08:20:05
0

# !/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通的服务器列表
    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通的服务器列表,在进行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()

相关内容

热门资讯

靠谱大容量TF卡推荐:三星T7... 三星原厂 · 全能微存储新基准 当平板扩容需求激增、Switch游戏掌机需加载多款3A游戏、航拍无人...
买不起大疆、影石的年轻人,排队... 文 | 表外表里 ,作者 | 陈梓洁,编辑 | 杨静、曹宾玲 “一台机器,旺季月入1500。” 去...
美国众议员当街打掉拍摄人员的手... 近日,美国KCCI电视台爆出的一段视频显示,美国众议员扎克·纳恩在街道上与跟踪拍摄人员发生口角,并动...
今天上凯道人数成关键!媒体人示... 海峡导报综合报道 台湾中联油脂致癌油风暴继续延烧,国民党今天(25日)在凯道举办“我是人、我反毒台”...
谷歌公布1500万次AI交互,... 导读:谷歌分析1500万次去标识化AI交互后发现,在一个典型职业中,AI大约可参与21%的任务,但完...
空调水管不出水不制冷 原因可能是空调缺氟或是氟利昂泄漏,可以修补泄漏点,添加适量的氟;原因可能是空调的功率不够,可以更换与...
洗衣机不出水怎样修理拆装 如果您的洗衣机出现不出水的问题,也许是因为以下几个原因:1. 水龙头未开启:在洗衣机不出水的情况下,...
原创 三... 随着REDMI K100系列两杯(Pro/ProMax)的入网,以及一款小米神秘新机,小米在8月份的...
洗衣机放不出水咋回事儿 洗衣机放不出水,可能是以下几个方面的原因: 1. 排水管道堵塞:洗衣机的排水管道如果被毛发等污垢堵...
美的电热水瓶不出水故障维修方法 1、 电热水瓶的电机是12V的串励电机。也就是说上电后热水瓶会自动加热,水沸腾时,温控器将会自动断开...