| 1 | #!/usr/bin/perl |
|---|
| 2 | # |
|---|
| 3 | # slightly modified by Freek Reedeker 2009 |
|---|
| 4 | # |
|---|
| 5 | # copyright Martin Pot 2003 |
|---|
| 6 | # http://martybugs.net/linux/hddtemp.cgi |
|---|
| 7 | # |
|---|
| 8 | # sensormc.cgi |
|---|
| 9 | |
|---|
| 10 | my @graphs; |
|---|
| 11 | my $numberOfColumns, $currentColumn; |
|---|
| 12 | $numberOfColumns = 2; |
|---|
| 13 | |
|---|
| 14 | my ($name, $descr); |
|---|
| 15 | # Get available daily graphs |
|---|
| 16 | # If a daily graph exists in the currrent directory it will be shown. |
|---|
| 17 | # To remove a daily graph go to the /usr/local/bin/lmsensor.pl script |
|---|
| 18 | # If you comment the sensor out of the "to monitor" list, its daily graph |
|---|
| 19 | # will be deleted |
|---|
| 20 | my $availableGraphs = `ls *-day.png`; |
|---|
| 21 | # Push them on @graphs array |
|---|
| 22 | while($availableGraphs =~ m/\G(.*)-.*.png\n/g) |
|---|
| 23 | { |
|---|
| 24 | push (@graphs, $1); |
|---|
| 25 | # print "<!--$1-->"."\n"; |
|---|
| 26 | } |
|---|
| 27 | |
|---|
| 28 | # get the server name (or you could hard code some description here) |
|---|
| 29 | my $svrname = $ENV{'SERVER_NAME'}; |
|---|
| 30 | |
|---|
| 31 | # get url parameters |
|---|
| 32 | my @values = split(/&/, $ENV{'QUERY_STRING'}); |
|---|
| 33 | foreach my $i (@values) |
|---|
| 34 | { |
|---|
| 35 | ($varname, $mydata) = split(/=/, $i); |
|---|
| 36 | if ($varname eq 'trend') |
|---|
| 37 | { |
|---|
| 38 | $name = $mydata; |
|---|
| 39 | } |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | if ($name eq '') |
|---|
| 43 | { |
|---|
| 44 | $descr = "summary"; |
|---|
| 45 | } |
|---|
| 46 | else |
|---|
| 47 | { |
|---|
| 48 | $descr = " ".$name." "; |
|---|
| 49 | # replace %20 codes with <space> in name |
|---|
| 50 | $descr =~ s/%20/ /g; |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | print "Content-type: text/html;\n\n"; |
|---|
| 54 | print <<END |
|---|
| 55 | <html> |
|---|
| 56 | <head> |
|---|
| 57 | <TITLE>$svrname Sensors :: $descr</TITLE> |
|---|
| 58 | <META HTTP-EQUIV="Refresh" CONTENT="300"> |
|---|
| 59 | <META HTTP-EQUIV="Cache-Control" content="no-cache"> |
|---|
| 60 | <META HTTP-EQUIV="Pragma" CONTENT="no-cache"> |
|---|
| 61 | <style> |
|---|
| 62 | body { font-family: Verdana,Tahoma,Arial,Helvetica; font-size:9pt} |
|---|
| 63 | .header { font-size: 16pt; font-weight: 900; } |
|---|
| 64 | </style> |
|---|
| 65 | </head> |
|---|
| 66 | <body bgcolor="#ffffff" topMargin='5'> |
|---|
| 67 | |
|---|
| 68 | <span class='header'>$svrname Sensors :: $descr</span> |
|---|
| 69 | <br><br> |
|---|
| 70 | END |
|---|
| 71 | ; |
|---|
| 72 | |
|---|
| 73 | if ($name eq '') |
|---|
| 74 | { |
|---|
| 75 | print "Daily Graphs (5 minute averages)"; |
|---|
| 76 | print "<br>"; |
|---|
| 77 | $currentColumn = 1; |
|---|
| 78 | #print start of table |
|---|
| 79 | print "<table border='0'>"; |
|---|
| 80 | #print start of table row |
|---|
| 81 | print "<tr>"; |
|---|
| 82 | foreach $graph (@graphs) |
|---|
| 83 | { |
|---|
| 84 | print "<td>"; |
|---|
| 85 | print "<a href='?trend=$graph'><img src='$graph-day.png' border='1'></a>"; |
|---|
| 86 | #print "<br>"; |
|---|
| 87 | #print "<br>"; |
|---|
| 88 | print "</td>"; |
|---|
| 89 | # Check for last column, continue on next row. |
|---|
| 90 | if ($currentColumn++ == $numberOfColumns){ |
|---|
| 91 | $currentColumn = 1; |
|---|
| 92 | print "</tr><tr>"; |
|---|
| 93 | } |
|---|
| 94 | } |
|---|
| 95 | # fill the remaining cells of the last row with empty data |
|---|
| 96 | while (($currentColumn-1) % $numberOfColumns){ |
|---|
| 97 | $currentColumn++; |
|---|
| 98 | print "<td></td>"; |
|---|
| 99 | } |
|---|
| 100 | print "</tr>"; |
|---|
| 101 | print "</table>"; |
|---|
| 102 | } |
|---|
| 103 | else |
|---|
| 104 | { |
|---|
| 105 | print <<END |
|---|
| 106 | Daily Graph (5 minute averages) |
|---|
| 107 | <br> |
|---|
| 108 | <img src='$name-day.png'> |
|---|
| 109 | <br> |
|---|
| 110 | Weekly Graph (30 minute averages) |
|---|
| 111 | <br> |
|---|
| 112 | <img src='$name-week.png'> |
|---|
| 113 | <br> |
|---|
| 114 | Monthly Graph (2 hour averages) |
|---|
| 115 | <br> |
|---|
| 116 | <img src='$name-month.png'> |
|---|
| 117 | <br> |
|---|
| 118 | Yearly Graph (12 hour averages) |
|---|
| 119 | <br> |
|---|
| 120 | <img src='$name-year.png'> |
|---|
| 121 | END |
|---|
| 122 | ; |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | print <<END |
|---|
| 126 | <br><br> |
|---|
| 127 | <a |
|---|
| 128 | href='http://oss.oetiker.ch/rrdtool/'> |
|---|
| 129 | <img src='http://oss.oetiker.ch/rrdtool/.pics/rrdtool.gif' |
|---|
| 130 | border='0'></a> |
|---|
| 131 | </body> |
|---|
| 132 | </html> |
|---|
| 133 | END |
|---|
| 134 | ; |
|---|
| 135 | |
|---|
| 136 | |
|---|