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)
#基于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()
#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'})
Win a contest, win a challenge
posted on 2018-05-12 13:11 pandaboy1123 阅读(203) 评论(0) 编辑 收藏 举报