cacti 批量监控
说明:这个暂时只能针对linux客户端进行操作,win端的暂无#!/bin/bash
#cacti的cli路径
path="/var/www/cacti/cli"
cd $path
#配置一些因人、机器而异的选项
tree_id=1 #树id(tree_id,查看cacti中的树情况: php add_tree.php --list-trees)
community_name=public #监控的项目名称
network1=eth0 #网卡名称,这里配置两个网卡
network2=eth1
#默认客户端主机ip在ips.txt文本里面,也可以单台操作,即$1参数为客户端ip
case $1 in
*.*.*.*)
host_ips=$1
;;
*)
host_ips=`cat ips.txt`
;;
esac
for host_ip in $host_ips
do
#添加cacti设备
#template为Host Template(ucd/net SNMP Host),avail为Downed Device Detection(SNMP),具体可查看:php add_device.php
php add_device.php --description="$host_ip" --ip="$host_ip" --template=3 --avail=snmp --version=2 --community=$community_name
#读取设备ID
host_ids=`php add_graphs.php --list-hosts | grep $host_ip | awk -F " " '{print $1}'`
#图像模板只有两种,cg为基本图像,ds为定制图像,eg:网卡,磁盘
#graph-template-id为【Associated Graph Templates】和【Associated Data Queries】里的选项,具体可查看:php add_graphs.php --list-graph-templates
#创建模板图像
php add_graphs.php --host-id="$host_ids" --graph-type=cg --graph-template-id=4 #4为:ucd/net - CPU Usage
php add_graphs.php --host-id="$host_ids" --graph-type=cg --graph-template-id=11 #11为:ucd/net - Load Average
php add_graphs.php --host-id="$host_ids" --graph-type=cg --graph-template-id=13 #13为:ucd/net - Memory Usage
#创建网卡数据图像
#可根据机器具体情况添加,查看:php add_graphs.php --host-id="$host_ids" --snmp-field=ifDescr --list-snmp-values
php 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=$network1
php 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=$network2
#创建分区数据图像
#可根据机器具体情况添加,查看:php add_graphs.php --host-id="$host_ids" --snmp-field=hrStorageDescr --list-snmp-values
php add_graphs.php --host-id="$host_ids" --graph-type=ds --graph-template-id=26 --snmp-query-id=8 --snmp-query-type-id=18 --snmp-field=hrStorageDescr --snmp-value="/"
php add_graphs.php --host-id="$host_ids" --graph-type=ds --graph-template-id=26 --snmp-query-id=8 --snmp-query-type-id=18 --snmp-field=hrStorageDescr --snmp-value="Physical memory"
#添加设备到相应的组
#默认为 Default Tree(自带),自定义的话需要再web节目创建后再查看其树id:php add_tree.php --list-trees
php add_tree.php --host-id="$host_ids" --type=node --node-type=host --tree-id=$tree_id
done
页:
[1]