From: root Date: Sat, 7 Apr 2007 16:30:09 +0000 (+0200) Subject: Merge. X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=cc0b9f43fe25834abfa41bb3bf57306865a608f8;hp=ec7c8cc04058bb8b9e921ae529f523d381808caf;p=nms Merge. --- diff --git a/clients/ciscong.pl b/clients/ciscong.pl index 76ec475..a2c0895 100644 --- a/clients/ciscong.pl +++ b/clients/ciscong.pl @@ -75,7 +75,7 @@ sub do_distro { # Prompt => '/[^\s\(]+(\([^\(]\)){0,1}[#>]/'); if (!defined($ios)) { print "Could not connect to $dip"; - return; + return 0; } $ios->login($nms::config::ios_user, $nms::config::ios_pass); $ios->enable; @@ -94,7 +94,7 @@ sub do_distro { if (ios_getroute($ios, "192.168.1.0") == 1) { print "Already routed up 192.168.1.0/24\n" ; - return; + return 0; } my $zyxeloldip = "192.168.1.1"; @@ -111,7 +111,7 @@ sub do_distro { print "Waiting for zyxel on $dip:$vlan timed out, wanted to set ip: $newip\n"; print LOG "Could not connect to $switchname\n"; stop_vlan($ios, $vlan); - return; + return 0; } last if $p->ping($zyxeloldip); print "pinging...\n"; @@ -130,6 +130,7 @@ sub do_distro { $ios->close(); + return 1; } ## Collect switch ips @@ -204,13 +205,14 @@ sub verify_run { while (1) { if ($counter > 4) { print "No answer from $dip:$vlan $ip, trying to route it up\n"; - do_distro($dip, $ip, $vlan, $switch); - my $pid = fork(); - if ($pid == 0) { - sleep 100; - system("perl ./ciscong2.pl $switch"); - exit 0; + my $ret = do_distro($dip, $ip, $vlan, $switch); + if ($ret == 0) { + # No answer from zyxel + last; } + print "Waiting for telnet to time out so we can do run ciscong.pl\n"; + sleep 100; + system("perl ./ciscong2.pl $switch"); last; } last if $p->ping($ip); diff --git a/clients/zyxelng.pl b/clients/zyxelng.pl index 3d02996..1641e96 100644 --- a/clients/zyxelng.pl +++ b/clients/zyxelng.pl @@ -53,7 +53,6 @@ $cmd = "ip ifconfig swif0 $newip/30"; print "Sending '$cmd'\n"; my $pid = fork(); if ($pid == 0) { - print "Sending ifconfig.. $cmd\n"; switch_exec($cmd, $switch); exit 0; } else { diff --git a/sql/get_rate.c b/sql/get_rate.c new file mode 100644 index 0000000..4e4a8b1 --- /dev/null +++ b/sql/get_rate.c @@ -0,0 +1,70 @@ +/* + gcc -fPIC -c get_rate.c -I$( pg_config --includedir-server ) + gcc -shared -o get_rate.so get_rate.o + */ + +#include "postgres.h" +#include +#include "fmgr.h" +#include "funcapi.h" +#include "catalog/pg_type.h" +#include "utils/lsyscache.h" +#include "utils/array.h" +#include "access/heapam.h" + +#ifdef PG_MODULE_MAGIC +PG_MODULE_MAGIC; +#endif + +PG_FUNCTION_INFO_V1(get_rate); + +Datum +get_rate(PG_FUNCTION_ARGS) +{ + float8 bytes_in_1 = PG_GETARG_FLOAT8(0); + float8 bytes_out_1 = PG_GETARG_FLOAT8(1); + float8 time_1 = PG_GETARG_FLOAT8(2); + + float8 bytes_in_2 = PG_GETARG_FLOAT8(3); + float8 bytes_out_2 = PG_GETARG_FLOAT8(4); + float8 time_2 = PG_GETARG_FLOAT8(5); + + bool no_wrap = PG_GETARG_BOOL(6); + + Datum values[2]; + + int16 elmlen; + bool elmbyval; + char elmalign; + + double in_rate, out_rate; + + if (bytes_in_2 >= bytes_in_1 && bytes_out_2 >= bytes_out_1) { + // regular case, no wraparound or reset + in_rate = (bytes_in_2 - bytes_in_1) / (time_2 - time_1); + out_rate = (bytes_out_2 - bytes_out_1) / (time_2 - time_1); + } else { + // is wraparound unlikely? + if (no_wrap + || (bytes_in_2 + 4294967296.0 - bytes_in_1) >= 2147483648.0 + || (bytes_out_2 + 4294967296.0 - bytes_out_1) >= 2147483648.0) { + // assume the switch zeroed in the middle of the poll interval + in_rate = bytes_in_2 / (2.0 * (time_2 - time_1)); + out_rate = bytes_out_2 / (2.0 * (time_2 - time_1)); + } else { + // probably wraparound + if (bytes_in_2 < bytes_in_1) + bytes_in_2 += 4294967296.0; + if (bytes_out_2 < bytes_out_1) + bytes_out_2 += 4294967296.0; + + in_rate = (bytes_in_2 - bytes_in_1) / (time_2 - time_1); + out_rate = (bytes_out_2 - bytes_out_1) / (time_2 - time_1); + } + } + + values[0] = Float8GetDatum(in_rate); + values[1] = Float8GetDatum(out_rate); + get_typlenbyvalalign(FLOAT8OID, &elmlen, &elmbyval, &elmalign); + PG_RETURN_ARRAYTYPE_P(construct_array(values, 2, FLOAT8OID, elmlen, elmbyval, elmalign)); +} diff --git a/web/index.html b/web/index.html index 5036d8c..8b06ef8 100644 --- a/web/index.html +++ b/web/index.html @@ -48,8 +48,8 @@
-
  • Utførte og køede kommandoer -
    Se og håndter kommandoer som er utført og fortsatt i køen +
  • Utførte og køede kommandoer +
    Se og håndter kommandoer som er utført og fortsatt i køen

  • @@ -57,6 +57,12 @@
  • Temperaturkart
    Temperaturkart for switchene
  • + +
    + +
  • MBD-status +
    Hva spiller folk mest? +
  • diff --git a/web/mbd-status.pl b/web/mbd-status.pl new file mode 100755 index 0000000..d8ac74e --- /dev/null +++ b/web/mbd-status.pl @@ -0,0 +1,44 @@ +#! /usr/bin/perl +use CGI; +use DBI; +use lib '../include'; +use nms; +my $cgi = CGI->new; + +my $dbh = nms::db_connect(); +print $cgi->header(-type=>'text/html; charset=utf-8', -refresh=>'10; http://nms.tg07.gathering.org/mbd-status.pl'); + +print <<"EOF"; + + + MBD status + + +

    MBD status

    + +

    Spill søkt etter siste 15 minutter:

    + + + + + + +EOF + +my $q = $dbh->prepare('select description,sum(active_servers) as active_servers from (select distinct on (game,port) * from mbd_log where ts >= now() - interval \'10 minutes\' order by game,port,ts desc ) t1 group by game,description order by sum(active_servers) desc, description;'); +$q->execute(); +while (my $ref = $q->fetchrow_hashref()) { + print <<"EOF"; + + + + +EOF +} +$dbh->disconnect; + +print <<"EOF"; +
    BeskrivelseAktive servere
    $ref->{'description'}$ref->{'active_servers'}
    + + +EOF diff --git a/web/nettkart-telnet.pl b/web/nettkart-telnet.pl index 783f53e..2a21bad 100755 --- a/web/nettkart-telnet.pl +++ b/web/nettkart-telnet.pl @@ -6,7 +6,7 @@ use nms; my $cgi = CGI->new; my $dbh = nms::db_connect(); -print $cgi->header(-type=>'text/html', -refresh=>'45; http://nms.tg07.gathering.org/nettkart-telnet.pl'); +print $cgi->header(-type=>'text/html; charset=utf-8', -refresh=>'45; http://nms.tg07.gathering.org/nettkart-telnet.pl'); print <<"EOF"; @@ -17,10 +17,7 @@ print <<"EOF"; EOF -my $q = $dbh->prepare('select * from switches natural join placements natural left join -( select switch,sum(bytes_in)/count(*) as -bytes_in,sum(bytes_out)/count(*) as bytes_out from get_datarate() group -by switch ) t1'); +my $q = $dbh->prepare('select * from switches natural join placements'); $q->execute(); while (my $ref = $q->fetchrow_hashref()) { $ref->{'placement'} =~ /\((\d+),(\d+)\),\((\d+),(\d+)\)/; diff --git a/web/nettkart-text.pl b/web/nettkart-text.pl index cf198dd..23e5cad 100755 --- a/web/nettkart-text.pl +++ b/web/nettkart-text.pl @@ -6,7 +6,7 @@ use nms; my $cgi = CGI->new; my $dbh = nms::db_connect(); -print $cgi->header(-type=>'text/html', -refresh=>'10; http://nms.tg07.gathering.org/nettkart-text.pl'); +print $cgi->header(-type=>'text/html; charset=utf-8', -refresh=>'10; http://nms.tg07.gathering.org/nettkart-text.pl'); print <<"EOF"; @@ -17,10 +17,7 @@ print <<"EOF"; EOF -my $q = $dbh->prepare('select * from switches natural join placements natural left join -( select switch,sum(bytes_in)/count(*) as -bytes_in,sum(bytes_out)/count(*) as bytes_out from get_datarate() group -by switch ) t1'); +my $q = $dbh->prepare('select * from switches natural join placements'); $q->execute(); while (my $ref = $q->fetchrow_hashref()) { $ref->{'placement'} =~ /\((\d+),(\d+)\),\((\d+),(\d+)\)/; diff --git a/web/nettkart-web.pl b/web/nettkart-web.pl index 040d476..8f37b1e 100755 --- a/web/nettkart-web.pl +++ b/web/nettkart-web.pl @@ -6,7 +6,7 @@ use nms; my $cgi = CGI->new; my $dbh = nms::db_connect(); -print $cgi->header(-type=>'text/html', -refresh=>'45; http://nms.tg07.gathering.org/nettkart-web.pl'); +print $cgi->header(-type=>'text/html; charset=utf-8', -refresh=>'45; http://nms.tg07.gathering.org/nettkart-web.pl'); print <<"EOF"; @@ -17,10 +17,7 @@ print <<"EOF"; EOF -my $q = $dbh->prepare('select * from switches natural join placements natural left join -( select switch,sum(bytes_in)/count(*) as -bytes_in,sum(bytes_out)/count(*) as bytes_out from get_datarate() group -by switch ) t1'); +my $q = $dbh->prepare('select * from switches natural join placements'); $q->execute(); while (my $ref = $q->fetchrow_hashref()) { $ref->{'placement'} =~ /\((\d+),(\d+)\),\((\d+),(\d+)\)/; diff --git a/web/nettkart.pl b/web/nettkart.pl index 89c63ea..bff972b 100755 --- a/web/nettkart.pl +++ b/web/nettkart.pl @@ -55,9 +55,7 @@ $text_img->stringFT($tclr, "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf", $text_img->stringFT($tclr, "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf", 10, 0, 40, 47 + (236-42)*4.0/4.0, "10 Mbit/sec"); $text_img->stringFT($tclr, "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf", 10, 0, 1000, 620, "NMS (C) 2005-2007 Tech:Server"); -my $q = $dbh->prepare('select * from switches natural join placements natural left join -( select switch,sum(bytes_in) as bytes_in,sum(bytes_out) as bytes_out from get_datarate() group -by switch ) t1 order by zorder'); +my $q = $dbh->prepare('select * from switches natural join placements natural left join current_datarate order by zorder'); $q->execute(); while (my $ref = $q->fetchrow_hashref()) { diff --git a/web/showswitch.pl b/web/showswitch.pl index 3be8769..72b1846 100755 --- a/web/showswitch.pl +++ b/web/showswitch.pl @@ -35,7 +35,7 @@ print <<"EOF";

    Switch $switch ($ref->{'sysname'})

    EOF -my $q = $dbh->prepare('select port,coalesce(description, \'Port \' || port) as description,extract(epoch from time) as time,bytes_in,bytes_out from polls natural join switches natural left join portnames where time between now() - \'1 day\'::interval and now() and switch=? order by switch,port,time;'); +my $q = $dbh->prepare('select port,coalesce(description, \'Port \' || port) as description,extract(epoch from time) as time,bytes_in,bytes_out from switches natural left join portnames natural join polls where time between now() - \'1 day\'::interval and now() and switch=? order by switch,port,time;'); $q->execute($switch); my (@totx, @toty1, @toty2) = (); diff --git a/web/smanagement.pl b/web/smanagement.pl index de7e1b8..90d61fb 100755 --- a/web/smanagement.pl +++ b/web/smanagement.pl @@ -89,7 +89,7 @@ sub get_addr_from_switchnum($) { my $cgi = new CGI; -print $cgi->header(-type=>'text/html'); +print $cgi->header(-type=>'text/html; charset=utf-8'); print << "EOF"; diff --git a/web/sshow.pl b/web/sshow.pl index b840ac8..5e0fbdc 100755 --- a/web/sshow.pl +++ b/web/sshow.pl @@ -74,7 +74,7 @@ WHERE gid = ?::text::int") my $cgi = new CGI; -print $cgi->header(-type=>'text/html'); +print $cgi->header(-type=>'text/html; charset=utf-8'); print << "EOF";