• Day73-CMDB(资产管理采集)的三种实现方式


    # 采集数据
    import subprocess
    import requests
    ret = subprocess.getoutput('ipconfig')
    # print(ret)
    # 正则处理获取想要的数据
    data_dict = {
        'nic':{},
        'disk':{},
        'mem':{},
    }
    # 发送数据
    req = requests.post('https://www.cnblogs.com/wupeiqi/articles/6192986.html',data=data_dict)
    print(req.text)
    1.Agent方式
    #基于paramikko模块,pip3 install paramiko
    #获取未采集的主机名
    import requests
    import paramiko
    ret = requests.get('https://www.cnblogs.com/wupeiqi/articles/6192986.html')
    # 通过paramikko链接远程服务器,执行命令
    # 创建SSH对象
    ssh = paramiko.SSHClient()
    # 允许链接不在know_hosts文件中的主机
    ssh.connect(hostname='xxx',port=8080,username='xxx',password='xxx')
    # 执行命令
    stdin,stdout,stderr = ssh.exec_command('ipconfig')
    # 获取命令结果
    res = stdout.read()
    # 关闭链接
    ssh.close()
    2.SSH类方式
    #1.安装saltstack
    # url:https://repo.saltstack.com/#windows
    # commend:alt-Minion-2018.3.0-Py2-AMD64-Setup.exe /S /master=yoursaltmaster /minion-name=yourminionname
    # Master准备:
    #             a.配置文件,监听本机IP
    #               vim/etx/salt/master
    #               interface:本机IP地址
    #             b.启动master
    #               /etc/init.d/salt-master start
    # Slave准备:
    #              a.配置文件,连接哪个master
    #               vim/etc/salt/minion
    #               master:远程master地址
    #               b.启动slave
    #               /etc/init.d/salt-minion start
    # 1.创建关系
    #       Master:
    #           Accepted Keys
    #           Denied Keys
    #           Unaccepted Keys
    #           c1.com
    #           c2.com
    #           Rejected Keys
    # 2.接受关系
    # 3.执行命令
    #        master:
    #         salt * cmd.run"ifconfig"
    # import  salt.client
    # local = salt.client.localClient()
    # result = local.cmd('*','cmd.run',{'ifconfig'})
    3.SaltStack
    Win a contest, win a challenge
  • 相关阅读:
    USB Device Finder
    Delphi Interfaces
    Why we need interfaces in Delphi
    PostQuitMessage, PostThreadMessage( WM_QUIT )
    state与status的区别
    SQLSERVER监控复制并使用数据库邮件功能发告警邮件
    干货分享:SQLSERVER使用裸设备
    SQLSERVER truncate table之后是否会重置表的自增值
    配置SQL Server去使用 Windows的 Large-Page/Huge-Page allocations
    SQLSERVER 数据库性能的的基本
  • 原文地址:https://www.cnblogs.com/pandaboy1123/p/9028446.html
Copyright © 2020-2023  润新知