hteesa 发表于 2015-3-13 08:42:01

cacti 脚本批量添加 graphs tree

#!/bin/bash
rm -f tree_ip tree_hostname
Rootdir="/usr/share/cacti/cli"
i=0
Add_tree(){
awk '{print $1}' $1 > tree_ip
awk '{print $2}' $1 > tree_hostname
php -q $Rootdir/add_tree.php --list-trees
echo "Please chose Tree ID:"
read id
while read line
       do
               arr_IP[$i]="$line"
               i=`expr $i + 1`
       done < ip
i=0
while read line
       do
               arr_HOSTNAME[$i]="$line"
               i=`expr $i + 1`
       done < hostname
for (( k=0;k<i;k++ ))
       do
               host_ids=`php $Rootdir/add_graphs.php --list-hosts | grep ${arr_IP[$k]} | awk -F " " '{print $1}'`
               php $Rootdir/add_tree.php --host-id="$host_ids" --type=node --node-type=host --tree-id=$id
       done
}
if [[ $# -ne 1 ]];then
       echo -e "Usage:sh$0 list
                list eg:1.1.1.1test@example.com"
      exit -1
fi
Add_tree $1
#php -q add_tree.php --list-trees

页: [1]
查看完整版本: cacti 脚本批量添加 graphs tree