From 134299c3d95a10ed11b184eac61a704c45d17000 Mon Sep 17 00:00:00 2001 From: Lasse Haugen Date: Fri, 31 Mar 2017 22:22:08 +0200 Subject: switches.txt as an api endpoint --- web/api/read/distro-management | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 web/api/read/distro-management (limited to 'web/api') diff --git a/web/api/read/distro-management b/web/api/read/distro-management new file mode 100755 index 0000000..2aa3273 --- /dev/null +++ b/web/api/read/distro-management @@ -0,0 +1,31 @@ +#! /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; + +my $target = $ENV{REQUEST_URI}; +$target =~ s/$ENV{SCRIPT_NAME}//; +$target =~ s/^\///; +my ($switch, $port) = split(/\//,$target,2); +my $q2; + +$nms::web::cc{'max-age'} = "5"; +$nms::web::cc{'stale-while-revalidate'} = "30"; + +$q2 = $nms::web::dbh->prepare('SELECT distro_name,sysname,subnet4,subnet6,traffic_vlan,distro_phy_port FROM switches WHERE placement is not null AND distro_name is not null AND distro_phy_port is not null'); + +$q2->execute(); +while (my $ref = $q2->fetchrow_hashref()) { + my $sysname = $ref->{'sysname'}; + my $distro = $ref->{'distro_name'}; + $nms::web::json{'distros'}{$distro}{$sysname} = $ref; +} + +finalize_output(); -- cgit v1.2.3 From bb862773d69bc5997bd1628a3f0505827e7cfe5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristian=20Lyngst=C3=B8l?= Date: Mon, 10 Apr 2017 14:06:23 +0200 Subject: TG17 stuff ? --- web/api/public/distro-tree | 25 +++++++++++++++++++++++++ web/api/public/switch-state | 22 ++++++++++++++++++++-- web/api/read/distro-tree | 25 ------------------------- web/api/read/switches-management | 4 ++-- 4 files changed, 47 insertions(+), 29 deletions(-) create mode 100755 web/api/public/distro-tree delete mode 100755 web/api/read/distro-tree (limited to 'web/api') diff --git a/web/api/public/distro-tree b/web/api/public/distro-tree new file mode 100755 index 0000000..5d93e1b --- /dev/null +++ b/web/api/public/distro-tree @@ -0,0 +1,25 @@ +#! /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'} = "20"; + +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'); + +$q2->execute(); +while (my $ref = $q2->fetchrow_hashref()) { + my $sysname = $ref->{'sysname'}; + my $phy = $ref->{'distro_phy_port'}; + my $distro = $ref->{'distro_name'}; + $nms::web::json{'distro-tree'}{$distro}{$phy} = $sysname; +} + +finalize_output(); diff --git a/web/api/public/switch-state b/web/api/public/switch-state index 8e98205..36dfeaf 100755 --- a/web/api/public/switch-state +++ b/web/api/public/switch-state @@ -40,7 +40,7 @@ while ( my $ref = $q->fetchrow_hashref() ) { $json{'switches'}{$sysname}{ifs}{$smallport}{'ifAlias'} = $port{'ifAlias'}; } if ($data{'ports'}{$porti}{'ifType'} ne "propVirtual" and - $data{'ports'}{$porti}{'ifAlias'} =~ m/trunk/i) { + $data{'ports'}{$porti}{'ifAlias'} =~ m/LAG member/i) { $json{'switches'}{$sysname}{'uplinks'}{'ifHCInOctets'} += $port{'ifHCInOctets'}; $json{'switches'}{$sysname}{'uplinks'}{'ifHCOutOctets'} += $port{'ifHCOutOctets'}; if ($port{'ifOperStatus'} eq "up") { @@ -48,6 +48,15 @@ while ( my $ref = $q->fetchrow_hashref() ) { } $json{'switches'}{$sysname}{'uplinks'}{'total'} += 1; } + if ($data{'ports'}{$porti}{'ifType'} ne "propVirtual" and + $data{'ports'}{$porti}{'ifAlias'} =~ m/Clients/i) { + $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; $json{'switches'}{$sysname}{totals}{'ifHCInOctets'} += $port{'ifHCInOctets'} || 0; @@ -91,7 +100,7 @@ while ( my $ref = $q2->fetchrow_hashref() ) { $json{'then'}{$sysname}{ifs}{$smallport}{'ifAlias'} = $port{'ifAlias'}; } if ($data{'ports'}{$porti}{'ifType'} ne "propVirtual" and - $data{'ports'}{$porti}{'ifAlias'} =~ m/trunk/i) { + $data{'ports'}{$porti}{'ifAlias'} =~ m/LAG member/i) { $json{'then'}{$sysname}{'uplinks'}{'ifHCInOctets'} += $port{'ifHCInOctets'}; $json{'then'}{$sysname}{'uplinks'}{'ifHCOutOctets'} += $port{'ifHCOutOctets'}; if ($port{'ifOperStatus'} eq "up") { @@ -99,6 +108,15 @@ while ( my $ref = $q2->fetchrow_hashref() ) { } $json{'then'}{$sysname}{'uplinks'}{'total'} += 1; } + if ($data{'ports'}{$porti}{'ifType'} ne "propVirtual" and + $data{'ports'}{$porti}{'ifAlias'} =~ m/Clients/i) { + $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; diff --git a/web/api/read/distro-tree b/web/api/read/distro-tree deleted file mode 100755 index 5d93e1b..0000000 --- a/web/api/read/distro-tree +++ /dev/null @@ -1,25 +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'} = "20"; - -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'); - -$q2->execute(); -while (my $ref = $q2->fetchrow_hashref()) { - my $sysname = $ref->{'sysname'}; - my $phy = $ref->{'distro_phy_port'}; - my $distro = $ref->{'distro_name'}; - $nms::web::json{'distro-tree'}{$distro}{$phy} = $sysname; -} - -finalize_output(); diff --git a/web/api/read/switches-management b/web/api/read/switches-management index 425262e..9d8bc53 100755 --- a/web/api/read/switches-management +++ b/web/api/read/switches-management @@ -20,9 +20,9 @@ $nms::web::cc{'max-age'} = "5"; $nms::web::cc{'stale-while-revalidate'} = "30"; if (!defined($switch)) { - $q2 = $nms::web::dbh->prepare('select sysname,mgmt_v4_addr,subnet4,subnet6,mgmt_v6_addr,mgmt_v4_gw,mgmt_v6_gw,mgmt_vlan,traffic_vlan,poll_frequency,last_updated,distro_name,distro_phy_port,community from switches where placement is not null'); + $q2 = $nms::web::dbh->prepare('select sysname,host(mgmt_v4_addr) as mgmt_v4_addr,subnet4,subnet6,host(mgmt_v6_addr) as mgmt_v6_addr,host(mgmt_v4_gw) as mgmt_v4_gw,host(mgmt_v6_gw) as mgmt_v6_gw,mgmt_vlan,traffic_vlan,poll_frequency,last_updated,distro_name,distro_phy_port,community from switches where placement is not null'); } else { - $q2 = $nms::web::dbh->prepare('select sysname,mgmt_v4_addr,subnet4,subnet6,mgmt_v6_addr,mgmt_v4_gw,mgmt_v6_gw,mgmt_vlan,traffic_vlan,poll_frequency,last_updated,distro_name,distro_phy_port,community from switches where placement is not null and sysname = ' . $nms::web::dbh->quote($switch) . ';'); + $q2 = $nms::web::dbh->prepare('select sysname,host(mgmt_v4_addr) as mgmt_v4_addr,subnet4,subnet6,host(mgmt_v6_addr) as mgmt_v6_addr,host(mgmt_v4_gw) as mgmt_v4_gw,host(mgmt_v6_gw) as mgmt_v6_gw,mgmt_vlan,traffic_vlan,poll_frequency,last_updated,distro_name,distro_phy_port,community from switches where placement is not null and sysname = ' . $nms::web::dbh->quote($switch) . ';'); } $q2->execute(); -- cgit v1.2.3 From 0b99608227d53c9eebb01fd7f98d1618cbb7a2cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristian=20Lyngst=C3=B8l?= Date: Sun, 16 Apr 2017 01:47:57 +0200 Subject: TG17 monster commit --- web/api/public/switch-state | 57 ++++++++++++++++++++++++++++----------------- web/api/read/oplog | 3 +++ 2 files changed, 39 insertions(+), 21 deletions(-) (limited to 'web/api') diff --git a/web/api/public/switch-state b/web/api/public/switch-state index 36dfeaf..77350c7 100755 --- a/web/api/public/switch-state +++ b/web/api/public/switch-state @@ -25,6 +25,8 @@ while ( my $ref = $q->fetchrow_hashref() ) { 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; @@ -41,21 +43,25 @@ while ( my $ref = $q->fetchrow_hashref() ) { } if ($data{'ports'}{$porti}{'ifType'} ne "propVirtual" and $data{'ports'}{$porti}{'ifAlias'} =~ m/LAG member/i) { - $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; + 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; } - $json{'switches'}{$sysname}{'uplinks'}{'total'} += 1; } if ($data{'ports'}{$porti}{'ifType'} ne "propVirtual" and $data{'ports'}{$porti}{'ifAlias'} =~ m/Clients/i) { - $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; + 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}{'clients'}{'total'} += 1; } $json{'switches'}{$sysname}{ifs}{$smallport}{'ifHCInOctets'} += $port{'ifHCInOctets'} || 0; $json{'switches'}{$sysname}{ifs}{$smallport}{'ifHCOutOctets'} += $port{'ifHCOutOctets'} || 0; @@ -67,6 +73,9 @@ while ( my $ref = $q->fetchrow_hashref() ) { } $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'}{'ciscoEnvMonTemperatureStatusValue'}{'1011'} || $data{'misc'}{'ciscoEnvMonTemperatureStatusValue'}{'1008'}; $json{'switches'}{$sysname}{'time'} = $ref->{'time'}; } @@ -94,28 +103,32 @@ while ( my $ref = $q2->fetchrow_hashref() ) { if ($porti =~ m/\.0$/) { next; } - if ($data{'ports'}{$porti}{'ifAlias'} =~ m/client/) { + if ($data{'ports'}{$porti}{'ifAlias'} =~ m/client/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/LAG member/i) { - $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; + 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; } - $json{'then'}{$sysname}{'uplinks'}{'total'} += 1; } if ($data{'ports'}{$porti}{'ifType'} ne "propVirtual" and $data{'ports'}{$porti}{'ifAlias'} =~ m/Clients/i) { - $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; + 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}{'clients'}{'total'} += 1; } $json{'then'}{$sysname}{ifs}{$smallport}{'ifHCInOctets'} += $port{'ifHCInOctets'} || 0; @@ -128,6 +141,8 @@ while ( my $ref = $q2->fetchrow_hashref() ) { } $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'}; } diff --git a/web/api/read/oplog b/web/api/read/oplog index 92511bb..15c6177 100755 --- a/web/api/read/oplog +++ b/web/api/read/oplog @@ -16,6 +16,9 @@ while (my $ref = $query->fetchrow_hashref()) { $meh{'id'} = $ref->{'id'}; $meh{'systems'} = $ref->{'systems'}; $meh{'timestamp'} = $ref->{'timestamp'}; + $meh{'timestamp'} =~ s/ /T/; + $meh{'timestamp'} =~ s/\+00$/Z/; + push @{$nms::web::json{'oplog'}},\%meh; } -- cgit v1.2.3 From 53fb0f8f3155748134fb1d908ac3e24a90217de2 Mon Sep 17 00:00:00 2001 From: Kristian Date: Wed, 19 Apr 2017 17:30:11 +0200 Subject: api/oplog: Time is !@#!@#!@#!@# (fixes non-utc times) --- web/api/read/oplog | 1 + 1 file changed, 1 insertion(+) (limited to 'web/api') diff --git a/web/api/read/oplog b/web/api/read/oplog index 15c6177..fb187ea 100755 --- a/web/api/read/oplog +++ b/web/api/read/oplog @@ -18,6 +18,7 @@ while (my $ref = $query->fetchrow_hashref()) { $meh{'timestamp'} = $ref->{'timestamp'}; $meh{'timestamp'} =~ s/ /T/; $meh{'timestamp'} =~ s/\+00$/Z/; + $meh{'timestamp'} =~ s/\+(\d\d)$/+\1:00/; push @{$nms::web::json{'oplog'}},\%meh; } -- cgit v1.2.3