#!/bin/bash
st=172.18.16.6
en=172.18.16.7
cli_dir=/data/htdocs/cacti/cli
php=/usr/local/php/bin/php
function check_ip ()
{
if [ `echo ${st} |cut -d "." -f 1-3` != `echo ${en} |cut -d "." -f 1-3` ]
then
echo "请保持IP段一致"
exit 1
fi
}
function add_host ()
{
IP_addr=$(echo ${st}|cut -d "." -f 1-3)
IP_st=$(echo ${st} | awk -F. '{print $4}')
IP_en=$(echo ${en} | awk -F. '{print $4}')
cd ${cli_dir}
for addr in $(seq ${IP_st} ${IP_en})
do
host=${IP_addr}.${addr}
#echo $host
#添加主机和主机模板类型 //可通过php add_device.php --list-host-templates 查看现有模板信息
$php $cli_dir/add_device.php --description=$host --ip=$host --template=7 --version=2 --community=ipanel
#提取主机host_id //可通过php add_graphs.php --list-hosts 查看现有主机信息
host_id=`php ${cli_dir}/add_graphs.php --list-hosts|grep -w $host |awk -F" " '{print $1}'`
#echo ${host_id}
#通过hosts_id添加图形模板 //可通过php add_graphs.php --list-graph-templates 查看现有图形模板信息
$php $cli_dir/add_graphs.php --host-id=${host_id} --graph-type=cg --graph-template-id=4
$php $cli_dir/add_graphs.php --host-id=${host_id} --graph-type=cg --graph-template-id=11
$php $cli_dir/add_graphs.php --host-id=${host_id} --graph-type=cg --graph-template-id=13
$php $cli_dir/add_graphs.php --host-id=${host_id} --graph-type=cg --graph-template-id=28
$php $cli_dir/add_graphs.php --host-id=${host_id} --graph-type=cg --graph-template-id=29
$php $cli_dir/add_graphs.php --host-id=${host_id} --graph-type=cg --graph-template-id=35
#添加网卡
#添加磁盘
#添加到tree //可通过php add_tree.php --list-trees 查看现有trees信息
$php $cli_dir/add_tree.php --host-id=${host_id} --type=node --node-type=host --tree-id=2
done
}
check_ip
add_host
st=172.18.16.6
en=172.18.16.7
cli_dir=/data/htdocs/cacti/cli
php=/usr/local/php/bin/php
function check_ip ()
{
if [ `echo ${st} |cut -d "." -f 1-3` != `echo ${en} |cut -d "." -f 1-3` ]
then
echo "请保持IP段一致"
exit 1
fi
}
function add_host ()
{
IP_addr=$(echo ${st}|cut -d "." -f 1-3)
IP_st=$(echo ${st} | awk -F. '{print $4}')
IP_en=$(echo ${en} | awk -F. '{print $4}')
cd ${cli_dir}
for addr in $(seq ${IP_st} ${IP_en})
do
host=${IP_addr}.${addr}
#echo $host
#添加主机和主机模板类型 //可通过php add_device.php --list-host-templates 查看现有模板信息
$php $cli_dir/add_device.php --description=$host --ip=$host --template=7 --version=2 --community=ipanel
#提取主机host_id //可通过php add_graphs.php --list-hosts 查看现有主机信息
host_id=`php ${cli_dir}/add_graphs.php --list-hosts|grep -w $host |awk -F" " '{print $1}'`
#echo ${host_id}
#通过hosts_id添加图形模板 //可通过php add_graphs.php --list-graph-templates 查看现有图形模板信息
$php $cli_dir/add_graphs.php --host-id=${host_id} --graph-type=cg --graph-template-id=4
$php $cli_dir/add_graphs.php --host-id=${host_id} --graph-type=cg --graph-template-id=11
$php $cli_dir/add_graphs.php --host-id=${host_id} --graph-type=cg --graph-template-id=13
$php $cli_dir/add_graphs.php --host-id=${host_id} --graph-type=cg --graph-template-id=28
$php $cli_dir/add_graphs.php --host-id=${host_id} --graph-type=cg --graph-template-id=29
$php $cli_dir/add_graphs.php --host-id=${host_id} --graph-type=cg --graph-template-id=35
#添加网卡
#添加磁盘
#添加到tree //可通过php add_tree.php --list-trees 查看现有trees信息
$php $cli_dir/add_tree.php --host-id=${host_id} --type=node --node-type=host --tree-id=2
done
}
check_ip
add_host