430fff4515
In the case of puppetmaster.o.o, we are actually returning 3 results, because of the following: # php -q /usr/share/cacti/cli/add_graphs.php --list-hosts | grep "puppetmaster" 5 ci-puppetmaster.openstack.org 9 ci-puppetmaster.openstack.org 85 old-puppetmaster.openstack.org 9 old-puppetmaster.openstack.org 86 puppetmaster.openstack.org 9 puppetmaster.openstack.org this is ofcource wrong and breaking cacti. Now match with leading tab, so we only return a single host. Change-Id: Ie4a692f4afbc31f82844a326d38e69d2e1aea549 Signed-off-by: Paul Belanger <pabelanger@redhat.com>
90 lines
3.2 KiB
Bash
90 lines
3.2 KiB
Bash
#!/bin/bash
|
|
|
|
cd /usr/share/cacti/cli
|
|
|
|
HOST_NAME=$1
|
|
|
|
HOST_TEMPLATE_ID=`php -q /usr/share/cacti/cli/add_device.php \
|
|
--list-host-templates |grep "Linux Host"|cut -f 1`
|
|
|
|
php -q add_device.php --description="$HOST_NAME" --ip="$HOST_NAME" \
|
|
--template=$HOST_TEMPLATE_ID --version=2 --community="public"
|
|
|
|
HOST_ID=`php -q add_graphs.php --list-hosts |grep -P "\t$HOST_NAME"|cut -f 1`
|
|
|
|
if [[ $HOST_NAME =~ vanilla\.ic\.openstack\.org ]]; then
|
|
TREE_NAME='Infra Cloud Vanilla'
|
|
elif [[ $HOST_NAME =~ chocolate\.ic\.openstack\.org ]]; then
|
|
TREE_NAME='Infra Cloud Chocolate'
|
|
else
|
|
TREE_NAME='All Hosts'
|
|
fi
|
|
|
|
TREE_ID=`php -q add_tree.php --list-trees |grep "$TREE_NAME"|cut -f 1`
|
|
php -q add_tree.php --type=node --node-type=host --tree-id=$TREE_ID \
|
|
--host-id=$HOST_ID
|
|
|
|
php -q poller_reindex_hosts.php --id=$HOST_ID
|
|
|
|
php -q add_graphs.php --list-graph-templates \
|
|
--host-template-id=$HOST_TEMPLATE_ID | \
|
|
while read line ; do
|
|
if echo $line | grep "Known" >/dev/null || [ "$line" == "" ] ; then
|
|
continue
|
|
fi
|
|
TEMPLATE_ID=`echo $line | cut -f 1 -d ' '`
|
|
php -q add_graphs.php --host-id=$HOST_ID --graph-type=cg \
|
|
--graph-template-id=$TEMPLATE_ID
|
|
done
|
|
|
|
function add_ds_graph {
|
|
TEMPLATE_NAME=$1
|
|
TYPE_NAME=$2
|
|
FIELD_NAME=$3
|
|
FIELD_VALUE=$4
|
|
|
|
TEMPLATE_ID=`php -q add_graphs.php --list-graph-templates | \
|
|
grep "$TEMPLATE_NAME"|cut -f 1`
|
|
TYPE_ID=`php -q add_graphs.php --snmp-query-id=$SNMP_QUERY_ID \
|
|
--list-query-types | grep "$TYPE_NAME"|cut -f 1`
|
|
|
|
php -q add_graphs.php --host-id=$HOST_ID --graph-type=ds \
|
|
--graph-template-id=$TEMPLATE_ID --snmp-query-id=$SNMP_QUERY_ID \
|
|
--snmp-query-type-id=$TYPE_ID --snmp-field=$FIELD_NAME \
|
|
--snmp-value=$FIELD_VALUE
|
|
}
|
|
|
|
# php -q add_graphs.php --list-graph-templates
|
|
# php -q add_graphs.php --snmp-query-id=$SNMP_QUERY_ID --list-query-types
|
|
|
|
SNMP_QUERY_ID=`php -q add_graphs.php --host-id=$HOST_ID --list-snmp-queries | \
|
|
grep "SNMP - Get Mounted Partitions"|cut -f 1`
|
|
|
|
add_ds_graph "Host MIB - Available Disk Space" "Available Disk Space" \
|
|
"hrStorageDescr" "/"
|
|
|
|
SNMP_QUERY_ID=`php -q add_graphs.php --host-id=$HOST_ID --list-snmp-queries | \
|
|
grep "SNMP - Interface Statistics"|cut -f 1`
|
|
|
|
for iface in $(php -q /usr/share/cacti/cli/add_graphs.php --host-id=$HOST_ID --snmp-field=ifName --list-snmp-values | \
|
|
grep -v -e "Known values" -e tap -e brq) ; do
|
|
add_ds_graph "Interface - Traffic (bits/sec)" "In/Out Bits (64-bit Counters)" \
|
|
"ifName" "$iface"
|
|
add_ds_graph "Interface - Errors/Discards" "In/Out Errors/Discarded Packets" \
|
|
"ifName" "$iface"
|
|
add_ds_graph "Interface - Unicast Packets" "In/Out Unicast Packets" \
|
|
"ifName" "$iface"
|
|
add_ds_graph "Interface - Non-Unicast Packets" "In/Out Non-Unicast Packets" \
|
|
"ifName" "$iface"
|
|
done
|
|
|
|
SNMP_QUERY_ID=`php -q add_graphs.php --host-id=$HOST_ID --list-snmp-queries | \
|
|
grep "ucd/net - Get IO Devices"|cut -f 1`
|
|
|
|
for disk in $(php -q add_graphs.php --host-id=$HOST_ID --snmp-field=diskIODevice --list-snmp-values | grep xvd[a-z]$) ; do
|
|
add_ds_graph "ucd/net - Device IO - Operations" "IO Operations" \
|
|
"diskIODevice" "$disk"
|
|
add_ds_graph "ucd/net - Device IO - Throughput" "IO Throughput" \
|
|
"diskIODevice" "$disk"
|
|
done
|