]> git.sesse.net Git - nms/blob - web/nettkart-telnet.pl
b3ea2dfa124c8e7e3e04ec9dbeb1b73b03e9fbc6
[nms] / web / nettkart-telnet.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-telnet.pl');
10
11 print <<"EOF";
12 <html>
13   <head>
14     <title>nettkart - telnet</title>
15   </head>
16   <body>
17     <map name="switches">
18 EOF
19
20 my $q = $dbh->prepare('select * from switches natural join placements natural left join
21 ( select switch,sum(bytes_in)/count(*) as
22 bytes_in,sum(bytes_out)/count(*) as bytes_out from get_datarate() group
23 by switch ) t1');
24 $q->execute();
25 while (my $ref = $q->fetchrow_hashref()) {
26         $ref->{'placement'} =~ /\((\d+),(\d+)\),\((\d+),(\d+)\)/;
27         
28         my $traffic = 4.0 * $ref->{'bytes_in'} + $ref->{'bytes_out'};  # average and convert to bits (should be about the same in practice)
29         my $ttext;
30         if ($traffic >= 1_000_000_000) {
31                 $ttext = sprintf "%.2f Gbit/port/sec", $traffic/1_000_000_000;
32         } elsif ($traffic => 1_000_000) {
33                 $ttext = sprintf "%.2f Mbit/port/sec", $traffic/1_000_000;
34         } else {
35                 $ttext = sprintf "%.2f kbit/port/sec", $traffic/1_000;
36         }
37
38         printf "      <area shape=\"rect\" coords=\"%u,%u,%u,%u\" target=\"blank\" href=\"telnet://$ref->{'ip'}\" alt=\"%s (%s)\" onmouseover=\"window.status='%s (%s)'; return true\" onmouseout=\"window.status=''\" />\n",
39                 $3, $4, $1, $2, $ref->{'switch'}, $ref->{'sysname'},
40                 $ttext, $ref->{'sysname'}, $ttext;
41 }
42 $dbh->disconnect;
43
44 print <<"EOF";
45     </map>
46
47     <p><img src="nettkart.pl" usemap="#switches" /></p>
48   </body>
49 </html>
50 EOF