]> git.sesse.net Git - nms/blob - web/stempmap-ptn.pl
initial import
[nms] / web / stempmap-ptn.pl
1 #!/usr/bin/perl
2 #
3 #
4
5 use CGI;
6 use GD;
7 use DBI;
8 use strict;
9 use warnings;
10
11 my $img = GD::Image->new('stemp-bg5.png');
12 my $cgi = CGI->new;
13
14 my $dbh = DBI->connect("dbi:Pg:dbname=snmpfetch;host=violet.tg05.gathering.org", "snmpfetch", "removed")
15         or die "Couldn't connect to database";
16
17 my $black = $img->colorAllocate(0,0,0);
18 my $white = $img->colorAllocate(255,255,255);
19 my $green = $img->colorAllocate(0,255,0);
20 my $blue = $img->colorAllocate(0,0,255);
21
22 my $avrgtemp = 54;
23 my $mintemp = 10.0;
24 my $maxtemp = 80.0;
25
26 my $color = &getcolor($avrgtemp);
27
28 for (my $i = $mintemp; $i <= $maxtemp; $i++) {
29         $img->line(600, 220 + $i - $mintemp, 645, 220 + $i - $mintemp, &getcolor($i));
30 }
31
32 $img->string(gdMediumBoldFont, 600, 200, "Freezing!$mintemp", $black);
33 $img->string(gdMediumBoldFont, 600, 210, "$mintemp C", $black);
34 $img->string(gdMediumBoldFont, 600, 220 + $maxtemp, "Too hot! $maxtemp", $black);
35 $img->string(gdMediumBoldFont, 600, 210 + $maxtemp, "$maxtemp C", $black);
36
37 my $px = 5;
38 my $py = 30;
39
40 #$img->stringUp(gdGiantFont,$px,$py - 2,"$avrgtemp",$white);
41 $img->filledRectangle($px - 0, $py - 17, $px + 12, $py + 5, $white);
42 $img->stringUp(gdLargeFont,$px - 4,$py - 1,"$avrgtemp",$blue);
43 $img->rectangle($px, $py, $px + 7,$py + 7,$black);
44 $img->filledRectangle($px + 1, $py + 1, $px + 6, $py + 6,$color);
45
46 print $cgi->header(-type=>'image/png');
47 print $img->png;
48
49 sub getcolor {
50         my ($temp) = @_;
51
52         my $percent = ($temp - $mintemp) / ($maxtemp - $mintemp);
53         my $colorred = 255 * $percent;
54         my $colorblue = 255 - $colorred;
55
56         return $img->colorAllocate($colorred, $colorblue, 0);
57 }