~ubuntu-branches/debian/jessie/digitemp/jessie

« back to all changes in this revision

Viewing changes to rrdb/temp-one.cgi

  • Committer: Bazaar Package Importer
  • Author(s): Jesus Roncero
  • Date: 2004-09-01 01:34:37 UTC
  • Revision ID: james.westby@ubuntu.com-20040901013437-eicsrrd40dr371u0
Tags: upstream-3.3.2
ImportĀ upstreamĀ versionĀ 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl -w
 
2
#
 
3
# DigiTemp v2.1 RRDB Temperature Graph (single sensor)
 
4
#
 
5
# Copyright 1997-2001 by Brian C. Lane <bcl@brianlane.com> www.brianlane.com
 
6
# All Rights Reserved
 
7
#
 
8
# This program is free software; you can redistribute it and/or modify it
 
9
# under the terms of the GNU General Public License as published by the Free
 
10
# Software Foundation; either version 2 of the License, or (at your option)
 
11
# any later version.
 
12
#
 
13
# This program is distributed in the hope that it will be useful, but WITHOUT
 
14
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
15
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 
16
# more details.
 
17
#
 
18
# You should have received a copy of the GNU General Public License along
 
19
# with this program; if not, write to the Free Software Foundation, Inc.,
 
20
# 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
 
21
#
 
22
 
 
23
# REQUIRES:
 
24
#  RRD tool binary
 
25
#  CGI (comes with perl5)
 
26
 
 
27
use RRDp;
 
28
use CGI;
 
29
 
 
30
$cgi = new CGI;                   # Load the CGI routines
 
31
 
 
32
# Find the RRD executable, look in the standard locations
 
33
# If your rrdtool is installed someplace else, fill in the proper location
 
34
# below:
 
35
if ( -x "/usr/bin/rrdtool") 
 
36
{
 
37
  RRDp::start "/usr/bin/rrdtool";
 
38
} elsif ( -x "/usr/local/bin/rrdtool") {
 
39
   RRDp::start "/usr/local/bin/rrdtool";
 
40
} elsif ( -x "/usr/local/rrdtool/bin/rrdtool" ) {
 
41
   RRDp::start "/usr/local/rrdtool/bin/rrdtool";
 
42
} else {
 
43
   die "Could not find rrdtool binary\n";
 
44
}
 
45
 
 
46
# The RRD database to get the data from
 
47
$rrd = "/tmp/digitemp.rrd";
 
48
 
 
49
 
 
50
# Make the variables easier to use and assign defaults if not set
 
51
if( !$cgi->param('starttime') )
 
52
{
 
53
    $starttime = "-1day";
 
54
} else {
 
55
    $starttime = $cgi->param('starttime');
 
56
}
 
57
if( !$cgi->param('endtime') )
 
58
{
 
59
    $endtime = time;
 
60
} else {
 
61
    $endtime = $cgi->param('endtime');
 
62
}
 
63
if( !$cgi->param('width') )
 
64
{
 
65
    $width = "400";
 
66
} else {
 
67
    $width = $cgi->param('width');
 
68
}
 
69
if( !$cgi->param('height') )
 
70
{
 
71
    $height = "100";
 
72
} else {
 
73
    $height = $cgi->param('height');
 
74
}
 
75
if( !$cgi->param('label') )
 
76
{
 
77
    $label="";
 
78
} else {
 
79
    $label = $cgi->param('label');
 
80
}
 
81
$var = $cgi->param('var');
 
82
 
 
83
if( !$cgi->param('color') )
 
84
{
 
85
  $color = "#000000";
 
86
} else {
 
87
  $color = $cgi->param('color');
 
88
}
 
89
 
 
90
# Diagnostic output
 
91
#print STDERR "start  = $starttime\n";
 
92
#print STDERR "end    = $endtime\n";
 
93
#print STDERR "width  = $width\n";
 
94
#print STDERR "height = $height\n";
 
95
#print STDERR "var    = $var\n";
 
96
#print STDERR "label  = $label\n";
 
97
#print STDERR "color = $color\n";
 
98
 
 
99
 
 
100
# Output a HTML header for the PNG image to follow
 
101
print $cgi->header('image/png');
 
102
 
 
103
# Generate the graph
 
104
RRDp::cmd "graph - --imgformat PNG",
 
105
    "--start '$starttime' --end '$endtime'",
 
106
    "--width $width --height $height",
 
107
    "DEF:temp_c=$rrd:$var:AVERAGE",
 
108
    "CDEF:temp_f=temp_c,9,*,5,/,32,+",
 
109
    "LINE1:temp_f#$color:'$label'";
 
110
 
 
111
$answer=RRDp::read;
 
112
 
 
113
print $$answer;
 
114
 
 
115
RRDp::end;