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/public') 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/public') 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/public') 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 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/public') 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 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/public') 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/public/switches | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'web/nms.gathering.org/api/public') 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/public') 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 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/public') 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 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'web/nms.gathering.org/api/public') 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()) { -- 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/public') 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/public') 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/public') 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 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'web/nms.gathering.org/api/public') 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()) { -- 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 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100755 web/nms.gathering.org/api/public/which-switch-am-i-on (limited to 'web/nms.gathering.org/api/public') 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 " + + +"; -- 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/public') 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 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 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'web/nms.gathering.org/api/public') 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 " -- 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/public') 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/public') 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/public') 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/public') 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/public') 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