def GetProcStstus(): procCfg = common.GetCfg('proccfg') if not procCfg: return None if len(procCfg["ProcCfg"]) == 0: return None ProcStatusDict = {} ProcStatus = [] for procInfo in procCfg["ProcCfg"]: pidList = GetProcPID(procInfo) if len(pidList) > 0: for pid in pidList: status = __GetProcStstus__(pid) status["ID"] = procInfo["ID"] status["ProcName"] = procInfo["ProcName"] status["Status"] = 1 status["ScanTime"] = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') ProcStatus.append(status) else: status = {} status["ID"] = procInfo["ID"] status["ProcName"] = procInfo["ProcName"] status["Status"] = 0 status["ScanTime"] = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') ProcStatus.append(status) ProcStatusDict["HostIP"] = cfgMgr.localIP ProcStatusDict["ProcStatus"] = ProcStatus return ProcStatusDict pass
def GetDirStstus(): # 获取本机配置信息 dirCfg = common.GetCfg('dircfg') if not dirCfg: return None if len(dirCfg["DirCfg"]) == 0: return None dirStatus = [] for cfg in dirCfg["DirCfg"]: status = __GetDirStstus__(cfg["DirName"]) if not status: status = {} status["Status"] = 0 else: status["Status"] = 1 status["ID"] = cfg["ID"] status["DirName"] = cfg["DirName"] status["ScanTime"] = datetime.datetime.now().strftime( '%Y-%m-%d %H:%M:%S') dirStatus.append(status) dirStatusDict = {} dirStatusDict["HostIP"] = cfgMgr.localIP dirStatusDict["DirStatus"] = dirStatus return dirStatusDict pass
def GetLinkStstus(): # 获取本机配置信息 linkCfg = common.GetCfg('linkcfg') if not linkCfg: return None if len(linkCfg["LinkCfg"]) == 0: return None linkStatus = [] for cfg in linkCfg["LinkCfg"]: linkType = cfg["LinkType"] status = {} status["ID"] = cfg["ID"] status["LinkName"] = cfg["LinkName"] if linkType == 1: # ping status["Status"] = __Ping__(cfg["CheckIP"]) elif linkType == 2: # telnet status["Status"] = __Telnet__(cfg["CheckIP"], cfg["CheckPort"]) status["ScanTime"] = datetime.datetime.now().strftime( '%Y-%m-%d %H:%M:%S') linkStatus.append(status) linkStatusDict = {} linkStatusDict["HostIP"] = cfgMgr.localIP linkStatusDict["LinkStatus"] = linkStatus return linkStatusDict
def run(): # 获取日志配置 logCfg = common.GetCfg("logcfg") if not logCfg: return None beginDT = datetime.datetime.now() while True: curDT = datetime.datetime.now() if (curDT - beginDT).seconds > 600: # 10分钟更新一次配置 beginDT = curDT tmpLogCfg = common.GetCfg("logcfg") if tmpLogCfg: logCfg = tmpLogCfg for cfg in logCfg["LogCfg"]: Handle(cfgMgr.localIP, cfg["LogName"], cfg["LogDir"]) time.sleep(30)
def ReadAndSend(): global logCfg if not logCfg or (datetime.datetime.now() - logCfg['lasttime']).seconds > 600: tmplogCfg = common.GetCfg("logcfg") if tmplogCfg: tmplogCfg['lasttime'] = datetime.datetime.now() logCfg = tmplogCfg if logCfg: for cfg in logCfg["LogCfg"]: Handle(cfgMgr.localIP, cfg["LogName"], cfg["LogDir"])