create_webpage_compact.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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]}" | 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. fi
  63. declare $group="${!group}
  64. DEF:var$i=\"$file\":var:AVERAGE LINE1:var$i#${color[${!group_color}]}:\"${split[0]}\""
  65. declare $group_color=$[ ${!group_color} + 1 ]
  66. c=$[ c + 1 ]
  67. i=$[ i + 1 ]
  68. done
  69. IFS=" "
  70. for group in $groups ; do
  71. group_unit=${group}_unit
  72. IFS=,
  73. echo "<h3>${!group_unit}</h3>"
  74. if [ "$graph_daily" -ne 0 ] ; then
  75. cat << EOF
  76. <RRD::GRAPH "$img_dir/$hostname-$group-daily.gif"
  77. --imginfo "<img src="$web_dir/%s" width="%lu" height="%lu">"
  78. --lazy
  79. --vertical-label "${!group_unit}"
  80. --title "Daily graph"
  81. --height $graph_height
  82. --width $graph_width ${!group}
  83. >
  84. EOF
  85. fi
  86. if [ "$graph_weekly" -ne 0 ] ; then
  87. cat << EOF
  88. <RRD::GRAPH "$img_dir/$hostname-$group-weekly.gif"
  89. --imginfo "<img src="$web_dir/%s" width="%lu" height="%lu">"
  90. --lazy
  91. --start -7d
  92. --vertical-label "${!group_unit}"
  93. --title "Weelky graph"
  94. --height $graph_height
  95. --width $graph_width ${!group}
  96. >
  97. EOF
  98. fi
  99. if [ "$graph_monthly" -ne 0 ] ; then
  100. cat << EOF
  101. <RRD::GRAPH "$img_dir/$hostname-$group-monthly.gif"
  102. --imginfo "<img src="$web_dir/%s" width="%lu" height="%lu">"
  103. --lazy
  104. --start -30d
  105. --vertical-label "${!group_unit}"
  106. --title "Monthly graph"
  107. --height $graph_height
  108. --width $graph_width ${!group}
  109. >
  110. EOF
  111. fi
  112. done
  113. cat << EOF
  114. </body>
  115. </html>
  116. EOF