- #!/bin/bash
- ip=('192.168.1.1' '192.168.1.2')
- tree=('test' 'test')
- function f_add_LinuxHost()
- {
- /usr/local/php/bin/php /usr/local/nginx/html/cacti/cli/add_device.php --description="$1" --ip="$1" --template=3 --version=2 --community=public > /tmp/cacti_cache.txt
- id=`cat /tmp/cacti_cache.txt | grep "Success" | awk -F "[:()]" '{print $3}'`
- /bin/rm -f /tmp/cacti_cache.txt
- }
- function f_add()
- {
- host_id=$1
- graph_type=$2
- graph_template_id=$3
- snmp_query_id=$4
- snmp_query_type_id=$5
- snmp_field=$6
- snmp_value=$7
- case $graph_type in
- ds)
- /usr/local/php/bin/php /usr/local/nginx/html/cacti/cli/add_graphs.php --host-id="$host_id" --graph-type="$graph_type" --graph-template-id="$graph_template_id" --snmp-query-id="$snmp_query_id" --snmp-query-type-id="$snmp_query_type_id" --snmp-field="$snmp_field" --snmp-value="$snmp_value"
- ;;
- cg)
- /usr/local/php/bin/php /usr/local/nginx/html/cacti/cli/add_graphs.php --host-id="$host_id" --graph-type="$graph_type" --graph-template-id="$graph_template_id"
- ;;
- *)
- echo "function parameter error!"
- ;;
- esac
- }
- function f_add_tree()
- {
- tree_id=`/usr/local/php/bin/php /usr/local/nginx/html/cacti/cli/add_tree.php --list-trees | egrep "\b$2\b" | awk '{print $1}'`
- if [ -z $tree_id ];then
- /usr/local/php/bin/php /usr/local/nginx/html/cacti/cli/add_tree.php --type=tree --name="$2"
- tree_id=`/usr/local/php/bin/php /usr/local/nginx/html/cacti/cli/add_tree.php --list-trees | egrep "\b$2\b" | awk '{print $1}'`
- fi
- /usr/local/php/bin/php /usr/local/nginx/html/cacti/cli/add_tree.php --type=node --node-type=host --tree-id="$tree_id" --host-id="$1"
- }
- for (( i=0; i<${#ip[@]}; i++ ))
- do
- f_add_LinuxHost ${ip[i]}
- f_add $id ds 2 1 14 ifName eth0
- f_add $id ds 2 1 14 ifName eth1
- f_add $id ds 3 2 6 dskDevice "/dev/sda3"
- f_add $id cg 4
- f_add $id cg 7
- f_add $id cg 11
- f_add $id cg 13
- f_add_tree $id ${tree[i]}
- done
f_add_LinuxHost ${ip[i]} #添加主机
f_add $id ds 2 1 14 ifName eth0 #添加网卡监控
f_add $id ds 2 1 14 ifName eth1 #添加网卡监控
f_add $id ds 3 2 6 dskDevice "/dev/sda3" #添加硬盘监控
f_add $id cg 4 #添加CPU监控
f_add $id cg 7 #添加ping监控
f_add $id cg 11 #添加load监控
f_add $id cg 13 #添加mem监控
f_add_tree $id ${tree[i]} #添加树并加入节点
本文转自运维笔记博客51CTO博客,原文链接http://blog.51cto.com/lihuipeng/778476如需转载请自行联系原作者
lihuipeng