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

相关内容

热门资讯

今日重大消息“新版wepoke... 您好:新版wepoker这款游戏可以开挂,确实是有挂的,需要了解加客服微信【9752949】很多玩家...
【第一资讯】“阿道夫十三水.辅... 有 亲,根据资深记者爆料阿道夫十三水是可以开挂的,确实有挂(咨询软件无需...
玩家攻略科普“情怀古诗词.开挂... 有 亲,根据资深记者爆料情怀古诗词是可以开挂的,确实有挂(咨询软件无需打...
玩家最新攻略“樱花炸金花.开挂... 网上科普关于“樱花炸金花有没有挂”话题很是火热,小编也是针对樱花炸金花作*弊开挂的方法以及开挂对应的...
盐城固态电池产线落地经开区,未... 12月21日,固态离子能源科技(武汉)有限公司在盐城举办固态动力电池技术成果发布活动,中外行业专家、...
玩家分享攻略“YY棋牌.辅助开... 网上科普关于“YY棋牌有没有挂”话题很是火热,小编也是针对YY棋牌作*弊开挂的方法以及开挂对应的知识...
重磅消息“衡阳十胡卡.开挂器?... 重磅消息“衡阳十胡卡.开挂器?”确实真的有挂您好,衡阳十胡卡这个游戏其实有挂的,确实是有挂的,需要了...
【第一消息】“微乐海南麻将.有... 【第一消息】“微乐海南麻将.有挂吗?”太坑了原来有挂您好,微乐海南麻将这个游戏其实有挂的,确实是有挂...
【第一消息】“飞鹰互娱.可以开... 您好:飞鹰互娱这款游戏可以开挂,确实是有挂的,需要了解加客服微信【9784099】很多玩家在这款游戏...
【今日要闻】“九九山城麻将.开... 家人们!今天小编来为大家解答九九山城麻将透视挂怎么安装这个问题咨询软件客服徽9784099的挂在哪里...