From 873418b97df1eb6686ab9379f70c525dbf46aeee Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Sat, 19 Mar 2016 20:50:02 +0000 Subject: NMS: Intelligent, undocumented active-ports-search --- web/nms.gathering.org/js/nms-info-box.js | 48 +++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 4 deletions(-) (limited to 'web') diff --git a/web/nms.gathering.org/js/nms-info-box.js b/web/nms.gathering.org/js/nms-info-box.js index 6b13498..0175b6f 100644 --- a/web/nms.gathering.org/js/nms-info-box.js +++ b/web/nms.gathering.org/js/nms-info-box.js @@ -140,6 +140,38 @@ nmsInfoBox._makeCommentTable = function(content) { return table; } +nmsInfoBox._searchSmart = function(id, sw) { + if (nmsData.smanagement.switches[sw].distro == id) { + console.log("ieh"); + return true; + } + if (id.match("[a-z]+.active")) { + console.log("hei: " + sw); + var family = id.match("[a-z]+"); + var limit = id; + limit = limit.replace(family + ".active>",""); + limit = limit.replace(family + ".active<",""); + limit = limit.replace(family + ".active=",""); + var operator = id.replace(family + ".active","")[0]; + if (limit == parseInt(limit)) { + if (operator == ">" ) { + if (nmsData.switchstate.switches[sw][family].live > limit) { + return true; + } + } else if (operator == "<") { + if (nmsData.switchstate.switches[sw][family].live < limit) { + return true; + } + } else if (operator == "=") { + if (nmsData.switchstate.switches[sw][family].live == limit) { + return true; + } + } + } + } + return false; +} + /* * FIXME: Not sure this belongs here, it's really part of the "Core" ui, * not just the infobox. @@ -153,11 +185,19 @@ nmsInfoBox._search = function() { } if(id) { for(var sw in nmsData.switches.switches) { - if(sw.indexOf(id) > -1) { - hits++; - nmsMap.setSwitchHighlight(sw,true); + if (id[0] == "/") { + if (nmsInfoBox._searchSmart(id.slice(1),sw)) { + nmsMap.setSwitchHighlight(sw,true); + } else { + nmsMap.setSwitchHighlight(sw,false); + } } else { - nmsMap.setSwitchHighlight(sw,false); + if(sw.indexOf(id) > -1) { + hits++; + nmsMap.setSwitchHighlight(sw,true); + } else { + nmsMap.setSwitchHighlight(sw,false); + } } } } else { -- cgit v1.2.3 From cc2534ef349680951afb0d0dfe7797843d10cccf Mon Sep 17 00:00:00 2001 From: Nicolai Tellefsen Date: Sat, 19 Mar 2016 19:54:14 +0100 Subject: NMS: Add basic add-switch interface --- web/nms.gathering.org/api/private/switch-add | 32 +------ web/nms.gathering.org/api/private/switch-update | 122 ++++++++++++++++++++++++ web/nms.gathering.org/index.html | 3 +- web/nms.gathering.org/js/nms-info-box.js | 45 ++++++++- 4 files changed, 169 insertions(+), 33 deletions(-) create mode 100755 web/nms.gathering.org/api/private/switch-update (limited to 'web') diff --git a/web/nms.gathering.org/api/private/switch-add b/web/nms.gathering.org/api/private/switch-add index 3d7b119..70d6212 100755 --- a/web/nms.gathering.org/api/private/switch-add +++ b/web/nms.gathering.org/api/private/switch-add @@ -83,40 +83,10 @@ foreach my $tmp2 (@tmp) { $nms::web::dbh->do("INSERT INTO SWITCHES (ip, sysname, switchtype, last_updated, locked, poll_frequency, community, lldp_chassis_id, secondary_ip, placement) VALUES ($template{'ip'}, $template{'sysname'}, $template{'switchtype'}, $template{'last_updated'}, $template{'locked'}, $template{'poll_frequency'}, $template{'community'}, $template{'lldp_chassis_id'}, $template{'secondary_ip'}, $template{'placement'});"); push @added, $switch{'sysname'}; - } else { - if (defined($switch{'placement'})) { - my %placement; - if ($switch{'placement'} eq "reset") { - %placement = guess_placement($switch{'sysname'}); - } else { - %placement = %{convertplace($switch{'placement'})}; - } - my ($x1,$x2,$y1,$y2); - $x1 = $placement{'x1'}; - $y1 = $placement{'y1'}; - $x2 = $placement{'xx'}; - $y2 = $placement{'yy'}; - $switch{'placement'} = "(($x1,$y1),($x2,$y2))"; - push @dups, "not really, but: " . $switch{'placement'}; - } - if (not defined($switch{'ip'}) and defined($switch{'mgtmt4'})) { - $switch{'ip'} = $switch{'mgtmt4'}; - } - if (not defined($switch{'secondary_ip'}) and defined($switch{'mgtmt6'})) { - $switch{'secondary_ip'} = $switch{'mgtmt6'}; - } - my @set; - map { - if (defined($template{$_})) { - push @set, "$_=" . $dbh->quote($switch{$_}); - } - } keys %switch; - $nms::web::dbh->do("UPDATE SWITCHES SET " . join(", ", @set) . "WHERE sysname=" . $dbh->quote($switch{'sysname'}) . ";"); - push @dups, $switch{'sysname'}; } } + $json{'switches_addded'} = \@added; -$json{'switches_updated'} = \@dups; print "X-ban: /api/.*switches.*\n"; finalize_output(); diff --git a/web/nms.gathering.org/api/private/switch-update b/web/nms.gathering.org/api/private/switch-update new file mode 100755 index 0000000..3d7b119 --- /dev/null +++ b/web/nms.gathering.org/api/private/switch-update @@ -0,0 +1,122 @@ +#! /usr/bin/perl +# vim:ts=8:sw=8 + +#use CGI qw(fatalsToBrowser); +use DBI; +use lib '../../../../include'; +use nms; +use nms::web qw(%get_params %json finalize_output get_input $dbh); +use nms::util qw(guess_placement); +use strict; +use warnings; +use JSON; +use Data::Dumper; + +$nms::web::cc{'max-age'} = "0"; + +my $in = get_input(); +my @tmp = @{JSON::XS::decode_json($in)}; + +my @added; +my @dups; + +my $sth = $nms::web::dbh->prepare("SELECT sysname FROM switches WHERE sysname=?"); + +my @fields = ('ip', 'sysname', 'switchtype', 'last_updated', 'locked', 'poll_frequency', 'community', 'lldp_chassis_id', 'secondary_ip', 'subnet4', 'subnet6', 'placement', 'distro', 'secondary_ip'); + +sub convertplace +{ + my %in = %{$_[0]}; + my %out = (); + + if (not defined $in{'x1'} and defined($in{'x'})) { + $out{'x1'} = int($in{'x'}); + $out{'y1'} = int($in{'y'}); + $out{'xx'} = int($in{'x'} + $in{'width'}); + $out{'yy'} = int($in{'y'} + $in{'height'}); + } else { + return \%in; + } + return \%out; +} + +foreach my $tmp2 (@tmp) { + my %switch = %{$tmp2}; + my $affected = 0; + my %template = (); + map { $template{$_} = 'DEFAULT' } @fields; + if (not defined($switch{'sysname'})) { + next; + } + + $sth->execute( $switch{'sysname'}); + while ( my @row = $sth->fetchrow_array ) { + $affected += 1; + } + + if ($affected == 0) { + my %placement; + if (not defined ($switch{'placement'})) { + %placement = guess_placement($switch{'sysname'}); + } else { + %placement = %{convertplace($switch{'placement'})}; + } + if (not defined($switch{'ip'}) and defined($switch{'mgtmt4'})) { + $switch{'ip'} = $switch{'mgtmt4'}; + } + if (not defined($switch{'secondary_ip'}) and defined($switch{'mgtmt6'})) { + $switch{'secondary_ip'} = $switch{'mgtmt6'}; + } + my ($x1,$x2,$y1,$y2); + $x1 = $placement{'x1'}; + $y1 = $placement{'y1'}; + $x2 = $placement{'xx'}; + $y2 = $placement{'yy'}; + $switch{'placement'} = "(($x1,$y1),($x2,$y2))"; + + map { + if (defined ($template{$_})) { + $template{$_} = $dbh->quote($switch{$_}); + } + } keys %switch; + + + $nms::web::dbh->do("INSERT INTO SWITCHES (ip, sysname, switchtype, last_updated, locked, poll_frequency, community, lldp_chassis_id, secondary_ip, placement) VALUES ($template{'ip'}, $template{'sysname'}, $template{'switchtype'}, $template{'last_updated'}, $template{'locked'}, $template{'poll_frequency'}, $template{'community'}, $template{'lldp_chassis_id'}, $template{'secondary_ip'}, $template{'placement'});"); + push @added, $switch{'sysname'}; + } else { + if (defined($switch{'placement'})) { + my %placement; + if ($switch{'placement'} eq "reset") { + %placement = guess_placement($switch{'sysname'}); + } else { + %placement = %{convertplace($switch{'placement'})}; + } + my ($x1,$x2,$y1,$y2); + $x1 = $placement{'x1'}; + $y1 = $placement{'y1'}; + $x2 = $placement{'xx'}; + $y2 = $placement{'yy'}; + $switch{'placement'} = "(($x1,$y1),($x2,$y2))"; + push @dups, "not really, but: " . $switch{'placement'}; + } + if (not defined($switch{'ip'}) and defined($switch{'mgtmt4'})) { + $switch{'ip'} = $switch{'mgtmt4'}; + } + if (not defined($switch{'secondary_ip'}) and defined($switch{'mgtmt6'})) { + $switch{'secondary_ip'} = $switch{'mgtmt6'}; + } + my @set; + map { + if (defined($template{$_})) { + push @set, "$_=" . $dbh->quote($switch{$_}); + } + } keys %switch; + $nms::web::dbh->do("UPDATE SWITCHES SET " . join(", ", @set) . "WHERE sysname=" . $dbh->quote($switch{'sysname'}) . ";"); + push @dups, $switch{'sysname'}; + } +} +$json{'switches_addded'} = \@added; +$json{'switches_updated'} = \@dups; + +print "X-ban: /api/.*switches.*\n"; +finalize_output(); diff --git a/web/nms.gathering.org/index.html b/web/nms.gathering.org/index.html index e70c9e3..a20ae67 100644 --- a/web/nms.gathering.org/index.html +++ b/web/nms.gathering.org/index.html @@ -74,6 +74,7 @@
  • Enable switch moving
  • Disable switch moving
  • +
  • Add switch
  • Keyboard Shortcuts
  • @@ -104,7 +105,7 @@ -
    +
    diff --git a/web/nms.gathering.org/js/nms-info-box.js b/web/nms.gathering.org/js/nms-info-box.js index 0175b6f..7e27ce7 100644 --- a/web/nms.gathering.org/js/nms-info-box.js +++ b/web/nms.gathering.org/js/nms-info-box.js @@ -65,6 +65,7 @@ nmsInfoBox._hide = function() nmsInfoBox._showing = ""; nmsInfoBox._editHide(); nmsInfoBox._snmpHide(); + nmsInfoBox._createHide(); } /* @@ -388,7 +389,7 @@ nmsInfoBox._editSave = function(sw, e) { var myData = nmsInfoBox._editStringify(sw); $.ajax({ type: "POST", - url: "/api/private/switch-add", + url: "/api/private/switch-update", dataType: "text", data:myData, success: function (data, textStatus, jqXHR) { @@ -398,3 +399,45 @@ nmsInfoBox._editSave = function(sw, e) { }); nmsInfoBox._editHide(); } + + +/* + * Display infobox for new switch + * + * TODO: Integrate and rebuild info-box display logic + */ +nmsInfoBox._createShow = function() +{ + var container = document.createElement("div"); + container.className = "col-md-5"; + container.id = "nmsInfoBox-create"; + container.style.zIndex = "999"; + + var swtop = document.getElementById("wrap"); + nmsInfoBox._hide(); + + container.innerHTML = '
    Add new switch
    '; + + swtop.appendChild(container); +} +nmsInfoBox._createSave = function(sw) { + var feedback = document.getElementById("create-switch-feedback"); + var myData = JSON.stringify([{'sysname':sw}]); + $.ajax({ + type: "POST", + url: "/api/private/switch-add", + dataType: "text", + data:myData, + success: function (data, textStatus, jqXHR) { + var result = JSON.parse(data); + if(result.switches_addded.length > 0) { + nmsInfoBox._createHide(); + } + } + }); +} +nmsInfoBox._createHide = function() { + var container = document.getElementById("nmsInfoBox-create"); + if (container != undefined) + container.parentNode.removeChild(container); +} -- cgit v1.2.3 From c7183bab82f51de2bd6294e227ecd4d419d7066e Mon Sep 17 00:00:00 2001 From: Nicolai Tellefsen Date: Sat, 19 Mar 2016 23:21:10 +0100 Subject: NMS: Fix disappearing BG on resizeEvent --- web/nms.gathering.org/js/nms-map.js | 3 +++ 1 file changed, 3 insertions(+) (limited to 'web') diff --git a/web/nms.gathering.org/js/nms-map.js b/web/nms.gathering.org/js/nms-map.js index 9bba1bf..3749a16 100644 --- a/web/nms.gathering.org/js/nms-map.js +++ b/web/nms.gathering.org/js/nms-map.js @@ -138,6 +138,9 @@ nmsMap._resizeEvent = function() { continue; nmsMap._c[a].c.height = nmsMap._canvas.height; nmsMap._c[a].c.width = nmsMap._canvas.width; + if(a == 'bg') { + nmsMap._drawBG(); + } } if (nmsMap._init != true) { console.log("Drawing shit"); -- cgit v1.2.3 From b2f71d875810476af383c0cfcf8e633a0fdb84f0 Mon Sep 17 00:00:00 2001 From: Nicolai Tellefsen Date: Sun, 20 Mar 2016 10:53:28 +0100 Subject: NMS: Fix nms-map load not triggering --- web/nms.gathering.org/js/nms-map.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'web') diff --git a/web/nms.gathering.org/js/nms-map.js b/web/nms.gathering.org/js/nms-map.js index 3749a16..bbb304f 100644 --- a/web/nms.gathering.org/js/nms-map.js +++ b/web/nms.gathering.org/js/nms-map.js @@ -59,7 +59,7 @@ nmsMap.init = function() { this._init = true; nmsData.addHandler("switches","nmsMap",function(){nmsMap._resizeEvent();}); window.addEventListener('resize',nmsMap._resizeEvent,true); - document.addEventListener('load',nmsMap._loadEvent,true); + window.addEventListener('load',nmsMap._loadEvent,true); } nmsMap.setSwitchColor = function(sw, color) { @@ -143,7 +143,6 @@ nmsMap._resizeEvent = function() { } } if (nmsMap._init != true) { - console.log("Drawing shit"); nmsMap._blurDrawn = false; nmsMap._drawBG(); nmsMap._drawAllSwitches(); -- cgit v1.2.3 From 2971d19f9835b0787813af22fd6bad3a6aca88e7 Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Sun, 20 Mar 2016 13:05:08 +0000 Subject: NMS: Add dhcp-summary --- web/nms.gathering.org/api/public/dhcp-summary | 19 +++++++++++++++++++ web/nms.gathering.org/js/nms.js | 1 + 2 files changed, 20 insertions(+) create mode 100755 web/nms.gathering.org/api/public/dhcp-summary (limited to 'web') diff --git a/web/nms.gathering.org/api/public/dhcp-summary b/web/nms.gathering.org/api/public/dhcp-summary new file mode 100755 index 0000000..31bc8eb --- /dev/null +++ b/web/nms.gathering.org/api/public/dhcp-summary @@ -0,0 +1,19 @@ +#! /usr/bin/perl +use lib '../../../../include'; +use nms::web; + +nms::web::setwhen('2h'); +my $q = $nms::web::dbh->prepare("select count(distinct mac) as clients,count(distinct ip) as addresses,count(mac) as acks from dhcp;"); +$q->execute(); +while (my $ref = $q->fetchrow_hashref()) { + $nms::web::json{'dhcp'}{'total'} = $ref; +} + +my $q2 = $nms::web::dbh->prepare("select count(distinct mac) as clients,count(distinct ip) as addresses,count(mac) as acks from dhcp where $nms::web::when;"); +$q2->execute(); +while (my $ref = $q2->fetchrow_hashref()) { + $nms::web::json{'dhcp'}{'recent'} = $ref; +} +$nms::web::cc{'max-age'} = "10"; +$nms::web::cc{'stale-while-revalidate'} = "15"; +finalize_output(); diff --git a/web/nms.gathering.org/js/nms.js b/web/nms.gathering.org/js/nms.js index 1270a7f..bf13c57 100644 --- a/web/nms.gathering.org/js/nms.js +++ b/web/nms.gathering.org/js/nms.js @@ -465,6 +465,7 @@ function initNMS() { nmsData.registerSource("ping", "/api/public/ping"); nmsData.registerSource("switches","/api/public/switches"); nmsData.registerSource("switchstate","/api/public/switch-state"); + nmsData.registerSource("dhcpsummary","/api/public/dhcp-summary"); // 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 -- cgit v1.2.3 From 7d97e4c3bead329419d594daac11644e14c000e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20Kir=C3=B8?= Date: Sun, 20 Mar 2016 20:32:22 +0100 Subject: readability in switch-state --- web/nms.gathering.org/api/public/switch-state | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'web') diff --git a/web/nms.gathering.org/api/public/switch-state b/web/nms.gathering.org/api/public/switch-state index 38f4c57..62d0078 100755 --- a/web/nms.gathering.org/api/public/switch-state +++ b/web/nms.gathering.org/api/public/switch-state @@ -7,10 +7,11 @@ use strict; use warnings; use Data::Dumper; -my $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);'); +my $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);'); $q->execute(); -while (my $ref = $q->fetchrow_hashref()) { +while ( my $ref = $q->fetchrow_hashref() ) { my $sysname = $ref->{'sysname'}; my %data = %{JSON::XS::decode_json($ref->{'data'})}; @@ -37,6 +38,7 @@ while (my $ref = $q->fetchrow_hashref()) { } $json{'switches'}{$sysname}{'time'} = $ref->{'time'}; } + $nms::web::cc{'max-age'} = "5"; $nms::web::cc{'stale-while-revalidate'} = "30"; finalize_output(); -- cgit v1.2.3 From 65bc1d20d443c987df5681b87967974c12169ed1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20Kir=C3=B8?= Date: Sun, 20 Mar 2016 20:32:42 +0100 Subject: strict and warnings in dhcp-summary. --- web/nms.gathering.org/api/public/dhcp-summary | 2 ++ 1 file changed, 2 insertions(+) (limited to 'web') diff --git a/web/nms.gathering.org/api/public/dhcp-summary b/web/nms.gathering.org/api/public/dhcp-summary index 31bc8eb..dd643b2 100755 --- a/web/nms.gathering.org/api/public/dhcp-summary +++ b/web/nms.gathering.org/api/public/dhcp-summary @@ -1,5 +1,7 @@ #! /usr/bin/perl use lib '../../../../include'; +use strict; +use warnings; use nms::web; nms::web::setwhen('2h'); -- cgit v1.2.3 From b5b57c04f96b3ddedf8b94dc2188e9d421b53cde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20Kir=C3=B8?= Date: Sun, 20 Mar 2016 20:33:02 +0100 Subject: line breakup in snmp --- web/nms.gathering.org/api/private/snmp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'web') diff --git a/web/nms.gathering.org/api/private/snmp b/web/nms.gathering.org/api/private/snmp index 4779659..f69ca62 100755 --- a/web/nms.gathering.org/api/private/snmp +++ b/web/nms.gathering.org/api/private/snmp @@ -13,7 +13,8 @@ use Data::Dumper; $nms::web::cc{'max-age'} = "10"; -my $q = $nms::web::dbh->prepare('select sysname,data from snmp natural join switches where id in (select max(id) from snmp where ' . $nms::web::when . 'group by switch);'); +my $q = $nms::web::dbh->prepare('select sysname,data from snmp natural join switches where id in (select max(id) from snmp where ' + . $nms::web::when . 'group by switch);'); $q->execute(); while (my $ref = $q->fetchrow_hashref()) { -- cgit v1.2.3 From f96901df27b451cb9f08a513932d0034042b0c0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20Kir=C3=B8?= Date: Sun, 20 Mar 2016 20:33:39 +0100 Subject: ping cleanup/formatting, and timestamp to seconds conversion improvement. --- web/nms.gathering.org/api/public/ping | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'web') diff --git a/web/nms.gathering.org/api/public/ping b/web/nms.gathering.org/api/public/ping index bf92440..ba572af 100755 --- a/web/nms.gathering.org/api/public/ping +++ b/web/nms.gathering.org/api/public/ping @@ -1,31 +1,35 @@ #! /usr/bin/perl use lib '../../../../include'; +use strict; +use warnings; use nms::web; #nms::web::setwhen('1s'); -my $q = $nms::web::dbh->prepare("SELECT DISTINCT ON (sysname) (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)"); +my $q = $nms::web::dbh->prepare("SELECT DISTINCT ON (sysname) (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'}}{'latency'} = $ref->{'latency_ms'}; - # This isn't pretty, feel free to fix, but I want age == seconds - # without decimals. - my ($h,$m,$ss) = split(':', $ref->{'age'}); - my ($s,undef) = split('\.', "$ss"); - - $nms::web::json{'switches'}{$ref->{'sysname'}}{'age'} = ($h*60*60) + ($m*60) + $s;# $$ref->{'age'}; + $nms::web::json{'switches'}{$ref->{'sysname'}}{'latency'} = $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'}}{'age'} = ($h*60*60) + ($m*60) + $s; # $$ref->{'age'}; } -my $qs = $nms::web::dbh->prepare("SELECT DISTINCT ON (switch) switch, latency_ms FROM ping_secondary_ip WHERE " . $nms::web::when . " ORDER BY switch, time DESC;"); +my $qs = $nms::web::dbh->prepare("SELECT DISTINCT ON (switch) switch, latency_ms FROM ping_secondary_ip WHERE " + . $nms::web::when . " ORDER BY switch, time DESC;"); $qs->execute(); -while (my $ref = $qs->fetchrow_hashref()) { - $nms::web::json{'switches'}{$ref->{'switch'}}{'latency_secondary'} = $ref->{'latency_ms'}; +while ( my $ref = $qs->fetchrow_hashref() ) { + $nms::web::json{'switches'}{$ref->{'switch'}}{'latency_secondary'} = $ref->{'latency_ms'}; } -my $lq = $nms::web::dbh->prepare("SELECT DISTINCT ON (linknet) linknet, latency1_ms, latency2_ms FROM linknet_ping WHERE ". $nms::web::when . " ORDER BY linknet, time DESC;"); +my $lq = $nms::web::dbh->prepare("SELECT DISTINCT ON (linknet) linknet, latency1_ms, latency2_ms FROM linknet_ping WHERE " + . $nms::web::when . " ORDER BY linknet, time DESC;"); $lq->execute(); -while (my $ref = $lq->fetchrow_hashref()) { - $nms::web::json{'linknets'}{$ref->{'linknet'}} = [ $ref->{'latency1_ms'}, $ref->{'latency2_ms'} ]; +while ( my $ref = $lq->fetchrow_hashref() ) { + $nms::web::json{'linknets'}{$ref->{'linknet'}} = [ $ref->{'latency1_ms'}, $ref->{'latency2_ms'} ]; } $nms::web::cc{'max-age'} = "1"; -- cgit v1.2.3 From 11fc373807b9a14ee14499165b00f5e775d11a59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20Kir=C3=B8?= Date: Sun, 20 Mar 2016 21:49:15 +0100 Subject: which switch an I on script file. --- web/nms.gathering.org/api/private/which-switch-am-i-on | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100755 web/nms.gathering.org/api/private/which-switch-am-i-on (limited to 'web') diff --git a/web/nms.gathering.org/api/private/which-switch-am-i-on b/web/nms.gathering.org/api/private/which-switch-am-i-on new file mode 100755 index 0000000..4adfb2b --- /dev/null +++ b/web/nms.gathering.org/api/private/which-switch-am-i-on @@ -0,0 +1,15 @@ +#! /usr/bin/perl +# vim:ts=8:sw=8 + +use lib '../../../../include'; +use nms::web; +use strict; +use warnings; + +my $query = $nms::web::dbh->prepare('select sysname,extract(epoch from date_trunc(\'second\',time)) as time,state,username,id,comment from switch_comments natural join switches where state != \'delete\' order by time desc'); +$query->execute(); +while (my $ref = $query->fetchrow_hashref()) { + push @{$nms::web::json{'comments'}{$ref->{'sysname'}}{'comments'}},$ref; +} + +nms::web::finalize_output(); -- cgit v1.2.3 From 6fa911c8565a54c9b56cfae479a92da094990876 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20Kir=C3=B8?= Date: Sun, 20 Mar 2016 23:53:46 +0100 Subject: which switch: getting IP and printing it. Need to style with html. --- .../api/private/which-switch-am-i-on | 23 ++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'web') diff --git a/web/nms.gathering.org/api/private/which-switch-am-i-on b/web/nms.gathering.org/api/private/which-switch-am-i-on index 4adfb2b..82436ea 100755 --- a/web/nms.gathering.org/api/private/which-switch-am-i-on +++ b/web/nms.gathering.org/api/private/which-switch-am-i-on @@ -5,11 +5,26 @@ use lib '../../../../include'; use nms::web; use strict; use warnings; +use Data::Dumper; -my $query = $nms::web::dbh->prepare('select sysname,extract(epoch from date_trunc(\'second\',time)) as time,state,username,id,comment from switch_comments natural join switches where state != \'delete\' order by time desc'); +#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 '88.92.5.67' << subnet4"); $query->execute(); -while (my $ref = $query->fetchrow_hashref()) { - push @{$nms::web::json{'comments'}{$ref->{'sysname'}}{'comments'}},$ref; + +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 $addr = $ENV{HTTP_X_FORWARDED_FOR} // $ENV{REMOTE_ADDR}; +print "-:" . $addr ."\n"; + + +# add start html: header + body etc. + +while ( my $ref = $query->fetchrow_hashref() ) { + print $ref->{sysname}. " @ " . $ref->{distro}; } -nms::web::finalize_output(); +# add end html -- cgit v1.2.3 From 4dffc5e5431c83595f2bd102f120ad6def011d22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20Kir=C3=B8?= Date: Mon, 21 Mar 2016 10:33:25 +0100 Subject: which switch html finished. --- web/nms.gathering.org/api/private/which-switch-am-i-on | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'web') diff --git a/web/nms.gathering.org/api/private/which-switch-am-i-on b/web/nms.gathering.org/api/private/which-switch-am-i-on index 82436ea..0d3f2b4 100755 --- a/web/nms.gathering.org/api/private/which-switch-am-i-on +++ b/web/nms.gathering.org/api/private/which-switch-am-i-on @@ -18,13 +18,23 @@ 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 $addr = $ENV{HTTP_X_FORWARDED_FOR} // $ENV{REMOTE_ADDR}; -print "-:" . $addr ."\n"; - # add start html: header + body etc. +print " + + +"; + +# print address +print "" . $addr ."
    "; +# print switch name and distroname. while ( my $ref = $query->fetchrow_hashref() ) { print $ref->{sysname}. " @ " . $ref->{distro}; } # add end html +print " + + +"; -- cgit v1.2.3 From 9f2d2bc0faba3eef6ddfd7cfaf87dc28988acecf Mon Sep 17 00:00:00 2001 From: Nicolai Tellefsen Date: Mon, 21 Mar 2016 12:21:16 +0100 Subject: NMS: Adjust temperature handler to new schema --- web/nms.gathering.org/js/nms-map-handlers.js | 49 ++++++++++++++++------------ 1 file changed, 28 insertions(+), 21 deletions(-) (limited to 'web') diff --git a/web/nms.gathering.org/js/nms-map-handlers.js b/web/nms.gathering.org/js/nms-map-handlers.js index fa33bad..b1d31f0 100644 --- a/web/nms.gathering.org/js/nms-map-handlers.js +++ b/web/nms.gathering.org/js/nms-map-handlers.js @@ -204,45 +204,52 @@ function colorFromSpeed(speed,factor) } -/* - * Tweaked this to scale from roughly 20C to 35C. Hence the -20 and /15 - * thing (e.g., "0" is 20 and "15" is 35 by the time we pass it to - * rgb_from_max()); - */ function temp_color(t) { if (t == undefined) { console.log("Temp_color, but temp is undefined"); return blue; } - t = parseInt(t) - 12; - t = Math.floor((t / 23) * 1000); + t = parseInt(t); + t = Math.floor(t * 10); return getColorStop(t); } function tempUpdater() { - for (sw in nms.switches_now["switches"]) { + if(!nmsData.switches) + return; + + for (sw in nmsData.switches["switches"]) { var t = "white"; var temp = ""; - if (nms.switches_now["switches"][sw]["temp"]) { - t = temp_color(nms.switches_now["switches"][sw]["temp"]); - temp = nms.switches_now["switches"][sw]["temp"] + "°C"; - } - - setSwitchColor(sw, t); - switchInfoText(sw, temp); + + if(!nmsData.snmp || !nmsData.snmp.snmp[sw]["misc"] || !nmsData.snmp.snmp[sw]["misc"]["enterprises.2636.3.1.13.1.7.7.1.0.0"]) + continue; + + tempObj = nmsData.snmp.snmp[sw]["misc"]["enterprises.2636.3.1.13.1.7.7.1.0.0"]; + Object.keys(tempObj).forEach(function (key) { + if(key == "") { + temp = tempObj[key] + "°C"; + t = temp_color(temp); + } + }); + + nmsMap.setSwitchColor(sw, t); + nmsMap.setSwitchInfo(sw, temp); } } function tempInit() -{ - drawGradient(["black",blue,lightblue,lightgreen,green,orange,red]); - setLegend(1,temp_color(15),"15 °C"); - setLegend(2,temp_color(20),"20 °C"); +{ + //Padded the gradient with extra colors for the upper unused values + drawGradient([blue,lightgreen,green,orange,red,red,red,red,red,red]); + setLegend(1,temp_color(0),"0 °C"); + setLegend(2,temp_color(15),"15 °C"); setLegend(3,temp_color(25),"25 °C"); - setLegend(4,temp_color(30),"30 °C"); - setLegend(5,temp_color(35),"35 °C"); + setLegend(4,temp_color(35),"35 °C"); + setLegend(5,temp_color(45),"45 °C"); + nmsData.addHandler("switchstate","mapHandler",tempUpdater); } function pingUpdater() -- cgit v1.2.3