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