create_webpage.sh 4.1 KB

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