]> git.sesse.net Git - nms/blob - web/nettkart-web.pl
Optomalize!
[nms] / web / nettkart-web.pl
1 #! /usr/bin/perl
2 use CGI;
3 use DBI;
4 use lib '../include';
5 use nms;
6 my $cgi = CGI->new;
7
8 my $dbh = nms::db_connect();
9 print $cgi->header(-type=>'text/html; charset=utf-8', -refresh=>'45; http://nms.tg07.gathering.org/nettkart-web.pl');
10
11 print <<"EOF";
12 <html>
13   <head>
14     <title>nettkart - web</title>
15   </head>
16   <body>
17     <map name="switches">
18 EOF
19
20 my $q = $dbh->prepare('select * from switches natural join placements');
21 $q->execute();
22 while (my $ref = $q->fetchrow_hashref()) {
23         $ref->{'placement'} =~ /\((\d+),(\d+)\),\((\d+),(\d+)\)/;
24         
25         my $traffic = 4.0 * $ref->{'bytes_in'} + $ref->{'bytes_out'};  # average and convert to bits (should be about the same in practice)
26         my $ttext;
27         if ($traffic >= 1_000_000_000) {
28                 $ttext = sprintf "%.2f Gbit/port/sec", $traffic/1_000_000_000;
29         } elsif ($traffic => 1_000_000) {
30                 $ttext = sprintf "%.2f Mbit/port/sec", $traffic/1_000_000;
31         } else {
32                 $ttext = sprintf "%.2f kbit/port/sec", $traffic/1_000;
33         }
34
35         printf "      <area shape=\"rect\" coords=\"%u,%u,%u,%u\" href=\"http://$ref->{'ip'}\" alt=\"%s (%s)\" onmouseover=\"window.status='%s (%s)'; return true\" onmouseout=\"window.status=''\" />\n",
36                 $3, $4, $1, $2, $ref->{'switch'}, $ref->{'sysname'},
37                 $ttext, $ref->{'sysname'}, $ttext;
38 }
39 $dbh->disconnect;
40
41 print <<"EOF";
42     </map>
43
44     <p><img src="nettkart.pl" usemap="#switches" /></p>
45   </body>
46 </html>
47 EOF