-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAddCacti
More file actions
76 lines (63 loc) · 4.01 KB
/
AddCacti
File metadata and controls
76 lines (63 loc) · 4.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/sh
#
#description:
#AddCacti this is the script to Batch add cacti monitor nodes
#
#### BEGIN INFO
# Provides: maycap
# Required-Start: cacti
# Should-Start: null
# version:1.0
# date:2015-5-31
### END INFO
device=/web/vhosts/cacti/cli/add_device.php
graphs=/web/vhosts/cacti/cli/add_graphs.php
tree=/web/vhosts/cacti/cli/add_tree.php
LIST=/root/bin/cacti.list
#Console -> Host Tempaltes -- ID
Host_Template=9
Community=public
Graph_Tree='Default Tree'
Parent_Node='vmhost'
for i in `cat $LIST`
do
hostname=${i%-*}
ip=${i#*-}
echo "Now add device $hostname ..."
php $device --description=$hostname --ip=$ip --template=$Host_Template --community=$Community
echo "Now add graphs ..."
#add interface 64 bits
HOST_ID=`php $graphs --list-hosts | grep $ip | awk '{print $1}'`
Graph_Template=`php $graphs --list-graph-templates | grep 'Interface - Traffic (bits/sec)' | awk '{print $1}'`
Snmp_query=`php $graphs --list-snmp-queries | grep 'SNMP - Interface Statistics' | awk '{print $1}'`
Snmp_query_type=`php $graphs --list-query-types --snmp-query-id=$Snmp_query | grep 'Bits (64-bit Counters)' | awk '{print $1}'`
php $graphs --host-id=$HOST_ID --graph-type=ds --graph-template-id=$Graph_Template --snmp-query-id=$Snmp_query --snmp-query-type-id=$Snmp_query_type --snmp-field=ifDescr --snmp-value="eth0"
#php $graphs --host-id=$HOST_ID --graph-type=ds --graph-template-id=$Graph_Template --snmp-query-id=$Snmp_query --snmp-query-type-id=$Snmp_query_type --snmp-field=ifType --snmp-value="ethernetCsmacd(6)"
#add ucd/net - CPU Usage - Load Average - Memory Usage
Graph_Template=`php $graphs --list-graph-templates | grep 'ucd/net - CPU Usage' | awk '{print $1}'`
php $graphs --host-id=$HOST_ID --graph-type=cg --graph-template-id=$Graph_Template
Graph_Template=`php $graphs --list-graph-templates | grep 'ucd/net - Load Average' | awk '{print $1}'`
php $graphs --host-id=$HOST_ID --graph-type=cg --graph-template-id=$Graph_Template
Graph_Template=`php $graphs --list-graph-templates | grep 'ucd/net - Memory Usage' | awk '{print $1}'`
php $graphs --host-id=$HOST_ID --graph-type=cg --graph-template-id=$Graph_Template
#add Host MIB - Available Disk Space
Graph_Template=`php $graphs --list-graph-templates | grep 'Host MIB - Available Disk Space' | awk '{print $1}'`
Snmp_query=`php $graphs --list-snmp-queries | grep 'SNMP - Get Mounted Partitions' | awk '{print $1}'`
Snmp_query_type=`php $graphs --list-query-types --snmp-query-id=$Snmp_query | grep 'Available Disk Space' | awk '{print $1}'`
php $graphs --host-id=$HOST_ID --graph-type=ds --graph-template-id=$Graph_Template --snmp-query-id=$Snmp_query --snmp-query-type-id=$Snmp_query_type --snmp-field=hrStorageDescr --snmp-value="/"
php $graphs --host-id=$HOST_ID --graph-type=ds --graph-template-id=$Graph_Template --snmp-query-id=$Snmp_query --snmp-query-type-id=$Snmp_query_type --snmp-field=hrStorageDescr --snmp-value="/web"
php $graphs --host-id=$HOST_ID --graph-type=ds --graph-template-id=$Graph_Template --snmp-query-id=$Snmp_query --snmp-query-type-id=$Snmp_query_type --snmp-field=hrStorageDescr --snmp-value="Swap space"
#add Host MIB - Disk IO - Bytes per Second
Graph_Template=`php $graphs --list-graph-templates | grep 'Host MIB - Disk IO - Bytes per Second' | awk '{print $1}'`
Snmp_query=`php $graphs --list-snmp-queries | grep 'SNMP - Get Disk IO' | awk '{print $1}'`
Snmp_query_type=`php $graphs --list-query-types --snmp-query-id=$Snmp_query | grep 'Host MIB - Disk IO - Bytes per second' | awk '{print $1}'`
php $graphs --host-id=$HOST_ID --graph-type=ds --graph-template-id=$Graph_Template --snmp-query-id=$Snmp_query --snmp-query-type-id=$Snmp_query_type --snmp-field=hrDiskIODescr --snmp-value="dm-0"
#add tree
Tree_id=`php $tree --list-trees | grep "$Graph_Tree" | awk '{print $1}'`
Parent_id=`php $tree --list-nodes --tree-id=$Tree_id | grep "$Parent_Node" | awk '{print $2}'`
php $tree --host-id=$HOST_ID --type=node --node-type=host --tree-id=$Tree_id --parent-node=$Parent_id
done
# cat cacti.list
# vm14-192.168.100.14
# vm15-192.168.100.15
# vm16-192.168.100.16