From cc2534ef349680951afb0d0dfe7797843d10cccf Mon Sep 17 00:00:00 2001 From: Nicolai Tellefsen Date: Sat, 19 Mar 2016 19:54:14 +0100 Subject: NMS: Add basic add-switch interface --- web/nms.gathering.org/api/private/switch-add | 32 +------ web/nms.gathering.org/api/private/switch-update | 122 ++++++++++++++++++++++++ 2 files changed, 123 insertions(+), 31 deletions(-) create mode 100755 web/nms.gathering.org/api/private/switch-update (limited to 'web/nms.gathering.org/api') diff --git a/web/nms.gathering.org/api/private/switch-add b/web/nms.gathering.org/api/private/switch-add index 3d7b119..70d6212 100755 --- a/web/nms.gathering.org/api/private/switch-add +++ b/web/nms.gathering.org/api/private/switch-add @@ -83,40 +83,10 @@ foreach my $tmp2 (@tmp) { $nms::web::dbh->do("INSERT INTO SWITCHES (ip, sysname, switchtype, last_updated, locked, poll_frequency, community, lldp_chassis_id, secondary_ip, placement) VALUES ($template{'ip'}, $template{'sysname'}, $template{'switchtype'}, $template{'last_updated'}, $template{'locked'}, $template{'poll_frequency'}, $template{'community'}, $template{'lldp_chassis_id'}, $template{'secondary_ip'}, $template{'placement'});"); push @added, $switch{'sysname'}; - } else { - if (defined($switch{'placement'})) { - my %placement; - if ($switch{'placement'} eq "reset") { - %placement = guess_placement($switch{'sysname'}); - } else { - %placement = %{convertplace($switch{'placement'})}; - } - my ($x1,$x2,$y1,$y2); - $x1 = $placement{'x1'}; - $y1 = $placement{'y1'}; - $x2 = $placement{'xx'}; - $y2 = $placement{'yy'}; - $switch{'placement'} = "(($x1,$y1),($x2,$y2))"; - push @dups, "not really, but: " . $switch{'placement'}; - } - if (not defined($switch{'ip'}) and defined($switch{'mgtmt4'})) { - $switch{'ip'} = $switch{'mgtmt4'}; - } - if (not defined($switch{'secondary_ip'}) and defined($switch{'mgtmt6'})) { - $switch{'secondary_ip'} = $switch{'mgtmt6'}; - } - my @set; - map { - if (defined($template{$_})) { - push @set, "$_=" . $dbh->quote($switch{$_}); - } - } keys %switch; - $nms::web::dbh->do("UPDATE SWITCHES SET " . join(", ", @set) . "WHERE sysname=" . $dbh->quote($switch{'sysname'}) . ";"); - push @dups, $switch{'sysname'}; } } + $json{'switches_addded'} = \@added; -$json{'switches_updated'} = \@dups; print "X-ban: /api/.*switches.*\n"; finalize_output(); diff --git a/web/nms.gathering.org/api/private/switch-update b/web/nms.gathering.org/api/private/switch-update new file mode 100755 index 0000000..3d7b119 --- /dev/null +++ b/web/nms.gathering.org/api/private/switch-update @@ -0,0 +1,122 @@ +#! /usr/bin/perl +# vim:ts=8:sw=8 + +#use CGI qw(fatalsToBrowser); +use DBI; +use lib '../../../../include'; +use nms; +use nms::web qw(%get_params %json finalize_output get_input $dbh); +use nms::util qw(guess_placement); +use strict; +use warnings; +use JSON; +use Data::Dumper; + +$nms::web::cc{'max-age'} = "0"; + +my $in = get_input(); +my @tmp = @{JSON::XS::decode_json($in)}; + +my @added; +my @dups; + +my $sth = $nms::web::dbh->prepare("SELECT sysname FROM switches WHERE sysname=?"); + +my @fields = ('ip', 'sysname', 'switchtype', 'last_updated', 'locked', 'poll_frequency', 'community', 'lldp_chassis_id', 'secondary_ip', 'subnet4', 'subnet6', 'placement', 'distro', 'secondary_ip'); + +sub convertplace +{ + my %in = %{$_[0]}; + my %out = (); + + if (not defined $in{'x1'} and defined($in{'x'})) { + $out{'x1'} = int($in{'x'}); + $out{'y1'} = int($in{'y'}); + $out{'xx'} = int($in{'x'} + $in{'width'}); + $out{'yy'} = int($in{'y'} + $in{'height'}); + } else { + return \%in; + } + return \%out; +} + +foreach my $tmp2 (@tmp) { + my %switch = %{$tmp2}; + my $affected = 0; + my %template = (); + map { $template{$_} = 'DEFAULT' } @fields; + if (not defined($switch{'sysname'})) { + next; + } + + $sth->execute( $switch{'sysname'}); + while ( my @row = $sth->fetchrow_array ) { + $affected += 1; + } + + if ($affected == 0) { + my %placement; + if (not defined ($switch{'placement'})) { + %placement = guess_placement($switch{'sysname'}); + } else { + %placement = %{convertplace($switch{'placement'})}; + } + if (not defined($switch{'ip'}) and defined($switch{'mgtmt4'})) { + $switch{'ip'} = $switch{'mgtmt4'}; + } + if (not defined($switch{'secondary_ip'}) and defined($switch{'mgtmt6'})) { + $switch{'secondary_ip'} = $switch{'mgtmt6'}; + } + my ($x1,$x2,$y1,$y2); + $x1 = $placement{'x1'}; + $y1 = $placement{'y1'}; + $x2 = $placement{'xx'}; + $y2 = $placement{'yy'}; + $switch{'placement'} = "(($x1,$y1),($x2,$y2))"; + + map { + if (defined ($template{$_})) { + $template{$_} = $dbh->quote($switch{$_}); + } + } keys %switch; + + + $nms::web::dbh->do("INSERT INTO SWITCHES (ip, sysname, switchtype, last_updated, locked, poll_frequency, community, lldp_chassis_id, secondary_ip, placement) VALUES ($template{'ip'}, $template{'sysname'}, $template{'switchtype'}, $template{'last_updated'}, $template{'locked'}, $template{'poll_frequency'}, $template{'community'}, $template{'lldp_chassis_id'}, $template{'secondary_ip'}, $template{'placement'});"); + push @added, $switch{'sysname'}; + } else { + if (defined($switch{'placement'})) { + my %placement; + if ($switch{'placement'} eq "reset") { + %placement = guess_placement($switch{'sysname'}); + } else { + %placement = %{convertplace($switch{'placement'})}; + } + my ($x1,$x2,$y1,$y2); + $x1 = $placement{'x1'}; + $y1 = $placement{'y1'}; + $x2 = $placement{'xx'}; + $y2 = $placement{'yy'}; + $switch{'placement'} = "(($x1,$y1),($x2,$y2))"; + push @dups, "not really, but: " . $switch{'placement'}; + } + if (not defined($switch{'ip'}) and defined($switch{'mgtmt4'})) { + $switch{'ip'} = $switch{'mgtmt4'}; + } + if (not defined($switch{'secondary_ip'}) and defined($switch{'mgtmt6'})) { + $switch{'secondary_ip'} = $switch{'mgtmt6'}; + } + my @set; + map { + if (defined($template{$_})) { + push @set, "$_=" . $dbh->quote($switch{$_}); + } + } keys %switch; + $nms::web::dbh->do("UPDATE SWITCHES SET " . join(", ", @set) . "WHERE sysname=" . $dbh->quote($switch{'sysname'}) . ";"); + push @dups, $switch{'sysname'}; + } +} +$json{'switches_addded'} = \@added; +$json{'switches_updated'} = \@dups; + +print "X-ban: /api/.*switches.*\n"; +finalize_output(); -- cgit v1.2.3 From 2971d19f9835b0787813af22fd6bad3a6aca88e7 Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Sun, 20 Mar 2016 13:05:08 +0000 Subject: NMS: Add dhcp-summary --- web/nms.gathering.org/api/public/dhcp-summary | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100755 web/nms.gathering.org/api/public/dhcp-summary (limited to 'web/nms.gathering.org/api') diff --git a/web/nms.gathering.org/api/public/dhcp-summary b/web/nms.gathering.org/api/public/dhcp-summary new file mode 100755 index 0000000..31bc8eb --- /dev/null +++ b/web/nms.gathering.org/api/public/dhcp-summary @@ -0,0 +1,19 @@ +#! /usr/bin/perl +use lib '../../../../include'; +use nms::web; + +nms::web::setwhen('2h'); +my $q = $nms::web::dbh->prepare("select count(distinct mac) as clients,count(distinct ip) as addresses,count(mac) as acks from dhcp;"); +$q->execute(); +while (my $ref = $q->fetchrow_hashref()) { + $nms::web::json{'dhcp'}{'total'} = $ref; +} + +my $q2 = $nms::web::dbh->prepare("select count(distinct mac) as clients,count(distinct ip) as addresses,count(mac) as acks from dhcp where $nms::web::when;"); +$q2->execute(); +while (my $ref = $q2->fetchrow_hashref()) { + $nms::web::json{'dhcp'}{'recent'} = $ref; +} +$nms::web::cc{'max-age'} = "10"; +$nms::web::cc{'stale-while-revalidate'} = "15"; +finalize_output(); -- cgit v1.2.3 From 7d97e4c3bead329419d594daac11644e14c000e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20Kir=C3=B8?= Date: Sun, 20 Mar 2016 20:32:22 +0100 Subject: readability in switch-state --- web/nms.gathering.org/api/public/switch-state | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'web/nms.gathering.org/api') 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(); -- cgit v1.2.3 From 65bc1d20d443c987df5681b87967974c12169ed1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20Kir=C3=B8?= Date: Sun, 20 Mar 2016 20:32:42 +0100 Subject: strict and warnings in dhcp-summary. --- web/nms.gathering.org/api/public/dhcp-summary | 2 ++ 1 file changed, 2 insertions(+) (limited to 'web/nms.gathering.org/api') 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'); -- cgit v1.2.3 From b5b57c04f96b3ddedf8b94dc2188e9d421b53cde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20Kir=C3=B8?= Date: Sun, 20 Mar 2016 20:33:02 +0100 Subject: line breakup in snmp --- web/nms.gathering.org/api/private/snmp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'web/nms.gathering.org/api') 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()) { -- cgit v1.2.3 From f96901df27b451cb9f08a513932d0034042b0c0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20Kir=C3=B8?= Date: Sun, 20 Mar 2016 20:33:39 +0100 Subject: ping cleanup/formatting, and timestamp to seconds conversion improvement. --- web/nms.gathering.org/api/public/ping | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'web/nms.gathering.org/api') 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"; -- cgit v1.2.3 From 11fc373807b9a14ee14499165b00f5e775d11a59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20Kir=C3=B8?= Date: Sun, 20 Mar 2016 21:49:15 +0100 Subject: which switch an I on script file. --- web/nms.gathering.org/api/private/which-switch-am-i-on | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100755 web/nms.gathering.org/api/private/which-switch-am-i-on (limited to 'web/nms.gathering.org/api') 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..4adfb2b --- /dev/null +++ b/web/nms.gathering.org/api/private/which-switch-am-i-on @@ -0,0 +1,15 @@ +#! /usr/bin/perl +# vim:ts=8:sw=8 + +use lib '../../../../include'; +use nms::web; +use strict; +use warnings; + +my $query = $nms::web::dbh->prepare('select sysname,extract(epoch from date_trunc(\'second\',time)) as time,state,username,id,comment from switch_comments natural join switches where state != \'delete\' order by time desc'); +$query->execute(); +while (my $ref = $query->fetchrow_hashref()) { + push @{$nms::web::json{'comments'}{$ref->{'sysname'}}{'comments'}},$ref; +} + +nms::web::finalize_output(); -- cgit v1.2.3 From 6fa911c8565a54c9b56cfae479a92da094990876 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20Kir=C3=B8?= Date: Sun, 20 Mar 2016 23:53:46 +0100 Subject: which switch: getting IP and printing it. Need to style with html. --- .../api/private/which-switch-am-i-on | 23 ++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'web/nms.gathering.org/api') 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 index 4adfb2b..82436ea 100755 --- a/web/nms.gathering.org/api/private/which-switch-am-i-on +++ b/web/nms.gathering.org/api/private/which-switch-am-i-on @@ -5,11 +5,26 @@ use lib '../../../../include'; use nms::web; use strict; use warnings; +use Data::Dumper; -my $query = $nms::web::dbh->prepare('select sysname,extract(epoch from date_trunc(\'second\',time)) as time,state,username,id,comment from switch_comments natural join switches where state != \'delete\' order by time desc'); +#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(); -while (my $ref = $query->fetchrow_hashref()) { - push @{$nms::web::json{'comments'}{$ref->{'sysname'}}{'comments'}},$ref; + +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}; +print "-:" . $addr ."\n"; + + +# add start html: header + body etc. + +while ( my $ref = $query->fetchrow_hashref() ) { + print $ref->{sysname}. " @ " . $ref->{distro}; } -nms::web::finalize_output(); +# add end html -- cgit v1.2.3 From 4dffc5e5431c83595f2bd102f120ad6def011d22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20Kir=C3=B8?= Date: Mon, 21 Mar 2016 10:33:25 +0100 Subject: which switch html finished. --- web/nms.gathering.org/api/private/which-switch-am-i-on | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'web/nms.gathering.org/api') 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 index 82436ea..0d3f2b4 100755 --- a/web/nms.gathering.org/api/private/which-switch-am-i-on +++ b/web/nms.gathering.org/api/private/which-switch-am-i-on @@ -18,13 +18,23 @@ 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}; -print "-:" . $addr ."\n"; - # add start html: header + body etc. +print " + + +"; + +# print address +print "" . $addr ."
"; +# print switch name and distroname. while ( my $ref = $query->fetchrow_hashref() ) { print $ref->{sysname}. " @ " . $ref->{distro}; } # add end html +print " + + +"; -- cgit v1.2.3 From 2c0576644afc26f4153ad316d2af216919c04fe4 Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Mon, 21 Mar 2016 18:50:25 +0100 Subject: NMS: Tweak searching of switch active ports etc --- web/nms.gathering.org/api/public/switch-state | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'web/nms.gathering.org/api') diff --git a/web/nms.gathering.org/api/public/switch-state b/web/nms.gathering.org/api/public/switch-state index 62d0078..6f7573c 100755 --- a/web/nms.gathering.org/api/public/switch-state +++ b/web/nms.gathering.org/api/public/switch-state @@ -20,7 +20,7 @@ while ( my $ref = $q->fetchrow_hashref() ) { my %port = %{$data{'ports'}{$porti}}; my $smallport = $porti; $smallport =~ s/[0-9-].*$//; - if ($porti =~ /ge-0\/0\/4[4-7]/ or $porti eq 'eth0') { + if ($porti =~ /ge-0\/0\/4[4-7]/) { $json{'switches'}{$sysname}{'uplinks'}{'ifHCInOctets'} += $port{'ifHCInOctets'}; $json{'switches'}{$sysname}{'uplinks'}{'ifHCOutOctets'} += $port{'ifHCOutOctets'}; if ($port{'ifOperStatus'} eq "up") { @@ -29,12 +29,15 @@ while ( my $ref = $q->fetchrow_hashref() ) { $json{'switches'}{$sysname}{'uplinks'}{'total'} += 1; } - $json{'switches'}{$sysname}{$smallport}{'ifHCInOctets'} += $port{'ifHCInOctets'}; - $json{'switches'}{$sysname}{$smallport}{'ifHCOutOctets'} += $port{'ifHCOutOctets'}; + $json{'switches'}{$sysname}{ifs}{$smallport}{'ifHCInOctets'} += $port{'ifHCInOctets'}; + $json{'switches'}{$sysname}{ifs}{$smallport}{'ifHCOutOctets'} += $port{'ifHCOutOctets'}; + $json{'switches'}{$sysname}{totals}{'ifHCInOctets'} += $port{'ifHCInOctets'}; + $json{'switches'}{$sysname}{totals}{'ifHCOutOctets'} += $port{'ifHCOutOctets'}; if ($port{'ifOperStatus'} eq "up") { - $json{'switches'}{$sysname}{$smallport}{'live'} += 1; + $json{'switches'}{$sysname}{ifs}{$smallport}{'live'} += 1; + $json{'switches'}{$sysname}{totals}{'live'} += 1; } - $json{'switches'}{$sysname}{$smallport}{'total'} += 1; + $json{'switches'}{$sysname}{totals}{'total'} += 1; } $json{'switches'}{$sysname}{'time'} = $ref->{'time'}; } -- cgit v1.2.3 From 7a6cf59e67d569a412f7670d9f04b2378c546dbc Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Mon, 21 Mar 2016 20:11:32 +0100 Subject: NMS: Remove switchtypes logic --- web/nms.gathering.org/api/private/switch-add | 4 ++-- web/nms.gathering.org/api/private/switch-update | 4 ++-- web/nms.gathering.org/api/public/switches | 3 +-- 3 files changed, 5 insertions(+), 6 deletions(-) (limited to 'web/nms.gathering.org/api') diff --git a/web/nms.gathering.org/api/private/switch-add b/web/nms.gathering.org/api/private/switch-add index 70d6212..48f62fc 100755 --- a/web/nms.gathering.org/api/private/switch-add +++ b/web/nms.gathering.org/api/private/switch-add @@ -22,7 +22,7 @@ my @dups; my $sth = $nms::web::dbh->prepare("SELECT sysname FROM switches WHERE sysname=?"); -my @fields = ('ip', 'sysname', 'switchtype', 'last_updated', 'locked', 'poll_frequency', 'community', 'lldp_chassis_id', 'secondary_ip', 'subnet4', 'subnet6', 'placement', 'distro', 'secondary_ip'); +my @fields = ('ip', 'sysname', 'last_updated', 'locked', 'poll_frequency', 'community', 'lldp_chassis_id', 'secondary_ip', 'subnet4', 'subnet6', 'placement', 'distro', 'secondary_ip'); sub convertplace { @@ -81,7 +81,7 @@ foreach my $tmp2 (@tmp) { } keys %switch; - $nms::web::dbh->do("INSERT INTO SWITCHES (ip, sysname, switchtype, last_updated, locked, poll_frequency, community, lldp_chassis_id, secondary_ip, placement) VALUES ($template{'ip'}, $template{'sysname'}, $template{'switchtype'}, $template{'last_updated'}, $template{'locked'}, $template{'poll_frequency'}, $template{'community'}, $template{'lldp_chassis_id'}, $template{'secondary_ip'}, $template{'placement'});"); + $nms::web::dbh->do("INSERT INTO SWITCHES (ip, sysname, last_updated, locked, poll_frequency, community, lldp_chassis_id, secondary_ip, placement,subnet4,subnet6,distro) VALUES ($template{'ip'}, $template{'sysname'}, $template{'last_updated'}, $template{'locked'}, $template{'poll_frequency'}, $template{'community'}, $template{'lldp_chassis_id'}, $template{'secondary_ip'}, $template{'placement'},$template{'subnet4'},$template{'subnet6'},$template{'distro'});"); push @added, $switch{'sysname'}; } } diff --git a/web/nms.gathering.org/api/private/switch-update b/web/nms.gathering.org/api/private/switch-update index 3d7b119..6507d2b 100755 --- a/web/nms.gathering.org/api/private/switch-update +++ b/web/nms.gathering.org/api/private/switch-update @@ -22,7 +22,7 @@ my @dups; my $sth = $nms::web::dbh->prepare("SELECT sysname FROM switches WHERE sysname=?"); -my @fields = ('ip', 'sysname', 'switchtype', 'last_updated', 'locked', 'poll_frequency', 'community', 'lldp_chassis_id', 'secondary_ip', 'subnet4', 'subnet6', 'placement', 'distro', 'secondary_ip'); +my @fields = ('ip', 'sysname', 'last_updated', 'locked', 'poll_frequency', 'community', 'lldp_chassis_id', 'secondary_ip', 'subnet4', 'subnet6', 'placement', 'distro', 'secondary_ip'); sub convertplace { @@ -81,7 +81,7 @@ foreach my $tmp2 (@tmp) { } keys %switch; - $nms::web::dbh->do("INSERT INTO SWITCHES (ip, sysname, switchtype, last_updated, locked, poll_frequency, community, lldp_chassis_id, secondary_ip, placement) VALUES ($template{'ip'}, $template{'sysname'}, $template{'switchtype'}, $template{'last_updated'}, $template{'locked'}, $template{'poll_frequency'}, $template{'community'}, $template{'lldp_chassis_id'}, $template{'secondary_ip'}, $template{'placement'});"); + $nms::web::dbh->do("INSERT INTO SWITCHES (ip, sysname, last_updated, locked, poll_frequency, community, lldp_chassis_id, secondary_ip, placement,subnet4,subnet6,distro) VALUES ($template{'ip'}, $template{'sysname'}, $template{'last_updated'}, $template{'locked'}, $template{'poll_frequency'}, $template{'community'}, $template{'lldp_chassis_id'}, $template{'secondary_ip'}, $template{'placement'},$template{'subnet4'},$template{'subnet6'},$template{'distro'});"); push @added, $switch{'sysname'}; } else { if (defined($switch{'placement'})) { diff --git a/web/nms.gathering.org/api/public/switches b/web/nms.gathering.org/api/public/switches index 8447b2b..7e7f10b 100755 --- a/web/nms.gathering.org/api/public/switches +++ b/web/nms.gathering.org/api/public/switches @@ -12,14 +12,13 @@ use Data::Dumper; $nms::web::cc{'max-age'} = "60"; -my $q2 = $nms::web::dbh->prepare('select switch,sysname,placement,ip,switchtype,poll_frequency,community,last_updated from switches where placement is not null'); +my $q2 = $nms::web::dbh->prepare('select switch,sysname,placement,ip,poll_frequency,community,last_updated from switches where placement is not null'); $q2->execute(); while (my $ref = $q2->fetchrow_hashref()) { $ref->{'placement'} =~ /\((-?\d+),(-?\d+)\),\((-?\d+),(-?\d+)\)/; my ($x1, $y1, $x2, $y2) = ($1, $2, $3, $4); my $sysname = $ref->{'sysname'}; - $nms::web::json{'switches'}{$ref->{'sysname'}}{'switchtype'} = $ref->{'switchtype'}; $nms::web::json{'switches'}{$ref->{'sysname'}}{'placement'}{'x'} = $x2; $nms::web::json{'switches'}{$ref->{'sysname'}}{'placement'}{'y'} = $y2; $nms::web::json{'switches'}{$ref->{'sysname'}}{'placement'}{'width'} = $x1 - $x2; -- cgit v1.2.3 From 9317bfc07c0fb7ef0fbbf3afa3a0cba293d3184e Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Mon, 21 Mar 2016 22:26:31 +0100 Subject: NMS: Add DHCP API --- web/nms.gathering.org/api/public/dhcp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100755 web/nms.gathering.org/api/public/dhcp (limited to 'web/nms.gathering.org/api') diff --git a/web/nms.gathering.org/api/public/dhcp b/web/nms.gathering.org/api/public/dhcp new file mode 100755 index 0000000..d432af0 --- /dev/null +++ b/web/nms.gathering.org/api/public/dhcp @@ -0,0 +1,19 @@ +#! /usr/bin/perl +# vim:ts=8:sw=8 + +use lib '../../../../include'; +use nms::web qw (%json finalize_output); +use strict; +use warnings; +use Data::Dumper; + +my $q = $nms::web::dbh->prepare('select distinct on (sysname) extract(epoch from date_trunc(\'second\',time)) as time,sysname from dhcp join switches on dhcp.switch = switches.switch where ' . $nms::web::when . ' order by sysname,time desc;'); +$q->execute(); +while ( my $ref = $q->fetchrow_hashref() ) { + my $sysname = $ref->{'sysname'}; + $json{'dhcp'}{$ref->{'sysname'}} = $ref->{'time'}; +} + +$nms::web::cc{'max-age'} = "5"; +$nms::web::cc{'stale-while-revalidate'} = "30"; +finalize_output(); -- cgit v1.2.3 From 490560f31c20dd8191ee1a0f8f6e90b2820d7c77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20Kir=C3=B8?= Date: Tue, 22 Mar 2016 13:03:34 +0100 Subject: API structure change. --- web/nms.gathering.org/api/private/comment-add | 24 ---- web/nms.gathering.org/api/private/comment-change | 24 ---- web/nms.gathering.org/api/private/comments | 15 --- web/nms.gathering.org/api/private/snmp | 30 ----- web/nms.gathering.org/api/private/switch-add | 92 ---------------- web/nms.gathering.org/api/private/switch-update | 122 --------------------- .../api/private/switches-management | 30 ----- .../api/private/which-switch-am-i-on | 40 ------- web/nms.gathering.org/api/read/comments | 15 +++ web/nms.gathering.org/api/read/snmp | 30 +++++ web/nms.gathering.org/api/read/switches-management | 30 +++++ .../api/read/which-switch-am-i-on | 40 +++++++ web/nms.gathering.org/api/write/comment-add | 24 ++++ web/nms.gathering.org/api/write/comment-change | 24 ++++ web/nms.gathering.org/api/write/switch-add | 92 ++++++++++++++++ web/nms.gathering.org/api/write/switch-update | 122 +++++++++++++++++++++ 16 files changed, 377 insertions(+), 377 deletions(-) delete mode 100755 web/nms.gathering.org/api/private/comment-add delete mode 100755 web/nms.gathering.org/api/private/comment-change delete mode 100755 web/nms.gathering.org/api/private/comments delete mode 100755 web/nms.gathering.org/api/private/snmp delete mode 100755 web/nms.gathering.org/api/private/switch-add delete mode 100755 web/nms.gathering.org/api/private/switch-update delete mode 100755 web/nms.gathering.org/api/private/switches-management delete mode 100755 web/nms.gathering.org/api/private/which-switch-am-i-on create mode 100755 web/nms.gathering.org/api/read/comments create mode 100755 web/nms.gathering.org/api/read/snmp create mode 100755 web/nms.gathering.org/api/read/switches-management create mode 100755 web/nms.gathering.org/api/read/which-switch-am-i-on create mode 100755 web/nms.gathering.org/api/write/comment-add create mode 100755 web/nms.gathering.org/api/write/comment-change create mode 100755 web/nms.gathering.org/api/write/switch-add create mode 100755 web/nms.gathering.org/api/write/switch-update (limited to 'web/nms.gathering.org/api') diff --git a/web/nms.gathering.org/api/private/comment-add b/web/nms.gathering.org/api/private/comment-add deleted file mode 100755 index 26ff734..0000000 --- a/web/nms.gathering.org/api/private/comment-add +++ /dev/null @@ -1,24 +0,0 @@ -#! /usr/bin/perl -# vim:ts=8:sw=8 -use lib '../../../../include'; -use utf8; -use nms::web qw($dbh db_safe_quote get_input finalize_output); -use strict; -use warnings; - -my $in = get_input(); -my %tmp = %{JSON::XS::decode_json($in)}; - -my $data = $dbh->quote($tmp{'comment'}); -my $switch = $dbh->quote($tmp{'switch'}); -my $user = $dbh->quote($ENV{'REMOTE_USER'} || "undefined"); - -my $q = $nms::web::dbh->prepare("INSERT INTO switch_comments (time,username,switch,comment) values (now(),$user,(select switch from switches where sysname = $switch limit 1),$data)"); -$q->execute(); - -$nms::web::cc{'max-age'} = '0'; -$nms::web::cc{'stale-while-revalidate'} = '0'; -$nms::web::json{'state'} = 'ok'; - -print "X-ban: /api/private/comments\n"; -finalize_output(); diff --git a/web/nms.gathering.org/api/private/comment-change b/web/nms.gathering.org/api/private/comment-change deleted file mode 100755 index fb7da54..0000000 --- a/web/nms.gathering.org/api/private/comment-change +++ /dev/null @@ -1,24 +0,0 @@ -#! /usr/bin/perl -# vim:ts=8:sw=8 -use lib '../../../../include'; -use utf8; -use nms; -use nms::web qw($dbh db_safe_quote get_input finalize_output); - -use strict; -use warnings; - -my $in = get_input(); -my %tmp = %{JSON::XS::decode_json($in)}; - -my $id = $dbh->quote($tmp{'comment'}); -my $state = $dbh->quote($tmp{'state'}); - -my $q = $nms::web::dbh->prepare("UPDATE switch_comments SET state = " . $state . " WHERE id = " . $id . ";"); -$q->execute(); - -$nms::web::cc{'max-age'} = '0'; -$nms::web::cc{'stale-while-revalidate'} = '0'; -$nms::web::json{'state'} = 'ok'; - -finalize_output(); diff --git a/web/nms.gathering.org/api/private/comments b/web/nms.gathering.org/api/private/comments deleted file mode 100755 index 4adfb2b..0000000 --- a/web/nms.gathering.org/api/private/comments +++ /dev/null @@ -1,15 +0,0 @@ -#! /usr/bin/perl -# vim:ts=8:sw=8 - -use lib '../../../../include'; -use nms::web; -use strict; -use warnings; - -my $query = $nms::web::dbh->prepare('select sysname,extract(epoch from date_trunc(\'second\',time)) as time,state,username,id,comment from switch_comments natural join switches where state != \'delete\' order by time desc'); -$query->execute(); -while (my $ref = $query->fetchrow_hashref()) { - push @{$nms::web::json{'comments'}{$ref->{'sysname'}}{'comments'}},$ref; -} - -nms::web::finalize_output(); diff --git a/web/nms.gathering.org/api/private/snmp b/web/nms.gathering.org/api/private/snmp deleted file mode 100755 index f69ca62..0000000 --- a/web/nms.gathering.org/api/private/snmp +++ /dev/null @@ -1,30 +0,0 @@ -#! /usr/bin/perl -# vim:ts=8:sw=8 - -use CGI qw(fatalsToBrowser); -use DBI; -use lib '../../../../include'; -use nms; -use nms::web; -use strict; -use warnings; -use JSON; -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);'); - -$q->execute(); -while (my $ref = $q->fetchrow_hashref()) { - my $sysname = $ref->{'sysname'}; - - # This is, strictly speaking, redundant. But by doing this, we can - # re-use the standard methods of finalize_output() and whatnot. - my $data = JSON::XS::decode_json($ref->{'data'}); - - $nms::web::json{'snmp'}{$ref->{'sysname'}} = $data; -} - -finalize_output(); diff --git a/web/nms.gathering.org/api/private/switch-add b/web/nms.gathering.org/api/private/switch-add deleted file mode 100755 index 48f62fc..0000000 --- a/web/nms.gathering.org/api/private/switch-add +++ /dev/null @@ -1,92 +0,0 @@ -#! /usr/bin/perl -# vim:ts=8:sw=8 - -#use CGI qw(fatalsToBrowser); -use DBI; -use lib '../../../../include'; -use nms; -use nms::web qw(%get_params %json finalize_output get_input $dbh); -use nms::util qw(guess_placement); -use strict; -use warnings; -use JSON; -use Data::Dumper; - -$nms::web::cc{'max-age'} = "0"; - -my $in = get_input(); -my @tmp = @{JSON::XS::decode_json($in)}; - -my @added; -my @dups; - -my $sth = $nms::web::dbh->prepare("SELECT sysname FROM switches WHERE sysname=?"); - -my @fields = ('ip', 'sysname', 'last_updated', 'locked', 'poll_frequency', 'community', 'lldp_chassis_id', 'secondary_ip', 'subnet4', 'subnet6', 'placement', 'distro', 'secondary_ip'); - -sub convertplace -{ - my %in = %{$_[0]}; - my %out = (); - - if (not defined $in{'x1'} and defined($in{'x'})) { - $out{'x1'} = int($in{'x'}); - $out{'y1'} = int($in{'y'}); - $out{'xx'} = int($in{'x'} + $in{'width'}); - $out{'yy'} = int($in{'y'} + $in{'height'}); - } else { - return \%in; - } - return \%out; -} - -foreach my $tmp2 (@tmp) { - my %switch = %{$tmp2}; - my $affected = 0; - my %template = (); - map { $template{$_} = 'DEFAULT' } @fields; - if (not defined($switch{'sysname'})) { - next; - } - - $sth->execute( $switch{'sysname'}); - while ( my @row = $sth->fetchrow_array ) { - $affected += 1; - } - - if ($affected == 0) { - my %placement; - if (not defined ($switch{'placement'})) { - %placement = guess_placement($switch{'sysname'}); - } else { - %placement = %{convertplace($switch{'placement'})}; - } - if (not defined($switch{'ip'}) and defined($switch{'mgtmt4'})) { - $switch{'ip'} = $switch{'mgtmt4'}; - } - if (not defined($switch{'secondary_ip'}) and defined($switch{'mgtmt6'})) { - $switch{'secondary_ip'} = $switch{'mgtmt6'}; - } - my ($x1,$x2,$y1,$y2); - $x1 = $placement{'x1'}; - $y1 = $placement{'y1'}; - $x2 = $placement{'xx'}; - $y2 = $placement{'yy'}; - $switch{'placement'} = "(($x1,$y1),($x2,$y2))"; - - map { - if (defined ($template{$_})) { - $template{$_} = $dbh->quote($switch{$_}); - } - } keys %switch; - - - $nms::web::dbh->do("INSERT INTO SWITCHES (ip, sysname, last_updated, locked, poll_frequency, community, lldp_chassis_id, secondary_ip, placement,subnet4,subnet6,distro) VALUES ($template{'ip'}, $template{'sysname'}, $template{'last_updated'}, $template{'locked'}, $template{'poll_frequency'}, $template{'community'}, $template{'lldp_chassis_id'}, $template{'secondary_ip'}, $template{'placement'},$template{'subnet4'},$template{'subnet6'},$template{'distro'});"); - push @added, $switch{'sysname'}; - } -} - -$json{'switches_addded'} = \@added; - -print "X-ban: /api/.*switches.*\n"; -finalize_output(); diff --git a/web/nms.gathering.org/api/private/switch-update b/web/nms.gathering.org/api/private/switch-update deleted file mode 100755 index 6507d2b..0000000 --- a/web/nms.gathering.org/api/private/switch-update +++ /dev/null @@ -1,122 +0,0 @@ -#! /usr/bin/perl -# vim:ts=8:sw=8 - -#use CGI qw(fatalsToBrowser); -use DBI; -use lib '../../../../include'; -use nms; -use nms::web qw(%get_params %json finalize_output get_input $dbh); -use nms::util qw(guess_placement); -use strict; -use warnings; -use JSON; -use Data::Dumper; - -$nms::web::cc{'max-age'} = "0"; - -my $in = get_input(); -my @tmp = @{JSON::XS::decode_json($in)}; - -my @added; -my @dups; - -my $sth = $nms::web::dbh->prepare("SELECT sysname FROM switches WHERE sysname=?"); - -my @fields = ('ip', 'sysname', 'last_updated', 'locked', 'poll_frequency', 'community', 'lldp_chassis_id', 'secondary_ip', 'subnet4', 'subnet6', 'placement', 'distro', 'secondary_ip'); - -sub convertplace -{ - my %in = %{$_[0]}; - my %out = (); - - if (not defined $in{'x1'} and defined($in{'x'})) { - $out{'x1'} = int($in{'x'}); - $out{'y1'} = int($in{'y'}); - $out{'xx'} = int($in{'x'} + $in{'width'}); - $out{'yy'} = int($in{'y'} + $in{'height'}); - } else { - return \%in; - } - return \%out; -} - -foreach my $tmp2 (@tmp) { - my %switch = %{$tmp2}; - my $affected = 0; - my %template = (); - map { $template{$_} = 'DEFAULT' } @fields; - if (not defined($switch{'sysname'})) { - next; - } - - $sth->execute( $switch{'sysname'}); - while ( my @row = $sth->fetchrow_array ) { - $affected += 1; - } - - if ($affected == 0) { - my %placement; - if (not defined ($switch{'placement'})) { - %placement = guess_placement($switch{'sysname'}); - } else { - %placement = %{convertplace($switch{'placement'})}; - } - if (not defined($switch{'ip'}) and defined($switch{'mgtmt4'})) { - $switch{'ip'} = $switch{'mgtmt4'}; - } - if (not defined($switch{'secondary_ip'}) and defined($switch{'mgtmt6'})) { - $switch{'secondary_ip'} = $switch{'mgtmt6'}; - } - my ($x1,$x2,$y1,$y2); - $x1 = $placement{'x1'}; - $y1 = $placement{'y1'}; - $x2 = $placement{'xx'}; - $y2 = $placement{'yy'}; - $switch{'placement'} = "(($x1,$y1),($x2,$y2))"; - - map { - if (defined ($template{$_})) { - $template{$_} = $dbh->quote($switch{$_}); - } - } keys %switch; - - - $nms::web::dbh->do("INSERT INTO SWITCHES (ip, sysname, last_updated, locked, poll_frequency, community, lldp_chassis_id, secondary_ip, placement,subnet4,subnet6,distro) VALUES ($template{'ip'}, $template{'sysname'}, $template{'last_updated'}, $template{'locked'}, $template{'poll_frequency'}, $template{'community'}, $template{'lldp_chassis_id'}, $template{'secondary_ip'}, $template{'placement'},$template{'subnet4'},$template{'subnet6'},$template{'distro'});"); - push @added, $switch{'sysname'}; - } else { - if (defined($switch{'placement'})) { - my %placement; - if ($switch{'placement'} eq "reset") { - %placement = guess_placement($switch{'sysname'}); - } else { - %placement = %{convertplace($switch{'placement'})}; - } - my ($x1,$x2,$y1,$y2); - $x1 = $placement{'x1'}; - $y1 = $placement{'y1'}; - $x2 = $placement{'xx'}; - $y2 = $placement{'yy'}; - $switch{'placement'} = "(($x1,$y1),($x2,$y2))"; - push @dups, "not really, but: " . $switch{'placement'}; - } - if (not defined($switch{'ip'}) and defined($switch{'mgtmt4'})) { - $switch{'ip'} = $switch{'mgtmt4'}; - } - if (not defined($switch{'secondary_ip'}) and defined($switch{'mgtmt6'})) { - $switch{'secondary_ip'} = $switch{'mgtmt6'}; - } - my @set; - map { - if (defined($template{$_})) { - push @set, "$_=" . $dbh->quote($switch{$_}); - } - } keys %switch; - $nms::web::dbh->do("UPDATE SWITCHES SET " . join(", ", @set) . "WHERE sysname=" . $dbh->quote($switch{'sysname'}) . ";"); - push @dups, $switch{'sysname'}; - } -} -$json{'switches_addded'} = \@added; -$json{'switches_updated'} = \@dups; - -print "X-ban: /api/.*switches.*\n"; -finalize_output(); diff --git a/web/nms.gathering.org/api/private/switches-management b/web/nms.gathering.org/api/private/switches-management deleted file mode 100755 index 6b5fdcd..0000000 --- a/web/nms.gathering.org/api/private/switches-management +++ /dev/null @@ -1,30 +0,0 @@ -#! /usr/bin/perl -# vim:ts=8:sw=8 - -use CGI qw(fatalsToBrowser); -use DBI; -use lib '../../../../include'; -use nms; -use nms::web; -use strict; -use warnings; -use Data::Dumper; - -$nms::web::cc{'max-age'} = "60"; - -my $q2 = $nms::web::dbh->prepare('select sysname,ip,poll_frequency,community,subnet4,subnet6,distro,last_updated from switches '); - -$q2->execute(); -while (my $ref = $q2->fetchrow_hashref()) { - my $sysname = $ref->{'sysname'}; - $nms::web::json{'switches'}{$ref->{'sysname'}} = $ref; -} - -my $q4 = $nms::web::dbh->prepare('select linknet, (select sysname from switches where switch = switch1) as sysname1, addr1, (select sysname from switches where switch = switch2) as sysname2,addr2 from linknets'); - -$q4->execute(); -while (my $ref = $q4->fetchrow_hashref()) { - $nms::web::json{'linknets'}{$ref->{'linknet'}} = $ref; -} - -finalize_output(); 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 deleted file mode 100755 index 0d3f2b4..0000000 --- a/web/nms.gathering.org/api/private/which-switch-am-i-on +++ /dev/null @@ -1,40 +0,0 @@ -#! /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 " - - -"; - -# print address -print "" . $addr ."
"; - -# print switch name and distroname. -while ( my $ref = $query->fetchrow_hashref() ) { - print $ref->{sysname}. " @ " . $ref->{distro}; -} - -# add end html -print " - - -"; diff --git a/web/nms.gathering.org/api/read/comments b/web/nms.gathering.org/api/read/comments new file mode 100755 index 0000000..4adfb2b --- /dev/null +++ b/web/nms.gathering.org/api/read/comments @@ -0,0 +1,15 @@ +#! /usr/bin/perl +# vim:ts=8:sw=8 + +use lib '../../../../include'; +use nms::web; +use strict; +use warnings; + +my $query = $nms::web::dbh->prepare('select sysname,extract(epoch from date_trunc(\'second\',time)) as time,state,username,id,comment from switch_comments natural join switches where state != \'delete\' order by time desc'); +$query->execute(); +while (my $ref = $query->fetchrow_hashref()) { + push @{$nms::web::json{'comments'}{$ref->{'sysname'}}{'comments'}},$ref; +} + +nms::web::finalize_output(); diff --git a/web/nms.gathering.org/api/read/snmp b/web/nms.gathering.org/api/read/snmp new file mode 100755 index 0000000..f69ca62 --- /dev/null +++ b/web/nms.gathering.org/api/read/snmp @@ -0,0 +1,30 @@ +#! /usr/bin/perl +# vim:ts=8:sw=8 + +use CGI qw(fatalsToBrowser); +use DBI; +use lib '../../../../include'; +use nms; +use nms::web; +use strict; +use warnings; +use JSON; +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);'); + +$q->execute(); +while (my $ref = $q->fetchrow_hashref()) { + my $sysname = $ref->{'sysname'}; + + # This is, strictly speaking, redundant. But by doing this, we can + # re-use the standard methods of finalize_output() and whatnot. + my $data = JSON::XS::decode_json($ref->{'data'}); + + $nms::web::json{'snmp'}{$ref->{'sysname'}} = $data; +} + +finalize_output(); diff --git a/web/nms.gathering.org/api/read/switches-management b/web/nms.gathering.org/api/read/switches-management new file mode 100755 index 0000000..6b5fdcd --- /dev/null +++ b/web/nms.gathering.org/api/read/switches-management @@ -0,0 +1,30 @@ +#! /usr/bin/perl +# vim:ts=8:sw=8 + +use CGI qw(fatalsToBrowser); +use DBI; +use lib '../../../../include'; +use nms; +use nms::web; +use strict; +use warnings; +use Data::Dumper; + +$nms::web::cc{'max-age'} = "60"; + +my $q2 = $nms::web::dbh->prepare('select sysname,ip,poll_frequency,community,subnet4,subnet6,distro,last_updated from switches '); + +$q2->execute(); +while (my $ref = $q2->fetchrow_hashref()) { + my $sysname = $ref->{'sysname'}; + $nms::web::json{'switches'}{$ref->{'sysname'}} = $ref; +} + +my $q4 = $nms::web::dbh->prepare('select linknet, (select sysname from switches where switch = switch1) as sysname1, addr1, (select sysname from switches where switch = switch2) as sysname2,addr2 from linknets'); + +$q4->execute(); +while (my $ref = $q4->fetchrow_hashref()) { + $nms::web::json{'linknets'}{$ref->{'linknet'}} = $ref; +} + +finalize_output(); diff --git a/web/nms.gathering.org/api/read/which-switch-am-i-on b/web/nms.gathering.org/api/read/which-switch-am-i-on new file mode 100755 index 0000000..0d3f2b4 --- /dev/null +++ b/web/nms.gathering.org/api/read/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 " + + +"; + +# print address +print "" . $addr ."
"; + +# print switch name and distroname. +while ( my $ref = $query->fetchrow_hashref() ) { + print $ref->{sysname}. " @ " . $ref->{distro}; +} + +# add end html +print " + + +"; diff --git a/web/nms.gathering.org/api/write/comment-add b/web/nms.gathering.org/api/write/comment-add new file mode 100755 index 0000000..26ff734 --- /dev/null +++ b/web/nms.gathering.org/api/write/comment-add @@ -0,0 +1,24 @@ +#! /usr/bin/perl +# vim:ts=8:sw=8 +use lib '../../../../include'; +use utf8; +use nms::web qw($dbh db_safe_quote get_input finalize_output); +use strict; +use warnings; + +my $in = get_input(); +my %tmp = %{JSON::XS::decode_json($in)}; + +my $data = $dbh->quote($tmp{'comment'}); +my $switch = $dbh->quote($tmp{'switch'}); +my $user = $dbh->quote($ENV{'REMOTE_USER'} || "undefined"); + +my $q = $nms::web::dbh->prepare("INSERT INTO switch_comments (time,username,switch,comment) values (now(),$user,(select switch from switches where sysname = $switch limit 1),$data)"); +$q->execute(); + +$nms::web::cc{'max-age'} = '0'; +$nms::web::cc{'stale-while-revalidate'} = '0'; +$nms::web::json{'state'} = 'ok'; + +print "X-ban: /api/private/comments\n"; +finalize_output(); diff --git a/web/nms.gathering.org/api/write/comment-change b/web/nms.gathering.org/api/write/comment-change new file mode 100755 index 0000000..fb7da54 --- /dev/null +++ b/web/nms.gathering.org/api/write/comment-change @@ -0,0 +1,24 @@ +#! /usr/bin/perl +# vim:ts=8:sw=8 +use lib '../../../../include'; +use utf8; +use nms; +use nms::web qw($dbh db_safe_quote get_input finalize_output); + +use strict; +use warnings; + +my $in = get_input(); +my %tmp = %{JSON::XS::decode_json($in)}; + +my $id = $dbh->quote($tmp{'comment'}); +my $state = $dbh->quote($tmp{'state'}); + +my $q = $nms::web::dbh->prepare("UPDATE switch_comments SET state = " . $state . " WHERE id = " . $id . ";"); +$q->execute(); + +$nms::web::cc{'max-age'} = '0'; +$nms::web::cc{'stale-while-revalidate'} = '0'; +$nms::web::json{'state'} = 'ok'; + +finalize_output(); diff --git a/web/nms.gathering.org/api/write/switch-add b/web/nms.gathering.org/api/write/switch-add new file mode 100755 index 0000000..48f62fc --- /dev/null +++ b/web/nms.gathering.org/api/write/switch-add @@ -0,0 +1,92 @@ +#! /usr/bin/perl +# vim:ts=8:sw=8 + +#use CGI qw(fatalsToBrowser); +use DBI; +use lib '../../../../include'; +use nms; +use nms::web qw(%get_params %json finalize_output get_input $dbh); +use nms::util qw(guess_placement); +use strict; +use warnings; +use JSON; +use Data::Dumper; + +$nms::web::cc{'max-age'} = "0"; + +my $in = get_input(); +my @tmp = @{JSON::XS::decode_json($in)}; + +my @added; +my @dups; + +my $sth = $nms::web::dbh->prepare("SELECT sysname FROM switches WHERE sysname=?"); + +my @fields = ('ip', 'sysname', 'last_updated', 'locked', 'poll_frequency', 'community', 'lldp_chassis_id', 'secondary_ip', 'subnet4', 'subnet6', 'placement', 'distro', 'secondary_ip'); + +sub convertplace +{ + my %in = %{$_[0]}; + my %out = (); + + if (not defined $in{'x1'} and defined($in{'x'})) { + $out{'x1'} = int($in{'x'}); + $out{'y1'} = int($in{'y'}); + $out{'xx'} = int($in{'x'} + $in{'width'}); + $out{'yy'} = int($in{'y'} + $in{'height'}); + } else { + return \%in; + } + return \%out; +} + +foreach my $tmp2 (@tmp) { + my %switch = %{$tmp2}; + my $affected = 0; + my %template = (); + map { $template{$_} = 'DEFAULT' } @fields; + if (not defined($switch{'sysname'})) { + next; + } + + $sth->execute( $switch{'sysname'}); + while ( my @row = $sth->fetchrow_array ) { + $affected += 1; + } + + if ($affected == 0) { + my %placement; + if (not defined ($switch{'placement'})) { + %placement = guess_placement($switch{'sysname'}); + } else { + %placement = %{convertplace($switch{'placement'})}; + } + if (not defined($switch{'ip'}) and defined($switch{'mgtmt4'})) { + $switch{'ip'} = $switch{'mgtmt4'}; + } + if (not defined($switch{'secondary_ip'}) and defined($switch{'mgtmt6'})) { + $switch{'secondary_ip'} = $switch{'mgtmt6'}; + } + my ($x1,$x2,$y1,$y2); + $x1 = $placement{'x1'}; + $y1 = $placement{'y1'}; + $x2 = $placement{'xx'}; + $y2 = $placement{'yy'}; + $switch{'placement'} = "(($x1,$y1),($x2,$y2))"; + + map { + if (defined ($template{$_})) { + $template{$_} = $dbh->quote($switch{$_}); + } + } keys %switch; + + + $nms::web::dbh->do("INSERT INTO SWITCHES (ip, sysname, last_updated, locked, poll_frequency, community, lldp_chassis_id, secondary_ip, placement,subnet4,subnet6,distro) VALUES ($template{'ip'}, $template{'sysname'}, $template{'last_updated'}, $template{'locked'}, $template{'poll_frequency'}, $template{'community'}, $template{'lldp_chassis_id'}, $template{'secondary_ip'}, $template{'placement'},$template{'subnet4'},$template{'subnet6'},$template{'distro'});"); + push @added, $switch{'sysname'}; + } +} + +$json{'switches_addded'} = \@added; + +print "X-ban: /api/.*switches.*\n"; +finalize_output(); diff --git a/web/nms.gathering.org/api/write/switch-update b/web/nms.gathering.org/api/write/switch-update new file mode 100755 index 0000000..6507d2b --- /dev/null +++ b/web/nms.gathering.org/api/write/switch-update @@ -0,0 +1,122 @@ +#! /usr/bin/perl +# vim:ts=8:sw=8 + +#use CGI qw(fatalsToBrowser); +use DBI; +use lib '../../../../include'; +use nms; +use nms::web qw(%get_params %json finalize_output get_input $dbh); +use nms::util qw(guess_placement); +use strict; +use warnings; +use JSON; +use Data::Dumper; + +$nms::web::cc{'max-age'} = "0"; + +my $in = get_input(); +my @tmp = @{JSON::XS::decode_json($in)}; + +my @added; +my @dups; + +my $sth = $nms::web::dbh->prepare("SELECT sysname FROM switches WHERE sysname=?"); + +my @fields = ('ip', 'sysname', 'last_updated', 'locked', 'poll_frequency', 'community', 'lldp_chassis_id', 'secondary_ip', 'subnet4', 'subnet6', 'placement', 'distro', 'secondary_ip'); + +sub convertplace +{ + my %in = %{$_[0]}; + my %out = (); + + if (not defined $in{'x1'} and defined($in{'x'})) { + $out{'x1'} = int($in{'x'}); + $out{'y1'} = int($in{'y'}); + $out{'xx'} = int($in{'x'} + $in{'width'}); + $out{'yy'} = int($in{'y'} + $in{'height'}); + } else { + return \%in; + } + return \%out; +} + +foreach my $tmp2 (@tmp) { + my %switch = %{$tmp2}; + my $affected = 0; + my %template = (); + map { $template{$_} = 'DEFAULT' } @fields; + if (not defined($switch{'sysname'})) { + next; + } + + $sth->execute( $switch{'sysname'}); + while ( my @row = $sth->fetchrow_array ) { + $affected += 1; + } + + if ($affected == 0) { + my %placement; + if (not defined ($switch{'placement'})) { + %placement = guess_placement($switch{'sysname'}); + } else { + %placement = %{convertplace($switch{'placement'})}; + } + if (not defined($switch{'ip'}) and defined($switch{'mgtmt4'})) { + $switch{'ip'} = $switch{'mgtmt4'}; + } + if (not defined($switch{'secondary_ip'}) and defined($switch{'mgtmt6'})) { + $switch{'secondary_ip'} = $switch{'mgtmt6'}; + } + my ($x1,$x2,$y1,$y2); + $x1 = $placement{'x1'}; + $y1 = $placement{'y1'}; + $x2 = $placement{'xx'}; + $y2 = $placement{'yy'}; + $switch{'placement'} = "(($x1,$y1),($x2,$y2))"; + + map { + if (defined ($template{$_})) { + $template{$_} = $dbh->quote($switch{$_}); + } + } keys %switch; + + + $nms::web::dbh->do("INSERT INTO SWITCHES (ip, sysname, last_updated, locked, poll_frequency, community, lldp_chassis_id, secondary_ip, placement,subnet4,subnet6,distro) VALUES ($template{'ip'}, $template{'sysname'}, $template{'last_updated'}, $template{'locked'}, $template{'poll_frequency'}, $template{'community'}, $template{'lldp_chassis_id'}, $template{'secondary_ip'}, $template{'placement'},$template{'subnet4'},$template{'subnet6'},$template{'distro'});"); + push @added, $switch{'sysname'}; + } else { + if (defined($switch{'placement'})) { + my %placement; + if ($switch{'placement'} eq "reset") { + %placement = guess_placement($switch{'sysname'}); + } else { + %placement = %{convertplace($switch{'placement'})}; + } + my ($x1,$x2,$y1,$y2); + $x1 = $placement{'x1'}; + $y1 = $placement{'y1'}; + $x2 = $placement{'xx'}; + $y2 = $placement{'yy'}; + $switch{'placement'} = "(($x1,$y1),($x2,$y2))"; + push @dups, "not really, but: " . $switch{'placement'}; + } + if (not defined($switch{'ip'}) and defined($switch{'mgtmt4'})) { + $switch{'ip'} = $switch{'mgtmt4'}; + } + if (not defined($switch{'secondary_ip'}) and defined($switch{'mgtmt6'})) { + $switch{'secondary_ip'} = $switch{'mgtmt6'}; + } + my @set; + map { + if (defined($template{$_})) { + push @set, "$_=" . $dbh->quote($switch{$_}); + } + } keys %switch; + $nms::web::dbh->do("UPDATE SWITCHES SET " . join(", ", @set) . "WHERE sysname=" . $dbh->quote($switch{'sysname'}) . ";"); + push @dups, $switch{'sysname'}; + } +} +$json{'switches_addded'} = \@added; +$json{'switches_updated'} = \@dups; + +print "X-ban: /api/.*switches.*\n"; +finalize_output(); -- cgit v1.2.3 From 7507d6f1dae6261ecb5ad59d556c264fd8e54e04 Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Tue, 22 Mar 2016 13:26:52 +0100 Subject: NMS: Hide community to all --- web/nms.gathering.org/api/read/switches-management | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'web/nms.gathering.org/api') diff --git a/web/nms.gathering.org/api/read/switches-management b/web/nms.gathering.org/api/read/switches-management index 6b5fdcd..b18c6cd 100755 --- a/web/nms.gathering.org/api/read/switches-management +++ b/web/nms.gathering.org/api/read/switches-management @@ -12,7 +12,7 @@ use Data::Dumper; $nms::web::cc{'max-age'} = "60"; -my $q2 = $nms::web::dbh->prepare('select sysname,ip,poll_frequency,community,subnet4,subnet6,distro,last_updated from switches '); +my $q2 = $nms::web::dbh->prepare('select sysname,ip,poll_frequency,subnet4,subnet6,distro,last_updated from switches '); $q2->execute(); while (my $ref = $q2->fetchrow_hashref()) { -- cgit v1.2.3 From 89c78bc9eab3b69fe31babe5e64f0343386f67be Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Tue, 22 Mar 2016 15:06:50 +0100 Subject: NMS: DHCP map --- web/nms.gathering.org/api/public/dhcp | 1 + web/nms.gathering.org/api/public/switch-state | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'web/nms.gathering.org/api') diff --git a/web/nms.gathering.org/api/public/dhcp b/web/nms.gathering.org/api/public/dhcp index d432af0..91d52af 100755 --- a/web/nms.gathering.org/api/public/dhcp +++ b/web/nms.gathering.org/api/public/dhcp @@ -7,6 +7,7 @@ use strict; use warnings; use Data::Dumper; +nms::web::setwhen('60m'); my $q = $nms::web::dbh->prepare('select distinct on (sysname) extract(epoch from date_trunc(\'second\',time)) as time,sysname from dhcp join switches on dhcp.switch = switches.switch where ' . $nms::web::when . ' order by sysname,time desc;'); $q->execute(); while ( my $ref = $q->fetchrow_hashref() ) { diff --git a/web/nms.gathering.org/api/public/switch-state b/web/nms.gathering.org/api/public/switch-state index 6f7573c..4907449 100755 --- a/web/nms.gathering.org/api/public/switch-state +++ b/web/nms.gathering.org/api/public/switch-state @@ -20,7 +20,7 @@ while ( my $ref = $q->fetchrow_hashref() ) { my %port = %{$data{'ports'}{$porti}}; my $smallport = $porti; $smallport =~ s/[0-9-].*$//; - if ($porti =~ /ge-0\/0\/4[4-7]/) { + if ($porti =~ /ge-0\/0\/4[4-7]$/) { $json{'switches'}{$sysname}{'uplinks'}{'ifHCInOctets'} += $port{'ifHCInOctets'}; $json{'switches'}{$sysname}{'uplinks'}{'ifHCOutOctets'} += $port{'ifHCOutOctets'}; if ($port{'ifOperStatus'} eq "up") { -- cgit v1.2.3 From 10271b0e95a424e191926a945fe785e9cce046c1 Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Tue, 22 Mar 2016 16:05:04 +0100 Subject: NMS: Update schema to FAP --- web/nms.gathering.org/api/public/switches | 2 +- web/nms.gathering.org/api/read/switches-management | 3 ++- web/nms.gathering.org/api/write/switch-add | 2 +- web/nms.gathering.org/api/write/switch-update | 3 ++- 4 files changed, 6 insertions(+), 4 deletions(-) (limited to 'web/nms.gathering.org/api') diff --git a/web/nms.gathering.org/api/public/switches b/web/nms.gathering.org/api/public/switches index 7e7f10b..3aa8af8 100755 --- a/web/nms.gathering.org/api/public/switches +++ b/web/nms.gathering.org/api/public/switches @@ -12,7 +12,7 @@ use Data::Dumper; $nms::web::cc{'max-age'} = "60"; -my $q2 = $nms::web::dbh->prepare('select switch,sysname,placement,ip,poll_frequency,community,last_updated from switches where placement is not null'); +my $q2 = $nms::web::dbh->prepare('select switch,sysname,placement,mgmt_v4_addr,mgmt_v6_addr,mgmt_v4_gw,mgmt_v4_netsize,mgmt_v6_gw,mgmt_v6_netsize,mgmt_vlan,traffic_vlan,last_config_fetch,current_mac,poll_frequency,community,last_updated,switchtype from switches where placement is not null'); $q2->execute(); while (my $ref = $q2->fetchrow_hashref()) { diff --git a/web/nms.gathering.org/api/read/switches-management b/web/nms.gathering.org/api/read/switches-management index b18c6cd..8235da7 100755 --- a/web/nms.gathering.org/api/read/switches-management +++ b/web/nms.gathering.org/api/read/switches-management @@ -12,7 +12,8 @@ use Data::Dumper; $nms::web::cc{'max-age'} = "60"; -my $q2 = $nms::web::dbh->prepare('select sysname,ip,poll_frequency,subnet4,subnet6,distro,last_updated from switches '); +#my $q2 = $nms::web::dbh->prepare('select sysname,ip,poll_frequency,subnet4,subnet6,distro,last_updated from switches '); +my $q2 = $nms::web::dbh->prepare('select switch,sysname,mgmt_v4_addr,mgmt_v6_addr,mgmt_v4_gw,mgmt_v4_netsize,mgmt_v6_gw,mgmt_v6_netsize,mgmt_vlan,traffic_vlan,last_config_fetch,current_mac,poll_frequency,community,last_updated,switchtype from switches where placement is not null'); $q2->execute(); while (my $ref = $q2->fetchrow_hashref()) { diff --git a/web/nms.gathering.org/api/write/switch-add b/web/nms.gathering.org/api/write/switch-add index 48f62fc..411a76b 100755 --- a/web/nms.gathering.org/api/write/switch-add +++ b/web/nms.gathering.org/api/write/switch-add @@ -22,7 +22,7 @@ my @dups; my $sth = $nms::web::dbh->prepare("SELECT sysname FROM switches WHERE sysname=?"); -my @fields = ('ip', 'sysname', 'last_updated', 'locked', 'poll_frequency', 'community', 'lldp_chassis_id', 'secondary_ip', 'subnet4', 'subnet6', 'placement', 'distro', 'secondary_ip'); +my @fields = ( 'community', 'current_mac', 'distro_name', 'distro_phy_port', 'lldp_chassis_id', 'mgmt_v4_addr', 'mgmt_v4_gw', 'mgmt_v4_netsize', 'mgmt_v6_addr', 'mgmt_v6_gw', 'mgmt_v6_netsize', 'mgmt_vlan', 'placement', 'poll_frequency', 'subnet4', 'subnet6', 'switchtype', 'sysname', 'traffic_vlan'); sub convertplace { diff --git a/web/nms.gathering.org/api/write/switch-update b/web/nms.gathering.org/api/write/switch-update index 6507d2b..14c8773 100755 --- a/web/nms.gathering.org/api/write/switch-update +++ b/web/nms.gathering.org/api/write/switch-update @@ -22,7 +22,8 @@ my @dups; my $sth = $nms::web::dbh->prepare("SELECT sysname FROM switches WHERE sysname=?"); -my @fields = ('ip', 'sysname', 'last_updated', 'locked', 'poll_frequency', 'community', 'lldp_chassis_id', 'secondary_ip', 'subnet4', 'subnet6', 'placement', 'distro', 'secondary_ip'); + +my @fields = ( 'community', 'current_mac', 'distro_name', 'distro_phy_port', 'lldp_chassis_id', 'mgmt_v4_addr', 'mgmt_v4_gw', 'mgmt_v4_netsize', 'mgmt_v6_addr', 'mgmt_v6_gw', 'mgmt_v6_netsize', 'mgmt_vlan', 'placement', 'poll_frequency', 'subnet4', 'subnet6', 'switchtype', 'sysname', 'traffic_vlan'); sub convertplace { -- cgit v1.2.3 From 72fb92979ca3dbbbeb55159ce3a9404b8ba49099 Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Tue, 22 Mar 2016 16:07:24 +0100 Subject: NMS: Hide community again --- web/nms.gathering.org/api/read/switches-management | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'web/nms.gathering.org/api') diff --git a/web/nms.gathering.org/api/read/switches-management b/web/nms.gathering.org/api/read/switches-management index 8235da7..1bb4c4c 100755 --- a/web/nms.gathering.org/api/read/switches-management +++ b/web/nms.gathering.org/api/read/switches-management @@ -13,7 +13,7 @@ use Data::Dumper; $nms::web::cc{'max-age'} = "60"; #my $q2 = $nms::web::dbh->prepare('select sysname,ip,poll_frequency,subnet4,subnet6,distro,last_updated from switches '); -my $q2 = $nms::web::dbh->prepare('select switch,sysname,mgmt_v4_addr,mgmt_v6_addr,mgmt_v4_gw,mgmt_v4_netsize,mgmt_v6_gw,mgmt_v6_netsize,mgmt_vlan,traffic_vlan,last_config_fetch,current_mac,poll_frequency,community,last_updated,switchtype from switches where placement is not null'); +my $q2 = $nms::web::dbh->prepare('select switch,sysname,mgmt_v4_addr,mgmt_v6_addr,mgmt_v4_gw,mgmt_v4_netsize,mgmt_v6_gw,mgmt_v6_netsize,mgmt_vlan,traffic_vlan,last_config_fetch,current_mac,poll_frequency,last_updated,switchtype from switches where placement is not null'); $q2->execute(); while (my $ref = $q2->fetchrow_hashref()) { -- cgit v1.2.3 From 79d9099cf563c276f67b07ca2e62fc51f40288be Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Tue, 22 Mar 2016 17:48:19 +0100 Subject: NMS: Expose trunks (ae*) fully publicly Thanks to mrglass and sjurtf. --- web/nms.gathering.org/api/public/switch-state | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'web/nms.gathering.org/api') diff --git a/web/nms.gathering.org/api/public/switch-state b/web/nms.gathering.org/api/public/switch-state index 4907449..7fa6ff5 100755 --- a/web/nms.gathering.org/api/public/switch-state +++ b/web/nms.gathering.org/api/public/switch-state @@ -19,7 +19,11 @@ while ( my $ref = $q->fetchrow_hashref() ) { for my $porti (keys %{$data{'ports'}}) { my %port = %{$data{'ports'}{$porti}}; my $smallport = $porti; - $smallport =~ s/[0-9-].*$//; + if (not $smallport =~ m/^ae/) { + $smallport =~ s/[0-9-].*$//; + } else { + $json{'switches'}{$sysname}{ifs}{$smallport}{'ifAlias'} = $port{'ifAlias'}; + } if ($porti =~ /ge-0\/0\/4[4-7]$/) { $json{'switches'}{$sysname}{'uplinks'}{'ifHCInOctets'} += $port{'ifHCInOctets'}; $json{'switches'}{$sysname}{'uplinks'}{'ifHCOutOctets'} += $port{'ifHCOutOctets'}; -- cgit v1.2.3 From 3e0ad5edff8cf33493b8b6aab92838c939fe5d69 Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Tue, 22 Mar 2016 20:13:35 +0100 Subject: NMS: Fix searching (again) --- web/nms.gathering.org/api/public/switches | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'web/nms.gathering.org/api') diff --git a/web/nms.gathering.org/api/public/switches b/web/nms.gathering.org/api/public/switches index 3aa8af8..72c77be 100755 --- a/web/nms.gathering.org/api/public/switches +++ b/web/nms.gathering.org/api/public/switches @@ -12,7 +12,7 @@ use Data::Dumper; $nms::web::cc{'max-age'} = "60"; -my $q2 = $nms::web::dbh->prepare('select switch,sysname,placement,mgmt_v4_addr,mgmt_v6_addr,mgmt_v4_gw,mgmt_v4_netsize,mgmt_v6_gw,mgmt_v6_netsize,mgmt_vlan,traffic_vlan,last_config_fetch,current_mac,poll_frequency,community,last_updated,switchtype from switches where placement is not null'); +my $q2 = $nms::web::dbh->prepare('select switch,sysname,distro_name,placement,mgmt_v4_addr,mgmt_v6_addr,mgmt_v4_gw,mgmt_v4_netsize,mgmt_v6_gw,mgmt_v6_netsize,mgmt_vlan,traffic_vlan,last_config_fetch,current_mac,poll_frequency,community,last_updated,switchtype from switches where placement is not null'); $q2->execute(); while (my $ref = $q2->fetchrow_hashref()) { @@ -23,6 +23,7 @@ while (my $ref = $q2->fetchrow_hashref()) { $nms::web::json{'switches'}{$ref->{'sysname'}}{'placement'}{'y'} = $y2; $nms::web::json{'switches'}{$ref->{'sysname'}}{'placement'}{'width'} = $x1 - $x2; $nms::web::json{'switches'}{$ref->{'sysname'}}{'placement'}{'height'} = $y1 - $y2; + $nms::web::json{'switches'}{$ref->{'sysname'}}{'distro_name'} = $ref->{'distro_name'}; } my $q4 = $nms::web::dbh->prepare('select linknet, (select sysname from switches where switch = switch1) as sysname1, (select sysname from switches where switch = switch2) as sysname2 from linknets'); -- cgit v1.2.3 From 348d197899f37e535feefd5055ae8ef553a71bdf Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Tue, 22 Mar 2016 23:27:32 +0100 Subject: NMS: "Dirty" hack to get switches.then in switch-state --- web/nms.gathering.org/api/public/switch-state | 39 +++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'web/nms.gathering.org/api') diff --git a/web/nms.gathering.org/api/public/switch-state b/web/nms.gathering.org/api/public/switch-state index 7fa6ff5..32cf9a6 100755 --- a/web/nms.gathering.org/api/public/switch-state +++ b/web/nms.gathering.org/api/public/switch-state @@ -46,6 +46,45 @@ while ( my $ref = $q->fetchrow_hashref() ) { $json{'switches'}{$sysname}{'time'} = $ref->{'time'}; } +nms::web::setwhen('15m','10m'); +my $q2 = $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);'); + +$q2->execute(); +while ( my $ref = $q2->fetchrow_hashref() ) { + my $sysname = $ref->{'sysname'}; + + my %data = %{JSON::XS::decode_json($ref->{'data'})}; + + for my $porti (keys %{$data{'ports'}}) { + my %port = %{$data{'ports'}{$porti}}; + my $smallport = $porti; + if (not $smallport =~ m/^ae/) { + $smallport =~ s/[0-9-].*$//; + } else { + $json{'then'}{$sysname}{ifs}{$smallport}{'ifAlias'} = $port{'ifAlias'}; + } + if ($porti =~ /ge-0\/0\/4[4-7]$/) { + $json{'then'}{$sysname}{'uplinks'}{'ifHCInOctets'} += $port{'ifHCInOctets'}; + $json{'then'}{$sysname}{'uplinks'}{'ifHCOutOctets'} += $port{'ifHCOutOctets'}; + if ($port{'ifOperStatus'} eq "up") { + $json{'then'}{$sysname}{'uplinks'}{'live'} += 1; + } + $json{'then'}{$sysname}{'uplinks'}{'total'} += 1; + } + + $json{'then'}{$sysname}{ifs}{$smallport}{'ifHCInOctets'} += $port{'ifHCInOctets'}; + $json{'then'}{$sysname}{ifs}{$smallport}{'ifHCOutOctets'} += $port{'ifHCOutOctets'}; + $json{'then'}{$sysname}{totals}{'ifHCInOctets'} += $port{'ifHCInOctets'}; + $json{'then'}{$sysname}{totals}{'ifHCOutOctets'} += $port{'ifHCOutOctets'}; + if ($port{'ifOperStatus'} eq "up") { + $json{'then'}{$sysname}{ifs}{$smallport}{'live'} += 1; + $json{'then'}{$sysname}{totals}{'live'} += 1; + } + $json{'then'}{$sysname}{totals}{'total'} += 1; + } + $json{'then'}{$sysname}{'time'} = $ref->{'time'}; +} $nms::web::cc{'max-age'} = "5"; $nms::web::cc{'stale-while-revalidate'} = "30"; finalize_output(); -- cgit v1.2.3 From 7b5eee1f23bb66a6de8484c4ff5ad5b2021915ea Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Wed, 23 Mar 2016 00:38:49 +0100 Subject: NMS: Remove netsize and add traffic Not perfect, but getting closer --- web/nms.gathering.org/api/public/switches | 2 +- web/nms.gathering.org/api/read/switches-management | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'web/nms.gathering.org/api') diff --git a/web/nms.gathering.org/api/public/switches b/web/nms.gathering.org/api/public/switches index 72c77be..890b7d7 100755 --- a/web/nms.gathering.org/api/public/switches +++ b/web/nms.gathering.org/api/public/switches @@ -12,7 +12,7 @@ use Data::Dumper; $nms::web::cc{'max-age'} = "60"; -my $q2 = $nms::web::dbh->prepare('select switch,sysname,distro_name,placement,mgmt_v4_addr,mgmt_v6_addr,mgmt_v4_gw,mgmt_v4_netsize,mgmt_v6_gw,mgmt_v6_netsize,mgmt_vlan,traffic_vlan,last_config_fetch,current_mac,poll_frequency,community,last_updated,switchtype from switches where placement is not null'); +my $q2 = $nms::web::dbh->prepare('select switch,sysname,distro_name,placement,mgmt_v4_addr,mgmt_v6_addr,mgmt_v4_gw,mgmt_v6_gw,mgmt_vlan,traffic_vlan,last_config_fetch,current_mac,poll_frequency,community,last_updated,switchtype from switches where placement is not null'); $q2->execute(); while (my $ref = $q2->fetchrow_hashref()) { diff --git a/web/nms.gathering.org/api/read/switches-management b/web/nms.gathering.org/api/read/switches-management index 1bb4c4c..7697671 100755 --- a/web/nms.gathering.org/api/read/switches-management +++ b/web/nms.gathering.org/api/read/switches-management @@ -13,7 +13,7 @@ use Data::Dumper; $nms::web::cc{'max-age'} = "60"; #my $q2 = $nms::web::dbh->prepare('select sysname,ip,poll_frequency,subnet4,subnet6,distro,last_updated from switches '); -my $q2 = $nms::web::dbh->prepare('select switch,sysname,mgmt_v4_addr,mgmt_v6_addr,mgmt_v4_gw,mgmt_v4_netsize,mgmt_v6_gw,mgmt_v6_netsize,mgmt_vlan,traffic_vlan,last_config_fetch,current_mac,poll_frequency,last_updated,switchtype from switches where placement is not null'); +my $q2 = $nms::web::dbh->prepare('select switch,sysname,mgmt_v4_addr,mgmt_v6_addr,mgmt_v4_gw,mgmt_v6_gw,mgmt_vlan,traffic_vlan,last_config_fetch,current_mac,poll_frequency,last_updated,switchtype from switches where placement is not null'); $q2->execute(); while (my $ref = $q2->fetchrow_hashref()) { -- cgit v1.2.3 From a1fa26ad5b0e2ca68265b4b875169db130af61e2 Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Wed, 23 Mar 2016 01:48:48 +0100 Subject: NMS: Move which-switch-am-i-on --- .../api/public/which-switch-am-i-on | 44 ++++++++++++++++++++++ .../api/read/which-switch-am-i-on | 40 -------------------- 2 files changed, 44 insertions(+), 40 deletions(-) create mode 100755 web/nms.gathering.org/api/public/which-switch-am-i-on delete mode 100755 web/nms.gathering.org/api/read/which-switch-am-i-on (limited to 'web/nms.gathering.org/api') diff --git a/web/nms.gathering.org/api/public/which-switch-am-i-on b/web/nms.gathering.org/api/public/which-switch-am-i-on new file mode 100755 index 0000000..6c25ab9 --- /dev/null +++ b/web/nms.gathering.org/api/public/which-switch-am-i-on @@ -0,0 +1,44 @@ +#! /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 ? << subnet4"); + +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 @xff = split(",",$ENV{HTTP_X_FORWARDED_FOR}); +my $addr = $xff[0] // $ENV{REMOTE_ADDR}; + +$query->execute($addr); + +# add start html: header + body etc. +print " + + +"; + +# print address +print "" . $addr ."
"; + +# print switch name and distroname. +while ( my $ref = $query->fetchrow_hashref() ) { + print $ref->{sysname}. " @ " . $ref->{distro}; + print "
"; +} + +# add end html +print " + + +"; diff --git a/web/nms.gathering.org/api/read/which-switch-am-i-on b/web/nms.gathering.org/api/read/which-switch-am-i-on deleted file mode 100755 index 0d3f2b4..0000000 --- a/web/nms.gathering.org/api/read/which-switch-am-i-on +++ /dev/null @@ -1,40 +0,0 @@ -#! /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 " - - -"; - -# print address -print "" . $addr ."
"; - -# print switch name and distroname. -while ( my $ref = $query->fetchrow_hashref() ) { - print $ref->{sysname}. " @ " . $ref->{distro}; -} - -# add end html -print " - - -"; -- cgit v1.2.3 From 6ba9bacb3fee3765a74c603c7fd2f9b492c5329d Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Wed, 23 Mar 2016 01:49:25 +0100 Subject: NMS: Shorter url --- web/nms.gathering.org/api/public/location | 44 ++++++++++++++++++++++ .../api/public/which-switch-am-i-on | 44 ---------------------- 2 files changed, 44 insertions(+), 44 deletions(-) create mode 100755 web/nms.gathering.org/api/public/location delete mode 100755 web/nms.gathering.org/api/public/which-switch-am-i-on (limited to 'web/nms.gathering.org/api') diff --git a/web/nms.gathering.org/api/public/location b/web/nms.gathering.org/api/public/location new file mode 100755 index 0000000..6c25ab9 --- /dev/null +++ b/web/nms.gathering.org/api/public/location @@ -0,0 +1,44 @@ +#! /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 ? << subnet4"); + +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 @xff = split(",",$ENV{HTTP_X_FORWARDED_FOR}); +my $addr = $xff[0] // $ENV{REMOTE_ADDR}; + +$query->execute($addr); + +# add start html: header + body etc. +print " + + +"; + +# print address +print "" . $addr ."
"; + +# print switch name and distroname. +while ( my $ref = $query->fetchrow_hashref() ) { + print $ref->{sysname}. " @ " . $ref->{distro}; + print "
"; +} + +# add end html +print " + + +"; diff --git a/web/nms.gathering.org/api/public/which-switch-am-i-on b/web/nms.gathering.org/api/public/which-switch-am-i-on deleted file mode 100755 index 6c25ab9..0000000 --- a/web/nms.gathering.org/api/public/which-switch-am-i-on +++ /dev/null @@ -1,44 +0,0 @@ -#! /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 ? << subnet4"); - -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 @xff = split(",",$ENV{HTTP_X_FORWARDED_FOR}); -my $addr = $xff[0] // $ENV{REMOTE_ADDR}; - -$query->execute($addr); - -# add start html: header + body etc. -print " - - -"; - -# print address -print "" . $addr ."
"; - -# print switch name and distroname. -while ( my $ref = $query->fetchrow_hashref() ) { - print $ref->{sysname}. " @ " . $ref->{distro}; - print "
"; -} - -# add end html -print " - - -"; -- cgit v1.2.3 From e4f3bbbaffcc7315f73ecf55a52ad61814d96100 Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Wed, 23 Mar 2016 02:52:26 +0100 Subject: NMS: Fix cache invalidation etc --- web/nms.gathering.org/api/read/switches-management | 2 +- web/nms.gathering.org/api/write/comment-add | 2 +- web/nms.gathering.org/api/write/comment-change | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) (limited to 'web/nms.gathering.org/api') diff --git a/web/nms.gathering.org/api/read/switches-management b/web/nms.gathering.org/api/read/switches-management index 7697671..292a6fb 100755 --- a/web/nms.gathering.org/api/read/switches-management +++ b/web/nms.gathering.org/api/read/switches-management @@ -13,7 +13,7 @@ use Data::Dumper; $nms::web::cc{'max-age'} = "60"; #my $q2 = $nms::web::dbh->prepare('select sysname,ip,poll_frequency,subnet4,subnet6,distro,last_updated from switches '); -my $q2 = $nms::web::dbh->prepare('select switch,sysname,mgmt_v4_addr,mgmt_v6_addr,mgmt_v4_gw,mgmt_v6_gw,mgmt_vlan,traffic_vlan,last_config_fetch,current_mac,poll_frequency,last_updated,switchtype from switches where placement is not null'); +my $q2 = $nms::web::dbh->prepare('select switch,sysname,mgmt_v4_addr,subnet4,subnet6,mgmt_v6_addr,mgmt_v4_gw,mgmt_v6_gw,mgmt_vlan,traffic_vlan,last_config_fetch,current_mac,poll_frequency,last_updated,switchtype from switches where placement is not null'); $q2->execute(); while (my $ref = $q2->fetchrow_hashref()) { diff --git a/web/nms.gathering.org/api/write/comment-add b/web/nms.gathering.org/api/write/comment-add index 26ff734..bcea6dc 100755 --- a/web/nms.gathering.org/api/write/comment-add +++ b/web/nms.gathering.org/api/write/comment-add @@ -20,5 +20,5 @@ $nms::web::cc{'max-age'} = '0'; $nms::web::cc{'stale-while-revalidate'} = '0'; $nms::web::json{'state'} = 'ok'; -print "X-ban: /api/private/comments\n"; +print "X-ban: /api/read/comments\n"; finalize_output(); diff --git a/web/nms.gathering.org/api/write/comment-change b/web/nms.gathering.org/api/write/comment-change index fb7da54..0bdabc0 100755 --- a/web/nms.gathering.org/api/write/comment-change +++ b/web/nms.gathering.org/api/write/comment-change @@ -21,4 +21,5 @@ $nms::web::cc{'max-age'} = '0'; $nms::web::cc{'stale-while-revalidate'} = '0'; $nms::web::json{'state'} = 'ok'; +print "X-ban: /api/read/comments\n"; finalize_output(); -- cgit v1.2.3 From 750c5c7224c0b6698780a2498ce7c0cffd65af3e Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Wed, 23 Mar 2016 05:35:17 +0100 Subject: NMS: SNMP map and remove switchtype and fix switch-add --- web/nms.gathering.org/api/read/switches-management | 3 +-- web/nms.gathering.org/api/write/switch-add | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) (limited to 'web/nms.gathering.org/api') diff --git a/web/nms.gathering.org/api/read/switches-management b/web/nms.gathering.org/api/read/switches-management index 292a6fb..9e12337 100755 --- a/web/nms.gathering.org/api/read/switches-management +++ b/web/nms.gathering.org/api/read/switches-management @@ -12,8 +12,7 @@ use Data::Dumper; $nms::web::cc{'max-age'} = "60"; -#my $q2 = $nms::web::dbh->prepare('select sysname,ip,poll_frequency,subnet4,subnet6,distro,last_updated from switches '); -my $q2 = $nms::web::dbh->prepare('select switch,sysname,mgmt_v4_addr,subnet4,subnet6,mgmt_v6_addr,mgmt_v4_gw,mgmt_v6_gw,mgmt_vlan,traffic_vlan,last_config_fetch,current_mac,poll_frequency,last_updated,switchtype from switches where placement is not null'); +my $q2 = $nms::web::dbh->prepare('select switch,sysname,mgmt_v4_addr,subnet4,subnet6,mgmt_v6_addr,mgmt_v4_gw,mgmt_v6_gw,mgmt_vlan,traffic_vlan,last_config_fetch,current_mac,poll_frequency,last_updated from switches where placement is not null'); $q2->execute(); while (my $ref = $q2->fetchrow_hashref()) { diff --git a/web/nms.gathering.org/api/write/switch-add b/web/nms.gathering.org/api/write/switch-add index 411a76b..0051111 100755 --- a/web/nms.gathering.org/api/write/switch-add +++ b/web/nms.gathering.org/api/write/switch-add @@ -22,7 +22,7 @@ my @dups; my $sth = $nms::web::dbh->prepare("SELECT sysname FROM switches WHERE sysname=?"); -my @fields = ( 'community', 'current_mac', 'distro_name', 'distro_phy_port', 'lldp_chassis_id', 'mgmt_v4_addr', 'mgmt_v4_gw', 'mgmt_v4_netsize', 'mgmt_v6_addr', 'mgmt_v6_gw', 'mgmt_v6_netsize', 'mgmt_vlan', 'placement', 'poll_frequency', 'subnet4', 'subnet6', 'switchtype', 'sysname', 'traffic_vlan'); +my @fields = ( 'community', 'current_mac', 'distro_name', 'distro_phy_port', 'lldp_chassis_id', 'mgmt_v4_addr', 'mgmt_v4_gw', 'mgmt_v6_addr', 'mgmt_v6_gw', 'mgmt_vlan', 'placement', 'poll_frequency', 'subnet4', 'subnet6', 'switchtype', 'sysname', 'traffic_vlan'); sub convertplace { @@ -81,7 +81,7 @@ foreach my $tmp2 (@tmp) { } keys %switch; - $nms::web::dbh->do("INSERT INTO SWITCHES (ip, sysname, last_updated, locked, poll_frequency, community, lldp_chassis_id, secondary_ip, placement,subnet4,subnet6,distro) VALUES ($template{'ip'}, $template{'sysname'}, $template{'last_updated'}, $template{'locked'}, $template{'poll_frequency'}, $template{'community'}, $template{'lldp_chassis_id'}, $template{'secondary_ip'}, $template{'placement'},$template{'subnet4'},$template{'subnet6'},$template{'distro'});"); + $nms::web::dbh->do("INSERT INTO SWITCHES (mgmt_v4_addr, sysname, poll_frequency, community, lldp_chassis_id, mgmt_v6_addr, placement,subnet4,subnet6,distro_name) VALUES ($template{'mgmt_v4_addr'}, $template{'sysname'}, $template{'poll_frequency'}, $template{'community'}, $template{'lldp_chassis_id'}, $template{'mgmt_v6_addr'}, $template{'placement'},$template{'subnet4'},$template{'subnet6'},$template{'distro_name'});"); push @added, $switch{'sysname'}; } } -- cgit v1.2.3 From 50a9e3fcb3e8e6f3ec13eebe1da8df7bdf7af45c Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Wed, 23 Mar 2016 10:53:45 +0100 Subject: NMS: Bump location and placement --- web/nms.gathering.org/api/public/location | 4 ++-- web/nms.gathering.org/api/read/switches-management | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'web/nms.gathering.org/api') diff --git a/web/nms.gathering.org/api/public/location b/web/nms.gathering.org/api/public/location index 6c25ab9..b940007 100755 --- a/web/nms.gathering.org/api/public/location +++ b/web/nms.gathering.org/api/public/location @@ -8,7 +8,7 @@ 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 ? << subnet4"); +my $query = $nms::web::dbh->prepare("select * from switches where ? << subnet4 or ? << subnet6"); print "Cache-Control: max-age=0"; print "Content-Type: text/html"; @@ -20,7 +20,7 @@ print "\n\n"; my @xff = split(",",$ENV{HTTP_X_FORWARDED_FOR}); my $addr = $xff[0] // $ENV{REMOTE_ADDR}; -$query->execute($addr); +$query->execute($addr,$addr); # add start html: header + body etc. print " diff --git a/web/nms.gathering.org/api/read/switches-management b/web/nms.gathering.org/api/read/switches-management index 9e12337..4461a90 100755 --- a/web/nms.gathering.org/api/read/switches-management +++ b/web/nms.gathering.org/api/read/switches-management @@ -12,7 +12,7 @@ use Data::Dumper; $nms::web::cc{'max-age'} = "60"; -my $q2 = $nms::web::dbh->prepare('select switch,sysname,mgmt_v4_addr,subnet4,subnet6,mgmt_v6_addr,mgmt_v4_gw,mgmt_v6_gw,mgmt_vlan,traffic_vlan,last_config_fetch,current_mac,poll_frequency,last_updated from switches where placement is not null'); +my $q2 = $nms::web::dbh->prepare('select switch,sysname,mgmt_v4_addr,subnet4,subnet6,mgmt_v6_addr,mgmt_v4_gw,mgmt_v6_gw,mgmt_vlan,traffic_vlan,last_config_fetch,current_mac,poll_frequency,last_updated,distro_phy_port from switches where placement is not null'); $q2->execute(); while (my $ref = $q2->fetchrow_hashref()) { -- cgit v1.2.3 From 38d386700282d87fffeec9cbcb7add0eaadae1f1 Mon Sep 17 00:00:00 2001 From: Magnus S Date: Wed, 23 Mar 2016 11:51:55 +0100 Subject: Update API.rst Moved public on top, since that is what I assume you want 3rd parties to use. Added the public URL as well. --- web/nms.gathering.org/api/API.rst | 70 ++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 34 deletions(-) (limited to 'web/nms.gathering.org/api') diff --git a/web/nms.gathering.org/api/API.rst b/web/nms.gathering.org/api/API.rst index 61fbb5a..8fcb657 100644 --- a/web/nms.gathering.org/api/API.rst +++ b/web/nms.gathering.org/api/API.rst @@ -19,6 +19,42 @@ Currently error handling sucks. This document is in no way complete, but it's a start. It will be updated as time permits and API's stabilize. +Public +...... + +Use URL https://nms-public.tg16.gathering.org + +/api/public/ping +---------------- + +Methods: GET +Update frequency: every second or so. + +Used to report linknet latency. + +The switch latency is being integrated into switch-state.pl and linknet +latency will similarly be moved. + +/api/public/switches +-------------------- + +Methods: GET +Update frequency: Infrequent (on topology/config changes) + +List all switches and map positions. + +Used to draw switches on a map and provide static information. + +/api/public/switch-state +------------------------ + +Methods: GET +Update frequency: Every second + +Provides state for each switch, including total port speed, uplink port +speed, latency and temperature. + + Private ....... @@ -77,37 +113,3 @@ Accepts an array of switches. Magic: If you set placement to be "reset", it will re-calculate placement based on sysname. For new switches, this is redundant as an empty placement-field will trigger the same behavior. - - -Public -...... - -/api/public/ping ----------------- - -Methods: GET -Update frequency: every second or so. - -Used to report linknet latency. - -The switch latency is being integrated into switch-state.pl and linknet -latency will similarly be moved. - -/api/public/switches --------------------- - -Methods: GET -Update frequency: Infrequent (on topology/config changes) - -List all switches and map positions. - -Used to draw switches on a map and provide static information. - -/api/public/switch-state ------------------------- - -Methods: GET -Update frequency: Every second - -Provides state for each switch, including total port speed, uplink port -speed, latency and temperature. -- cgit v1.2.3 From c96b6ff54b3d1df27b31803262688ca6b35ab003 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20Kir=C3=B8?= Date: Wed, 23 Mar 2016 12:44:26 +0100 Subject: Public api doc updated. Still work in progress. --- web/nms.gathering.org/api/API.rst | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'web/nms.gathering.org/api') diff --git a/web/nms.gathering.org/api/API.rst b/web/nms.gathering.org/api/API.rst index 8fcb657..7d5c88b 100644 --- a/web/nms.gathering.org/api/API.rst +++ b/web/nms.gathering.org/api/API.rst @@ -22,7 +22,23 @@ as time permits and API's stabilize. Public ...... -Use URL https://nms-public.tg16.gathering.org +Use URL https://nms-public.tg16.gathering.org/api/public + +/api/public/dhcp +---------------- + +Methods: GET +Update frequency: every second or so. + +Used to report time since last dhcp lease. + +/api/public/dhcp-summary +------------------------ + +Methods: GET +Update frequency: every second or so. + +Used to report dhcp lease stats. Both recent stats, and total stats. /api/public/ping ---------------- -- cgit v1.2.3 From a174cec51faa448973056847e5c664801222c739 Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Wed, 23 Mar 2016 17:35:48 +0100 Subject: NMS: API: Expose temperature too in public --- web/nms.gathering.org/api/public/switch-state | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'web/nms.gathering.org/api') diff --git a/web/nms.gathering.org/api/public/switch-state b/web/nms.gathering.org/api/public/switch-state index 32cf9a6..2a2b5b6 100755 --- a/web/nms.gathering.org/api/public/switch-state +++ b/web/nms.gathering.org/api/public/switch-state @@ -32,7 +32,6 @@ while ( my $ref = $q->fetchrow_hashref() ) { } $json{'switches'}{$sysname}{'uplinks'}{'total'} += 1; } - $json{'switches'}{$sysname}{ifs}{$smallport}{'ifHCInOctets'} += $port{'ifHCInOctets'}; $json{'switches'}{$sysname}{ifs}{$smallport}{'ifHCOutOctets'} += $port{'ifHCOutOctets'}; $json{'switches'}{$sysname}{totals}{'ifHCInOctets'} += $port{'ifHCInOctets'}; @@ -43,6 +42,7 @@ while ( my $ref = $q->fetchrow_hashref() ) { } $json{'switches'}{$sysname}{totals}{'total'} += 1; } + $json{'switches'}{$sysname}{'temp'} = $data{'misc'}{'enterprises.2636.3.1.13.1.7.7.1.0.0'}{''}; $json{'switches'}{$sysname}{'time'} = $ref->{'time'}; } @@ -83,6 +83,7 @@ while ( my $ref = $q2->fetchrow_hashref() ) { } $json{'then'}{$sysname}{totals}{'total'} += 1; } + $json{'then'}{$sysname}{'temp'} = $data{'misc'}{'enterprises.2636.3.1.13.1.7.7.1.0.0'}{''}; $json{'then'}{$sysname}{'time'} = $ref->{'time'}; } $nms::web::cc{'max-age'} = "5"; -- cgit v1.2.3 From 2f08210fde3f168facc06327ec05a20467f4fe1b Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Thu, 24 Mar 2016 00:44:56 +0100 Subject: NMS: Update public API for temperature --- web/nms.gathering.org/api/public/switch-state | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'web/nms.gathering.org/api') diff --git a/web/nms.gathering.org/api/public/switch-state b/web/nms.gathering.org/api/public/switch-state index 2a2b5b6..2fff681 100755 --- a/web/nms.gathering.org/api/public/switch-state +++ b/web/nms.gathering.org/api/public/switch-state @@ -42,7 +42,7 @@ while ( my $ref = $q->fetchrow_hashref() ) { } $json{'switches'}{$sysname}{totals}{'total'} += 1; } - $json{'switches'}{$sysname}{'temp'} = $data{'misc'}{'enterprises.2636.3.1.13.1.7.7.1.0.0'}{''}; + $json{'switches'}{$sysname}{'temp'} = $data{'misc'}{'jnxOperatingTemp'}{'7.1.0.0'}; $json{'switches'}{$sysname}{'time'} = $ref->{'time'}; } -- cgit v1.2.3 From 7c6589dd177deaba473fdde3fd48c283f5e369bc Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Thu, 24 Mar 2016 21:12:08 +0100 Subject: NMS: Expose ET-interfaces and more --- web/nms.gathering.org/api/public/switch-state | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'web/nms.gathering.org/api') diff --git a/web/nms.gathering.org/api/public/switch-state b/web/nms.gathering.org/api/public/switch-state index 2fff681..62e497c 100755 --- a/web/nms.gathering.org/api/public/switch-state +++ b/web/nms.gathering.org/api/public/switch-state @@ -19,7 +19,7 @@ while ( my $ref = $q->fetchrow_hashref() ) { for my $porti (keys %{$data{'ports'}}) { my %port = %{$data{'ports'}{$porti}}; my $smallport = $porti; - if (not $smallport =~ m/^ae/) { + if (not $smallport =~ m/^ae/ and not $smallport =~ m/^et/) { $smallport =~ s/[0-9-].*$//; } else { $json{'switches'}{$sysname}{ifs}{$smallport}{'ifAlias'} = $port{'ifAlias'}; -- cgit v1.2.3 From f0a12faa1dceb7c21e1688164342aa58e8f136f2 Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Thu, 24 Mar 2016 21:14:23 +0100 Subject: NMS: Fix et-interfaces in both locations --- web/nms.gathering.org/api/public/switch-state | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'web/nms.gathering.org/api') diff --git a/web/nms.gathering.org/api/public/switch-state b/web/nms.gathering.org/api/public/switch-state index 62e497c..0e28cfd 100755 --- a/web/nms.gathering.org/api/public/switch-state +++ b/web/nms.gathering.org/api/public/switch-state @@ -59,7 +59,7 @@ while ( my $ref = $q2->fetchrow_hashref() ) { for my $porti (keys %{$data{'ports'}}) { my %port = %{$data{'ports'}{$porti}}; my $smallport = $porti; - if (not $smallport =~ m/^ae/) { + if (not $smallport =~ m/^ae/ and not $smallport =~ m/^et/) { $smallport =~ s/[0-9-].*$//; } else { $json{'then'}{$sysname}{ifs}{$smallport}{'ifAlias'} = $port{'ifAlias'}; -- cgit v1.2.3 From 004f4efcfd0779f4307b90fed139dc87d01ad0b9 Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Sat, 26 Mar 2016 03:48:12 +0100 Subject: NMS: Various performance tweaks --- web/nms.gathering.org/api/public/dhcp | 2 +- web/nms.gathering.org/api/public/dhcp-summary | 7 +------ web/nms.gathering.org/api/public/ping | 6 +++--- web/nms.gathering.org/api/public/switch-state | 6 ++++++ 4 files changed, 11 insertions(+), 10 deletions(-) (limited to 'web/nms.gathering.org/api') diff --git a/web/nms.gathering.org/api/public/dhcp b/web/nms.gathering.org/api/public/dhcp index 91d52af..7b048d1 100755 --- a/web/nms.gathering.org/api/public/dhcp +++ b/web/nms.gathering.org/api/public/dhcp @@ -15,6 +15,6 @@ while ( my $ref = $q->fetchrow_hashref() ) { $json{'dhcp'}{$ref->{'sysname'}} = $ref->{'time'}; } -$nms::web::cc{'max-age'} = "5"; +$nms::web::cc{'max-age'} = "10"; $nms::web::cc{'stale-while-revalidate'} = "30"; finalize_output(); diff --git a/web/nms.gathering.org/api/public/dhcp-summary b/web/nms.gathering.org/api/public/dhcp-summary index dd643b2..a0e5609 100755 --- a/web/nms.gathering.org/api/public/dhcp-summary +++ b/web/nms.gathering.org/api/public/dhcp-summary @@ -5,16 +5,11 @@ use warnings; use nms::web; nms::web::setwhen('2h'); -my $q = $nms::web::dbh->prepare("select count(distinct mac) as clients,count(distinct ip) as addresses,count(mac) as acks from dhcp;"); -$q->execute(); -while (my $ref = $q->fetchrow_hashref()) { - $nms::web::json{'dhcp'}{'total'} = $ref; -} my $q2 = $nms::web::dbh->prepare("select count(distinct mac) as clients,count(distinct ip) as addresses,count(mac) as acks from dhcp where $nms::web::when;"); $q2->execute(); while (my $ref = $q2->fetchrow_hashref()) { - $nms::web::json{'dhcp'}{'recent'} = $ref; + $nms::web::json{'dhcp'} = $ref; } $nms::web::cc{'max-age'} = "10"; $nms::web::cc{'stale-while-revalidate'} = "15"; diff --git a/web/nms.gathering.org/api/public/ping b/web/nms.gathering.org/api/public/ping index ba572af..db46b00 100755 --- a/web/nms.gathering.org/api/public/ping +++ b/web/nms.gathering.org/api/public/ping @@ -4,7 +4,7 @@ use strict; use warnings; use nms::web; -#nms::web::setwhen('1s'); +nms::web::setwhen('10s'); 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)"); @@ -32,6 +32,6 @@ while ( my $ref = $lq->fetchrow_hashref() ) { $nms::web::json{'linknets'}{$ref->{'linknet'}} = [ $ref->{'latency1_ms'}, $ref->{'latency2_ms'} ]; } -$nms::web::cc{'max-age'} = "1"; -$nms::web::cc{'stale-while-revalidate'} = "5"; +$nms::web::cc{'max-age'} = "2"; +$nms::web::cc{'stale-while-revalidate'} = "15"; finalize_output(); diff --git a/web/nms.gathering.org/api/public/switch-state b/web/nms.gathering.org/api/public/switch-state index 0e28cfd..a6caea9 100755 --- a/web/nms.gathering.org/api/public/switch-state +++ b/web/nms.gathering.org/api/public/switch-state @@ -19,6 +19,9 @@ while ( my $ref = $q->fetchrow_hashref() ) { for my $porti (keys %{$data{'ports'}}) { my %port = %{$data{'ports'}{$porti}}; my $smallport = $porti; + if ($porti =~ m/\.0$/) { + next; + } if (not $smallport =~ m/^ae/ and not $smallport =~ m/^et/) { $smallport =~ s/[0-9-].*$//; } else { @@ -59,6 +62,9 @@ while ( my $ref = $q2->fetchrow_hashref() ) { for my $porti (keys %{$data{'ports'}}) { my %port = %{$data{'ports'}{$porti}}; my $smallport = $porti; + if ($porti =~ m/\.0$/) { + next; + } if (not $smallport =~ m/^ae/ and not $smallport =~ m/^et/) { $smallport =~ s/[0-9-].*$//; } else { -- cgit v1.2.3