aboutsummaryrefslogtreecommitdiffstats
path: root/web/api
diff options
context:
space:
mode:
authorOle Mathias Heggem <ole@sdok.no>2017-04-19 23:16:07 +0200
committerOle Mathias Heggem <ole@sdok.no>2017-04-19 23:16:07 +0200
commit7b97188b728c85c498acc8acdce1750c472f2c85 (patch)
tree12c1436ab7eb97e9434e774671e8ffea134d61db /web/api
parentf70f65f7466a480a45a8260b35887cb7ed36b466 (diff)
parent7d404abf07d865d253ac2cfc353741e8d4af4867 (diff)
Merge remote-tracking branch 'refs/remotes/tech-server/master'
Diffstat (limited to 'web/api')
-rwxr-xr-xweb/api/public/distro-tree (renamed from web/api/read/distro-tree)0
-rwxr-xr-xweb/api/public/switch-state59
-rwxr-xr-xweb/api/read/distro-management31
-rwxr-xr-xweb/api/read/oplog4
-rwxr-xr-xweb/api/read/switches-management4
5 files changed, 83 insertions, 15 deletions
diff --git a/web/api/read/distro-tree b/web/api/public/distro-tree
index 5d93e1b..5d93e1b 100755
--- a/web/api/read/distro-tree
+++ b/web/api/public/distro-tree
diff --git a/web/api/public/switch-state b/web/api/public/switch-state
index 8e98205..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;
@@ -40,13 +42,26 @@ 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) {
- $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;
+ $data{'ports'}{$porti}{'ifAlias'} =~ m/LAG member/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/Clients/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}{'uplinks'}{'total'} += 1;
}
$json{'switches'}{$sysname}{ifs}{$smallport}{'ifHCInOctets'} += $port{'ifHCInOctets'} || 0;
$json{'switches'}{$sysname}{ifs}{$smallport}{'ifHCOutOctets'} += $port{'ifHCOutOctets'} || 0;
@@ -58,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'};
}
@@ -85,19 +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/trunk/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;
+ $data{'ports'}{$porti}{'ifAlias'} =~ m/LAG member/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/Clients/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}{'uplinks'}{'total'} += 1;
}
$json{'then'}{$sysname}{ifs}{$smallport}{'ifHCInOctets'} += $port{'ifHCInOctets'} || 0;
@@ -110,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/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();
diff --git a/web/api/read/oplog b/web/api/read/oplog
index 92511bb..fb187ea 100755
--- a/web/api/read/oplog
+++ b/web/api/read/oplog
@@ -16,6 +16,10 @@ 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/;
+ $meh{'timestamp'} =~ s/\+(\d\d)$/+\1:00/;
+
push @{$nms::web::json{'oplog'}},\%meh;
}
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();