aboutsummaryrefslogtreecommitdiffstats
path: root/web/api/public
diff options
context:
space:
mode:
Diffstat (limited to 'web/api/public')
-rwxr-xr-xweb/api/public/config31
-rwxr-xr-xweb/api/public/dhcp36
-rwxr-xr-xweb/api/public/dhcp-summary16
-rwxr-xr-xweb/api/public/distro-tree27
-rwxr-xr-xweb/api/public/location44
-rwxr-xr-xweb/api/public/ping35
-rwxr-xr-xweb/api/public/switch-state156
-rwxr-xr-xweb/api/public/switches32
8 files changed, 0 insertions, 377 deletions
diff --git a/web/api/public/config b/web/api/public/config
deleted file mode 100755
index 0f0d322..0000000
--- a/web/api/public/config
+++ /dev/null
@@ -1,31 +0,0 @@
-#! /usr/bin/perl
-# vim:ts=8:sw=8
-
-use DBI;
-use lib '/opt/gondul/include';
-use nms;
-use nms::web;
-use strict;
-use warnings;
-use Data::Dumper;
-
-$nms::web::cc{'max-age'} = "3600";
-
-my $hostname = $ENV{'HTTP_HOST'} || "";
-my $q2 = $nms::web::dbh->prepare('select id, publicvhost, shortname, data from config order by id desc limit 1;');
-
-$q2->execute();
-$nms::web::json{'config'}{'data'} = 0;
-$nms::web::json{'config'}{'shortname'} = "notset";
-$nms::web::json{'config'}{'publicvhost'} = "notset";
-while (my $ref = $q2->fetchrow_hashref()) {
- $nms::web::json{'config'} = $ref;
- $nms::web::json{'config'}{'data'} = JSON::XS::decode_json($ref->{'data'});
- if ($ref->{'publicvhost'} eq $hostname) {
- $nms::web::json{'config'}{'public'} = "true";
- } else {
- $nms::web::json{'config'}{'public'} = "false";
- }
-}
-
-finalize_output();
diff --git a/web/api/public/dhcp b/web/api/public/dhcp
deleted file mode 100755
index 3e56f59..0000000
--- a/web/api/public/dhcp
+++ /dev/null
@@ -1,36 +0,0 @@
-#! /usr/bin/perl
-# vim:ts=8:sw=8
-
-use lib '/opt/gondul/include';
-use nms::web qw (%json finalize_output);
-use strict;
-use warnings;
-use Data::Dumper;
-
-nms::web::setwhen('60m');
-#my $q = $nms::web::dbh->prepare('select distinct on (name) extract(epoch from date_trunc(\'second\',time)) as time,name from dhcp join networks on dhcp.network = networks.network where ' . $nms::web::when . ' order by name,time desc;');
-my $q_v4 = $nms::web::dbh->prepare("select distinct on (name) extract(epoch from date_trunc('second', metrics.time)) as time, networks.name as name from metrics JOIN networks ON (data->>'clientip')::inet <<= networks.subnet4 where $nms::web::when order by name,time desc;");
-$q_v4->execute();
-while ( my $ref = $q_v4->fetchrow_hashref() ) {
- my $sysname = $ref->{'sname'};
- $json{'dhcp4'}{$ref->{'name'}} = $ref->{'time'};
-}
-
-my $q_v6 = $nms::web::dbh->prepare("select distinct on (name) extract(epoch from date_trunc('second', metrics.time)) as time, networks.name as name from metrics JOIN networks ON (data->>'clientip')::inet <<= networks.subnet6 where $nms::web::when order by name,time desc;");
-$q_v6->execute();
-while ( my $ref = $q_v6->fetchrow_hashref() ) {
- my $sysname = $ref->{'sname'};
- $json{'dhcp6'}{$ref->{'name'}} = $ref->{'time'};
-}
-
-
-#my $q2 = $nms::web::dbh->prepare("select name,count(distinct mac) as clients,count(distinct ip) as addresses,count(mac) as acks from dhcp natural join networks where $nms::web::when group by networks.name;");
-my $q2 = $nms::web::dbh->prepare("SELECT networks.name, count(distinct data->>'clientmac') as clients, count(distinct data->>'clientip') as addresses, count(data->>'clientmac') as acks from metrics JOIN networks ON (data->>'clientip')::inet <<= networks.subnet4 WHERE $nms::web::when GROUP BY networks.name;");
-$q2->execute();
-while (my $ref = $q2->fetchrow_hashref()) {
- $nms::web::json{'networks'}{$ref->{name}} = $ref;
-}
-
-$nms::web::cc{'max-age'} = "10";
-$nms::web::cc{'stale-while-revalidate'} = "30";
-finalize_output();
diff --git a/web/api/public/dhcp-summary b/web/api/public/dhcp-summary
deleted file mode 100755
index beed463..0000000
--- a/web/api/public/dhcp-summary
+++ /dev/null
@@ -1,16 +0,0 @@
-#! /usr/bin/perl
-use lib '/opt/gondul/include';
-use strict;
-use warnings;
-use nms::web;
-
-nms::web::setwhen('2h');
-
-my $q2 = $nms::web::dbh->prepare("select count(DISTINCT data ->> 'clientip') as clients, family(inet (data ->> 'clientip')) as family from metrics where $nms::web::when GROUP by family;");
-$q2->execute();
-while (my $ref = $q2->fetchrow_hashref()) {
- $nms::web::json{'dhcp'}{$ref->{'family'}} = $ref->{'clients'};
-}
-$nms::web::cc{'max-age'} = "10";
-$nms::web::cc{'stale-while-revalidate'} = "15";
-finalize_output();
diff --git a/web/api/public/distro-tree b/web/api/public/distro-tree
deleted file mode 100755
index 49ce607..0000000
--- a/web/api/public/distro-tree
+++ /dev/null
@@ -1,27 +0,0 @@
-#! /usr/bin/perl
-# vim:ts=8:sw=8
-
-use CGI qw(fatalsToBrowser);
-use DBI;
-use lib '/opt/gondul/include';
-use nms;
-use nms::web;
-use strict;
-use warnings;
-use Data::Dumper;
-
-$nms::web::cc{'max-age'} = "5";
-$nms::web::cc{'stale-while-revalidate'} = "30";
-
-my $q2 = $nms::web::dbh->prepare('select sysname,distro_phy_port,distro_name from switches where placement is not null and distro_name is not null and distro_phy_port is not null and deleted = false');
-
-$q2->execute();
-while (my $ref = $q2->fetchrow_hashref()) {
- my $sysname = $ref->{'sysname'};
- my $distro = $ref->{'distro_name'};
- my $phy = $ref->{'distro_phy_port'};
- $nms::web::json{'distro-tree-phy'}{$distro}{$phy} = $sysname;
- $nms::web::json{'distro-tree-sys'}{$distro}{$sysname} = $phy;
-}
-
-finalize_output();
diff --git a/web/api/public/location b/web/api/public/location
deleted file mode 100755
index b960bb2..0000000
--- a/web/api/public/location
+++ /dev/null
@@ -1,44 +0,0 @@
-#! /usr/bin/perl
-# vim:ts=8:sw=8
-
-use lib '/opt/gondul/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 deleted = false and (? << subnet4 or ? << subnet6)");
-
-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,$addr);
-
-# add start html: header + body etc.
-print "
-<html>
- <body style=\"text-align: center; font-size: 50pt;\">
-";
-
-# print address
-print "" . $addr ."<br \>";
-
-# print switch name and distroname.
-while ( my $ref = $query->fetchrow_hashref() ) {
- print $ref->{sysname}. " @ " . $ref->{distro};
- print "<br />";
-}
-
-# add end html
-print "
- </body>
-</html>
-";
diff --git a/web/api/public/ping b/web/api/public/ping
deleted file mode 100755
index 52dffbc..0000000
--- a/web/api/public/ping
+++ /dev/null
@@ -1,35 +0,0 @@
-#! /usr/bin/perl
-use lib '/opt/gondul/include';
-use strict;
-use warnings;
-use nms::web;
-
-nms::web::setwhen('25s');
-
-my $q = $nms::web::dbh->prepare("SELECT DISTINCT ON (sysname) (" . $nms::web::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'}}{'latency4'} = $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'}}{'age4'} = ($h*60*60) + ($m*60) + $s; # $$ref->{'age'};
-}
-
-my $q2 = $nms::web::dbh->prepare("SELECT DISTINCT ON (sysname) (" . $nms::web::now . " - time) as age,sysname, latency_ms FROM ping_secondary_ip NATURAL JOIN switches WHERE time in (select max(time) from ping where "
- . $nms::web::when . " group by switch)");
-
-$q2->execute();
-while (my $ref = $q2->fetchrow_hashref()) {
- $nms::web::json{'switches'}{$ref->{'sysname'}}{'latency6'} = $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'}}{'age6'} = ($h*60*60) + ($m*60) + $s; # $$ref->{'age'};
-}
-
-$nms::web::cc{'max-age'} = "1";
-$nms::web::cc{'stale-while-revalidate'} = "5";
-finalize_output();
diff --git a/web/api/public/switch-state b/web/api/public/switch-state
deleted file mode 100755
index 2aff40c..0000000
--- a/web/api/public/switch-state
+++ /dev/null
@@ -1,156 +0,0 @@
-#! /usr/bin/perl
-# vim:ts=8:sw=8
-
-use lib '/opt/gondul/include';
-use nms::web qw (%json finalize_output);
-use strict;
-use warnings;
-use Data::Dumper;
-
-#my $target = $ENV{REQUEST_URI};
-#$target =~ s/$ENV{SCRIPT_NAME}//;
-#$target =~ s/^\///;
-#my ($switch, $port) = split(/\//,$target,2);
-my $port;
-my $switch;
-my $q;
-
-#if (!defined($switch)) {
- $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) and switches.deleted = \'f\' and not switches.tags \?& array[\'ignoreswitchstate\'];');
-#} else {
-# $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) and sysname = ' . $nms::web::dbh->quote($switch) . ';');
-#}
-
-$q->execute();
-while ( my $ref = $q->fetchrow_hashref() ) {
- my $sysname = $ref->{'sysname'};
-
- my %data = %{JSON::XS::decode_json($ref->{'data'})};
-
- $json{'switches'}{$sysname}{'clients'}{'live'} = 0;
- $json{'then'}{$sysname}{'clients'}{'live'} = 0;
- for my $porti (keys %{$data{'ports'}}) {
- if (defined($port) and $port ne "" and $port ne $porti) {
- next;
- }
- my %port = %{$data{'ports'}{$porti}};
- my $smallport = $porti;
- if ($porti =~ m/\.0$/) {
- next;
- }
- if ($data{'ports'}{$porti}{'ifAlias'} =~ m/C:/i) {
- $smallport =~ s/[0-9-].*$//;
- } else {
- $json{'switches'}{$sysname}{ifs}{$smallport}{'ifAlias'} = $port{'ifAlias'};
- }
- if ($data{'ports'}{$porti}{'ifType'} ne "propVirtual" and
- $data{'ports'}{$porti}{'ifAlias'} =~ m/G:/i) {
- if ($port{'ifAdminStatus'} eq "up") {
- $json{'switches'}{$sysname}{'uplinks'}{'ifHCInOctets'} += $port{'ifHCInOctets'};
- $json{'switches'}{$sysname}{'uplinks'}{'ifHCOutOctets'} += $port{'ifHCOutOctets'};
- if ($port{'ifOperStatus'} eq "up") {
- $json{'switches'}{$sysname}{'uplinks'}{'live'} += 1;
- }
- $json{'switches'}{$sysname}{'uplinks'}{'total'} += 1;
- }
- }
- if ($data{'ports'}{$porti}{'ifType'} ne "propVirtual" and
- $data{'ports'}{$porti}{'ifAlias'} =~ m/C:/i) {
- if ($port{'ifAdminStatus'} eq "up") {
- $json{'switches'}{$sysname}{'clients'}{'ifHCInOctets'} += $port{'ifHCInOctets'};
- $json{'switches'}{$sysname}{'clients'}{'ifHCOutOctets'} += $port{'ifHCOutOctets'};
- if ($port{'ifOperStatus'} eq "up") {
- $json{'switches'}{$sysname}{'clients'}{'live'} += 1;
- }
- $json{'switches'}{$sysname}{'clients'}{'total'} += 1;
- }
- }
- $json{'switches'}{$sysname}{ifs}{$smallport}{'ifHCInOctets'} += $port{'ifHCInOctets'} || 0;
- $json{'switches'}{$sysname}{ifs}{$smallport}{'ifHCOutOctets'} += $port{'ifHCOutOctets'} || 0;
- if ($smallport ne "loopback") {
- $json{'switches'}{$sysname}{totals}{'ifHCInOctets'} += $port{'ifHCInOctets'} || 0;
- $json{'switches'}{$sysname}{totals}{'ifHCOutOctets'} += $port{'ifHCOutOctets'} || 0;
- }
- if ($port{'ifOperStatus'} eq "up") {
- $json{'switches'}{$sysname}{ifs}{$smallport}{'live'} += 1;
- $json{'switches'}{$sysname}{totals}{'live'} += 1;
- }
- $json{'switches'}{$sysname}{totals}{'total'} += 1;
- }
-
- $json{'switches'}{$sysname}{vcp}{jnxVirtualChassisPortInOctets} = $data{'vcp'}{'jnxVirtualChassisPortInOctets'};
- $json{'switches'}{$sysname}{vcp}{jnxVirtualChassisPortOutOctets} = $data{'vcp'}{'jnxVirtualChassisPortOutOctets'};
- $json{'switches'}{$sysname}{'temp'} = $data{'misc'}{'jnxOperatingTemp'}{'7.1.0.0'} || $data{'misc'}{'jnxOperatingTemp'}{'7.1.0.0'} || $data{'misc'}{'jnxOperatingTemp'}{'7.2.0.0'} || $data{'misc'}{'jnxOperatingTemp'}{'7.3.0.0'} || $data{'misc'}{'jnxOperatingTemp'}{'7.4.0.0'} || $data{'misc'}{'jnxOperatingTemp'}{'7.5.0.0'} || $data{'misc'}{'jnxOperatingTemp'}{'7.6.0.0'} || $data{'misc'}{'ciscoEnvMonTemperatureStatusValue'}{'1011'} || $data{'misc'}{'ciscoEnvMonTemperatureStatusValue'}{'1008'};
- $json{'switches'}{$sysname}{'time'} = $ref->{'time'};
-}
-
-nms::web::setwhen('15m','10m');
-my $q2;
-if (!defined($switch)) {
- $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) and switches.deleted = \'f\' and not switches.tags \?& array[\'ignoreswitchstate\'];');
-} else {
- $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) and switches.deleted = \'f\' and not switches.tags \?& array[\'ignoreswitchstate\'] and sysname = ' . $nms::web::dbh->quote($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'}}) {
- if (defined($port) and $port ne "" and $port ne $porti) {
- next;
- }
- my %port = %{$data{'ports'}{$porti}};
- my $smallport = $porti;
- if ($porti =~ m/\.0$/) {
- next;
- }
- if ($data{'ports'}{$porti}{'ifAlias'} =~ m/C:/i) {
- $smallport =~ s/[0-9-].*$//;
- } else {
- $json{'then'}{$sysname}{ifs}{$smallport}{'ifAlias'} = $port{'ifAlias'};
- }
- if ($data{'ports'}{$porti}{'ifType'} ne "propVirtual" and
- $data{'ports'}{$porti}{'ifAlias'} =~ m/G:/i) {
- if ($port{'ifAdminStatus'} eq "up") {
- $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;
- }
- }
- if ($data{'ports'}{$porti}{'ifType'} ne "propVirtual" and
- $data{'ports'}{$porti}{'ifAlias'} =~ m/C:/i) {
- if ($port{'ifAdminStatus'} eq "up") {
- $json{'then'}{$sysname}{'clients'}{'ifHCInOctets'} += $port{'ifHCInOctets'};
- $json{'then'}{$sysname}{'clients'}{'ifHCOutOctets'} += $port{'ifHCOutOctets'};
- if ($port{'ifOperStatus'} eq "up") {
- $json{'then'}{$sysname}{'clients'}{'live'} += 1;
- }
- $json{'then'}{$sysname}{'clients'}{'total'} += 1;
- }
- }
-
- $json{'then'}{$sysname}{ifs}{$smallport}{'ifHCInOctets'} += $port{'ifHCInOctets'} || 0;
- $json{'then'}{$sysname}{ifs}{$smallport}{'ifHCOutOctets'} += $port{'ifHCOutOctets'} || 0;
- $json{'then'}{$sysname}{totals}{'ifHCInOctets'} += $port{'ifHCInOctets'} || 0;
- $json{'then'}{$sysname}{totals}{'ifHCOutOctets'} += $port{'ifHCOutOctets'} || 0;
- 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}{vcp}{jnxVirtualChassisPortInOctets} = $data{'vcp'}{'jnxVirtualChassisPortInOctets'};
- $json{'then'}{$sysname}{vcp}{jnxVirtualChassisPortOutOctets} = $data{'vcp'}{'jnxVirtualChassisPortOutOctets'};
- $json{'then'}{$sysname}{'temp'} = $data{'misc'}{'jnxOperatingTemp'}{'7.1.0.0'} || $data{'misc'}{'ciscoEnvMonTemperatureStatusValue'}{'1011'} || $data{'misc'}{'ciscoEnvMonTemperatureStatusValue'}{'1008'};
- $json{'then'}{$sysname}{'time'} = $ref->{'time'};
-}
-$nms::web::cc{'max-age'} = "5";
-$nms::web::cc{'stale-while-revalidate'} = "30";
-finalize_output();
-
diff --git a/web/api/public/switches b/web/api/public/switches
deleted file mode 100755
index 9bb63d8..0000000
--- a/web/api/public/switches
+++ /dev/null
@@ -1,32 +0,0 @@
-#! /usr/bin/perl
-# vim:ts=8:sw=8
-
-use CGI qw(fatalsToBrowser);
-use DBI;
-use lib '/opt/gondul/include';
-use nms;
-use nms::web;
-use strict;
-use warnings;
-use Data::Dumper;
-
-$nms::web::cc{'max-age'} = "5";
-$nms::web::cc{'stale-while-revalidate'} = "30";
-
-my $q2 = $nms::web::dbh->prepare('select switch, sysname, tags, distro_name, placement, last_updated from switches where placement is not null and deleted = false');
-
-$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'}}{'placement'}{'x'} = $x2;
- $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 $data = JSON::XS::decode_json($ref->{'tags'});
- $nms::web::json{'switches'}{$ref->{'sysname'}}{'tags'} = $data;
-}
-
-finalize_output();