diff options
-rwxr-xr-x | clients/ping.pl | 2 | ||||
-rwxr-xr-x | clients/snmpfetchng.pl | 4 | ||||
-rwxr-xr-x | web/nms.gathering.org/api/public/dhcp | 1 | ||||
-rwxr-xr-x | web/nms.gathering.org/api/public/switch-state | 2 | ||||
-rwxr-xr-x | web/nms.gathering.org/api/public/switches | 2 | ||||
-rwxr-xr-x | web/nms.gathering.org/api/read/switches-management | 3 | ||||
-rwxr-xr-x | web/nms.gathering.org/api/write/switch-add | 2 | ||||
-rwxr-xr-x | web/nms.gathering.org/api/write/switch-update | 3 | ||||
-rw-r--r-- | web/nms.gathering.org/index.html | 15 | ||||
-rw-r--r-- | web/nms.gathering.org/js/nms-map-handlers.js | 74 | ||||
-rw-r--r-- | web/nms.gathering.org/js/nms.js | 12 |
11 files changed, 94 insertions, 26 deletions
diff --git a/clients/ping.pl b/clients/ping.pl index 174342a..3f4139e 100755 --- a/clients/ping.pl +++ b/clients/ping.pl @@ -15,7 +15,7 @@ my $dbh = nms::db_connect(); $dbh->{AutoCommit} = 0; $dbh->{RaiseError} = 1; -my $q = $dbh->prepare("SELECT switch,host(ip) as ip,host(secondary_ip) as secondary_ip FROM switches WHERE ip is not null ORDER BY random()"); +my $q = $dbh->prepare("SELECT switch,host(mgmt_v4_addr) as ip,host(mgmt_v6_addr) as secondary_ip FROM switches WHERE mgmt_v4_addr is not null ORDER BY random()"); my $lq = $dbh->prepare("SELECT linknet,addr1,addr2 FROM linknets"); while (1) { diff --git a/clients/snmpfetchng.pl b/clients/snmpfetchng.pl index 36dd675..630347d 100755 --- a/clients/snmpfetchng.pl +++ b/clients/snmpfetchng.pl @@ -23,13 +23,13 @@ $dbh->{RaiseError} = 1; my $qualification = <<"EOF"; (last_updated IS NULL OR now() - last_updated > poll_frequency) AND (locked='f' OR now() - last_updated > '15 minutes'::interval) -AND ip is not null +AND mgmt_v4_addr is not null EOF # Borrowed from snmpfetch.pl our $qswitch = $dbh->prepare(<<"EOF") SELECT - sysname,switch,host(ip) as ip,community, + sysname,switch,host(mgmt_v4_addr) as ip,community, DATE_TRUNC('second', now() - last_updated - poll_frequency) AS overdue FROM switches diff --git a/web/nms.gathering.org/api/public/dhcp b/web/nms.gathering.org/api/public/dhcp index d432af0..91d52af 100755 --- a/web/nms.gathering.org/api/public/dhcp +++ b/web/nms.gathering.org/api/public/dhcp @@ -7,6 +7,7 @@ use strict; use warnings; use Data::Dumper; +nms::web::setwhen('60m'); my $q = $nms::web::dbh->prepare('select distinct on (sysname) extract(epoch from date_trunc(\'second\',time)) as time,sysname from dhcp join switches on dhcp.switch = switches.switch where ' . $nms::web::when . ' order by sysname,time desc;'); $q->execute(); while ( my $ref = $q->fetchrow_hashref() ) { diff --git a/web/nms.gathering.org/api/public/switch-state b/web/nms.gathering.org/api/public/switch-state index 6f7573c..4907449 100755 --- a/web/nms.gathering.org/api/public/switch-state +++ b/web/nms.gathering.org/api/public/switch-state @@ -20,7 +20,7 @@ while ( my $ref = $q->fetchrow_hashref() ) { my %port = %{$data{'ports'}{$porti}}; my $smallport = $porti; $smallport =~ s/[0-9-].*$//; - if ($porti =~ /ge-0\/0\/4[4-7]/) { + if ($porti =~ /ge-0\/0\/4[4-7]$/) { $json{'switches'}{$sysname}{'uplinks'}{'ifHCInOctets'} += $port{'ifHCInOctets'}; $json{'switches'}{$sysname}{'uplinks'}{'ifHCOutOctets'} += $port{'ifHCOutOctets'}; if ($port{'ifOperStatus'} eq "up") { diff --git a/web/nms.gathering.org/api/public/switches b/web/nms.gathering.org/api/public/switches index 7e7f10b..3aa8af8 100755 --- a/web/nms.gathering.org/api/public/switches +++ b/web/nms.gathering.org/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,placement,ip,poll_frequency,community,last_updated from switches where placement is not null'); +my $q2 = $nms::web::dbh->prepare('select switch,sysname,placement,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()) { diff --git a/web/nms.gathering.org/api/read/switches-management b/web/nms.gathering.org/api/read/switches-management index 6b5fdcd..1bb4c4c 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,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 '); +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()) { diff --git a/web/nms.gathering.org/api/write/switch-add b/web/nms.gathering.org/api/write/switch-add index 48f62fc..411a76b 100755 --- a/web/nms.gathering.org/api/write/switch-add +++ b/web/nms.gathering.org/api/write/switch-add @@ -22,7 +22,7 @@ my @dups; my $sth = $nms::web::dbh->prepare("SELECT sysname FROM switches WHERE sysname=?"); -my @fields = ('ip', 'sysname', 'last_updated', 'locked', 'poll_frequency', 'community', 'lldp_chassis_id', 'secondary_ip', 'subnet4', 'subnet6', 'placement', 'distro', 'secondary_ip'); +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'); sub convertplace { diff --git a/web/nms.gathering.org/api/write/switch-update b/web/nms.gathering.org/api/write/switch-update index 6507d2b..14c8773 100755 --- a/web/nms.gathering.org/api/write/switch-update +++ b/web/nms.gathering.org/api/write/switch-update @@ -22,7 +22,8 @@ my @dups; my $sth = $nms::web::dbh->prepare("SELECT sysname FROM switches WHERE sysname=?"); -my @fields = ('ip', 'sysname', 'last_updated', 'locked', 'poll_frequency', 'community', 'lldp_chassis_id', 'secondary_ip', 'subnet4', 'subnet6', 'placement', 'distro', 'secondary_ip'); + +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'); sub convertplace { diff --git a/web/nms.gathering.org/index.html b/web/nms.gathering.org/index.html index 02ae93c..b244d1b 100644 --- a/web/nms.gathering.org/index.html +++ b/web/nms.gathering.org/index.html @@ -59,9 +59,10 @@ <ul class="dropdown-menu" role="menu"> <li><a href="#ping" onclick="setUpdater(handler_ping)">Ping map</a></li> <li><a href="#uplink" onclick="setUpdater(handler_uplinks)">Uplink map</a></li> + <li><a href="#dhcp" onclick="setUpdater(handler_dhcp)">DHCP map</a></li> + <li><a href="#comment" onclick="setUpdater(handler_comment)">Comment spotter</a></li> <li><a href="#temp" onclick="setUpdater(handler_temp)">Temperature map</a></li> <li><a href="#traffic" onclick="setUpdater(handler_traffic)">Traffic map</a></li> - <li><a href="#comment" onclick="setUpdater(handler_comment)">Comment spotter</a></li> <li><a href="#traffictot" onclick="setUpdater(handler_traffic_tot)">Total switch traffic</a></li> <li><a href="#disco" onclick="setUpdater(handler_disco)">DISCO</a></li> <li class="divider"> </li> @@ -145,22 +146,26 @@ </tr> <tr> <td>3</td> - <td>View temperature map</td> + <td>View DHCP map</td> </tr> <tr> <td>4</td> - <td>View uplink traffic map</td> + <td>View comment spotter map</td> </tr> <tr> <td>5</td> - <td>View comment spotter map</td> + <td>View temperature map</td> </tr> <tr> <td>6</td> - <td>View total switch traffic map</td> + <td>View uplink traffic map</td> </tr> <tr> <td>7</td> + <td>View total switch traffic map</td> + </tr> + <tr> + <td>9</td> <td>View Disco map</td> </tr> <tr> diff --git a/web/nms.gathering.org/js/nms-map-handlers.js b/web/nms.gathering.org/js/nms-map-handlers.js index 9584841..0bec084 100644 --- a/web/nms.gathering.org/js/nms-map-handlers.js +++ b/web/nms.gathering.org/js/nms-map-handlers.js @@ -49,6 +49,12 @@ var handler_traffic_tot = { name:"Switch traffic map" }; +var handler_dhcp = { + init:dhcpInit, + tag:"dhcp", + name:"DHCP map" +}; + var handler_disco = { init:discoInit, tag:"disco", @@ -68,7 +74,8 @@ var handlers = [ handler_traffic, handler_disco, handler_comment, - handler_traffic_tot + handler_traffic_tot, + handler_dhcp ]; /* @@ -95,12 +102,12 @@ function uplinkUpdater() if (uplinks == 0) { nmsMap.setSwitchColor(sw,"white"); - } else if (nuplinks == uplinks) { - nmsMap.setSwitchColor(sw,green); - } else if (nuplinks - uplinks == 1) { - nmsMap.setSwitchColor(sw, orange); - } else if (nuplinks - uplinks == 2) { + } else if (uplinks == 1) { nmsMap. setSwitchColor(sw, red); + } else if (uplinks == 2) { + nmsMap.setSwitchColor(sw, orange); + } else if (uplinks == 3) { + nmsMap.setSwitchColor(sw,green); } else if (uplinks > 3) { nmsMap.setSwitchColor(sw, blue); } @@ -115,9 +122,9 @@ function uplinkInit() nmsData.addHandler("switches","mapHandler",uplinkUpdater); nmsData.addHandler("switchstate","mapHandler",uplinkUpdater); setLegend(1,"white","0 uplinks"); - setLegend(2,red,"2 missing"); - setLegend(3,orange,"1 missing"); - setLegend(4,green,"0 missing"); + setLegend(2,red,"1 uplink"); + setLegend(3,orange,"2 uplinks"); + setLegend(4,green,"3 uplinks"); setLegend(5,blue,"4 uplinks"); } @@ -339,6 +346,55 @@ function commentInit() setLegend(5,green ,"Old/inactive only"); } +function getDhcpColor(stop) +{ + stop = parseInt(stop); + stop = stop * 0.85; + if (stop < 0) + stop = 1000; + if (stop > 1000) + stop = 1000; + return getColorStop(stop); +} + +function dhcpUpdater() +{ + var realnow = Date.now(); + var now = Math.floor(realnow / 1000); + if (nmsData.dhcp == undefined || nmsData.dhcp.dhcp == undefined) { + return + } + if (nmsData.switches == undefined || nmsData.switches.switches == undefined) { + return; + } + try { + for (var sw in nmsData.switches.switches) { + var c = "white"; + if (nmsData.dhcp.dhcp[sw] == undefined) { + nmsMap.setSwitchColor(sw,c); + continue; + } + var s = nmsData.dhcp.dhcp[sw]; + var then = parseInt(s); + c = getDhcpColor(now - then); + nmsMap.setSwitchColor(sw, c); + } + } catch(e) { + console.log(e); + } +} + +function dhcpInit() +{ + drawGradient([green,lightgreen,orange,red]); + nmsData.addHandler("dhcp","mapHandler",dhcpUpdater); + setLegend(1,"white","Undefined"); + setLegend(2,getDhcpColor(1),"1 Second old"); + setLegend(3,getDhcpColor(300),"300 Seconds old"); + setLegend(4,getDhcpColor(900),"900 Seconds old"); + setLegend(5,getDhcpColor(1200),"1200 Seconds old"); +} + /* * Testing-function to randomize colors of linknets and switches */ diff --git a/web/nms.gathering.org/js/nms.js b/web/nms.gathering.org/js/nms.js index 12823eb..49cacde 100644 --- a/web/nms.gathering.org/js/nms.js +++ b/web/nms.gathering.org/js/nms.js @@ -463,6 +463,7 @@ function initNMS() { nmsData.registerSource("switches","/api/public/switches"); nmsData.registerSource("switchstate","/api/public/switch-state"); nmsData.registerSource("dhcpsummary","/api/public/dhcp-summary"); + nmsData.registerSource("dhcp","/api/public/dhcp"); // This is a magic dummy-source, it's purpose is to give a unified // way to get ticks every second. It is mainly meant to allow map @@ -524,18 +525,21 @@ function setMapModeFromN(e,key) setUpdater(handler_uplinks); break; case '3': - setUpdater(handler_temp); + setUpdater(handler_dhcp); break; case '4': - setUpdater(handler_traffic); + setUpdater(handler_comment); break; case '5': - setUpdater(handler_comment); + setUpdater(handler_temp); break; case '6': - setUpdater(handler_traffic_tot); + setUpdater(handler_traffic); break; case '7': + setUpdater(handler_traffic_tot); + break; + case '9': setUpdater(handler_disco); break; } |