加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

通过hp ilo对机器的状态进行监控

发布时间:2020-12-17 17:14:02 所属栏目:Python 来源:网络整理
导读:今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 #!/usr/bin/python2.7import hpiloimport sysimport timeimport osimport jsonimport argparsedef check_log(fname): if not os.path.exists(fname):

以下代码由PHP站长网 52php.cn收集自互联网

现在PHP站长网小编把它分享给大家,仅供参考

#!/usr/bin/python2.7

import hpilo
import sys
import time
import os
import json
import argparse

def check_log(fname):
    if not os.path.exists(fname):
        os.mknod("/tmp/ilo_error.log")

check_log('/tmp/ilo_error.log')


avg = argparse.ArgumentParser()
avg.add_argument('-H',help="Plz input destination IP")
avg.add_argument('-U',help="Plz input destination port")
avg.add_argument('-P',help="Plz input connect user")
qq = avg.parse_args()

ls = os.linesep
rs = hpilo.Ilo(qq.H,qq.U,qq.P)
li = rs.get_server_event_log()
the_time = (time.time() - 259200)
save_list = []
yes = 1
error_num = 0
for y in li:
    for z,k in y.items():
        if z == 'description':
            err_rs = k.split(':')
            if err_rs[0] == 'POST Error':
                error_info = y['description']
                error_time = y['initial_update']
                error_time_strp = time.strptime(error_time,"%m/%d/%Y %H:%M")
                error_times = int(time.mktime(error_time_strp))
                read_liens = open('/tmp/ilo_error.log','r')
                if the_time < error_times:
                    for m in read_liens:
                        m = json.loads(m)
                        if not len(m) == 0:
                            for line in m:
                                #print line[1],error_times,line[2],error_info,line[0]
                                if line[1] == error_times and line[2] == error_info and  line[0] < 3:
                                    print "ERROR: %s" % error_info
                                    error_num = line[0] + 1
                                    save_list.append([error_num,error_info])
                                    error_num += 1
                                    yes = 0
                                    break
                                elif line[1] == error_times and line[2] == error_info and  line[0] == 3:
                                    save_list.append(line)
                                    yes = 0
                            if yes == 1:
                                print "ERROR: %s" % error_info
                                save_list.append([1,error_info])
                        else:
                            print "ERROR: %s" % error_info
                            save_list.append([1,error_info])
                            error_num += 1
                read_liens.close()
if error_num == 0:
    print "OK!"
    exit(0)
else:    
    fobj = open('/tmp/ilo_error.log','w')
    fobj.writelines(json.dumps(save_list))
    fobj.close()
    exit(1)

以上内容由PHP站长网【52php.cn】收集整理供大家参考研究

如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读