shell script for adding compaq insight machines

Templates, scripts for templates, scripts and requests for templates.

Moderators: Developers, Moderators

Post Reply
joseph

shell script for adding compaq insight machines

Post by joseph »

Here's a shell scipt I wrote to simplify the adding of compaq machines to cacti.

It's pretty crude but maybe someone can use it. One thing that's hard coded is the graph hierarchy tp which to add the machine.

It is recommended that you save a mysqldump before running this thing.


#!/bin/bash


if [ -n $1 -o -n $2 -o -n $3 ] ; then
echo
else
echo "usage host name ip snmpcommunity";
exit;
fi

echo "Creating Data sources"
mysql cacti -e "INSERT INTO rrd_ds VALUES ('',0,0,'"$1"-cpu-utilization',1,600,0,100,13,'on','"$1"-cpu-util','<path_rra>/"$1"-cpu-utili.rrd',300,0);";
mysql cacti -e "INSERT INTO rrd_ds VALUES ('',0,0,'"$1"-ram-free',1,600,0,1000000000000000,13,'on','"$1"-ram-free','<path_rra>/"$1"-ram-free.rrd',300,0);";
mysql cacti -e "INSERT INTO rrd_ds VALUES ('',0,0,'"$1"-ram-total',1,600,0,1000000000000000,13,'on','"$1"-ram-total','<path_rra>/"$1"-ram-total.rrd',300,0);";
cpu=`mysql cacti -s -e "select id from rrd_ds where name='"$1"-cpu-utilization'"`;
echo $cpu;
echo "Creating RRA's";
mysql cacti -e "INSERT INTO lnk_ds_rra VALUES("$cpu",1);"
mysql cacti -e "INSERT INTO lnk_ds_rra VALUES("$cpu",2);"
mysql cacti -e "INSERT INTO lnk_ds_rra VALUES("$cpu",3);"
mysql cacti -e "INSERT INTO lnk_ds_rra VALUES("$cpu",4);"
echo "Done"
echo "Creating Data Input";
mysql cacti -e "INSERT INTO src_data VALUES('',41,"$cpu",'"$2"');"
mysql cacti -e "INSERT INTO src_data VALUES('',42,"$cpu",'"$3"');"
mysql cacti -e "INSERT INTO src_data VALUES('',43,"$cpu",'enterprises.232.11.2.3.1.1.2.1');"
mysql cacti -e "INSERT INTO src_data VALUES('',44,"$cpu",'');"
ramfree=`mysql cacti -s -e "select id from rrd_ds where name='"$1"-ram-free'"`;echo $ramfree;
echo "Creating RRA's";
mysql cacti -e "INSERT INTO lnk_ds_rra VALUES("$ramfree",1);"
mysql cacti -e "INSERT INTO lnk_ds_rra VALUES("$ramfree",2);"
mysql cacti -e "INSERT INTO lnk_ds_rra VALUES("$ramfree",3);"
mysql cacti -e "INSERT INTO lnk_ds_rra VALUES("$ramfree",4);"
echo "Done"
mysql cacti -e "INSERT INTO src_data VALUES('',41,"$ramfree",'"$2"');"
mysql cacti -e "INSERT INTO src_data VALUES('',42,"$ramfree",'"$3"');"
mysql cacti -e "INSERT INTO src_data VALUES('',43,"$ramfree",'enterprises.232.11.2.13.2.0');"
mysql cacti -e "INSERT INTO src_data VALUES('',44,"$ramfree",'');"
ramtotal=`mysql cacti -s -e "select id from rrd_ds where name='"$1"-ram-total'"`;
echo $ramtotal;
echo "Creating RRA's";
mysql cacti -e "INSERT INTO lnk_ds_rra VALUES("$ramtotal",1);"
mysql cacti -e "INSERT INTO lnk_ds_rra VALUES("$ramtotal",2);"
mysql cacti -e "INSERT INTO lnk_ds_rra VALUES("$ramtotal",3);"
mysql cacti -e "INSERT INTO lnk_ds_rra VALUES("$ramtotal",4);"
echo "Done"
mysql cacti -e "INSERT INTO src_data VALUES('',41,"$ramtotal",'"$2"');"
mysql cacti -e "INSERT INTO src_data VALUES('',42,"$ramtotal",'"$3"');"
mysql cacti -e "INSERT INTO src_data VALUES('',43,"$ramtotal",'enterprises.232.11.2.13.1.0');"
mysql cacti -e "INSERT INTO src_data VALUES('',44,"$ramtotal",'');"
echo "Creating cdefs for Ram and Drive usage";
mysql cacti -e "INSERT INTO rrd_ds_cdef VALUES('', '"$1"-Ram-Percent',1);";

echo "Done";


