From d6e686bffbbd71d63cec96c5b4ec2b2a60760da8 Mon Sep 17 00:00:00 2001 From: Duncan Laurie Date: Tue, 6 Jan 2004 01:44:08 +0000 Subject: [PATCH] add scripts for creating RRDtool graphs from SDR CSV output --from Fredrik Ohrn --- ipmitool/Makefile.am | 2 +- ipmitool/configure.in | 1 + ipmitool/contrib/Makefile.am | 38 ++++++ ipmitool/contrib/collect_data.sh | 24 ++++ ipmitool/contrib/create_rrds.sh | 35 ++++++ ipmitool/contrib/create_webpage.sh | 186 +++++++++++++++++++++++++++++ 6 files changed, 285 insertions(+), 1 deletion(-) create mode 100644 ipmitool/contrib/Makefile.am create mode 100755 ipmitool/contrib/collect_data.sh create mode 100755 ipmitool/contrib/create_rrds.sh create mode 100755 ipmitool/contrib/create_webpage.sh diff --git a/ipmitool/Makefile.am b/ipmitool/Makefile.am index 74f11c0..3355f99 100644 --- a/ipmitool/Makefile.am +++ b/ipmitool/Makefile.am @@ -38,7 +38,7 @@ MAINTAINERCLEANFILES = Makefile.in aclocal.m4 configure configure-stamp \ config.guess config.sub depcomp install-sh ltmain.sh missing \ mkinstalldirs config.h.in stamp-h.in $(distdir).tar.gz -SUBDIRS = lib src include doc +SUBDIRS = lib src include doc contrib dist-hook: ipmitool.spec cp ipmitool.spec $(distdir) diff --git a/ipmitool/configure.in b/ipmitool/configure.in index 0a7024b..1ed2eee 100644 --- a/ipmitool/configure.in +++ b/ipmitool/configure.in @@ -120,6 +120,7 @@ AM_CONDITIONAL(IPMIEVD, test "x$enable_ipmievd" = "xyes") AC_CONFIG_FILES([ipmitool.spec Makefile doc/Makefile + contrib/Makefile lib/Makefile include/Makefile include/ipmitool/Makefile diff --git a/ipmitool/contrib/Makefile.am b/ipmitool/contrib/Makefile.am new file mode 100644 index 0000000..99ddb21 --- /dev/null +++ b/ipmitool/contrib/Makefile.am @@ -0,0 +1,38 @@ +# Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# Redistribution of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# Redistribution in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# Neither the name of Sun Microsystems, Inc. or the names of +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# This software is provided "AS IS," without a warranty of any kind. +# ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, +# INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A +# PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. +# SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE +# FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING +# OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL +# SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, +# OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR +# PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF +# LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, +# EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. +# +# You acknowledge that this software is not designed or intended for use +# in the design, construction, operation or maintenance of any nuclear +# facility. + +MAINTAINERCLEANFILES = Makefile.in + +EXTRA_DIST = collect_data.sh create_rrds.sh create_webpage.sh + diff --git a/ipmitool/contrib/collect_data.sh b/ipmitool/contrib/collect_data.sh new file mode 100755 index 0000000..71f3bc8 --- /dev/null +++ b/ipmitool/contrib/collect_data.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +# Edit the variables + +hostname=$HOSTNAME + +ipmi_cmd="/usr/local/bin/ipmitool -I open" +rrd_dir="/some/dir/rrd" + +# No need to edit below this point. + +IFS=" +" + +for line in `eval $ipmi_cmd -c sdr list full` ; do + + IFS=, + + split=($line) + + file="$rrd_dir/$hostname-${split[0]}.rrd" + + rrdupdate "$file" "N:${split[1]}" +done diff --git a/ipmitool/contrib/create_rrds.sh b/ipmitool/contrib/create_rrds.sh new file mode 100755 index 0000000..ae07ae5 --- /dev/null +++ b/ipmitool/contrib/create_rrds.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# Edit the variables + +hostname=$HOSTNAME + +ipmi_cmd="/usr/local/bin/ipmitool -I open" +rrd_dir="/some/dir/rrd" + +# No need to edit below this point. + +IFS=" +" + +for line in `eval $ipmi_cmd -c -v sdr list full` ; do + + IFS=, + + split=($line) + + file="$rrd_dir/$hostname-${split[0]}.rrd" + + if [ -e "$file" ] ; then + echo "Skipping existing file $file" + continue + fi + + echo "Creating file $file" + + rrdtool create "$file" \ + --step 300 DS:var:GAUGE:900:${split[16]}:${split[17]} \ + RRA:AVERAGE:0.5:1:288 \ + RRA:AVERAGE:0.5:6:336 \ + RRA:AVERAGE:0.5:12:720 +done diff --git a/ipmitool/contrib/create_webpage.sh b/ipmitool/contrib/create_webpage.sh new file mode 100755 index 0000000..a7fd6a7 --- /dev/null +++ b/ipmitool/contrib/create_webpage.sh @@ -0,0 +1,186 @@ +#!/bin/bash + +# Edit the variables + +hostname=$HOSTNAME + +ipmi_cmd="/usr/local/bin/ipmitool -I open" +rrd_dir="/some/dir/rrd" + +# Full path to the rrdcgi executable. +rrdcgi=/usr/local/bin/rrdcgi + +# Where should rrdcgi store the graphs? This path must be within the +# document root and writable by the webserver user. +img_dir=/usr/local/apache2/htdocs/images/graphs + +# Where will the graphs show up on the webserver? +web_dir=/images/graphs + +# No need to edit below this point. + +color[0]="0000FF" +color[1]="00FF00" +color[2]="FF0000" +color[3]="FFFF00" +color[4]="FF00FF" +color[5]="00FFFF" +color[6]="4444AA" +color[7]="44AA44" +color[8]="AA4444" +color[9]="AAAA44" +color[10]="AA44AA" +color[11]="44AAAA" + +cat << EOF +#!$rrdcgi + + +$hostname + + +

$hostname

+EOF + + +IFS=" +" + +i=0 +groups= + +for line in `eval $ipmi_cmd -c -v sdr list full` ; do + + IFS=, + + split=($line) + + file="$rrd_dir/$hostname-${split[0]}.rrd" + group=`echo "${split[2]} ${split[*]:10:6}" | tr ' .-' ___` + + group_color=${group}_color + + if [ -z "${!group}" ] ; then + groups="$groups $group" + + declare $group_color=0 + + group_unit=${group}_unit + declare $group_unit="${split[2]}" + + group_title=${group}_title + declare $group_title="${split[5]} / ${split[6]}" + + group_thres=${group}_thres + declare $group_thres="${split[10]},${split[11]},${split[12]},${split[13]},${split[14]},${split[15]}" + fi + + declare $group="${!group} + DEF:var$i=\"$file\":var:AVERAGE LINE1:var$i#${color[${!group_color}]}:\"${split[0]}\"" + + declare $group_color=$[ ${!group_color} + 1 ] + + c=$[ c + 1 ] + i=$[ i + 1 ] +done + +IFS=" " + +for group in $groups ; do + + group_unit=${group}_unit + group_title=${group}_title + group_thres=${group}_thres + + IFS=, + + split=(${!group_thres}) + + thres= + + if [ -n "${split[0]}" ] ; then + if [ -n "${split[3]}" ] ; then + thres=" + HRULE:${split[0]}#000000 + HRULE:${split[3]}#000000:\"Upper & lower non-recoverable thresholds\"" + else + thres=" + HRULE:${split[0]}#000000:\"Upper non-recoverable threshold\"" + fi + else + if [ -n "${split[3]}" ] ; then + thres=" + HRULE:${split[3]}#000000:\"Lower non-recoverable threshold\"" + fi + fi + + if [ -n "${split[1]}" ] ; then + if [ -n "${split[4]}" ] ; then + thres="$thres + HRULE:${split[1]}#FF0000 + HRULE:${split[4]}#FF0000:\"Upper & lower critical thresholds\"" + else + thres="$thres + HRULE:${split[1]}#FF0000:\"Upper critical threshold\"" + fi + else + if [ -n "${split[4]}" ] ; then + thres="$thres + HRULE:${split[4]}#FF0000:\"Lower critical threshold\"" + fi + fi + + if [ -n "${split[2]}" ] ; then + if [ -n "${split[5]}" ] ; then + thres="$thres + HRULE:${split[2]}#FFCC00 + HRULE:${split[5]}#FFCC00:\"Upper & lower warning thresholds\"" + else + thres="$thres + HRULE:${split[2]}#FFCC00:\"Upper warning threshold\"" + fi + else + if [ -n "${split[5]}" ] ; then + thres="$thres + HRULE:${split[5]}#FFCC00:\"Lower warning threshold\"" + fi + fi + + + cat << EOF +

${!group_title}

+" + --lazy + --height 200 + --vertical-label "${!group_unit}" + --title "Daily graph" + --width 576 ${!group} $thres +> +" + --lazy + --start -7d + --height 200 + --vertical-label "${!group_unit}" + --title "Weelky graph" + --width 672 ${!group} $thres +> +EOF +#" +# --lazy +# --start -30d +# --height 200 +# --vertical-label "${!group_unit}" +# --title "Monthly graph" +# --width 720 ${!group} $thres +#> +#EOF + +done + +cat << EOF + + +EOF