11 my $night = defined($cgi->param('night'));
13 my $dbh = nms::db_connect();
15 GD::Image->trueColor(1);
18 $img = GD::Image->new('bg07.png');
20 my ($width, $height) = ($img->width, $img->height);
22 $img = GD::Image->new($width, $height);
23 $img->alphaBlending(0);
25 my $blank = $img->colorAllocateAlpha(0, 0, 0, 127);
26 $img->filledRectangle(0, 0, $img->width - 1, $img->height - 1, $blank);
28 $text_img = GD::Image->new($width, $height);
29 $text_img->alphaBlending(0);
30 $text_img->saveAlpha(1);
31 my $blank = $text_img->colorAllocateAlpha(0, 0, 0, 127);
32 $text_img->filledRectangle(0, 0, $text_img->width - 1, $text_img->height - 1, $blank);
34 $img = GD::Image->new('bg07.png');
38 my $blk = $img->colorResolve(0, 0, 0);
41 my $i = 4.0 * ($y - 236.0) / (42.0 - 237.0);
42 my $clr = get_color($i);
44 $img->filledRectangle(12, $y, 33, $y+1, $clr);
45 $text_img->filledRectangle(12, $y, 33, $y+1, $clr);
48 $text_img->rectangle(12,42,33,236,$blk);
50 my $tclr = $night ? $text_img->colorResolve(255, 255, 255) : $blk;
51 $text_img->stringFT($tclr, "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf", 10, 0, 40, 47 + (236-42)*0.0/4.0, "100 Gbit/sec");
52 $text_img->stringFT($tclr, "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf", 10, 0, 40, 47 + (236-42)*1.0/4.0, "10 Gbit/sec");
53 $text_img->stringFT($tclr, "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf", 10, 0, 40, 47 + (236-42)*2.0/4.0, "1 Gbit/sec");
54 $text_img->stringFT($tclr, "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf", 10, 0, 40, 47 + (236-42)*3.0/4.0, "100 Mbit/sec");
55 $text_img->stringFT($tclr, "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf", 10, 0, 40, 47 + (236-42)*4.0/4.0, "10 Mbit/sec");
56 $text_img->stringFT($tclr, "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf", 10, 0, 1000, 620, "NMS (C) 2005-2007 Tech:Server");
58 my $q = $dbh->prepare('select * from switches natural join placements natural left join
59 ( select switch,sum(bytes_in) as bytes_in,sum(bytes_out) as bytes_out from get_datarate() group
60 by switch ) t1 order by zorder');
62 while (my $ref = $q->fetchrow_hashref()) {
65 # 10Mbit/switch = green
66 # 100Mbit/switch = yellow
68 # 10Gbit/switch = white
72 if (defined($ref->{'bytes_in'})) {
74 my $traffic = 4.0 * $ref->{'bytes_in'} + $ref->{'bytes_out'}; # average and convert to bits (should be about the same in practice)
76 my $max = 10_000_000_000.0; # 10Gbit
77 my $min = 10_000_000.0; # 10Mbit
78 if ($traffic >= $min) {
79 $intensity = log($traffic / $min) / log(10);
80 $intensity = 3.0 if ($intensity > 3.0);
82 $clr = get_color($intensity);
84 $clr = $img->colorResolve(0, 0, 255);
87 $ref->{'placement'} =~ /\((\d+),(\d+)\),\((\d+),(\d+)\)/;
88 $img->filledRectangle($3,$4,$1,$2,$clr);
89 $text_img->filledRectangle($3,$4,$1,$2,$clr);
91 $img->rectangle($3,$4,$1,$2,$blk);
92 $text_img->rectangle($3,$4,$1,$2,$blk);
93 $text_img->stringUp(gdSmallFont,$3,$2-3,$ref->{'sysname'},$blk);
97 print $cgi->header(-type=>'image/png');
99 my $magick = Image::Magick->new;
100 $magick->BlobToImage($img->png);
101 $magick->Blur(sigma=>10.0, channels=>'All');
102 $magick->Gamma(gamma=>1.90);
104 my $m2 = Image::Magick->new;
105 $m2->Read('snmp-bg.png');
107 $m2->Composite(image=>$magick, compose=>'Atop');
109 my $m3 = Image::Magick->new;
110 $m3->BlobToImage($text_img->png);
111 $m2->Composite(image=>$m3, compose=>'Atop');
113 $img = $m2->ImageToBlob();
120 my $intensity = shift;
121 my $gamma = 1.0/1.90;
122 if ($intensity > 3.0) {
123 return $img->colorResolve(255.0 * ((4.0 - $intensity) ** $gamma), 255.0 * ((4.0 - $intensity) ** $gamma), 255.0 * ((4.0 - $intensity) ** $gamma));
124 } elsif ($intensity > 2.0) {
125 return $img->colorResolve(255.0, 255.0 * (($intensity - 2.0) ** $gamma), 255.0 * (($intensity - 2.0) ** $gamma));
126 } elsif ($intensity > 1.0) {
127 return $img->colorResolve(255.0, 255.0 * ((2.0 - $intensity) ** $gamma), 0);
129 return $img->colorResolve(255.0 * ($intensity ** $gamma), 255, 0);