srv111 192.168.1.111 11161
srv112 192.168.1.112 11161
srv113 192.168.1.113 11161
srv114 192.168.1.114 11161
srv115 192.168.1.115 11161
使用下面指令查一下要使用的 templates
# php add_device.php --list-host-templates
Valid Device Templates: (id, name)
0 None
1 Cisco Router
2 Generic SNMP Device
3 Net-SNMP Device
4 Windows Device
編輯 shell script 檔
#!/bin/bash
while read HOST IP PORT
do
php add_device.php --description=${HOST} --ip=${IP} --port=${PORT} --community=public --template=3;
done < ./srv-host
查詢 id
php add_graphs.php --list-hosts
新增 graphs
#!/bin/bash
#硬碟容量
for id in {1..5}
do
hostname=`php add_graphs.php --list-hosts |grep "^${id}"|awk '{print $4}'`
disks=`php add_graphs.php --list-snmp-values --host-id=${id} --snmp-query-id=2 --snmp-field=dskDevice | grep -Ev "${id}|usb"`
for disk in ${disks}
do
echo "${id} ${hostname} ${disk}"
php add_graphs.php --host-id=${id} --graph-type=ds --graph-template-id=25 --snmp-query-id=2 --snmp-query-type-id=16 --snmp-field=dskDevice --snmp-value=${disk}
done
#網卡容量
names=`php add_graphs.php --list-snmp-values --host-id=${id} --snmp-field=ifName | grep -Ev "${id}|usb"`
for name in ${names}
do
echo "${id} ${hostname} ${name}"
php add_graphs.php --host-id=${id} --graph-type=ds --graph-template-id=4 --snmp-query-id=1 --snmp-query-type-id=5 --snmp-field=ifName --snmp-value=${name}
done
done
參數取得
--graph-template-id= --host-id=[ID] --list-graph-templates
--snmp-query-id= --host-id=[ID] --list-snmp-queries
--snmp-query-type-id= --host-id=[ID] --list-query-types --snmp-query-id=[ID]
--snmp-field= --list-snmp-fields --host-id=[ID]
--snmp-value= --list-snmp-values --host-id=[ID] --snmp-field=[Filed]
reference:
https://blog.xuite.net/misgarlic/weblogic/47243432
https://www.itread01.com/content/1549017217.html
https://developer.aliyun.com/article/429541
http://napmas.blogspot.com/2011/09/cacti-command-line-interface.html
0 意見:
張貼留言