11 GD::Image->trueColor(1);
13 my $img = GD::Image->new('snmp-bg.png');
14 #my $img = GD::Image->new(100,100);
17 my $dbh = DBI->connect("dbi:Pg:dbname=snmpfetch;host=violet.tg05.gathering.org", "snmpfetch", "removed")
18 or die "Couldn't connect to database";
20 my $sgetpoll = $dbh->prepare('select switch,(select temp from temppoll where switches.switch=temppoll.switch AND temp != 0 order by id desc limit 1) AS temp,placement from switches natural join placements');
22 my $black = $img->colorAllocate(0,0,0);
23 my $white = $img->colorAllocate(255,255,255);
24 my $green = $img->colorAllocate(0,255,0);
25 my $blue = $img->colorAllocate(0,0,255);
32 my $color = &getcolor($avrgtemp);
34 open (OUT, "> /tmp/outtemps");
35 for (my $i = 0; $i < $steps; $i++) {
36 my $diff = $maxtemp - $mintemp;
37 my $temp = $mintemp + ($maxtemp - $mintemp) * ((($diff / $steps) * $i)/$diff);
38 $img->line(5, $i, 45, $i, &getcolor2($temp));
42 $img->string(gdMediumBoldFont, 50, 0, "Freezing!", $black);
43 $img->string(gdMediumBoldFont, 50, $steps - 11, "Too hot!", $black);
44 $img->string(gdMediumBoldFont, 50, 12, "$mintemp C", $black);
45 $img->string(gdMediumBoldFont, 50, $steps - 22, "$maxtemp C", $black);
47 #$img->string(gdMediumBoldFont, 600, 200, "Freezing!$mintemp", $black);
48 #$img->string(gdMediumBoldFont, 600, 210, "$mintemp C", $black);
49 #$img->string(gdMediumBoldFont, 600, 220 + $maxtemp, "Too hot! $maxtemp", $black);
50 #$img->string(gdMediumBoldFont, 600, 210 + $maxtemp, "$maxtemp C", $black);
54 while (my $ref = $sgetpoll->fetchrow_hashref()) {
55 next if (!defined($ref->{'temp'}));
57 $ref->{'placement'} =~ /\((\d+),(\d+)\),\((\d+),(\d+)\)/;
58 $avrgtemp = $ref->{'temp'};
61 my $roundtemp = sprintf ("%.0f", $avrgtemp);
62 $color = getcolor($avrgtemp);
63 $img->filledRectangle($px - 0, $py - 17, $px + 12, $py + 5, $white);
64 $img->stringUp(gdGiantFont,$px - 1,$py - 1,"$roundtemp",$blue);
65 $img->rectangle($px, $py, $px + 10,$py + 10,$black);
66 $img->filledRectangle($px + 1, $py + 1, $px + 9, $py + 9,$color);
69 print $cgi->header(-type=>'image/png');
75 my $t = ($temp - $mintemp) / ($maxtemp - $mintemp);
79 my $colorred = 255 * $t;
80 my $colorblue = 255 - $colorred;
82 return $img->colorResolve($colorred, 0, $colorblue);
88 my $t = ($temp - $mintemp) / ($maxtemp - $mintemp);
92 my $colorred = 255 * $t;
93 my $colorblue = 255 - $colorred;
95 return $img->colorResolve($colorred, 0, $colorblue);