]> git.sesse.net Git - nms/commitdiff
Merge. master
authorroot <root@space>
Sat, 7 Apr 2007 16:30:09 +0000 (18:30 +0200)
committerroot <root@space>
Sat, 7 Apr 2007 16:30:09 +0000 (18:30 +0200)
12 files changed:
clients/ciscong.pl
clients/zyxelng.pl
sql/get_rate.c [new file with mode: 0644]
web/index.html
web/mbd-status.pl [new file with mode: 0755]
web/nettkart-telnet.pl
web/nettkart-text.pl
web/nettkart-web.pl
web/nettkart.pl
web/showswitch.pl
web/smanagement.pl
web/sshow.pl

index 76ec4759102a2d9556f1352ec28bc68ec8230d46..a2c08954eb00ec5806b9c1dc035801cf3dc6eeb4 100644 (file)
@@ -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);
index 3d029967e80903ec2b6d41c73e1bb019c356eb24..1641e96993b79cae117113fb49a9e5e06b5e8b9c 100644 (file)
@@ -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 (file)
index 0000000..4e4a8b1
--- /dev/null
@@ -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 <string.h>
+#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));
+}
index 5036d8c71d8650bcdfc41aa5255868a4a55d45c4..8b06ef8dbbbf3696f37ca7ddebe09a5a511bd626 100644 (file)
@@ -48,8 +48,8 @@
 
       <br />
 
-      <li><a href="sshow.pl">Utførte og køede kommandoer</a>
-        <br /><i>Se og håndter kommandoer som er utført og fortsatt i køen</i>
+      <li><a href="sshow.pl">Utførte og køede kommandoer</a>
+        <br /><i>Se og håndter kommandoer som er utført og fortsatt i køen</i>
       </li>
 
       <br />
       <li><a href="stempmap.pl">Temperaturkart</a>
         <br /><i>Temperaturkart for switchene</i>
       </li>
+
+      <br />
+
+      <li><a href="mbd-status.pl">MBD-status</a>
+        <br /><i>Hva spiller folk mest?</i>
+      </li>
     </ul>
   </body>
 </html>
diff --git a/web/mbd-status.pl b/web/mbd-status.pl
new file mode 100755 (executable)
index 0000000..d8ac74e
--- /dev/null
@@ -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";
+<html>
+  <head>
+    <title>MBD status</title>
+  </head>
+  <body>
+    <h1>MBD status</h1>
+
+    <p>Spill søkt etter siste 15 minutter:</p>
+
+    <table>
+      <tr>
+        <th>Beskrivelse</th>
+       <th>Aktive servere</th>
+      </tr>
+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";
+      <tr>
+        <td>$ref->{'description'}</td>
+       <td>$ref->{'active_servers'}</td>
+      </tr>
+EOF
+}
+$dbh->disconnect;
+
+print <<"EOF";
+    </table>
+  </body>
+</html>
+EOF
index 783f53ebf8e71bd68db213523d2ca389bc3b51ef..2a21bad5c397028be24e297696b29616595bb066 100755 (executable)
@@ -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";
 <html>
@@ -17,10 +17,7 @@ print <<"EOF";
     <map name="switches">
 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+)\)/;
index cf198dd36ee20fca507bfd27403172215b0aa73c..23e5cad1898c810930e21181da494f3c3792fcbd 100755 (executable)
@@ -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";
 <html>
@@ -17,10 +17,7 @@ print <<"EOF";
     <map name="switches">
 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+)\)/;
index 040d4767865e5ee2a5566a60ff079caf0be4933f..8f37b1efd12b63b6af21aa73879934bbee47c4c3 100755 (executable)
@@ -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";
 <html>
@@ -17,10 +17,7 @@ print <<"EOF";
     <map name="switches">
 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+)\)/;
index 89c63eaca08af3b9de603ec83b37084acdbebec1..bff972bbd4b9a08f3f5ac96ffbcc956df1c8d4c6 100755 (executable)
@@ -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()) {
 
index 3be8769c34dafdd0127203a52756049fe20bf343..72b18462b10e3e07098e19c7224be381b5f94fa2 100755 (executable)
@@ -35,7 +35,7 @@ print <<"EOF";
     <h1>Switch $switch ($ref->{'sysname'})</h1>
 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) = ();
index de7e1b8d134d4df33b69b99bfae02d59e7c810fd..90d61fbe5d0423ef7b28acbd7461cefc08292897 100755 (executable)
@@ -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";
 <html>
index b840ac8a70a1b940e0951d8f7b2dfe24b64de3fd..5e0fbdce5e3fd901305a3c6350fc4eaf91ceb56a 100755 (executable)
@@ -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";
 <html>