CACTI System Bulk Add Device Script
" features ":
Automatically add device, automatically generate template image;
Automatically generate data images for remote fetching;
Automatically added to the appropriate group.
" ready to Work ":
1. Start the client SNMPD service and set the snmpd.conf file:
/etc/init.d/snmpdstart; Chkconfig snmpd on
[email protected]. ssh]# cat/etc/snmp/snmpd.conf
Com2sec notconfiguser Default Public
Group Notconfiggroup v1 Notconfiguser
Group Notconfiggroup v2c Notconfiguser
View SystemView included. 1.3.6.1.2.1.1
View SystemView included. 1.3.6.1.2.1.25.1.1
Access Notconfiggroup "" Any noauth exact none none
Group Myrwgroup any local
Group Myrogroup any mynetwork
View all included. 1 80
Access Myrogroup "" Any Noauth 0 all none None
Access Myrwgroup "" Any Noauth 0 all all
Syslocation Ser02 (edit/etc/snmp/snmpd.conf)
Syscontact Root <[email protected]> (configure/etc/snmp/snmp.conf)
Pass. 1.3.6.1.4.1.4413.4.1/usr/bin/ucd5820stat
2. Verify client SNMP traffic on the cacti server:
Snmpwalk-v 2c-c Public 172.30.10.1 (if exception, replace the above configuration with client snmpd.conf configuration)
3. Be familiar with the cacti provided by the add device, graphs and other PHP scripts:
Cacti provides a number of PHP scripts that can be completed by calling to add batch work.
The script is stored in the following path:/VAR/WWW/HTML/CLI
-rw-r--r--. 1 Apache Apache 7372 Apr add_data_query.php
-rw-r--r--. 1 Apache Apache 11403 APR 2012add_device.php
-rw-r--r--. 1 Apache Apache 18738 Apr 2012add_graphs.php
-rw-r--r--. 1 Apache Apache 5940 APR add_graph_template.php
-rw-r--r--. 1 Apache Apache 6876 APR add_perms.php
-rw-r--r--. 1 Apache Apache 9887 Apr add_tree.php
" script Description ":
[Storage Path]:/VAR/WWW/HTML/CLI
[Device list file]:/var/www/html/cli/ips.txt
[File format]:
Cat Ips.txt
Ser01 172.30.10.1
Ser02 172.30.10.2
[Script file]: /var/www/html/cli/addhost.sh
#!/bin/bash#cacti Batch plus monitor # read IP list myfile=/var/www/html/cli/ips.txtwhile read host_info do host_name=$ (echo $host _info |awk ' {print $1} ') host_ip=$ (Echo $host _info |awk ' {print $2} ') #添加cacti设备 phpadd_ device.php --description= "$host _name" --ip= "$host _ip"--ping_method=icmp --template=8 -- version=2 --community= "Public" #读取设备ID (gerp -w for exact match, otherwise all keywords that contain the IP to be queried are listed, result in getting multiple Host-id, the program does not perform properly) host_ids= ' php add_graphs.php --list-hosts |grep -w $host _ip |awk ' {print$1} ' #创建模板图像 phpadd_graphs.php -- Host-id= "$host _ids" --graph-type=cg--graph-template-id=4 php add_ Graphs.php--host-id= "$host _ids" --graph-type=cg --graph-template-id=7 phpadd_ Graphs.php --host-id= "$host _ids" --graph-type=cg--graph-Template-id=8 phpadd_graphs.php --host-id= "$host _ids" --graph-type= Cg--graph-template-id=9 phpadd_graphs.php --host-id= "$host _ids" --graph-type= Cg--graph-template-id=10 phpadd_graphs.php --host-id= "$host _ids" --graph-type= Cg--graph-template-id=11 phpadd_graphs.php --host-id= "$host _ids" --graph-type= Cg--graph-template-id=12 phpadd_graphs.php --host-id= "$host _ids" --graph-type= Cg--graph-template-id=21 phpadd_graphs.php --host-id= "$host _ids" --graph-type= Cg--graph-template-id=41 phpadd_graphs.php --host-id= "$host _ids" --graph-type= cg--graph-template-id=271 #创建网卡数据图像 phpadd_graphs.php --host-id= "$host _ IDs " --graph-type=ds --graph-template-id=2 --snmp-query-id=1--snmp-query-type-id=16 --snmp-field=ifdescr --snmp-value= "Eth0" #创建分区数据图像 phpadd_graphs.php --host-id= "$host _ids" --graph-type=ds --graph-template-id=26 --snmp-query-id=8--snmp-query-type-id=18 --snmp-field=hrstoragedescr -- Snmp-value= "/" phpadd_graphs.php --host-id= "$host _ids" --graph-type=ds - -graph-template-id=26 --snmp-query-id=8--snmp-query-type-id=18 --snmp-field=hrstoragedescr -- Snmp-value= "Memory buffers" phpadd_graphs.php --host-id= "$host _ids" -- graph-type=ds --graph-template-id=26 --snmp-query-id=8--snmp-query-type-id=18 -- Snmp-field=hrstoragedescr --snmp-value= "PhysicalMemory" phpadd_graphs.php --host-id= "$host _ids" --graph-type=ds --graph-template-id=26 --snmp-query-id=8-- Snmp-query-type-id=18 --snmp-field=hrstoragedescr --snmp-value= "Swapspace" # Add a device to the appropriate group phpadd_tree.php&Nbsp;--host-id= "$host _ids" --type=node --node-type=host--tree-id=9done < $MYFILE ##--Script End--##
Parameter description:
PHP add_device.php Usage Notes:
This is the add device where--templates is the application's host template, which can be viewed through add_device.php–list-host-templates, followed by the SNMP parameters
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/7C/9B/wKiom1bToVLiSffHAABcbzZmksQ896.png "style=" float: none; "title=" Cacti1.png "alt=" Wkiom1btovlisffhaabcbzzmksq896.png "/>
add_graphs.php Usage Note:
This is a drawing script, you can see what graphics templates are available through add_graphs.php--list-templates, you can view the drawing template from the manual add monitoring drawing, and then confirm the template ID
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/7C/9B/wKiom1bToVLx5cilAABU-nllwHs827.png "title=" Cacti2.png "style=" Float:none; "alt=" Wkiom1btovlx5cilaabu-nllwhs827.png "/>
Execute the program:
Notice and warning ignore, see below have successfully added information can.
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/7C/9A/wKioL1bTpB2yn8VdAAB4H6DcSBw424.png "style=" float: none; "title=" Cacti3.png "alt=" Wkiol1btpb2yn8vdaab4h6dcsbw424.png "/>
Confirm with cacti system devices, whether or not to add success.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/7C/9B/wKiom1bTo6jCy6VCAAEUUPZnQxc351.png "title=" Cacti4.png "style=" Float:none; "alt=" Wkiom1bto6jcy6vcaaeuupznqxc351.png "/>
The bulk of the work to add to the end of the basic, please check the actual situation to confirm each host.
This article is from the "IT Operations Experience consolidation" blog, please be sure to keep this source http://milton.blog.51cto.com/833904/1745891
CACTI System Bulk Add Device Script