您的位置:首页 > 运维架构

一键添加cacti监控脚本

2012-02-10 14:52 295 查看
看到朋友的一篇文章介绍了此东东,修改了一下测试可用:

#!/bin/bash

ip=('192.168.1.1' '192.168.1.2' '192.168.1.3' '192.168.1.4' )

tree=('test1' 'test2' 'test3' 'test4')

base_type=(7 4 11 13)

#type 4 CPU

#type 7 PING

#type 11 LOAD

#type 13 MEM

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_network()

{

/usr/local/php/bin/php /usr/local/nginx/html/cacti/cli/add_graphs.php --host-id="$1" --graph-type=ds --graph-template-id=2 --snmp-query-id=1 --snmp-query-type-id=14 --snmp-field=ifName --snmp-value=eth0

/usr/local/php/bin/php /usr/local/nginx/html/cacti/cli/add_graphs.php --host-id="$1" --graph-type=ds --graph-template-id=2 --snmp-query-id=1 --snmp-query-type-id=14 --snmp-field=ifName --snmp-value=eth1

}

function f_add_base()

{

/usr/local/php/bin/php /usr/local/nginx/html/cacti/cli/add_graphs.php --host-id="$1" --graph-type=cg --graph-template-id="$2"

}

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_network $id

for type in ${base_type[@]}

do

f_add_base $id $type

done f_add_tree $id ${tree[i]}

done

需要注意的是:
ip=('192.168.1.1' '192.168.1.2' '192.168.1.3' '192.168.1.4' )
tree=('test1' 'test2' 'test3' 'test4')

这里的IP和对应加入的tree 要一一对应

监控硬盘还不会,待会还要研究一下。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  linux 职场 cacti 休闲