def process(self): """ 获取当前资产信息 1. 在资产中获取主机名 cert_new 2. 在本地cert文件中获取主机名 cert_old 如果cert文件中为空,表示是新资产 - 则将 cert_new 写入该文件中,发送数据到服务器(新资产) 如果两个名称不相等 - 如果 db=new 则,表示应该主动修改,new为唯一ID - 如果 db=old 则,表示 :return: """ server_info = plugins.get_server_info() if not server_info.status: return local_cert = self.load_local_cert() if local_cert: if local_cert == server_info.data['hostname']: pass else: server_info.data['hostname'] = local_cert else: self.write_local_cert(server_info.data['hostname']) # 发送的数据格式: # {"hostname":"","disk":{"status":"","data":{},"error":"","message":""},"cpu":{}} server_json = Json.dumps(server_info.data) self.post_asset(server_json, self.callback)
def process(self): """ 获取当前资产信息 1。在资产中获取主机名,cert_new 2.在本地cert文件中获取主机名 cert_old 如果cert文件中为空,表示是新资产 则将cert_new写入该文件中,发送数据到服务器(新资产) 如果两个名字不相等 如果db=new, 应主动修改, new为唯一ID :return: """ server_info = plugins.get_server_info() if not server_info.status: return local_cert = self.load_local_cert() if local_cert: if local_cert == server_info.data['hostname']: pass else: server_info.data['hostname'] = local_cert else: self.write_local_cert(server_info.data['hostname']) server_json = Json.dumps(server_info.data) self.post_asset(server_json, self.callback)
def process(self): # 采集资产 # from src.package import pack # data_dict = pack # hostname=self.file_host() # if hostname: # data_dict["hostname"]=hostname # else: # #获取当前主机名 # #写入nid文件 # data_dict["hostname"]="slave1" # 将资产数据发送到API(POST) # self.send_data(data_dict) # 获取指定主机名的资产信息 # {"status":True,"message":None,"error":None,"data":{"disk":<lib.response.BaseResponse object at 0x0}} server_info = plugins.get_server_info() if not server_info.status: return local_cert = self.load_local_cert() if local_cert: if local_cert == server_info.data["hostname"]: pass else: server_info.data["hostname"] = local_cert else: self.write_local_cert(server_info.data["hostname"]) # 序列化成字符串 server_json = Json.dumps(server_info.data) # 发送到API self.post_asset(server_json, self.callback)
def run(self, manager_ip, info_dict): # 获取硬件服务器资产信息 server_info = plugins.get_server_info(manager_ip=manager_ip, info_dict=info_dict) # 序列化获取到的资产 server_json = Json.dumps(server_info.data) # 发送资产数据到api接口 self.post_asset(server_json, self.callback)
def run(self, hostname): # 获取指定主机名的资产信息 # {"status":True,"message":None,"error":None,"data":{"disk":<lib.response.BaseResponse object at 0x0}} server_info = plugins.get_server_info(hostname) # 序列化成字符串 server_json = Json.dumps(server_info.data) # 发送到API self.post_asset(server_json, self.callback)
def run(self, hostname): # 获取指定主机名的资产信息 # {'status': True, 'message': None, 'error': None, 'data': {'disk': <lib.response.BaseResponse object at 0x00000000014686A0>, 'main_board': <lib.response.BaseResponse object at 0x00000000014689B0>, 'nic': <lib.response.BaseResponse object at 0x0000000001478278>, 'memory': <lib.response.BaseResponse object at 0x0000000001468F98>, 'os_platform': 'linux', 'os_version': 'CentOS release 6.6 (Final)', 'hostname': 'c1.com', 'cpu': <lib.response.BaseResponse object at 0x0000000001468E10>}} server_info = plugins.get_server_info(hostname) # 序列化成字符串 server_json = Json.dumps(server_info.data) # 发送到API self.post_asset(server_json, self.callback)
def get_server_info(host_dict): response = BasicPlugin(host_dict).linux() for k, v in PLUGINS_DICT.items(): module_path, cls_name = v.rsplit('.', 1) cls = getattr(importlib.import_module(module_path), cls_name) obj = cls(host_dict).linux() response.data[k] = obj server_json = Json.dumps(response.data) return server_json
def run(self, hostname, module): print(hostname) # ssh salt 方式会链接hostname来进行执行命令 server_info = plugins.get_server_info(hostname) server_info.data['hostname'] = hostname server_json = Json.dumps(server_info.data) print(server_json) if module == 'database': self.post_database(server_json, self.callback) elif module == 'asset': self.post_asset(server_json, self.callback)
def process(self): """ :return: """ server_info = plugins.get_server_info() if not server_info.status: return server_json = Json.dumps(server_info.data) print(server_json) return server_json
def process(self): """ 获取软件服务器资产信息 cmdb数据库中保存的hostname要与Agent端settings文件中设置的HOSTNAME保持一致 :return: """ # 获取资产 server_info = plugins.get_server_info() # 如果获取失败退出此函数 if not server_info.status: return # 序列化获取到的资产 server_json = Json.dumps(server_info.data) # 发送资产数据到api接口 self.post_asset(server_json, self.callback)
def process(self): #获取服务器信息 server_info = plugin.get_server_info() #接根据本地的服务器ID,从而保证在服务器的主机id被修改后,提交数据时是根据本地存储的来方法 if not server_info: return local_cert = self.load_local_cert() if local_cert: if local_cert == server_info.data['hostname']: pass else: server_info.data['hostname'] = local_cert else: self.write_local_cert(server_info.data['hostname']) #接下来是对数据进行序列化,和发送到对应的url server_json = Json.dumps(server_info.data) self.post_asset(server_json, self.callback)
def process(self): """ :return: """ server_info = get_server_info() if not server_info.status: return local_cert = self.load_local_cert() if local_cert: pass else: self.write_local_cert() local_cert = self.load_local_cert() server_info.data.setdefault('unique_id', local_cert) server_json = Json.dumps(server_info.data) print(server_json) self.post_asset(server_json, self.callback)
def process(self): """ 获取资产信息 :return: """ server_info = plugin.get_server_info() # print(server_info.status, server_info.data) if not server_info.status: return local_cert = self.load_local_cert() if local_cert: if local_cert != server_info.data['hostname']: # 如果文件中保存的cert标识与系统hostname不同,则已文件为准 server_info.data['hostname'] = local_cert else: self.write_local_cert(server_info.data['hostname']) data_to_json = Json.dumps(server_info.data) print(data_to_json) self.post_asset(data_to_json, self.callback)
def process(self): ''' 获取当前资产的信息 1,在资产中获取主机名 cert_new 2,在本地cert文件中获取主机名 cert_old :return: ''' server_info = plugins.get_server_info() if not server_info.status: return local_sert = self.load_local_cert() if local_sert: if local_sert == server_info.data['hostname']: pass else: server_info.data['hostname'] = local_sert else: self.write_local_cert(server_info.data['hostname']) server_json = Json.dumps(server_info.data) self.post_asset(server_json, self.callback)
def process(self): server_info = plugins.get_server_info( ) # 这里server_info是一个对象 BaseResponse的实例 对象。 # print(server_info.data) # print(type(server_info.data)) if not server_info.status: # 如果这个值为 false 说明,发成了错误。那就直接返回。不再进行下一步的操作 return local_cert = self.load_local_cert() # 获取到所有的主机名 if local_cert: if local_cert == server_info.data['hostname']: pass else: server_info.data['hostname'] = local_cert # 如果不相等将本地保存的 主机名赋值给他。保证后端接收到的是,这个唯一的主机名 else: self.write_local_cert( server_info.data['hostname']) # 如果当前文件中没有主机名,就写入 server_json = Json.dumps(server_info.data) # 使用自定制的 序列化工具,将对象序列化。 self.post_asset(server_json, self.callback) # 使用父类的方法。发送所有的数据。
def process(self): """ 获取当前资产信息 1. 在资产中获取主机名 cert_new 2. 在本地cert文件中获取主机名 cert_old 如果cert文件中为空,表示是新资产 - 则将 cert_new 写入该文件中,发送数据到服务器(新资产) 如果两个名称不相等 - 如果 db=new 则,表示应该主动修改,new为唯一ID - 如果 db=old 则,表示 :return: """ server_info = plugins.get_server_info() """server_info = { 'status': True, 'message': None, 'data': {'os_platform': 'linux', 'os_version': 'CentOS release 6.6', 'hostname': 'c1.com', 'cpu': {'status': True, 'message': None, 'data': XXOO, 'error': None}, }, 'error': None}""" if not server_info.status: return local_cert = self.load_local_cert() if local_cert: if local_cert == server_info.data['hostname']: pass else: server_info.data['hostname'] = local_cert else: self.write_local_cert(server_info.data['hostname']) server_json = Json.dumps(server_info.data) self.post_asset(server_json, self.callback)
def run(self, hostname): server_info = plugins.get_server_info(hostname) #主机信息(基本信息、指标信息) server_json = Json.dumps(server_info.data) self.post_asset(server_json, self.callback) #以post方式提交数据到服务端
def run(self, hostname): server_info = plugins.get_server_info(hostname) server_json = Json.dumps(server_info.data) self.post_asset(server_json, self.callback)
def process(self): # 获取指定主机名的资产信息 server_info = plugins.get_server_info('hostname') server_json = Json.dumps(server_info.data) return server_json
def run(self, hostname): server_info = plugins.get_server_info(hostname) server_json = Json.dumps(server_info.data) print(server_json)
def run(self, hostname): # ssh salt 方式会链接hostname来进行执行命令 server_info = plugins.get_server_info(hostname) server_json = Json.dumps(server_info.data) self.post_asset(server_json, self.callback)