#!/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
#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/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/27181165/viewspace-1107560/