数以千计的服务器存活状态检查
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()

相关内容

热门资讯

伊朗确认前往美国参加世界杯:将... 当地时间5月6日,伊朗国家足球队主教练在接受采访时表示,伊朗国家足球队将于美加墨世界杯开始前14天抵...
雷达、机库、营房、燃料库、飞机... 据《华盛顿邮报》5月6日报道,通过卫星影像分析发现,自2月28日战事爆发以来,伊朗空袭已在中东美军军...
从买买买到租租租,“租用一代”... “五一”假期还在路上,年轻人已经“租”起来了。 “租三天,不到300块钱。”五一放假前一周,清清已给...
【品牌】摩托罗拉大折叠屏新机定... 此前联想预热将于5月19日19点举行联想天禧AI一体多端全场景新品超能之夜活动,届时将带来多款新品,...
常州欣隽益取得接线端子用快速冲... 国家知识产权局信息显示,常州欣隽益科技有限公司取得一项名为“接线端子用快速冲切装置”的专利,授权公告...
美媒:特朗普在结束伊朗战争问题... 据“国会山”网站5月6日报道,周二晚间,美国总统特朗普突然宣布终止旨在打破伊朗对霍尔木兹海峡掌控的军...
和创硅材料取得熔融石英制品擦洗... 国家知识产权局信息显示,东海县和创硅材料有限公司取得一项名为“一种熔融石英制品的擦洗脱泥装置”的专利...
美商务部长再就爱泼斯坦案接受国... 5月6日,美国商务部长卢特尼克“自愿”就其与爱泼斯坦的关系接受美国国会众议院监督与政府改革委员会的问...
“五一”小长假黄金零售市场新变... 【大河财立方 记者 孙凯杰】 “五一”小长假,黄金价格出现一波短暂调整,线下黄金零售市场热度如何?5...
以军3周来首次袭击黎巴嫩首都 据以色列总理内塔尼亚胡和国防部长卡茨当地时间5月6日晚发表的联合声明,以军当天对黎巴嫩首都贝鲁特南郊...