First, analysis
For now, there are four ways to collect assets, namely:
- Agent
- SSH classes, such as: Paramiko
- Saltstack
- Puppet (Ruby Development)
For the first three are developed in the Python language, the last one for Ruby, so we will focus on the previous three specific content.
Second, Agent
1. Features and application scenarios:
Applicable to the server, from each server side sends the data to the API interface, the API interacts with the database to complete the data communication, the performance is relatively high, the speed is fast, but each server must install the agent.
2. Usage:
Import Subprocessimport requests# Each server, there is such a py file. V1=subprocess.getoutput (' ipconfig ') #执行Windows命令, return information assigned to v1value=v1[68:88] #字符串切片取值v2 =subprocess.getoutput (' dir ') #同上value2 =v2[0:10]url= "http://127.0.0.1:8000/asset.html" #API接口URLresponse =requests.post (url,data={' K1 ': value, ' K2 ': value2}) #向API通过post方式, data is passed in a dictionary to return an object. Print (Response.text) #打印对象的text信息
Three, SSH class (for example: Paramiko)
1. Features and application scenarios:
Applies to fewer servers,
CMDB Asset Acquisition