diff options
author | Kristian Lyngstol <kly@kly.no> | 2016-07-01 16:38:36 +0200 |
---|---|---|
committer | Kristian Lyngstol <kly@kly.no> | 2016-07-01 16:38:36 +0200 |
commit | 18be7f053b6a7a8cd19a7340466b68f579eb33cd (patch) | |
tree | 5b340a37751ea9c9da799ba124cd0a9a4f4e8344 | |
parent | f3e530f42e350f17f42cf3f8f0f310f433effef9 (diff) |
Implement tags and various other minor tweaks
-rwxr-xr-x | include/config.pm | 2 | ||||
-rwxr-xr-x | web/api/public/dhcp | 5 | ||||
-rwxr-xr-x | web/api/public/switch-state | 10 | ||||
-rwxr-xr-x | web/api/public/switches | 4 | ||||
-rwxr-xr-x | web/api/write/switch-update | 7 | ||||
-rw-r--r-- | web/js/nms-info-box.js | 12 | ||||
-rw-r--r-- | web/js/nms-map-handlers.js | 68 | ||||
-rw-r--r-- | web/js/nms-search.js | 2 |
8 files changed, 82 insertions, 28 deletions
diff --git a/include/config.pm b/include/config.pm index 99cc6ba..8d4ae19 100755 --- a/include/config.pm +++ b/include/config.pm @@ -36,6 +36,8 @@ our @snmp_objects = [ ['ifOutQLen'], ['sysUpTime'], ['ciscoEnvMonTemperatureStatusValue'], + ['ipIfStatsHCInOctets'], + ['ipIfStatsHCOutOctets'], ['entPhysicalSerialNum'], ['entPhysicalName'], ['entPhysicalHardwareRev'], diff --git a/web/api/public/dhcp b/web/api/public/dhcp index ea42b8f..88f1eb5 100755 --- a/web/api/public/dhcp +++ b/web/api/public/dhcp @@ -14,6 +14,11 @@ while ( my $ref = $q->fetchrow_hashref() ) { my $sysname = $ref->{'sysname'}; $json{'dhcp'}{$ref->{'sysname'}} = $ref->{'time'}; } +my $q2 = $nms::web::dbh->prepare("select sysname,count(distinct mac) as clients,count(distinct ip) as addresses,count(mac) as acks from dhcp natural join switches where $nms::web::when group by switches.sysname;"); +$q2->execute(); +while (my $ref = $q2->fetchrow_hashref()) { + $nms::web::json{'switches'}{$ref->{sysname}} = $ref; +} $nms::web::cc{'max-age'} = "10"; $nms::web::cc{'stale-while-revalidate'} = "30"; diff --git a/web/api/public/switch-state b/web/api/public/switch-state index 2e82836..47de6d5 100755 --- a/web/api/public/switch-state +++ b/web/api/public/switch-state @@ -22,13 +22,13 @@ while ( my $ref = $q->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{'switches'}{$sysname}{ifs}{$smallport}{'ifAlias'} = $port{'ifAlias'}; } - if ($porti =~ /Gi1\/0\/4[78]$/ || - $data{'ports'}{$porti}{'ifAlias'} =~ m/uplink/) { + 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") { @@ -71,8 +71,8 @@ while ( my $ref = $q2->fetchrow_hashref() ) { } else { $json{'then'}{$sysname}{ifs}{$smallport}{'ifAlias'} = $port{'ifAlias'}; } - if ($porti =~ /Gi1\/0\/4[78]$/ || - $data{'ports'}{$porti}{'ifAlias'} =~ m/uplink/) { + 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") { diff --git a/web/api/public/switches b/web/api/public/switches index e6a37f8..ce95e5f 100755 --- a/web/api/public/switches +++ b/web/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_v6_gw,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,tags,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()) { @@ -24,6 +24,8 @@ while (my $ref = $q2->fetchrow_hashref()) { $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; } 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'); diff --git a/web/api/write/switch-update b/web/api/write/switch-update index 15b85ae..797a14b 100755 --- a/web/api/write/switch-update +++ b/web/api/write/switch-update @@ -23,7 +23,7 @@ my @dups; my $sth = $nms::web::dbh->prepare("SELECT sysname FROM switches WHERE sysname=?"); -my @fields = ( 'community', 'current_mac', 'distro_name', 'distro_phy_port', 'lldp_chassis_id', 'mgmt_v4_addr', 'mgmt_v4_gw', 'mgmt_v4_netsize', 'mgmt_v6_addr', 'mgmt_v6_gw', 'mgmt_v6_netsize', 'mgmt_vlan', 'placement', 'poll_frequency', 'subnet4', 'subnet6', 'switchtype', 'sysname', 'traffic_vlan'); +my @fields = ( 'community', 'tags','current_mac', 'distro_name', 'distro_phy_port', 'lldp_chassis_id', 'mgmt_v4_addr', 'mgmt_v4_gw', 'mgmt_v4_netsize', 'mgmt_v6_addr', 'mgmt_v6_gw', 'mgmt_v6_netsize', 'mgmt_vlan', 'placement', 'poll_frequency', 'subnet4', 'subnet6', 'switchtype', 'sysname', 'traffic_vlan'); sub convertplace { @@ -82,7 +82,7 @@ foreach my $tmp2 (@tmp) { } keys %switch; - $nms::web::dbh->do("INSERT INTO SWITCHES (ip, sysname, last_updated, locked, poll_frequency, community, lldp_chassis_id, secondary_ip, placement,subnet4,subnet6,distro) VALUES ($template{'ip'}, $template{'sysname'}, $template{'last_updated'}, $template{'locked'}, $template{'poll_frequency'}, $template{'community'}, $template{'lldp_chassis_id'}, $template{'secondary_ip'}, $template{'placement'},$template{'subnet4'},$template{'subnet6'},$template{'distro'});"); + $nms::web::dbh->do("INSERT INTO SWITCHES (ip, sysname, last_updated, locked, poll_frequency, tags, community, lldp_chassis_id, secondary_ip, placement,subnet4,subnet6,distro) VALUES ($template{'ip'}, $template{'sysname'}, $template{'last_updated'}, $template{'locked'}, $template{'poll_frequency'}, $template{'tags'}, $template{'community'}, $template{'lldp_chassis_id'}, $template{'secondary_ip'}, $template{'placement'},$template{'subnet4'},$template{'subnet6'},$template{'distro'});"); push @added, $switch{'sysname'}; } else { if (defined($switch{'placement'})) { @@ -100,6 +100,9 @@ foreach my $tmp2 (@tmp) { $switch{'placement'} = "(($x1,$y1),($x2,$y2))"; push @dups, "not really, but: " . $switch{'placement'}; } + if (defined($switch{'tags'})) { + $switch{'tags'} =~ s/'/"/g; + } if (not defined($switch{'ip'}) and defined($switch{'mgtmt4'})) { $switch{'ip'} = $switch{'mgtmt4'}; } diff --git a/web/js/nms-info-box.js b/web/js/nms-info-box.js index ca5b6c7..535069f 100644 --- a/web/js/nms-info-box.js +++ b/web/js/nms-info-box.js @@ -833,12 +833,18 @@ var switchEditPanel = function () { nmsInfoBox._editValues = {}; var place; + var tags; for (var v in swi) { if (v == "placement") { place = JSON.stringify(swi[v]); template[v] = place; continue; } + if (v == "tags") { + tags = JSON.stringify(swi[v]); + template[v] = tags; + continue; + } template[v] = nmsInfoBox._nullBlank(swi[v]); } for (var v in swm) { @@ -895,6 +901,12 @@ var switchEditPanel = function () { pval.value = place; } } + if (tags) { + var ptags = document.getElementById("edit-" + this.sw + "-tags"); + if (ptags) { + ptags.value = tags; + } + } }; this.save = function () { diff --git a/web/js/nms-map-handlers.js b/web/js/nms-map-handlers.js index b88b858..0abad4c 100644 --- a/web/js/nms-map-handlers.js +++ b/web/js/nms-map-handlers.js @@ -135,21 +135,23 @@ function uplinkInfo(sw) ret.score =0; if (testTree(nmsData,['switchstate','switches',sw,'uplinks','live'])) { var u = parseInt(nmsData.switchstate.switches[sw].uplinks.live); + var t = parseInt(nmsData.switchstate.switches[sw].uplinks.total); ret.data[0].value = u; - ret.data[0].description = "Uplinks"; + ret.data[0].description = "Active uplinks"; + ret.data[1] = {}; + ret.data[1].value = t; + ret.data[1].description = "Configured uplinks"; if (nmsData.switches.switches[sw].subnet4 == undefined || nmsData.switches.switches[sw].subnet4 == null) { - if (u == 0) { - ret.score = 700 - ret.why = "0 uplinks with clientnet?"; + if (u == t) { + ret.score = 0 + ret.why = "All uplinks up"; } else if (u == 1) { - ret.score = 600; - ret.why = "Only 1 uplink"; - } else if (u == 2) { - ret.score = 0; + ret.score = 800; + ret.why = "Only 1 of " + t + " uplinks alive"; } else { - ret.score = 500; - ret.why = u + " uplinks"; + ret.score = 650; + ret.why = u + " of " + t + " uplinks alive"; } } } @@ -396,8 +398,8 @@ function pingInfo(sw) if (v4 == undefined && v6 == undefined) { ret.score = 1000; ret.why = "No IPv4 or IPv6 ping reply"; - } else if(v6 == undefined) { - ret.score = 250; + } else if(v6 == undefined && !tagged(sw,'ignorev6')) { + ret.score = 450; ret.why = "No IPv6 ping reply"; } else if (v4 == undefined) { ret.score = 800; @@ -406,6 +408,9 @@ function pingInfo(sw) v4 = parseFloat(v4) ; v6 = parseFloat(v6) ; + if (tagged(sw,'ignorev6')) { + v6 = 0; + } if (v4 > ret.score || v6 > ret.score) { ret.why = "Latency"; ret.score = parseInt(v4 > v6 ? v4 : v6); @@ -491,6 +496,20 @@ function dhcpInfo(sw) { ret.why = "No management data for DHCP"; } } + if (testTree(nmsData,['dhcp','switches',sw,'clients'])) { + ret.data[1] = {}; + ret.data[1].value = nmsData.dhcp.switches[sw].clients; + ret.data[1].description = "Active clients"; + ret.data[2] = {}; + ret.data[2].value = nmsData.dhcp.switches[sw].addresses; + ret.data[2].description = "Active IPs"; + } + if (testTree(nmsData,['switches','switches',sw, 'tags'])) { + if (nmsData.switches.switches[sw].tags.includes('ignoredhcp')) { + ret.score = 0; + ret.why += "(Ignored)"; + } + } return ret; } @@ -635,6 +654,15 @@ function cpuUpdater() { } } +function tagged(sw, tag) { + if (testTree(nmsData,['switches','switches',sw, 'tags'])) { + if (nmsData.switches.switches[sw].tags.includes(tag)) { + return true; + } + } + return false; +} + function mgmtInfo(sw) { var ret = new handlerInfo("mgmt","Management info"); ret.score = 0; @@ -643,16 +671,16 @@ function mgmtInfo(sw) { var mg = nmsData.smanagement.switches[sw]; ret.data = [{ - value: mg.mgmt_v4_addr || "", + value: mg.mgmt_v4_addr || "N/A", description: "Management IP (v4)" }, { - value: mg.mgmt_v6_addr || "", + value: mg.mgmt_v6_addr || "N/A", description: "Management IP (v6)" }, { - value: mg.subnet4 || "", + value: mg.subnet4 || "N/A", description: "Subnet (v4)" }, { - value: mg.subnet6 || "", + value: mg.subnet6 || "N/A", description: "Subnet (v6)" }]; if ((mg.mgmt_v4_addr == undefined || mg.mgmt_v4_addr == "") && (mg.mgmt_v6_addr == undefined || mg.mgmt_v6_addr == "")) { @@ -660,10 +688,13 @@ function mgmtInfo(sw) { ret.score = 1000; } else if (mg.mgmt_v4_addr == undefined || mg.mgmt_v4_addr == "") { ret.why = "No IPv4 management IP"; - ret.score = 140; + ret.score = 550; } else if (mg.mgmt_v6_addr == undefined || mg.mgmt_v6_addr == "") { ret.why = "No IPv6 management IP"; - ret.score = 139; + ret.score = 550; + if (tagged(sw,'ignorev6')) { + ret.score = 0; + } } } else { ret.score = 1000; @@ -673,7 +704,6 @@ function mgmtInfo(sw) { ret.data[0].description = "Management info"; }; return ret; - } function cpuInit() { diff --git a/web/js/nms-search.js b/web/js/nms-search.js index a292814..1167b51 100644 --- a/web/js/nms-search.js +++ b/web/js/nms-search.js @@ -91,7 +91,7 @@ nmsSearch.searchTest = function(id, sw) { if (nmsData.snmp.snmp[sw].misc.entPhysicalSerialNum[x] == "") { continue; } - if (re.test(nmsData.snmp.snmp[sw].misc.entPhysicalSerialNum[x])) { + if (re.test("serial:" + nmsData.snmp.snmp[sw].misc.entPhysicalSerialNum[x])) { return true; } } |