cacti批量新增監控

wang_0720發表於2014-03-11
#!/bin/bash           
#read ip list
PHP=/usr/local/php/bin/php
CLI=/usr/local/apache/htdocs/cacti/cli
host_ips=`cat /usr/local/scripts/ips.txt`    
for host_ip in $host_ips
do
        #add devices   
        ${PHP} ${CLI}/add_device.php --description="$host_ip" --ip="$host_ip" --template=3 --version=2 --community="public"
         
        #obtain device's id    
        host_ids=`${PHP} ${CLI}/add_graphs.php --list-hosts | grep -w "$host_ip" | awk -F " " '{print $1}'`    
         
        #create template's graph 
       for graph_id in `4 11 13`
       do 
               ${PHP} ${CLI}/add_graphs.php --host-id="$host_ids" --graph-type=cg --graph-template-id="$graph_id"
         done
        #create NIC graph
        ${PHP} ${CLI}/add_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"    
        ${PHP} ${CLI}/add_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="eth1"    
       
        #add devices to groups
        ${PHP} ${CLI}/add_tree.php --host-id="$host_ids" --type=node --node-type=host --tree-id=1
done

cat ips.txt
192.168.151.40
192.168.151.23
192.168.151.2
192.168.151.141

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/27181165/viewspace-1107560/,如需轉載,請註明出處,否則將追究法律責任。

相關文章