cacti批量添加device和graph

cacti添加监控项和绘图项不一般得麻烦,华为s5700交换机有48口,鼠标点得点到死。
好在有一些cli工具可以帮助我们批量添加。
工具目录:
/var/www/html/cli
脚本中涉及到的host-id template-id 等各种id请参阅文章底部的使用手册,理明白各id用途再使用本脚本。
cat add_multi.sh

#!/bin/bash
# path=/var/www/html/cli
for host_ip in $(cat hosts)
do
echo $host_ip
php -q add_device.php --description=$host_ip --ip="$host_ip" --template=6
host_id=$(php -q add_graphs.php --list-hosts --quiet|grep $host_ip|awk -F " " '{print $1}')
php -q add_graphs.php --host-id=$host_id --graph-type=cg --graph-template-id=24
######php add_graphs.php --host-id=$host_id --snmp-field=ifDescr --list-snmp-values
for host_if in $(php -q add_graphs.php --host-id=$host_id --snmp-field=ifDescr --list-snmp-values --quiet)
do
echo $host_if
php -q add_graphs.php --host-id=$host_id --graph-type=ds --graph-title='|host_description| - Traffic - |query_ifName|' --graph-template-id=12 --snmp-quer
y-id=3 --snmp-query-type-id=6 --snmp-field=ifDescr --snmp-value="$host_if"
done
done

sh add_multi.sh

