Hi,
Thank you for your great job, I use it to manage around 100 Cisco 2960.
To create my weathermaps I use a script in bash.
I use three files, one is the script and the two others are for the position of each node :
The script file :
Code: Select all
#!/bin/bash
##################################################
# Configuration
##################################################
CACTI_DB="cacti_database_name"
CACTI_USER="cacti_user" #in my case I create a user in read only
CACTI_PASSWORD="cacti_password"
CACTI_IP="cacti_ip_address"
##################################################
# Get device name and position
##################################################
echo -n "Cacti device name : "; read -e DEVICE_NAME
echo -n "Overlibgraph device port index : "; read -e DEVICE_OVERLIBGRAPH_PORT
echo -n "Position switch (like 200 50) : "; read -e DEVICE_POSITION
DEVICE_ID=$(mysql --host="$CACTI_IP" --user="$CACTI_USER" --password="$CACTI_PASSWORD" "$CACTI_DB" -Bse "SELECT id FROM host WHERE description='$DEVICE_NAME'";)
#check if device exist
if [ "$DEVICE_ID" = "" ]
then
echo "No device found... exit";
exit
else
##################################################
# Create port nodes
##################################################
#lower case the name of device to match with rdd files
DEVICE_NAME_LC=$(echo "$DEVICE_NAME" | awk '{print tolower($0)}')
#empty result file if exist
echo "" > $DEVICE_NAME
# get switch ports and data IDs
mysql --host="$CACTI_IP" --user="$CACTI_USER" --password="$CACTI_PASSWORD" "$CACTI_DB" -Bse "SELECT data_local.id AS data_id, graph_local.snmp_index AS snmp_index, SUBSTRING(graph_local.snmp_index, 4, 2) AS sw_port, SUBSTRING(graph_local.snmp_index, 1, 3) AS sw_port_type FROM data_local INNER JOIN graph_local ON (data_local.host_id=graph_local.host_id AND data_local.snmp_index=graph_local.snmp_index) WHERE data_local.host_id=$DEVICE_ID AND data_template_id=73 AND graph_template_id=48" | while read DATA_ID SNMP_INDEX SW_PORT SW_PORT_TYPE;
do
# get graphs speed IDs
GRAPH_SPEED_ID=$(mysql --host="$CACTI_IP" --user="$CACTI_USER" --password="$CACTI_PASSWORD" "$CACTI_DB" -Bse "SELECT id FROM graph_local WHERE host_id=$DEVICE_ID AND graph_template_id=2 AND snmp_index=$SNMP_INDEX";)
# get ethernet port type (fast or giga) and port position
if [ "$SW_PORT_TYPE" = "100" ]
then
POSITION=$(sed -n $SW_PORT'p' distrib_48_position_fast)
SW_PORT_TYPE_NAME="F"
elif [ "$SW_PORT_TYPE" = "101" ]
then
POSITION=$(sed -n $SW_PORT'p' distrib_48_position_giga)
SW_PORT_TYPE_NAME="G"
fi
# write file
echo "NODE $DEVICE_NAME-$SW_PORT_TYPE_NAME$SW_PORT
INFOURL /cacti/graph.php?rra_id=all&local_graph_id=$GRAPH_SPEED_ID
OVERLIBGRAPH /cacti/graph_image.php?rra_id=0&graph_nolegend=true&graph_height=100&graph_width=300&local_graph_id=$GRAPH_SPEED_ID
ICON images/port_{node:this:inscaletag}.png
TARGET gauge:/var/lib/cacti/rra/${DEVICE_NAME_LC}_int_status_$DATA_ID.rrd:int_status:-
USESCALE ifstatus in percent
POSITION $DEVICE_NAME $POSITION
" >> $DEVICE_NAME
done
##################################################
# Create switch node
##################################################
# get graphs speed IDs
DEVICE_GRAPH_SPEED_ID=$(mysql --host="$CACTI_IP" --user="$CACTI_USER" --password="$CACTI_PASSWORD" "$CACTI_DB" -Bse "SELECT id FROM graph_local WHERE host_id=$DEVICE_ID AND graph_template_id=2 AND snmp_index=$DEVICE_OVERLIBGRAPH_PORT";)
echo "NODE $DEVICE_NAME
LABEL $DEVICE_NAME
ZORDER 200
LABELOFFSET W
LABELFONT 111
LABELANGLE 90
LABELOUTLINECOLOR none
LABELBGCOLOR none
INFOURL /cacti/graph.php?rra_id=all&local_graph_id=$DEVICE_GRAPH_SPEED_ID
OVERLIBGRAPH /cacti/graph_image.php?rra_id=0&graph_nolegend=true&graph_height=100&graph_width=300&local_graph_id=$DEVICE_GRAPH_SPEED_ID
ICON images/sw_2960_distrib.png
POSITION $DEVICE_POSITION" >> $DEVICE_NAME
exit
fi
The position file fort FAST nodes (in my case named "distrib_48_position_fast", used in the script):
Code: Select all
-384 -12
-384 16
-355 -12
-355 16
-326 -12
-326 16
-297 -12
-297 16
-268 -12
-268 16
-239 -12
-239 16
-198 -12
-198 16
-169 -12
-169 16
-140 -12
-140 16
-111 -12
-111 16
-82 -12
-82 16
-53 -12
-53 16
-12 -12
-12 16
17 -12
17 16
46 -12
46 16
75 -12
75 16
104 -12
104 16
133 -12
133 16
174 -12
174 16
203 -12
203 16
232 -12
232 16
261 -12
261 16
290 -12
290 16
319 -12
319 16
The line 1 is for port 1, line 2 fort port 2, etc...
The position file fort GIGA nodes (in my case named "distrib_48_position_giga", used in the script):
After executing the script :
>> Copy/Paste the result of script (stored in a file named as switch name) in the conf file
Script execution :
Two switchs configured in one minute :p
I'm working to determine if port is on top or bottom (the first switch is corrected direct in conf file).
It's not awesome but usefull.
Regards,
Ch3i.