def remove_port(self, config_type, zone_name, port, protocol): """ Remove port and protocol from a zone :param config_type: :param zone_name: :param port: :param protocol: :return: """ cmd = '' if zone_name != '': if config_type == 'permanent': cmd = 'firewall-cmd --permanent --zone=' + zone_name + ' --remove-port=' + port + '/' + protocol else: cmd = 'firewall-cmd --zone=' + zone_name + ' --remove-port=' + port + '/' + protocol else: if config_type == 'permanent': cmd = 'firewall-cmd --permanent' + ' --remove-port=' + port + '/' + protocol else: cmd = 'firewall-cmd' + ' --remove-port=' + port + '/' + protocol result = os.system(cmd) if result == 0: return 'remove port success', True else: log.error(const.REMOVE_PORT_FAILED+port+'&'+protocol) return 'remove port failed', False
def get_ps_io(pid): """ get one process io info :param pid: :return: """ # read_list = commands.getoutput('cat /proc/'+str(p)+'/io |grep "read_bytes"').split(':') # write_list = commands.getoutput('cat /proc/'+str(p)+'/io |grep "^write_bytes"').split(':') # cancelled_list = commands.getoutput('cat /proc/'+str(p)+'/io |grep "cancelled_write_bytes"').split(':') result = [] try: out_list = commands.getoutput('cat /proc/'+pid+'/io').split('\n') read = out_list[len(out_list)-3].split(':')[1] write = out_list[len(out_list)-2].split(':')[1] cancelled = out_list[len(out_list)-1].split(':')[1] ret_dict = { 'pid': pid, 'read_bytes': read, 'write_bytes': write, 'cancelled_write_bytes': cancelled } result.append(ret_dict) return result except Exception as e: log.error(e) return result
def disable_service(self, zone_name, service_name, config_type): """ :param zone_name: :param service_name: :param config_type: :return: """ services_list = self.get_service(config_type) if service_name not in services_list: log.error('invalid service name:'+service_name) return 'error: invalid service name:'+service_name, False cmd = '' if config_type == 'permanent': if zone_name == '': cmd = 'firewall-cmd --permanent --remove-service=' + service_name else: cmd = 'firewall-cmd --permanent --zone=' + zone_name + ' --remove-service=' + service_name else: if zone_name == '': cmd = 'firewall-cmd --remove-service=' + service_name else: cmd = 'firewall-cmd --zone=' + zone_name + ' --remove-service=' + service_name result = os.system(cmd) if result == 0: return 'disable success', True else: log.error(const.DISABLE_SERVICE_FAILED+service_name) return const.DISABLE_SERVICE_FAILED+service_name, False
def add_port(self, config_type, zone_name, port, protocol): """ Add port and protocol to a zone :param config_type: :param zone_name: :param port: :param protocol: :return: """ prot = ('udp', 'tcp') if self.port_isvalid(port) and protocol in prot: log.debug(port) port = self.change_type(port) cmd = '' if zone_name != '': if config_type == 'permanent': cmd = 'firewall-cmd --permanent --zone=' + zone_name + ' --add-port=' + port + '/' + protocol else: cmd = 'firewall-cmd --zone=' + zone_name + ' --add-port=' + port + '/' + protocol else: if config_type == 'permanent': cmd = 'firewall-cmd --permanent' + ' --add-port=' + port + '/' + protocol else: cmd = 'firewall-cmd' + ' --add-port=' + port + '/' + protocol result = os.system(cmd) if result == 0: return 'add port success', True else: log.error(const.ADD_PORT_FAILED+port+'&'+protocol) return 'add port failed', False else: log.error(const.PORT_OR_PROTOCOL_INVALID+port+'&'+protocol) return 'port or protocol is invalid ,please resume load', False
def get_udp_info(cls): """ get udp info :return: """ udp_info = {} try: logger.debug("udp begin:======>") rtinfo = functions.launchcmd('sar -n UDP 1 1').readlines() logger.debug("commands finished! ") if rtinfo: continue_falg = True for item in rtinfo: if continue_falg: if "idgm" in item: continue_falg = False continue tmplist = item.split() udp_info["time"] = tmplist[0] udp_info["idgm/s"] = tmplist[1] udp_info["odgm/s"] = tmplist[2] udp_info["noport/s"] = tmplist[3] udp_info["idgmerr/s"] = tmplist[4] break except IOError, e: logger.error(e.message, e) return False, udp_info
def change_interface_zone(self, config_type, zone_name, interface): """ Change the zone an interface belongs to :param config_type: :param zone_name: :param interface: :return: """ if interface == '' or interface == ' ': log.error('interface is invalid:'+interface) return 'interface is invalid', False if zone_name != '': if config_type == 'permanent': cmd = 'firewall-cmd --permanent --zone=' + zone_name + ' --change-interface=' + interface else: cmd = 'firewall-cmd --zone=' + zone_name + ' --change-interface=' + interface else: if config_type == 'permanent': cmd = 'firewall-cmd --permanent' + ' --change-interface=' + interface else: cmd = 'firewall-cmd' + ' --change-interface=' + interface result = os.system(cmd) if result == 0: return 'change the zone an interface belongs to success', True else: log.error(const.CHANGE_INTERFACE_FAILED+interface+'&'+zone_name) return const.CHANGE_INTERFACE_FAILED+interface+'&'+zone_name, False
def view_kernellogdetail_get(cls, request): """ Get kernel log detail. """ try: offset = int(request.GET['offset']) limit = int(request.GET['limit']) if request.GET['order'] == 'asc': desc = False else: desc = True except Exception: offset = 0 limit = 10 desc = True try: search = request.GET['search'] except Exception: search = None try: # get file detail retstr = cls.view_log_detail(limit, offset, desc, search) return True, retstr except Exception, e: logger.error(e) return False, util.getResult(message.RESULT_TYPE_ERROR, message.FILE_NOT_EXISTS)
def get_socket_info(cls): """ get socket info :return: """ socket_info = {} try: logger.debug("socket begin:======>") rtinfo = functions.launchcmd('sar -n SOCK 1 1').readlines() logger.debug("commands finished! ") if rtinfo: continue_falg = True for item in rtinfo: if continue_falg: if "totsck" in item: continue_falg = False continue tmplist = item.split() socket_info["time"] = tmplist[0] socket_info["totsck"] = tmplist[1] socket_info["tcpsck"] = tmplist[2] socket_info["udpsck"] = tmplist[3] socket_info["rawsck"] = tmplist[4] socket_info["ip-frag"] = tmplist[5] socket_info["tcp-tw"] = tmplist[6] break except IOError, e: logger.error(e.message, e) return False, socket_info
def task_producer(name, body, arguments): """ :param name: queue name :param body: message body :return: """ global connection global channel # credentials = pika.PlainCredentials("inspur", "inspur") # # flag, server = getServerInfo() # flag, ip = getRabbitmqIp() # # ip = server.get("IP") # parameters = pika.ConnectionParameters(host=ip, port=5672, virtual_host="/", credentials=credentials) # # parameters = pika.ConnectionParameters(host="localhost", port=5672, virtual_host="/", credentials=credentials) # connection = pika.BlockingConnection(parameters) # channel = connection.channel() # channel.queue_declare(queue=name, durable=True, auto_delete=True, arguments=arguments) # body = json.dumps(body) # channel.basic_publish(exchange="", routing_key=name, body=body) # connection.close() try: send_message(name, body, arguments) except Exception as e: # logging.error(str(e.message)) credentials = pika.PlainCredentials("inspur", "inspur") flag, ip = getRabbitmqIp() parameters = pika.ConnectionParameters(host=ip, port=5672, virtual_host="/", credentials=credentials) connection = pika.BlockingConnection(parameters) channel = connection.channel() logger.error("in taskmonitor --> " + str(e)) logger.error("in taskmonitor --> " + traceback.print_exc())
def get(self, request, format=None): psMemCpuInfo = {} commands_MEM = "ps -aux|sort -k4nr|grep -v 'USER'|head -n 1" commands_CPU = "ps -aux|sort -k3nr|grep -v 'USER'|head -n 1" try: ps_MEM_info = functions.launchcmd(commands_MEM).readline() ps_CPU_info = functions.launchcmd(commands_CPU).readline() logger.debug("ps_MEM_info ===> " + ps_MEM_info) logger.debug("ps_CPU_info ===> " + ps_CPU_info) psMemCpuInfo["psmeminfo"] = format_process_info(ps_MEM_info) if psMemCpuInfo["psmeminfo"]["pid"].isdigit() and psutil.pid_exists(int(psMemCpuInfo["psmeminfo"]["pid"])): psMemCpuInfo["psmeminfo"]["name"] = psutil.Process(int(psMemCpuInfo["psmeminfo"]["pid"])).name() else: psMemCpuInfo["psmeminfo"]["name"] = "" psMemCpuInfo["pscpuinfo"] = format_process_info(ps_CPU_info) if psMemCpuInfo["pscpuinfo"]["pid"].isdigit() and psutil.pid_exists(int(psMemCpuInfo["pscpuinfo"]["pid"])): psMemCpuInfo["pscpuinfo"]["name"] = psutil.Process(int(psMemCpuInfo["pscpuinfo"]["pid"])).name() else: psMemCpuInfo["pscpuinfo"]["name"] = "" except Exception, exception: logger.error("PsCpuMemInfo error! ===> " + exception.message) return Response(psMemCpuInfo, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def get(self, request, format=None): logger.debug("net begin:") netinfo = {} try: commands_net = "sar -n DEV 1 1" logger.debug(commands_net) net_info_list = subprocess.Popen(commands_net, stdout=subprocess.PIPE, shell=True).stdout.readlines() logger.debug("commands finshed!") rx = 0 tx = 0 for net_info in net_info_list: if -1 != net_info.find(":") or -1 != net_info.find(":"): if -1 == net_info.find("rxkB"): rx = rx + float(net_info.split()[4]) tx = tx + float(net_info.split()[5]) netinfo["rx"] = rx netinfo["tx"] = tx except Exception, exception: logger.error("NetIOInfo error ===> " + exception.message) return Response(netinfo, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def get(self, request, itemid, format=None): """ Get ps list. """ psInfo = [] commands = "" num = 10 if request.GET.get("num"): num = request.GET["num"] if "cpu" == itemid: commands = "pidstat | sort -k7nr |grep -v 'PID' | head -n " + str(num) else: commands = "ps -aux|sort -k4nr|grep -v 'USER'|head -n " + str(num) try: ps_info = functions.launchcmd(commands).readlines() for psitem in ps_info: format_iteminfo = [] if "cpu" == itemid: format_iteminfo = format_pidstat_info(psitem) else: format_iteminfo = format_process_info(psitem) if format_iteminfo["pid"].isdigit() and psutil.pid_exists(int(format_iteminfo["pid"])): format_iteminfo["name"] = psutil.Process(int(format_iteminfo["pid"])).name() else: format_iteminfo["name"] = "" psInfo.append(format_iteminfo) except Exception, exception: logger.error("PsInfo error! ===> " + exception.message)
def read_settings(): """ get server info (IP and port) :return: """ server_settings_path = "{}{}".format(settings.BASE_DIR, '/uniserver.ini') agent_settings_path = "{}{}".format(settings.BASE_DIR, '/uniagent.ini') server = {} try: with open(server_settings_path) as settingsInfo: lines = settingsInfo.readlines() for line in lines: if strip(line).startswith("server_ip="): server['IP'] = strip(line.split('server_ip=')[1]) elif strip(line).startswith("server_port="): server['PORT'] = strip(line.split('server_port=')[1]) elif strip(line).startswith("node_name="): server['ALIAS'] = strip(line.split('node_name=')[1]) with open(agent_settings_path) as agentSettings: alines = agentSettings.readlines() for aline in alines: if strip(aline).startswith("agent_id="): server['AGENTID'] = strip(aline.split('agent_id=')[1]) break except Exception, e: logger.error("read_settings method failed! err_msg : {}".format( str(e.message))) return False, str(e.message)
def command(pid): """ :return: ps -eo result """ res_list = [] # cmd = 'ps -eo pid,etime,stime,flag,nice,sched' cmd = 'ps -p '+pid+' -o pid,etime,stime,flag,nice,sched' res = os.popen(cmd).readlines() for line in res[1:len(res)]: ps_line = line.split() p = int(pid) try: ps_name = psutil.Process(p).name() ps_dict = { 'pid': pid, 'name': ps_name, 'etime': ps_line[1], 'stime': ps_line[2], 'flag': ps_line[3], 'nice': ps_line[4], 'sched': ps_line[5] } except psutil.NoSuchProcess: log.error("ps life cycle error: No such process: "+pid) continue res_list.append(ps_dict) return res_list
def remove_interface(self, config_type, zone_name, interface): """ Remove a interface from a zone :param config_type: :param zone_name: :param interface: :return: """ if interface == '' or interface == ' ': log.error('interface is invalid:'+interface) return 'interface is invalid', False cmd = '' if zone_name != '': if config_type == 'permanent': cmd = 'firewall-cmd --permanent --zone=' + zone_name + ' --remove-interface=' + interface else: cmd = 'firewall-cmd --zone=' + zone_name + ' --remove-interface=' + interface else: if config_type == 'permanent': cmd = 'firewall-cmd --permanent' + ' --remove-interface=' + interface else: cmd = 'firewall-cmd' + ' --remove-interface=' + interface result = os.system(cmd) if result == 0: return 'remove interface success', True else: log.error(const.REMOVE_INTERFACE_FAILED+interface) return 'remove interface failed', False
def upload_file_post(cls, request): """ upload file. :param request: :return: """ try: if request.GET == 0: return False, message.PATH_CONTAIN_ILLEGAL_CHAR up_path = None # only upload to settings.FILETRANS_ROOT_PATH,else return error if request.GET.get('path'): up_path = request.GET['path'] if up_path.find('..') >= 0: return False, message.PATH_CONTAIN_ILLEGAL_CHAR # check file size,range 0-500MB retflg, retstr = common.FilePubServ.check_filesize( request.FILES['file']) if not retflg: return retflg, retstr # delete the file path to get file name retflg, retstr = common.FilePubServ.rule_filename( request.data['fileName']) if not retflg: return retflg, retstr file_name = retstr # check file name retflg, retstr = common.FilePubServ.file_name_validity(file_name) if not retflg: return retflg, retstr # upload file if up_path: file_path = settings.FILETRANS_ROOT_PATH + up_path + '/' else: file_path = settings.FILETRANS_ROOT_PATH retflg, retstr = common.FilePubServ.make_path(file_path) if not retflg: return retflg, retstr fn = file_path + file_name fn = fn.encode(settings.DEFAULT_CHARSET) if fn: if os.path.exists(fn): return False, message.FILE_EXISTS retstr = common.FilePubServ.upload_file( request.FILES['file'], fn) return True, retstr except Exception, e: logger.error("upload failed! : {}".format(str(e))) return False, common.MSG_EXCEPT
def get_throughput_info(cls): """ get throughput info :return: """ throughput_list = {} try: logger.debug("throughput begin:======>") rtinfo = functions.launchcmd('sar -n ALL 1 1').readlines() logger.debug("commands finished! ") if rtinfo: continue_falg = True falg = True for item in rtinfo: throughput_info = {} if continue_falg: if "IFACE" in item: continue_falg = False continue if "rxerr" in item: falg = False continue if "call" in item: break tmplist = item.split() if tmplist is None or tmplist == []: continue if falg: throughput_info["time"] = tmplist[0] throughput_info["name"] = tmplist[1] throughput_info["rxpck/s"] = tmplist[2] throughput_info["txpck/s"] = tmplist[3] throughput_info["rxkB/s"] = tmplist[4] throughput_info["txkB/s"] = tmplist[5] throughput_info["rxcmp/s"] = tmplist[6] throughput_info["txcmp/s"] = tmplist[7] throughput_info["rxmcst/s"] = tmplist[8] throughput_list[tmplist[1]] = throughput_info else: throughput_info = throughput_list[tmplist[1]] throughput_info["rxerr/s"] = tmplist[2] throughput_info["txerr/s"] = tmplist[3] throughput_info["coll/s"] = tmplist[4] throughput_info["rxdrop/s"] = tmplist[5] throughput_info["txdrop/s"] = tmplist[6] throughput_info["txcarr/s"] = tmplist[7] throughput_info["rxfram/s"] = tmplist[8] throughput_info["rxfifo/s"] = tmplist[9] throughput_info["txfifo/s"] = tmplist[10] throughput_list[tmplist[1]] = throughput_info except IOError, e: logger.error(e.message, e) return False, throughput_list
def set_panic_mode(self, mode): """ set the system firewall panic mode:on or off :return: true or false """ cmd = 'firewall-cmd --panic-'+mode result = os.system(cmd) if result == 0: return True else: log.error(const.SET_PANIC_MODE_FAILED+mode) return False
def set_default_zone(self, zone_name): """ set the default zone :return: true or false """ cmd = 'firewall-cmd --set-default-zone='+zone_name result = os.system(cmd) if result == 0: return True else: log.error(const.SET_DEFAULT_ZONE_FAILED+zone_name) return False
def getAgentId(): agent_settings_path = "{}{}".format(settings.BASE_DIR, '/uniagent.ini') agentid = '' try: with open(agent_settings_path) as settingsInfo: lines = settingsInfo.readlines() for line in lines: if strip(line).startswith("agent_id="): agentid = strip(line.split('agent_id=')[1]) except Exception, e: logger.error("getAgentId method failed! err_msg : {}".format( str(e.message))) return False, str(e.message)
def get_iptrafic_info(cls): """ get iptrafic info :return: """ iptrafic_info = {} try: logger.debug("iptrafic begin:======>") rtinfo = functions.launchcmd('sar -n ALL 1 1').readlines() logger.debug("commands finished! ") if rtinfo: continue_falg = True falg = True for item in rtinfo: if continue_falg: if "irec" in item: continue_falg = False continue if "ihdrerr" in item: falg = False continue if "imsg" in item: break tmplist = item.split() if tmplist is None or tmplist == []: continue if falg: iptrafic_info["time"] = tmplist[0] iptrafic_info["irec/s"] = tmplist[1] iptrafic_info["fwddgm/s"] = tmplist[2] iptrafic_info["idel/s"] = tmplist[3] iptrafic_info["orq/s"] = tmplist[4] iptrafic_info["asmrq/s"] = tmplist[5] iptrafic_info["asmok/s"] = tmplist[6] iptrafic_info["fragok/s"] = tmplist[7] iptrafic_info["fragcrt/s"] = tmplist[8] else: iptrafic_info["ihdrerr/s"] = tmplist[1] iptrafic_info["iadrerr/s"] = tmplist[2] iptrafic_info["iukwnpr/s"] = tmplist[3] iptrafic_info["idisc/s"] = tmplist[4] iptrafic_info["odisc/s"] = tmplist[5] iptrafic_info["onort/s"] = tmplist[6] iptrafic_info["asmf/s"] = tmplist[7] iptrafic_info["fragf/s"] = tmplist[8] except IOError, e: logger.error(e.message, e) return False, iptrafic_info
def view_unicornlogdetail_get(cls): """ Get unicorn log detail. """ try: # get file detail retstr = cls.log_unicorn_detail() return True, retstr except Exception, e: logger.error(e) return False, util.getResult(message.RESULT_TYPE_ERROR, message.FILE_NOT_EXISTS)
def get(self, request, format=None): disk_ps_info = {} try: logger.debug("diskinfo begin--------------") net_info_list = functions.launchcmd('iotop -P -b -n 1 | head -n 4').readlines() logger.debug("net_info_list -1 ====== " + net_info_list[-1]) disk_ps_info["psdiskinfo"] = net_info_list[-1].split()[0] logger.debug("psdiskinfo ===> " + disk_ps_info["psdiskinfo"]) if disk_ps_info["psdiskinfo"].isdigit() and psutil.pid_exists(int(disk_ps_info["psdiskinfo"])): disk_ps_info["name"] = psutil.Process(int(disk_ps_info["psdiskinfo"])).name() else: disk_ps_info["name"] = "" except Exception, exception: logger.error("DiskIOInfo error!===>" + exception.message) return Response(disk_ps_info, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def get_firewalld_status(self): """ :return: the firewalld status:running or not running """ status_list = ['running', 'not running'] firewall_status = 1 cmd = 'firewall-cmd --state' result = os.popen(cmd).read().strip('\n') if result.find('not running') > -1: firewall_status = 0 elif result == 'running': firewall_status = 1 else: firewall_status = -1 log.error(const.FIREWALLD_NOT_INSTALL) return firewall_status
def reload_firewall(self, is_complete): """ reload the system firewall :param is_complete: :return: """ cmd = '' if is_complete == 'TRUE': cmd = 'firewall-cmd --complete-reload' else: cmd = 'firewall-cmd --reload' result = os.system(cmd) if result == 0: return True else: log.error(const.RELOAD_FIREWALL_FAILED) return False
def getServerInfo(): server_settings_path = "{}{}".format(settings.BASE_DIR, '/uniserver.ini') server = {} try: with open(server_settings_path) as settingsInfo: lines = settingsInfo.readlines() for line in lines: if strip(line).startswith("server_ip="): server['IP'] = strip(line.split('server_ip=')[1]) elif strip(line).startswith("server_port="): server['PORT'] = strip(line.split('server_port=')[1]) elif strip(line).startswith("node_name="): server['ALIAS'] = strip(line.split('node_name=')[1]) except Exception, e: logger.error("getServerInfo method failed! err_msg : {}".format( str(e.message))) return False, str(e.message)
def postinfo(to, api, domain, port, params, method='POST'): """ use httplib POST api data :param to: :param api: :param domain: :param port: :param params :param method :return: """ httpclient = None obj = None if not httpdstate(): # the server already down return obj try: headers = { 'Content-Type': 'application/json', 'Accept-encoding': 'gzip' } httpclient = httplib.HTTPConnection(domain, port, timeout=to) httpclient.request(method, api, params, headers) # response is a HTTPResponse object response = httpclient.getresponse() # if response.status == 200: # obj = json.loads(response.read()) # else: # logger.debug('method:postinfo response status is not 200 -- {} {} {} {}'.format(method, api, # str(response.status), # response.reason)) obj = response.status return obj except Exception: error_msg0 = str(sys.exc_info()[0]) error_msg1 = str(sys.exc_info()[1]) logger.error("method:postinfo Exception -- {}:{}{} {}{}".format( domain, str(port), api, error_msg0, error_msg1)) finally: if httpclient: httpclient.close() return obj
def get_tcp_info(cls): """ get tcp info :return: """ tcp_info = {} try: logger.debug("tcp begin:======>") rtinfo = functions.launchcmd('sar -n ALL 1 1').readlines() logger.debug("commands finished! ") if rtinfo: continue_falg = True falg = True for item in rtinfo: if continue_falg: if "active" in item: continue_falg = False continue if "atmptf" in item: falg = False continue if "idgm" in item: break tmplist = item.split() if tmplist is None or tmplist == []: continue if falg: tcp_info["time"] = tmplist[0] tcp_info["active/s"] = tmplist[1] tcp_info["passive/s"] = tmplist[2] tcp_info["iseg/s"] = tmplist[3] tcp_info["oseg/s"] = tmplist[4] else: tcp_info["atmptf/s"] = tmplist[1] tcp_info["estres/s"] = tmplist[2] tcp_info["retrans/s"] = tmplist[3] tcp_info["isegerr/s"] = tmplist[4] tcp_info["orsts/s"] = tmplist[5] except IOError, e: logger.error(e.message, e) return False, tcp_info
def enable_service(self, zone_name, service_name, config_type, timeout): """ :param zone_name: :param service_name: :param config_type: :return: """ if service_name == '': return 'service name can not be empty', False cmd = '' if config_type == 'permanent': if zone_name == '': if timeout == '': cmd = 'firewall-cmd --permanent --add-service=' + service_name else: cmd = 'firewall-cmd --permanent --add-service=' + service_name + ' --timeout=' + timeout else: if timeout == '': cmd = 'firewall-cmd --permanent --zone=' + zone_name + ' --add-service=' + service_name else: cmd = 'firewall-cmd --permanent --zone=' + zone_name + ' --add-service=' + service_name + \ ' --timeout=' + timeout else: if zone_name == '': if timeout == '': cmd = 'firewall-cmd --add-service=' + service_name else: cmd = 'firewall-cmd --add-service=' + service_name + \ ' --timeout=' + timeout else: if timeout == '': cmd = 'firewall-cmd --zone=' + zone_name + ' --add-service=' + service_name else: cmd = 'firewall-cmd --zone=' + zone_name + ' --add-service=' + service_name + \ ' --timeout=' + timeout result = os.system(cmd) if result == 0: return 'enable success', True else: log.error(const.ENABLE_SERVICE_FAILED+service_name) return const.ENABLE_SERVICE_FAILED+service_name, False
def heartBeatWithServer(self): agentInfo = {'type': constr.NODE_STATUS, 'token': constr.NODE_TOKEN} flag, agentid = utils.getAgentId() if not (flag and agentid): return agentInfo['id'] = agentid logger.debug("node hb info : {}".format(str(agentInfo))) try: self.channel.basic_publish(exchange='exchangeTest', routing_key='heartBeatKey', body=json.dumps(agentInfo)) except Exception, e: logger.error("heartbeat exception: {}".format(e.message)) credentials = pika.PlainCredentials('inspur', 'inspur') flag, rabbitmq_ip = utils.getRabbitmqIp() # 这里可以连接远程IP,请记得打开远程端口 parameters = pika.ConnectionParameters(rabbitmq_ip, 5672, '/', credentials) self.connection = pika.BlockingConnection(parameters) self.channel = self.connection.channel() pass