aboutsummaryrefslogtreecommitdiffstats
path: root/web/nms-public.gathering.org/old/nettkart-text.pl
blob: 673ade5f3846fd4749e6bb2cd1c57c0818a9c815 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#! /usr/bin/perl
use CGI;
use DBI;
use lib '../../include';
use nms;
my $cgi = CGI->new;

my $dbh = nms::db_connect();

my $night = defined($cgi->param('night'));

if ($night) {
print $cgi->header(-type=>'text/html; charset=utf-8', -refresh=>'10; nettkart-text.pl?night=1');
} else {
print $cgi->header(-type=>'text/html; charset=utf-8', -refresh=>'10; ' . CGI::url());
}

my $tag = "";

$tag = "bgcolor=black" if($night);

print <<"EOF";
<html>
  <head>
    <title>nettkart</title>
  </head>
  <body $tag>
    <map name="switches">
EOF

my $q = $dbh->prepare("select * from switches natural join placements where ip <> inet '127.0.0.1'");
$q->execute();
while (my $ref = $q->fetchrow_hashref()) {
	$ref->{'placement'} =~ /\((\d+),(\d+)\),\((\d+),(\d+)\)/;
	
	my $traffic = 4.0 * $ref->{'bytes_in'} + $ref->{'bytes_out'};  # average and convert to bits (should be about the same in practice)
	my $ttext;
	if ($traffic >= 1_000_000_000) {
		$ttext = sprintf "%.2f Gbit/port/sec", $traffic/1_000_000_000;
	} elsif ($traffic => 1_000_000) {
		$ttext = sprintf "%.2f Mbit/port/sec", $traffic/1_000_000;
	} else {
		$ttext = sprintf "%.2f kbit/port/sec", $traffic/1_000;
	}

	printf "      <area shape=\"rect\" coords=\"%u,%u,%u,%u\" href=\"showswitch.pl?id=%u\" alt=\"%s (%s)\" onmouseover=\"window.status='%s (%s)'; return true\" onmouseout=\"window.status=''\" />\n",
		$3, $4, $1, $2, $ref->{'switch'}, $ref->{'sysname'},
		$ttext, $ref->{'sysname'}, $ttext;
}
$dbh->disconnect;

my $image = "nettkart.pl";

$image = "nettkart.pl?night=1" if ($night);


print <<"EOF";
    </map>

    <p><img src="$image" usemap="#switches" /></p>
  </body>
</html>
EOF