CMDB Asset Acquisition

Source: Internet
Author: User

Agent (Mode)

1: Each server needs to install agent to achieve fast acquisition speed, simple, resulting in a performance loss gets the asset for each server and has a return value: V=subprocess.getoutput (' dir ') or Ipconfig returned to API  API for storage   (API  1.url  2. Specify the sending data format  3. and has a return value to the client) 2: Scenario: Companies with more services
Client: Import subprocessv1=subprocess.getoutput (' ipconfig ') # print (v1) value1=v1[20:30]  #采集到一套资产v2 = Subprocess.getoutput (' dir ')  #采集到另外一条命令 # Print (v2) value2=v2[0:5] #连接到数据库, write to the database  data to send url= above the URL "http// 127.0.0.1:8000/asset.html "Import requestsresponse=requests.post (url,data={' K1 ': value1, ' K2 ': value2})   # Data sent to the specified URL after sending the data has a return value, received URL to return information print (Response.text)
Server Api:from app01 Import viewsurlpatterns = [    url (R ' ^admin/', admin.site.urls),    url (r ' ^asset.html$ ', Views.asset),]from django.shortcuts import render,httpresponse# Create your views here.def asset (Request):   # Receive messages from users    if Request.method = = "POST":        print (Request. POST)        #并写入数据库        return HttpResponse (' 1002 ')    else:        return HttpResponse (' 1001 ') #

    

Paramiko (SSH mode)

Import Paramiko module by remote execution of a command each server needs to install SSH remote process: The central control machine to the server to collect information, collected information returned to the central control machine and then the central control machine to return the information to the API, API received the message and returned to the central control machine to collect the asset information placed in the central control Machine (Paramiko module) v=subprocess.getoutget (' ipconfig ') to get the central control machine acquisition information in the control machine in the information returned to the API, API in the storage advantages: no agent disadvantage: Network Slow application scenario: Fewer servers of the company
############## Paramiko, central control machine put a copy #############"""-remotely connect to the server, execute commands, get results-Send results API"""ImportParamiko#To create an SSH objectSsh=Paramiko. Sshclient ()#allow connections to hosts that are not in the Know_hosts fileSsh.set_missing_host_key_policy (Paramiko. Autoaddpolicy ())#connecting to a serverSsh.connect (hostname='192.168.24.129', port=22,username='Root', password='123456')#Execute CommandStdin,stdout,stderr = Ssh.exec_command ('ls')#indicates that it is going to connect, to execute commands on the connection#Get command Resultsresult =Stdout.read ()#Close Connectionssh.close ()#and get the results .Value=result[0:10]Print(value)ImportRequestsurl="http://127.0.0.1:8000/asset.html"Response=requests.post (url,data={'K1': Value,'K2':'v2'})Print(Response.text)
SSH Remote Connection
 fromApp01ImportViewsurlpatterns=[url (r'^admin/', admin.site.urls), url (r'^asset.html$', Views.asset),] fromDjango.shortcutsImportRender,httpresponse#Create your views here.defAsset (Request):#receive messages from users    ifRequest.method = ="POST":        Print(Request. POST)#and write to the database        returnHttpResponse ('1002')    Else:        returnHttpResponse ('1001')#
API

Saltstack

1. Installation and Configuration

""" 1. Installing the Salt-master    Yum install salt-master2. Modify the configuration file: Vim/etc/salt/master    interface:0.0.0.0    # Represents the IP local IP3 of master. Start the    service Salt-master restart (remember to shut down the firewall systemctl stop firewalld)"" "
Master
""" 1. Install salt-minion    Yum installation salt-minion2. Modify           The address of the configuration file vim/etc/salt/minion master:10.211.55.4 # Master    or    Master:        -10.211.55.4        -10.211.55.5    random_master:true    id:c2.salt.com                    # The unique ID3 that the client displays in Salt-master. Start    service salt-minion Restart remember to shut down the firewall systemctl stop firewalld)"" "
Minion

2. Authorization

-key--key-A Manual authorization Salt-key-r  salve_id      #  deny Salve Salt-key of the specified ID  -D salve_id      #  Delete Salve of the specified ID
Master

3. Execution of commands

Remote operation of the salve on the master server

' c2.salt.com ' cmd.run  'ifconfig'salt'ls'
Shell-based command
Import== local.cmd ('c2.salt.com'cmd.run ', ['ifconfig'])
Salt-based API

CMDB Asset Acquisition

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.