echo "Pupulating cdefs for Ram and Drive usage";
rampercentcdefid=`mysql cacti -s -e "select id from rrd_ds_cdef where name='"$1"-Ram-Percent'"`;
echo $key;
mysql cacti -e "INSERT INTO rrd_ds_cdef_item VALUES('', 0, "$rampercentcdefid", '', 'on', 31, 'Data Source',1);";
mysql cacti -e "INSERT INTO rrd_ds_cdef_item VALUES('', "$ramfree", "$rampercentcdefid", '', '', 31, 'Data Source',2);";
mysql cacti -e "INSERT INTO rrd_ds_cdef_item VALUES('', 0, "$rampercentcdefid", '', '', 28, 'CDEF Function',3);";
mysql cacti -e "INSERT INTO rrd_ds_cdef_item VALUES('', 0, "$rampercentcdefid", '', 'on', 31, 'Data Source',4);";
mysql cacti -e "INSERT INTO rrd_ds_cdef_item VALUES('', 0, "$rampercentcdefid", '', '', 30, 'CDEF Function',5);";
mysql cacti -e "INSERT INTO rrd_ds_cdef_item VALUES('', 0, "$rampercentcdefid", 100, '', 31, 'Custom Entry',6);";
mysql cacti -e "INSERT INTO rrd_ds_cdef_item VALUES('', 0, "$rampercentcdefid", '', '', 29, 'CDEF Function',7);";


echo "Done";

echo "Creating graphs";
mysql cacti -s -e "INSERT INTO rrd_graph VALUES ('',1,'"$1"-CPU-Utilization',120,500,0,0,'','on','',2,'',1000,'on','on','',0,'');"
mysql cacti -s -e "INSERT INTO rrd_graph VALUES ('',1,'"$1"-CPU-Utilization',120,500,0,0,'','on','',2,'',1000,'on','on','',0,'');"
mysql cacti -s -e "INSERT INTO rrd_graph VALUES ('',1,'"$1"-Ram-Percent',120,500,0,0,'','on','',2,'',1000,'on','on','',0,'');"

echo "Done";

echo "Populating Graph Items";
key=`mysql cacti -s -e "select id from rrd_graph where title='"$1"-CPU-Utilization'"`;
echo $key;
mysql cacti -s -e "INSERT INTO rrd_graph_item VALUES ('',"$cpu",1,'','',0,"$key",7,1,'',0,1,'',1,'');";


graphid=`mysql cacti -s -e "select id from rrd_graph where title='"$1"-Ram-Percent'";`
echo $graphid;
mysql cacti -s -e "INSERT INTO rrd_graph_item VALUES ('',"$ramtotal",96,'','',0,"$graphid",7,1,'',"$rampercentcdefid",1,'',1,'');"
mysql cacti -s -e "INSERT INTO rrd_graph_item VALUES ('',"$ramfree",0,'','',0,"$graphid",7,1,'',"$rampercentcdefid",2,'',1,'')"
echo "Creating Graph Hiearachy";

rootid=`mysql cacti -s -e "select id from graph_hierarchy_items where title='N-Sync'";`
#"
maxgraph=`mysql cacti -s -e "select max(sequence) from graph_hierarchy_items where id="$rootid";"`;
mysql cacti -s -e "INSERT INTO graph_hierarchy_items VALUES('',3,0,1,'"$1"','Heading',"$rootid","$maxgraph");"

treeid=`mysql cacti -s -e "select id from graph_hierarchy_items where title='"$1"'";`
key=`mysql cacti -s -e "select id from rrd_graph where title='"$1"-CPU-Utilization'"`;
mysql cacti -s -e "INSERT INTO graph_hierarchy_items VALUES('',3,"$key",1,'"$1"-CPU-Utilization','Graph',"$treeid","$maxgraph");"
let "maxgraph +=1";
echo $maxgraph;
key=`mysql cacti -s -e "select id from rrd_graph where title='"$1"-Ram-Percent'"`;
echo $maxgraph;
echo "Done";

num=1;

type="a";
while [ -n "$type" ]
do

type=`snmpwalk $2 $3 .host.hrStorage.hrStorageTable.hrStorageEntry.hrStorageType.$num`;
type=`echo $type | cut -f2 -d'=' | cut -f 4 -d'.'`;

