Example #1
0
    def execute(self):
        #linux上通过命令获取数据
        server_info = PluginManager().exec_plugin()

        # 【status】数据正确时发送,[basic]基本信息,hostname做为唯一标识
        #只有唯一标识数据正确才会发送到后台处理
        if server_info['basic']['status']:

            hostname = server_info['basic']['data']['hostname']
            certname = open(settings.CERT_PATH, 'r',
                            encoding='utf-8').read().strip()  #读
            #文件为空时,表示第一次写入,则把hostname写入文件,sserver_info['basic']['data']['hostname']未改变
            if not certname:
                with open(settings.CERT_PATH, 'w', encoding='utf-8') as f:  #写
                    f.write(hostname)
            #文件不为空时,表示已写入过,即使hostname有变更,则仍以certname为准 ,
            else:
                server_info['basic']['data']['hostname'] = certname

        #【status】数据错误时,打印错误信息
        for key in list(server_info.keys()):

            if not server_info[key]['status']:
                print('>>', server_info[key]['data'])
        #发送资产信息到api,执行基类下的post_asset()方法
        self.post_asset(server_info)
Example #2
0
    def exe(self):
        obj = PluginManager()
        server_dict = obj.exec_plugin()
        new_hostname = server_dict['basic']['data']['hostname']
        cert_path = os.path.join(settings.BASEDIR, 'conf', 'cert.txt')

        f = open(cert_path, mode='r')
        old_hostname = f.read()
        f.close()

        if not old_hostname:
            """第一次运行"""
            with open(cert_path, mode='w') as ff:
                ff.write(new_hostname)
        else:
            server_dict['basic']['data']['hostname'] = old_hostname
        print('[%s]POST [client info] to server' %
              datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
        # 将client端信息发送给server
        rep = self.post_server_info(server_dict)
        # 查询server端返回结果是否有ssd任务要执行
        task_list = rep.get('task', None)
        # 查询server端返回结果是否有任务要执行
        server_task_list = rep.get('stask', None)
        if task_list:
            self.post_task_res(task_list)
        if server_task_list:
            self.post_stask_res(server_task_list)
Example #3
0
 def exe(self):
     '''
     执行上报client硬件信息
     :return:
     '''
     obj = PluginManager()
     server_dict = obj.exec_plugin()
     server_dict['cert_id'] = self.cert_id
     # 将client端信息发送给server
     rep = self.post_info(server_dict, self.api, 'Client_Info')
Example #4
0
 def process(self):
     """
     获取当前资产信息
     :return:
     """
     server_info = PluginManager().exec_plugin()
     self.post_asset(server_info)
Example #5
0
File: client.py Project: Fosity/SAR
 def execute(self):
     """
     """
     result_info = PluginManager().exec_plugin()
     result_info['hostname']=open(os.path.join(settings.BASEDIR, 'config/certhostname'), 'r', encoding='utf-8').read()
     print(result_info)
     self.post_asset(result_info)
Example #6
0
    def exec(self):
        obj = PluginManager()
        server_dict = obj.exec_plugin()
        new_hostname = server_dict['basic']['data']['hostname']
        cert_path = os.path.join(settings.BASEDIR, 'conf', 'cert')

        f = open(cert_path, mode='r')
        old_hostname = f.read()
        f.close()

        if not old_hostname:
            """第一次运行"""
            with open(cert_path, mode='w') as ff:
                ff.write(new_hostname)
        else:
            server_dict['basic']['data']['hostname'] = old_hostname
        print('采集到的服务器信息:', server_dict)
        self.post_server_info(server_dict)
Example #7
0
File: client.py Project: fat39/cmdb
 def execute(self):
     server_info = PluginManager().exec_plugin()
     hostname = server_info["basic"]["data"]["hostname"]
     certname = open(settings.CERT_PATH, "r",
                     encoding="utf-8").read().strip()
     if not certname:
         with open(settings.CERT_PATH, "w", encoding="utf-8") as f:
             f.write(hostname)
     else:
         server_info["basic"]["data"]["hostname"] = certname
     self.post_asset(server_info)
Example #8
0
    def execute(self):
        server_info = PluginManager().exec_plugin()
        hostname = server_info['basic']['data']['hostname']
        certname = open(settings.CERT_PATH,'r',encoding='utf-8').read().strip()
        if not certname:
            with open(settings.CERT_PATH,'w',encoding='utf-8') as f:
                f.write(hostname)
        else:
            server_info['basic']['data']['hostname'] = certname

        self.post_asset(server_info)
Example #9
0
    def excute(self):
        servier_info = PluginManager().exec_plugin()  # 采集数据

        # 唯一标识符处理
        hostname = servier_info['basic']['data']['hostname']  # 获得主机名,用来验证唯一标识符
        certname = open(settings.CERT_PATH, 'r',
                        encoding='utf-8').read().strip()  # 获得服务器上的文件中的主机名
        if not certname:
            with open(settings.CERT_PATH, 'w',
                      encoding='utf-8') as f:  # 如果文件中不存在该主机名,表示该主机名未初始化,写入文件即可
                f.write(hostname)
        else:
            # 用文件中的主机名覆盖被用户修改过的主机名,防止出现主机重复导致数量叠加错误
            servier_info['basic']['data']['hostname'] = certname

        self.post_asset(servier_info)  # 子类对象调用父类方法来发送数据
Example #10
0
 def tesk(self, host):
     obj = PluginManager(host)
     server_dic = obj.exec_plugin()
     self.post_server_info(server_dic)
Example #11
0
 def exec(self):
     obj = PluginManager()
     server_dic = obj.exec_plugin()
     self.post_server_info(server_dic)
Example #12
0
 def execute(self):
     host_list = self.get_host()
     for host in host_list:
         server_info = PluginManager(host).exec_plugin()
         self.post_asset(server_info)
Example #13
0
 def execute(self):
     server_info = PluginManager().exec_plugin()
     self.post_asset(server_info)
Example #14
0
File: client.py Project: Fosity/SAR
 def execute(self):
     """
     """
     result_info = PluginManager(settings.HOST_NAME).exec_plugin()
     self.post_asset(result_info)
Example #15
0
 def run(self, host):
     server_info = PluginManager(host).exec_plugin()  # 该两种采集方式都需传入主机host信息
     self.post_asset(server_info)
Example #16
0
 def run(self,host):
     server_info = PluginManager(host).exec_plugin()
     self.post_asset(server_info)
Example #17
0
# 启动


from lib.config.settings import settings
from src.plugins import PluginManager
from src.plugins import basic, cpu, disk, memory, nic

if __name__ == '__main__':
    

    res = PluginManager().execute()
    print(res)
    # ssh
    # host_list = ['c1.com', 'c2.com']
    # for host in host_list:
    #     res = PluginManager(host).execute()
    #     print(res)

    # basic.Basic().process()
    # cpu.Cpu().process()
    # memory.Memory().process()
    # disk.Disk().process()
    # nic.Nic().process()