bj-cnc-1.arkii.cn
Adding bj-cnc-1.arkii.cn (bj-cnc-s5700-1.arkii.cn) as "Huawei" using SNMP v2 with community "public"
Success - new device-id: (100)
Graph Added - graph-id: (7835) - data-source-ids: (6968)
Console9/0/0
Graph Added - graph-id: (7836) - data-source-ids: (6969, 6969)
Eth-Trunk1
Graph Added - graph-id: (7837) - data-source-ids: (6970, 6970)
GigabitEthernet0/0/1
Graph Added - graph-id: (7838) - data-source-ids: (6971, 6971)
GigabitEthernet0/0/10
Graph Added - graph-id: (7839) - data-source-ids: (6972, 6972)
GigabitEthernet0/0/11
Graph Added - graph-id: (7840) - data-source-ids: (6973, 6973)
GigabitEthernet0/0/12
Graph Added - graph-id: (7841) - data-source-ids: (6974, 6974)
GigabitEthernet0/0/13
Graph Added - graph-id: (7842) - data-source-ids: (6975, 6975)
GigabitEthernet0/0/14
Graph Added - graph-id: (7843) - data-source-ids: (6976, 6976)
GigabitEthernet0/0/15
Graph Added - graph-id: (7844) - data-source-ids: (6977, 6977)
GigabitEthernet0/0/16
Graph Added - graph-id: (7845) - data-source-ids: (6978, 6978)
GigabitEthernet0/0/17
Graph Added - graph-id: (7846) - data-source-ids: (6979, 6979)
GigabitEthernet0/0/18
Graph Added - graph-id: (7847) - data-source-ids: (6980, 6980)
GigabitEthernet0/0/19
Graph Added - graph-id: (7848) - data-source-ids: (6981, 6981)
GigabitEthernet0/0/2
Graph Added - graph-id: (7849) - data-source-ids: (6982, 6982)
GigabitEthernet0/0/20
Graph Added - graph-id: (7850) - data-source-ids: (6983, 6983)
GigabitEthernet0/0/21
Graph Added - graph-id: (7851) - data-source-ids: (6984, 6984)
GigabitEthernet0/0/22
Graph Added - graph-id: (7852) - data-source-ids: (6985, 6985)
GigabitEthernet0/0/23
Graph Added - graph-id: (7853) - data-source-ids: (6986, 6986)
GigabitEthernet0/0/24
Graph Added - graph-id: (7854) - data-source-ids: (6987, 6987)
GigabitEthernet0/0/25
Graph Added - graph-id: (7855) - data-source-ids: (6988, 6988)
GigabitEthernet0/0/26
Graph Added - graph-id: (7856) - data-source-ids: (6989, 6989)
GigabitEthernet0/0/27
Graph Added - graph-id: (7857) - data-source-ids: (6990, 6990)
GigabitEthernet0/0/28
Graph Added - graph-id: (7858) - data-source-ids: (6991, 6991)
GigabitEthernet0/0/29
Graph Added - graph-id: (7859) - data-source-ids: (6992, 6992)
GigabitEthernet0/0/3
Graph Added - graph-id: (7860) - data-source-ids: (6993, 6993)
GigabitEthernet0/0/30
Graph Added - graph-id: (7861) - data-source-ids: (6994, 6994)
GigabitEthernet0/0/31
Graph Added - graph-id: (7862) - data-source-ids: (6995, 6995)
GigabitEthernet0/0/32
Graph Added - graph-id: (7863) - data-source-ids: (6996, 6996)
GigabitEthernet0/0/33
Graph Added - graph-id: (7864) - data-source-ids: (6997, 6997)
GigabitEthernet0/0/34
Graph Added - graph-id: (7865) - data-source-ids: (6998, 6998)
GigabitEthernet0/0/35
Graph Added - graph-id: (7866) - data-source-ids: (6999, 6999)
GigabitEthernet0/0/36
Graph Added - graph-id: (7867) - data-source-ids: (7000, 7000)
GigabitEthernet0/0/37
Graph Added - graph-id: (7868) - data-source-ids: (7001, 7001)
GigabitEthernet0/0/38
Graph Added - graph-id: (7869) - data-source-ids: (7002, 7002)
GigabitEthernet0/0/39
Graph Added - graph-id: (7870) - data-source-ids: (7003, 7003)
GigabitEthernet0/0/4
Graph Added - graph-id: (7871) - data-source-ids: (7004, 7004)
GigabitEthernet0/0/40
Graph Added - graph-id: (7872) - data-source-ids: (7005, 7005)
GigabitEthernet0/0/41
Graph Added - graph-id: (7873) - data-source-ids: (7006, 7006)
GigabitEthernet0/0/42
Graph Added - graph-id: (7874) - data-source-ids: (7007, 7007)
GigabitEthernet0/0/43
Graph Added - graph-id: (7875) - data-source-ids: (7008, 7008)
GigabitEthernet0/0/44
Graph Added - graph-id: (7876) - data-source-ids: (7009, 7009)
GigabitEthernet0/0/45
Graph Added - graph-id: (7877) - data-source-ids: (7010, 7010)
GigabitEthernet0/0/46
Graph Added - graph-id: (7878) - data-source-ids: (7011, 7011)
GigabitEthernet0/0/47
Graph Added - graph-id: (7879) - data-source-ids: (7012, 7012)
GigabitEthernet0/0/48
Graph Added - graph-id: (7880) - data-source-ids: (7013, 7013)
GigabitEthernet0/0/5
Graph Added - graph-id: (7881) - data-source-ids: (7014, 7014)
GigabitEthernet0/0/6
Graph Added - graph-id: (7882) - data-source-ids: (7015, 7015)
GigabitEthernet0/0/7
Graph Added - graph-id: (7883) - data-source-ids: (7016, 7016)
GigabitEthernet0/0/8
Graph Added - graph-id: (7884) - data-source-ids: (7017, 7017)
GigabitEthernet0/0/9
Graph Added - graph-id: (7885) - data-source-ids: (7018, 7018)
InLoopBack0
Graph Added - graph-id: (7886) - data-source-ids: (7019, 7019)
MEth0/0/1
Graph Added - graph-id: (7887) - data-source-ids: (7020, 7020)
NULL0
Graph Added - graph-id: (7888) - data-source-ids: (7021, 7021)
Vlanif1
Graph Added - graph-id: (7889) - data-source-ids: (7022, 7022)
Vlanif200
Graph Added - graph-id: (7890) - data-source-ids: (7023, 7023)
XGigabitEthernet0/1/1
Graph Added - graph-id: (7891) - data-source-ids: (7024, 7024)
XGigabitEthernet0/1/2
Graph Added - graph-id: (7892) - data-source-ids: (7025, 7025)

参考资料
www.cacti.net