if [ "$type" = "hrStorageFixedDisk" ]; then
echo "Disk Found";
echo "Finding Drive Letter";
label=`snmpwalk $2 $3 .host.hrStorage.hrStorageTable.hrStorageEntry.hrStorageDescr.$num | cut -f2 -d'=' | cut -f1 -d":"| sed -e "s/ //"`;
#Creating datasources
echo $label;
mysql cacti -e "INSERT INTO rrd_ds VALUES ('',0,0,'"$1"-"$label"-drive-space',1,600,0,10000000000000,13,'on','"$1"-"$label"-drive-spa','<path_rra>/"$1"-"$label"-drive-spa.rrd',300,0);";
mysql cacti -e "INSERT INTO rrd_ds VALUES ('',0,0,'"$1"-"$label"-drive-total',1,600,0,10000000000000,13,'on','"$1"-"$label"-drive-tot','<path_rra>/"$1"-"$label"-drive-tot.rrd',300,0);";
drivespace=`mysql cacti -s -e "select id from rrd_ds where name='"$1"-"$label"-drive-space'"`;
echo $drivespace;
echo "Creating RRAs";
mysql cacti -e "INSERT INTO lnk_ds_rra VALUES("$drivespace",1);"
mysql cacti -e "INSERT INTO lnk_ds_rra VALUES("$drivespace",2);"
mysql cacti -e "INSERT INTO lnk_ds_rra VALUES("$drivespace",3);"
mysql cacti -e "INSERT INTO lnk_ds_rra VALUES("$drivespace",4);"
echo "Done"
mysql cacti -e "INSERT INTO src_data VALUES('',41,"$drivespace",'"$2"');"
mysql cacti -e "INSERT INTO src_data VALUES('',42,"$drivespace",'"$3"');"
mysql cacti -e "INSERT INTO src_data VALUES('',43,"$drivespace",'host.hrStorage.hrStorageTable.hrStorageEntry.hrStorageUsed."$num"');"
mysql cacti -e "INSERT INTO src_data VALUES('',44,"$drivespace",'');"
drivetotal=`mysql cacti -s -e "select id from rrd_ds where name='"$1"-"$label"-drive-total'"`;
echo $drivetotal;
mysql cacti -e "INSERT INTO lnk_ds_rra VALUES("$drivetotal",1);"
mysql cacti -e "INSERT INTO lnk_ds_rra VALUES("$drivetotal",2);"
mysql cacti -e "INSERT INTO lnk_ds_rra VALUES("$drivetotal",3);"
mysql cacti -e "INSERT INTO lnk_ds_rra VALUES("$drivetotal",4);"

mysql cacti -e "INSERT INTO src_data VALUES('',41,"$drivetotal",'"$2"');"
mysql cacti -e "INSERT INTO src_data VALUES('',42,"$drivetotal",'"$3"');"
mysql cacti -e "INSERT INTO src_data VALUES('',43,"$drivetotal",'host.hrStorage.hrStorageTable.hrStorageEntry.hrStorageSize."$num"');"
mysql cacti -e "INSERT INTO src_data VALUES('',44,"$drivetotal",'');"
echo "Done";
mysql cacti -e "INSERT INTO rrd_ds_cdef VALUES('', '"$1"-"$label"-Drive-Percent',1);";

drivepercentcdefid=`mysql cacti -s -e "select id from rrd_ds_cdef where name='"$1"-"$label"-Drive-Percent'"`;
echo $key;
mysql cacti -e "INSERT INTO rrd_ds_cdef_item VALUES('', 0, "$drivepercentcdefid", '', 'on', 31, 'Data Source',1);";
mysql cacti -e "INSERT INTO rrd_ds_cdef_item VALUES('', "$drivetotal", "$drivepercentcdefid", '', '', 31, 'Data Source',2);";
mysql cacti -e "INSERT INTO rrd_ds_cdef_item VALUES('', 0, "$drivepercentcdefid", '', '', 30, 'CDEF Function',3);";
mysql cacti -e "INSERT INTO rrd_ds_cdef_item VALUES('', 0, "$drivepercentcdefid", 100,'', 31, 'Custom Entry',4);";
mysql cacti -e "INSERT INTO rrd_ds_cdef_item VALUES('', 0, "$drivepercentcdefid", '', '', 29, 'CDEF Function',5);";


mysql cacti -s -e "INSERT INTO rrd_graph VALUES ('',1,'"$1"-"$label"-Drive-Percent',120,500,100,0,'','','',2,'',1000,'on','on','',0,'');"
key=`mysql cacti -s -e "select id from rrd_graph where title='"$1"-"$label"-Drive-Percent'";

echo $key;
mysql cacti -s -e "INSERT INTO rrd_graph_item VALUES ('',"$drivespace",96,'','',0,"$key",7,1,'',"$drivepercentcdefid",1,'',1,'');"
mysql cacti -s -e "INSERT INTO rrd_graph_item VALUES ('',"$drivetotal",0,'','',0,"$key",7,1,'',"$drivepercentcdefid",2,'',1,'')"
let "maxgraph +=1";
echo $maxgraph;
key=`mysql cacti -s -e "select id from rrd_graph where title='"$1"-"$label"-Drive-Percent'"`;
mysql cacti -s -e "INSERT INTO graph_hierarchy_items VALUES('',3,"$key",1,'"$1"-"$label"-Drive-Percent','Graph',"$treeid","$maxgraph");"
fi
let "num += 1";
done

echo "Done"
Tof

Post by Tof »

Is there a update for this nice script ??? :)

thanks
Fred
Cacti User
Posts: 81
Joined: Fri Jan 03, 2003 11:43 am

Post by Fred »

I think it's called Cacti 0.8. :)
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests