1#!/bin/bash 2# 3# Copyright (c) 2003-2004 Fredrik Ohrn. All Rights Reserved. 4# 5# See the included COPYING file for license details. 6# 7 8# Edit the variables 9 10hostname=$HOSTNAME 11 12ipmi_cmd="/usr/local/bin/ipmitool -I open" 13rrd_dir="/some/dir/rrd" 14 15# Full path to the rrdcgi executable. 16rrdcgi=/usr/local/bin/rrdcgi 17 18# Where should rrdcgi store the graphs? This path must be within the 19# document root and writable by the webserver user. 20img_dir=/usr/local/apache2/htdocs/images/graphs 21 22# Where will the graphs show up on the webserver? 23web_dir=/images/graphs 24 25# Size of graph area (excluding title, legends etc.) 26graph_width=500 27graph_height=150 28 29# Graphs to include on page 30graph_daily=1 31graph_weekly=1 32graph_monthly=0 33 34 35# No need to edit below this point. 36 37color[0]="2020FF" 38color[1]="20FF20" 39color[2]="FF2020" 40color[3]="FF21FF" 41color[4]="21FFFF" 42color[5]="FFFF21" 43color[6]="8F21FF" 44color[7]="21FF8F" 45color[8]="FF8F21" 46color[9]="FF2190" 47color[10]="2190FF" 48color[11]="90FF21" 49 50cat << EOF 51#!$rrdcgi 52<html> 53<head> 54<title>$hostname</title> 55<RRD::GOODFOR 300> 56<body> 57<h2>$hostname</h2> 58EOF 59 60 61IFS=" 62" 63 64i=0 65groups= 66 67for line in `eval $ipmi_cmd -c -v sdr list full` ; do 68 69 IFS=, 70 71 split=($line) 72 73 file="$rrd_dir/$hostname-${split[0]}.rrd" 74 group=`echo "${split[2]} ${split[*]:10:6}" | tr ' .-' ___` 75 76 group_color=${group}_color 77 78 if [ -z "${!group}" ] ; then 79 groups="$groups $group" 80 81 declare $group_color=0 82 83 group_unit=${group}_unit 84 declare $group_unit="${split[2]}" 85 86 group_title=${group}_title 87 declare $group_title="${split[5]} / ${split[6]}" 88 89 group_thres=${group}_thres 90 declare $group_thres="${split[10]},${split[11]},${split[12]},${split[13]},${split[14]},${split[15]}" 91 fi 92 93 declare $group="${!group} 94 DEF:var$i=\"$file\":var:AVERAGE LINE1:var$i#${color[${!group_color}]}:\"${split[0]}\"" 95 96 declare $group_color=$[ ${!group_color} + 1 ] 97 98 c=$[ c + 1 ] 99 i=$[ i + 1 ] 100done 101 102IFS=" " 103 104for group in $groups ; do 105 106 group_unit=${group}_unit 107 group_title=${group}_title 108 group_thres=${group}_thres 109 110 IFS=, 111 112 split=(${!group_thres}) 113 114 thres= 115 116 if [ -n "${split[0]}" ] ; then 117 if [ -n "${split[3]}" ] ; then 118 thres=" 119 HRULE:${split[0]}#000000 120 HRULE:${split[3]}#000000:\"Upper & lower non-recoverable thresholds\"" 121 else 122 thres=" 123 HRULE:${split[0]}#000000:\"Upper non-recoverable threshold\"" 124 fi 125 else 126 if [ -n "${split[3]}" ] ; then 127 thres=" 128 HRULE:${split[3]}#000000:\"Lower non-recoverable threshold\"" 129 fi 130 fi 131 132 if [ -n "${split[1]}" ] ; then 133 if [ -n "${split[4]}" ] ; then 134 thres="$thres 135 HRULE:${split[1]}#FF0000 136 HRULE:${split[4]}#FF0000:\"Upper & lower critical thresholds\"" 137 else 138 thres="$thres 139 HRULE:${split[1]}#FF0000:\"Upper critical threshold\"" 140 fi 141 else 142 if [ -n "${split[4]}" ] ; then 143 thres="$thres 144 HRULE:${split[4]}#FF0000:\"Lower critical threshold\"" 145 fi 146 fi 147 148 if [ -n "${split[2]}" ] ; then 149 if [ -n "${split[5]}" ] ; then 150 thres="$thres 151 HRULE:${split[2]}#FFCC00 152 HRULE:${split[5]}#FFCC00:\"Upper & lower warning thresholds\"" 153 else 154 thres="$thres 155 HRULE:${split[2]}#FFCC00:\"Upper warning threshold\"" 156 fi 157 else 158 if [ -n "${split[5]}" ] ; then 159 thres="$thres 160 HRULE:${split[5]}#FFCC00:\"Lower warning threshold\"" 161 fi 162 fi 163 164 echo "<h3>${!group_title}</h3>" 165 166 if [ "$graph_daily" -ne 0 ] ; then 167 cat << EOF 168<RRD::GRAPH "$img_dir/$hostname-$group-daily.gif" 169 --imginfo "<img src="$web_dir/%s" width="%lu" height="%lu">" 170 --lazy 171 --vertical-label "${!group_unit}" 172 --title "Daily graph" 173 --height $graph_height 174 --width $graph_width ${!group} $thres 175> 176EOF 177 fi 178 179 if [ "$graph_weekly" -ne 0 ] ; then 180 cat << EOF 181<RRD::GRAPH "$img_dir/$hostname-$group-weekly.gif" 182 --imginfo "<img src="$web_dir/%s" width="%lu" height="%lu">" 183 --lazy 184 --start -7d 185 --vertical-label "${!group_unit}" 186 --title "Weelky graph" 187 --height $graph_height 188 --width $graph_width ${!group} $thres 189> 190EOF 191 fi 192 193 if [ "$graph_monthly" -ne 0 ] ; then 194 cat << EOF 195<RRD::GRAPH "$img_dir/$hostname-$group-monthly.gif" 196 --imginfo "<img src="$web_dir/%s" width="%lu" height="%lu">" 197 --lazy 198 --start -30d 199 --vertical-label "${!group_unit}" 200 --title "Monthly graph" 201 --height $graph_height 202 --width $graph_width ${!group} $thres 203> 204EOF 205 fi 206done 207 208cat << EOF 209</body> 210</html> 211EOF 212