Add Host cacti bulk flow diagram

[root@iZ2zecs4lwn56p5g1e7c63Z cli]# php add_device.php 
Cacti Add Device Utility, Version 1.2.7 (DB: 1.2.7), Copyright (C) 2004-2019 The Cacti Group

usage: add_device.php --description=[description] --ip=[IP] --template=[ID] [--notes="[]"] [--disable]
    [--poller=[id]] [--site=[id] [--external-id=[S]] [--proxy] [--threads=[1]
    [--avail=[ping]] --ping_method=[icmp] --ping_port=[N/A, 1-65534] --ping_timeout=[N] --ping_retries=[2]
    [--version=[0|1|2|3]] [--community=] [--port=161] [--timeout=500]
    [--username= --password=] [--authproto=] [--privpass= --privproto=] [--context=] [--engineid=]
    [--quiet]

Required:
    --description  the name that will be displayed by Cacti in the graphs
    --ip           self explanatory (can also be a FQDN)

Optional:
    --proxy        if specified, allows adding a second host with same ip address
    --template     0, is a number (read below to get a list of templates)
    --location     '', The physical location of the Device.
    --notes        '', General information about this host.  Must be enclosed using double quotes.
    --external-id  '', An external ID to align Cacti devices with devices from other systems.
    --disable      0, 1 to add this host but to disable checks and 0 to enable it
    --poller       0, numeric poller id that will perform data collection for the device.
    --site         0, numeric site id that will be associated with the device.
    --threads      1, numeric number of threads to poll device with.
    --avail        pingsnmp, [ping][none, snmp, pingsnmp, pingorsnmp]
    --ping_method  tcp, icmp|tcp|udp
    --ping_port    '', 1-65534
    --ping_retries 2, the number of time to attempt to communicate with a host
    --ping_timeout N, the ping timeout in milliseconds.  Defaults to database setting.
    --version      1, 0|1|2|3, snmp version.  0 for no snmp
    --community    '', snmp community string for snmpv1 and snmpv2.  Leave blank for no community
    --port         161
    --timeout      500
    --username     '', snmp username for snmpv3
    --password     '', snmp password for snmpv3
    --authproto    '', snmp authentication protocol for snmpv3
    --privpass     '', snmp privacy passphrase for snmpv3
    --privproto    '', snmp privacy protocol for snmpv3
    --context      '', snmp context for snmpv3
    --engineid     '', snmp engineid for snmpv3
    --max_oids     10, 1-60, the number of OIDs that can be obtained in a single SNMP Get request

List Options:
    --list-host-templates
    --list-communities
    --quiet - batch mode value return

[root@iZ2zecs4lwn56p5g1e7c63Z cli]# 

[root@iZ2zecs4lwn56p5g1e7c63Z cli]# php add_graphs.php 
Cacti Add Graphs Utility, Version 1.2.7 (DB: 1.2.7), Copyright (C) 2004-2019 The Cacti Group

usage: add_graphs.php --graph-type=[cg|ds] --graph-template-id=[ID]
    --host-id=[ID] [--graph-title=title] [graph options] [--force] [--quiet]

Cacti utility for creating graphs via a command line interface.  This utility can
create both Data Query (ds) type Graphs as well as Graph Template (cg) type graphs.

For Non Data Query (cg) Graphs:
    [--input-fields="[data-template-id:]field-name=value ..."] [--force]

    --input-fields  If your data template allows for custom input data, you may specify that
                    here.  The data template id is optional and applies where two input fields
                    have the same name.
    --force         If you set this flag, then new cg graphs will be created, even though they
                    may already exist

For Data Query (ds) Graphs:
    --snmp-query-id=[ID] --snmp-query-type-id=[ID] --snmp-field=[SNMP Field] 
                         --snmp-value=[SNMP Value] | --snmp-value-regex=[REGEX]
    [--graph-title=S]       Defaults to what ever is in the Graph Template/Data Template.
    [--reindex-method=N]    The reindex method to be used for that data query.
                            NOTE: If Data Query is already associated, the reindex method will NOT be changed.

    Valid --reindex-methos include
        0|None   = No reindexing
        1|Uptime = Uptime goes Backwards (Default)
        2|Index  = Index Count Changed
        3|Fields = Verify all Fields

    NOTE: You may supply multiples of the --snmp-field and --snmp-value | --snmp-value-regex arguments.

List Options:
    --list-hosts
    --list-graph-templates [--host-template-id=[ID]]
    --list-input-fields --graph-template-id=[ID]
    --list-snmp-queries
    --list-query-types  --snmp-query-id [ID]
    --list-snmp-fields  --host-id=[ID] [--snmp-query-id=[ID]]
    --list-snmp-values  --host-id=[ID] [--snmp-query-id=[ID]] --snmp-field=[Field]

[root@iZ2zecs4lwn56p5g1e7c63Z cli]# 
[root@iZ2zecs4lwn56p5g1e7c63Z cli]# php add_tree.php 
Cacti Add Tree Utility, Version 1.2.7 (DB: 1.2.7), Copyright (C) 2004-2019 The Cacti Group

usage: add_tree.php  --type=[tree|node] [type-options] [--quiet]

Tree options:
    --name=[Tree Name]
    --sort-method=[manual|alpha|natural|numeric]

Node options:
    --node-type=[header|site|host|graph]
    --tree-id=[ID]
    [--parent-node=[ID] [Node Type Options]]

Header node options:
    --name=[Name]

Site node options:
    --site-id=[ID]
Host node options:
    --host-id=[ID]
    [--host-group-style=[1|2]]
    (host group styles:
     1 = Graph Template,
     2 = Data Query Index)

Graph node options:
    --graph-id=[ID]

List Options:
    --list-sites
    --list-hosts
    --list-trees
    --list-nodes --tree-id=[ID]
    --list-graphs --host-id=[ID]
[root@iZ2zecs4lwn56p5g1e7c63Z cli]# 
#! / bin / bash 
#cacti batch add monitoring 
# script path / var / the WWW / HTML / Cacti / cli / 
# read a list of IP 
MYFILE = / var / the WWW / HTML / Cacti / cli / ips.txt
 the while the Read host_info
   do 
  host_name = $ ( echo | $ host_info awk  ' {}. 1 Print $ ' ) 
  host_ip = $ ( echo $ host_info | awk  ' {} Print $ 2 ' ) 
   # adding cacti apparatus 
   PHP add_device.php --description = " $ host_name " - = -ip " $ host_ip "= = ICMP --template --ping_method 0 --version = 2 --community = " gsws " 
   # reading device ID (gerp an exact match for the -w, otherwise it will list all the query contains the keyword ip, leading to obtain a plurality of host- ID , the program can not be executed properly) 
   host_ids = `PHP-add_graphs.php the hosts --list | grep - W $ host_ip | awk  ' {}. 1 Print $ ' ` 
   # Create a template image 
   #php add_graphs.php --host - the above mentioned id = " $ host_ids " --graph-CG of the type = --graph-template- the above mentioned id = 36 
   # card data to create an image 
   PHP add_graphs.php --host- the above mentioned id="$host_ids" --graph-type=ds --graph-template-id=41 --snmp-query-id=4 --snmp-query-type-id=16 --snmp-field=ifOperStatus --snmp-value="Up"
   #添加设备到相应的组
   if [[ $host_name =~ "BGP" ]]
   then
   php add_tree.php --host-id="$host_ids" --type=node --node-type=host --tree-id=4
   elif [[ $host_name =~ "24小时" ]]
   then
   php add_tree.php --host-id="$host_ids" --type=node --node-type=host --tree-id=2
   elif [[ $host_name =~ "海外" ]]
   then
   php add_tree.php --host-id="$host_ids" --type=node --node-type=host --tree-id=3
   elif [[ $host_name =~ "单线" ]]
   then
   php add_tree.php --host-id="$host_ids" --type=node --node-type=host --tree-id=5
   else
   php add_tree.php --host-id="$host_ids" --type=node --node-type=host --tree-id=6
   fi  
done < $MYFILE   
##--脚本结束--##

Script which need to fill in ID, use the above command can be found, fill in according to their own environment.

Ips.txt file content and form are as follows:

Hostname 1 IP1

Hostname 2 IP2

Guess you like

Origin www.cnblogs.com/qiufengluolei/p/11922343.html