diff options
Diffstat (limited to 'web')
| -rwxr-xr-x | web/nms.gathering.org/api/private/snmp | 3 | ||||
| -rwxr-xr-x | web/nms.gathering.org/api/private/which-switch-am-i-on | 40 | ||||
| -rwxr-xr-x | web/nms.gathering.org/api/public/dhcp-summary | 2 | ||||
| -rwxr-xr-x | web/nms.gathering.org/api/public/ping | 32 | ||||
| -rwxr-xr-x | web/nms.gathering.org/api/public/switch-state | 6 | 
5 files changed, 66 insertions, 17 deletions
| diff --git a/web/nms.gathering.org/api/private/snmp b/web/nms.gathering.org/api/private/snmp index 4779659..f69ca62 100755 --- a/web/nms.gathering.org/api/private/snmp +++ b/web/nms.gathering.org/api/private/snmp @@ -13,7 +13,8 @@ use Data::Dumper;  $nms::web::cc{'max-age'} = "10"; -my $q = $nms::web::dbh->prepare('select sysname,data from snmp natural join switches where id in (select max(id) from snmp where ' . $nms::web::when . 'group by switch);'); +my $q = $nms::web::dbh->prepare('select sysname,data from snmp natural join switches where id in (select max(id) from snmp where ' +        . $nms::web::when . 'group by switch);');  $q->execute();  while (my $ref = $q->fetchrow_hashref()) { diff --git a/web/nms.gathering.org/api/private/which-switch-am-i-on b/web/nms.gathering.org/api/private/which-switch-am-i-on new file mode 100755 index 0000000..0d3f2b4 --- /dev/null +++ b/web/nms.gathering.org/api/private/which-switch-am-i-on @@ -0,0 +1,40 @@ +#! /usr/bin/perl +# vim:ts=8:sw=8 + +use lib '../../../../include'; +use nms::web; +use strict; +use warnings; +use Data::Dumper; + +#my $query = $nms::web::dbh->prepare("select * from switches where '185.110.150.7' << subnet4"); +my $query = $nms::web::dbh->prepare("select * from switches where '88.92.5.67' << subnet4"); +$query->execute(); + +print "Cache-Control: max-age=0"; +print "Content-Type: text/html"; +print "\n\n"; + +# get user ip from somewhere. +# HTTP_X_FORWARDED_FOR is set by varnish. When using varnish, the REMOTE_ADDR will always be localhost. +my $addr = $ENV{HTTP_X_FORWARDED_FOR} // $ENV{REMOTE_ADDR}; + +# add start html: header + body etc. +print " +<html> +    <body style=\"text-align: center; font-size: 50pt;\"> +"; + +# print address +print "" . $addr ."<br \>"; + +# print switch name and distroname. +while ( my $ref = $query->fetchrow_hashref() ) { +    print $ref->{sysname}. " @ " . $ref->{distro}; +} + +# add end html +print " +    </body> +</html> +"; diff --git a/web/nms.gathering.org/api/public/dhcp-summary b/web/nms.gathering.org/api/public/dhcp-summary index 31bc8eb..dd643b2 100755 --- a/web/nms.gathering.org/api/public/dhcp-summary +++ b/web/nms.gathering.org/api/public/dhcp-summary @@ -1,5 +1,7 @@  #! /usr/bin/perl  use lib '../../../../include'; +use strict; +use warnings;  use nms::web;  nms::web::setwhen('2h'); diff --git a/web/nms.gathering.org/api/public/ping b/web/nms.gathering.org/api/public/ping index bf92440..ba572af 100755 --- a/web/nms.gathering.org/api/public/ping +++ b/web/nms.gathering.org/api/public/ping @@ -1,31 +1,35 @@  #! /usr/bin/perl  use lib '../../../../include'; +use strict; +use warnings;  use nms::web;  #nms::web::setwhen('1s'); -my $q = $nms::web::dbh->prepare("SELECT DISTINCT ON (sysname) (now() - time) as age,sysname, latency_ms FROM ping NATURAL JOIN switches WHERE time in (select max(time) from ping where " . $nms::web::when . " group by switch)"); +my $q = $nms::web::dbh->prepare("SELECT DISTINCT ON (sysname) (now() - time) as age,sysname, latency_ms FROM ping NATURAL JOIN switches WHERE time in (select max(time) from ping where " +        . $nms::web::when . " group by switch)"); +  $q->execute();  while (my $ref = $q->fetchrow_hashref()) { -	$nms::web::json{'switches'}{$ref->{'sysname'}}{'latency'} = $ref->{'latency_ms'}; -	# This isn't pretty, feel free to fix, but I want age == seconds -	# without decimals. -	my ($h,$m,$ss) = split(':', $ref->{'age'}); -	my ($s,undef) = split('\.', "$ss"); -	 -	$nms::web::json{'switches'}{$ref->{'sysname'}}{'age'} = ($h*60*60) + ($m*60) + $s;#  $$ref->{'age'}; +    $nms::web::json{'switches'}{$ref->{'sysname'}}{'latency'} = $ref->{'latency_ms'}; +    # Get seconds, without decimlas, from timestamp. +    # '00:01:01.435601' => 61 seconds. +    my ( $h, $m, $s ) = split( ':|\.', $ref->{'age'} ); +    $nms::web::json{'switches'}{$ref->{'sysname'}}{'age'} = ($h*60*60) + ($m*60) + $s; # $$ref->{'age'};  } -my $qs = $nms::web::dbh->prepare("SELECT DISTINCT ON (switch) switch, latency_ms FROM ping_secondary_ip WHERE " . $nms::web::when .  " ORDER BY switch, time DESC;"); +my $qs = $nms::web::dbh->prepare("SELECT DISTINCT ON (switch) switch, latency_ms FROM ping_secondary_ip WHERE " +        . $nms::web::when .  " ORDER BY switch, time DESC;");  $qs->execute(); -while (my $ref = $qs->fetchrow_hashref()) { -	$nms::web::json{'switches'}{$ref->{'switch'}}{'latency_secondary'} = $ref->{'latency_ms'}; +while ( my $ref = $qs->fetchrow_hashref() ) { +    $nms::web::json{'switches'}{$ref->{'switch'}}{'latency_secondary'} = $ref->{'latency_ms'};  } -my $lq = $nms::web::dbh->prepare("SELECT DISTINCT ON (linknet) linknet, latency1_ms, latency2_ms FROM linknet_ping WHERE ". $nms::web::when . " ORDER BY linknet, time DESC;"); +my $lq = $nms::web::dbh->prepare("SELECT DISTINCT ON (linknet) linknet, latency1_ms, latency2_ms FROM linknet_ping WHERE " +        . $nms::web::when . " ORDER BY linknet, time DESC;");  $lq->execute(); -while (my $ref = $lq->fetchrow_hashref()) { -	$nms::web::json{'linknets'}{$ref->{'linknet'}} = [ $ref->{'latency1_ms'}, $ref->{'latency2_ms'} ]; +while ( my $ref = $lq->fetchrow_hashref() ) { +    $nms::web::json{'linknets'}{$ref->{'linknet'}} = [ $ref->{'latency1_ms'}, $ref->{'latency2_ms'} ];  }  $nms::web::cc{'max-age'} = "1"; diff --git a/web/nms.gathering.org/api/public/switch-state b/web/nms.gathering.org/api/public/switch-state index 38f4c57..62d0078 100755 --- a/web/nms.gathering.org/api/public/switch-state +++ b/web/nms.gathering.org/api/public/switch-state @@ -7,10 +7,11 @@ use strict;  use warnings;  use Data::Dumper; -my $q = $nms::web::dbh->prepare('select sysname,extract(epoch from date_trunc(\'second\',time)) as time,data from snmp natural join switches where id in (select max(id) from snmp where ' . $nms::web::when . 'group by switch);'); +my $q = $nms::web::dbh->prepare('select sysname,extract(epoch from date_trunc(\'second\',time)) as time,data from snmp natural join switches where id in (select max(id) from snmp where ' +        . $nms::web::when . 'group by switch);');  $q->execute(); -while (my $ref = $q->fetchrow_hashref()) { +while ( my $ref = $q->fetchrow_hashref() ) {  	my $sysname = $ref->{'sysname'};  	my %data = %{JSON::XS::decode_json($ref->{'data'})}; @@ -37,6 +38,7 @@ while (my $ref = $q->fetchrow_hashref()) {  	}  	$json{'switches'}{$sysname}{'time'} = $ref->{'time'};  } +  $nms::web::cc{'max-age'} = "5";  $nms::web::cc{'stale-while-revalidate'} = "30";  finalize_output(); | 
