class Supervise(object): hostServicesMap = {} hostServiceStatue = {} ''' (1)全局共享变量--记录各个服务的检测状态,结构{"host":[{serviceName:状态},{serviceName:状态}]} (1)获取当前主机的服务列表 (2)创建对应的task并添加到task中 ''' def __init__(self): self.dao = BichonDao() self.taskScheduler = TimeScheduler() servers = self.dao.selectServer() for server in servers: service = self.dao.selectService(server.id) Supervise.hostServicesMap.setdefault(server.host, service) self.initScheduler() '''之后实现''' def initScheduler(self): pass '''获取服务的检测状态''' @staticmethod def getServiceStatue(hostKey): return Supervise.hostServiceStatue.get(hostKey)
def __init__(self): self.dao = BichonDao() self.taskScheduler = TimeScheduler() servers = self.dao.selectServer() for server in servers: service = self.dao.selectService(server.id) Supervise.hostServicesMap.setdefault(server.host, service) self.initScheduler()
def __init__(self): BaseLoggingObj.__init__(self) self.bichondao = BichonDao() try: self.initAllServer() except Exception, e: self.logging.error("brokers init false!")
def __init__(self): self.dao = BichonDao()
class CheckService(object): checkStatue = {} def __init__(self): self.dao = BichonDao() def processCheck(self, hostKey, processName): broker = BrokerService.getBroker(hostKey) return broker.processCheck(processName) def portCheck(self, hostKey, port): broker = BrokerService.getBroker(hostKey) return broker.portCheck(port) def urlCheck(self, host, port, resource): return LocalCheck.httpCheck(host, port, resource=resource) @lock def check(self, host, name, port): """mysql check""" psData = self.processCheck(host.encode("utf-8"), name.encode("utf-8")) portData = self.portCheck(host.encode("utf-8"), port.encode("utf-8")) if (len(portData) >= 1) and (len(psData) >= 4): return True else: return False def checkInstalled(self, hostKey, softName): broker = BrokerService.getBroker(hostKey) data = broker.execCmd("service " + softName + " status") if "unrecognized" in data[1]: d = broker.execCmd("which " + softName) if d[0] != 0: return False else: return True else: return True def mysqlCheck(self, host, name="mysql", port="3306"): """mysql check""" return self.check(host, name, port) def nginxCheck(self, host, port, name="nginx"): """mysql check""" return self.check(host, name, port) def checkSoftInstallStatus(self, hostKey): softs = self.dao.selectAllSoft()[0] data = [] for s in softs: d = {} statue = self.checkInstalled(hostKey, s["serviceName"]) d["name"] = s["serviceName"] d["statue"] = statue data.append(d) return data def checkServiceRunning(self, hostKey, serviceName): broker = BrokerService.getBroker(hostKey) data = broker.execCmd("service " + serviceName + " status") if "unrecognized" in data[1] or "is not running" in data[1]: return False else: return True def iptablesList(self, hostKey): broker = BrokerService.getBroker(hostKey) data = broker.execCmd("iptables -L") return data
class CheckService(object): checkStatue = {} def __init__(self): self.dao = BichonDao() def processCheck(self, hostKey, processName): broker = BrokerService.getBroker(hostKey) return broker.processCheck(processName) def portCheck(self, hostKey, port): broker = BrokerService.getBroker(hostKey) return broker.portCheck(port) def urlCheck(self, host, port, resource): return LocalCheck.httpCheck(host, port, resource=resource) @lock def check(self, host, name, port): '''mysql check''' psData = self.processCheck(host.encode("utf-8"), name.encode("utf-8")) portData = self.portCheck(host.encode("utf-8"), port.encode("utf-8")) if (len(portData) >= 1) and (len(psData) >= 4): return True else: return False def checkInstalled(self, hostKey, softName): broker = BrokerService.getBroker(hostKey) data = broker.execCmd("service " + softName + " status") if "unrecognized" in data[1]: d = broker.execCmd("which " + softName) if d[0] != 0: return False else: return True else: return True def mysqlCheck(self, host, name="mysql", port="3306"): '''mysql check''' return self.check(host, name, port) def nginxCheck(self, host, port, name="nginx"): '''mysql check''' return self.check(host, name, port) def checkSoftInstallStatus(self, hostKey): softs = self.dao.selectAllSoft()[0] data = [] for s in softs: d = {} statue = self.checkInstalled(hostKey, s["serviceName"]) d["name"] = s["serviceName"] d["statue"] = statue data.append(d) return data def checkServiceRunning(self, hostKey, serviceName): broker = BrokerService.getBroker(hostKey) data = broker.execCmd("service " + serviceName + " status") if "unrecognized" in data[1] or "is not running" in data[1]: return False else: return True def iptablesList(self, hostKey): broker = BrokerService.getBroker(hostKey) data = broker.execCmd("iptables -L") return data
path = request.values.get("path") data=fileService.readFile(host,path) return jsonify(data=data, error=False, msg="") @app.route("/updateConfig",methods=['GET', 'POST']) def updateConfig(): host = request.values.get("host") data = request.values.get("data") path = request.values.get("path") data=fileService.overwriteFile(host,path,data) return jsonify(data=data, error=False, msg="") if __name__ == '__main__': dao = BichonDao() cpu = CpuService() mem = MemService() disk = FileSystemService() process = ProcessService() check = CheckService() net = NetService() iptable=IptableService() execService=ExecService() fileService=FileService() taskHelper = TaskHelper() app.run(debug=True)