# 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;
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";
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";
$ios->close();
+ return 1;
}
## Collect switch ips
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);
print "Sending '$cmd'\n";
my $pid = fork();
if ($pid == 0) {
- print "Sending ifconfig.. $cmd\n";
switch_exec($cmd, $switch);
exit 0;
} else {
--- /dev/null
+/*
+ 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));
+}
<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>
--- /dev/null
+#! /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
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>
<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+)\)/;
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>
<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+)\)/;
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>
<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+)\)/;
$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()) {
<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) = ();
my $cgi = new CGI;
-print $cgi->header(-type=>'text/html');
+print $cgi->header(-type=>'text/html; charset=utf-8');
print << "EOF";
<html>
my $cgi = new CGI;
-print $cgi->header(-type=>'text/html');
+print $cgi->header(-type=>'text/html; charset=utf-8');
print << "EOF";
<html>