From 0788f2f663297fadcc39cd034a4037399c0f2b4b Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Mon, 23 May 2016 19:25:15 +0200 Subject: front: De-noise the ping handler in lack of ping That was supposed to be a debug thing... --- web/js/nms-map-handlers.js | 1 - 1 file changed, 1 deletion(-) diff --git a/web/js/nms-map-handlers.js b/web/js/nms-map-handlers.js index 9c9f03a..205adda 100644 --- a/web/js/nms-map-handlers.js +++ b/web/js/nms-map-handlers.js @@ -356,7 +356,6 @@ function pingInfo(sw) ret.score = 900; } } catch(e) { - console.log(e); ret.data[0].value = "N/A - no ping replies"; ret.why = "No ping replies"; ret.score = 999; -- cgit v1.2.3 From d22ac1f0d70acc7c7bb78f72538212494f089e00 Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Mon, 23 May 2016 19:30:15 +0200 Subject: Switch broken sleep(0.5) with working sleep(0.5) (ish) Perl, you're one bad decision after an other. --- collectors/ping.pl | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/collectors/ping.pl b/collectors/ping.pl index c50ea87..c1a4af3 100755 --- a/collectors/ping.pl +++ b/collectors/ping.pl @@ -1,7 +1,7 @@ #! /usr/bin/perl use DBI; use POSIX; -use Time::HiRes; +use Time::HiRes qw(sleep time); use Net::Oping; use strict; use warnings; @@ -15,11 +15,15 @@ my $dbh = nms::db_connect(); $dbh->{AutoCommit} = 0; $dbh->{RaiseError} = 1; -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 or mgmt_v6_addr is not null ORDER BY random()"); -my $lq = $dbh->prepare("SELECT linknet,addr1,addr2 FROM linknets WHERE addr1 is not null and addr2 is not null"); +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 or mgmt_v6_addr is not null ORDER BY random();"); +my $lq = $dbh->prepare("SELECT linknet,addr1,addr2 FROM linknets WHERE addr1 is not null and addr2 is not null;"); +my $last = time(); +my $target = 1.0; while (1) { - sleep(0.5); + my $now = time(); + sleep($target - ($now - $last)); + $last = time(); # ping loopbacks my $ping = Net::Oping->new; $ping->timeout(0.2); @@ -58,7 +62,9 @@ while (1) { my $drops = 0; while (my ($ip, $latency) = each %$result) { my $switch = $ip_to_switch{$ip}; - next if (!defined($switch)); + if (!defined($switch)) { + next; + } if (!defined($latency)) { $drops += $dropped{$ip}; -- cgit v1.2.3 From 2b46011f06a3515dc7604059341ab9168fcfc508 Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Mon, 23 May 2016 19:47:36 +0200 Subject: build: Add a bunch of switches --- ansible/roles/basics/tasks/main.yml | 3 +++ ansible/roles/test/tasks/main.yml | 3 ++- extras/tools/make_switches.json.sh | 46 +++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100755 extras/tools/make_switches.json.sh diff --git a/ansible/roles/basics/tasks/main.yml b/ansible/roles/basics/tasks/main.yml index a168afe..5dd5b5d 100644 --- a/ansible/roles/basics/tasks/main.yml +++ b/ansible/roles/basics/tasks/main.yml @@ -44,15 +44,18 @@ register: ip tags: - start + - test - name: workaround to get gondul-front-ip shell: "docker inspect gondul-front-test | grep IPAddress | sed 's/[^0-9.]//g' | grep 172.17 | uniq" register: ipfront tags: - start + - test - name: Display IP tags: - start + - test debug: msg: "Varnish test is available at http://{{ ip.stdout }}/ uncached ip: http://{{ ipfront.stdout }}/ " diff --git a/ansible/roles/test/tasks/main.yml b/ansible/roles/test/tasks/main.yml index 7bcf1c4..55f9a4f 100644 --- a/ansible/roles/test/tasks/main.yml +++ b/ansible/roles/test/tasks/main.yml @@ -28,5 +28,6 @@ body_format: json user: demo password: demo - body: "{{[ { 'sysname': 'foobar1', 'mgmt_v4_addr': '127.0.0.1' }, { 'sysname': 'foobar2', 'mgmt_v4_addr': '127.0.0.1' }, { 'sysname': 'foobar3', 'mgmt_v4_addr': '127.0.0.1' }, { 'sysname': 'foobar4', 'mgmt_v4_addr': '127.0.0.1' }, { 'sysname': 'foobar5', 'mgmt_v4_addr': '127.0.0.1' }, { 'sysname': 'foobar6', 'mgmt_v4_addr': '127.0.0.1' }, { 'sysname': 'foobar7', 'mgmt_v4_addr': '127.0.0.1' }, { 'sysname': 'foobar8', 'mgmt_v4_addr': '127.0.0.1' }, { 'sysname': 'foobar9', 'mgmt_v4_addr': '127.0.0.1' }, { 'sysname': 'foobar10', 'mgmt_v4_addr': '127.0.0.1' }, { 'sysname': 'foobar11', 'mgmt_v4_addr': '127.0.0.1' }, { 'sysname': 'foobar12', 'mgmt_v4_addr': '127.0.0.1' }, { 'sysname': 'foobar13', 'mgmt_v4_addr': '127.0.0.1' }, { 'sysname': 'foobar14', 'mgmt_v4_addr': '127.0.0.1' }, { 'sysname': 'foobar15', 'mgmt_v4_addr': '127.0.0.1' }, { 'sysname': 'foobar16', 'mgmt_v4_addr': '127.0.0.1' }, { 'sysname': 'foobar17', 'mgmt_v4_addr': '127.0.0.1' }, { 'sysname': 'foobar18', 'mgmt_v4_addr': '127.0.0.1' }, { 'sysname': 'foobar19', 'mgmt_v4_addr': '127.0.0.1' }]}}" + body: '[{"mgmt_v4_addr":"127.0.0.1","sysname":""},{"distro":"core","mgmt_v4_addr":"127.0.0.2","sysname":"distro0"},{"distro":"distro0","mgmt_v4_addr":"127.0.0.3","sysname":"row1-1"},{"distro":"distro0","mgmt_v4_addr":"127.0.0.4","sysname":"row1-2"},{"distro":"distro0","mgmt_v4_addr":"127.0.0.5","sysname":"row3-1"},{"distro":"distro0","mgmt_v4_addr":"127.0.0.6","sysname":"row3-2"},{"distro":"distro0","mgmt_v4_addr":"127.0.0.7","sysname":"row5-1"},{"distro":"distro0","mgmt_v4_addr":"127.0.0.8","sysname":"row5-2"},{"distro":"distro0","mgmt_v4_addr":"127.0.0.9","sysname":"row7-1"},{"distro":"distro0","mgmt_v4_addr":"127.0.0.10","sysname":"row7-2"},{"distro":"distro0","mgmt_v4_addr":"127.0.0.11","sysname":"row9-1"},{"distro":"distro0","mgmt_v4_addr":"127.0.0.12","sysname":"row9-2"},{"distro":"core","mgmt_v4_addr":"127.0.0.13","sysname":"distro1"},{"distro":"distro1","mgmt_v4_addr":"127.0.0.14","sysname":"row11-1"},{"distro":"distro1","mgmt_v4_addr":"127.0.0.15","sysname":"row11-2"},{"distro":"distro1","mgmt_v4_addr":"127.0.0.16","sysname":"row13-1"},{"distro":"distro1","mgmt_v4_addr":"127.0.0.17","sysname":"row13-2"},{"distro":"distro1","mgmt_v4_addr":"127.0.0.18","sysname":"row15-1"},{"distro":"distro1","mgmt_v4_addr":"127.0.0.19","sysname":"row15-2"},{"distro":"distro1","mgmt_v4_addr":"127.0.0.20","sysname":"row17-1"},{"distro":"distro1","mgmt_v4_addr":"127.0.0.21","sysname":"row17-2"},{"distro":"distro1","mgmt_v4_addr":"127.0.0.22","sysname":"row19-1"},{"distro":"distro1","mgmt_v4_addr":"127.0.0.23","sysname":"row19-2"},{"distro":"core","mgmt_v4_addr":"127.0.0.24","sysname":"distro2"},{"distro":"distro2","mgmt_v4_addr":"127.0.0.25","sysname":"row21-1"},{"distro":"distro2","mgmt_v4_addr":"127.0.0.26","sysname":"row21-2"},{"distro":"distro2","mgmt_v4_addr":"127.0.0.27","sysname":"row23-1"},{"distro":"distro2","mgmt_v4_addr":"127.0.0.28","sysname":"row23-2"},{"distro":"distro2","mgmt_v4_addr":"127.0.0.29","sysname":"row25-1"},{"distro":"distro2","mgmt_v4_addr":"127.0.0.30","sysname":"row25-2"},{"distro":"distro2","mgmt_v4_addr":"127.0.0.31","sysname":"row27-1"},{"distro":"distro2","mgmt_v4_addr":"127.0.0.32","sysname":"row27-2"},{"distro":"distro2","mgmt_v4_addr":"127.0.0.33","sysname":"row29-1"},{"distro":"distro2","mgmt_v4_addr":"127.0.0.34","sysname":"row29-2"},{"distro":"core","mgmt_v4_addr":"127.0.0.35","sysname":"distro3"},{"distro":"distro3","mgmt_v4_addr":"127.0.0.36","sysname":"row31-1"},{"distro":"distro3","mgmt_v4_addr":"127.0.0.37","sysname":"row31-2"},{"distro":"distro3","mgmt_v4_addr":"127.0.0.38","sysname":"row33-1"},{"distro":"distro3","mgmt_v4_addr":"127.0.0.39","sysname":"row33-2"},{"distro":"distro3","mgmt_v4_addr":"127.0.0.40","sysname":"row35-1"},{"distro":"distro3","mgmt_v4_addr":"127.0.0.41","sysname":"row35-2"},{"distro":"distro3","mgmt_v4_addr":"127.0.0.42","sysname":"row37-1"},{"distro":"distro3","mgmt_v4_addr":"127.0.0.43","sysname":"row37-2"},{"distro":"distro3","mgmt_v4_addr":"127.0.0.44","sysname":"row39-1"},{"distro":"distro3","mgmt_v4_addr":"127.0.0.45","sysname":"row39-2"},{"distro":"core","mgmt_v4_addr":"127.0.0.46","sysname":"noc"}]' + diff --git a/extras/tools/make_switches.json.sh b/extras/tools/make_switches.json.sh new file mode 100755 index 0000000..4f7098a --- /dev/null +++ b/extras/tools/make_switches.json.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +CORE="core" +DISTRO="distro" +ROWS0="1 3 5 7 9" +ROWS1="11 13 15 17 19" +ROWS2="21 23 25 27 29" +ROWS3="31 33 35 37 39" +N=1 +inc() { + N=$(( $N + 1 )) +} +echo "[{\"sysname\": \"$core\", \"mgmt_v4_addr\": \"127.0.0.$N\"}," +inc +mkswitch() { + cat <<_EOF_ +{"sysname": "$1", "distro": "$2", "mgmt_v4_addr": "127.0.0.$N"}, +_EOF_ +inc +} +mkswitch ${DISTRO}0 core +for a in $ROWS0; do + mkswitch row${a}-1 distro0 + mkswitch row${a}-2 distro0 +done + +mkswitch ${DISTRO}1 core +for a in $ROWS1; do + mkswitch row${a}-1 distro1 + mkswitch row${a}-2 distro1 +done + +mkswitch ${DISTRO}2 core +for a in $ROWS2; do + mkswitch row${a}-1 distro2 + mkswitch row${a}-2 distro2 +done +mkswitch ${DISTRO}3 core +for a in $ROWS3; do + mkswitch row${a}-1 distro3 + mkswitch row${a}-2 distro3 +done +cat <<_WOF_ +{"sysname": "noc", "distro": "core", "mgmt_v4_addr": "127.0.0.$N" }] +_WOF_ + -- cgit v1.2.3 From 8397e793cb95640b42b99f0ee41a7ee32b15adaa Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Mon, 23 May 2016 20:04:24 +0200 Subject: Tweak test-data and ping-intervals Not _exactly_ dx16 data, but.... --- ansible/roles/test/tasks/main.yml | 2 +- collectors/ping.pl | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ansible/roles/test/tasks/main.yml b/ansible/roles/test/tasks/main.yml index 55f9a4f..8f105b9 100644 --- a/ansible/roles/test/tasks/main.yml +++ b/ansible/roles/test/tasks/main.yml @@ -28,6 +28,6 @@ body_format: json user: demo password: demo - body: '[{"mgmt_v4_addr":"127.0.0.1","sysname":""},{"distro":"core","mgmt_v4_addr":"127.0.0.2","sysname":"distro0"},{"distro":"distro0","mgmt_v4_addr":"127.0.0.3","sysname":"row1-1"},{"distro":"distro0","mgmt_v4_addr":"127.0.0.4","sysname":"row1-2"},{"distro":"distro0","mgmt_v4_addr":"127.0.0.5","sysname":"row3-1"},{"distro":"distro0","mgmt_v4_addr":"127.0.0.6","sysname":"row3-2"},{"distro":"distro0","mgmt_v4_addr":"127.0.0.7","sysname":"row5-1"},{"distro":"distro0","mgmt_v4_addr":"127.0.0.8","sysname":"row5-2"},{"distro":"distro0","mgmt_v4_addr":"127.0.0.9","sysname":"row7-1"},{"distro":"distro0","mgmt_v4_addr":"127.0.0.10","sysname":"row7-2"},{"distro":"distro0","mgmt_v4_addr":"127.0.0.11","sysname":"row9-1"},{"distro":"distro0","mgmt_v4_addr":"127.0.0.12","sysname":"row9-2"},{"distro":"core","mgmt_v4_addr":"127.0.0.13","sysname":"distro1"},{"distro":"distro1","mgmt_v4_addr":"127.0.0.14","sysname":"row11-1"},{"distro":"distro1","mgmt_v4_addr":"127.0.0.15","sysname":"row11-2"},{"distro":"distro1","mgmt_v4_addr":"127.0.0.16","sysname":"row13-1"},{"distro":"distro1","mgmt_v4_addr":"127.0.0.17","sysname":"row13-2"},{"distro":"distro1","mgmt_v4_addr":"127.0.0.18","sysname":"row15-1"},{"distro":"distro1","mgmt_v4_addr":"127.0.0.19","sysname":"row15-2"},{"distro":"distro1","mgmt_v4_addr":"127.0.0.20","sysname":"row17-1"},{"distro":"distro1","mgmt_v4_addr":"127.0.0.21","sysname":"row17-2"},{"distro":"distro1","mgmt_v4_addr":"127.0.0.22","sysname":"row19-1"},{"distro":"distro1","mgmt_v4_addr":"127.0.0.23","sysname":"row19-2"},{"distro":"core","mgmt_v4_addr":"127.0.0.24","sysname":"distro2"},{"distro":"distro2","mgmt_v4_addr":"127.0.0.25","sysname":"row21-1"},{"distro":"distro2","mgmt_v4_addr":"127.0.0.26","sysname":"row21-2"},{"distro":"distro2","mgmt_v4_addr":"127.0.0.27","sysname":"row23-1"},{"distro":"distro2","mgmt_v4_addr":"127.0.0.28","sysname":"row23-2"},{"distro":"distro2","mgmt_v4_addr":"127.0.0.29","sysname":"row25-1"},{"distro":"distro2","mgmt_v4_addr":"127.0.0.30","sysname":"row25-2"},{"distro":"distro2","mgmt_v4_addr":"127.0.0.31","sysname":"row27-1"},{"distro":"distro2","mgmt_v4_addr":"127.0.0.32","sysname":"row27-2"},{"distro":"distro2","mgmt_v4_addr":"127.0.0.33","sysname":"row29-1"},{"distro":"distro2","mgmt_v4_addr":"127.0.0.34","sysname":"row29-2"},{"distro":"core","mgmt_v4_addr":"127.0.0.35","sysname":"distro3"},{"distro":"distro3","mgmt_v4_addr":"127.0.0.36","sysname":"row31-1"},{"distro":"distro3","mgmt_v4_addr":"127.0.0.37","sysname":"row31-2"},{"distro":"distro3","mgmt_v4_addr":"127.0.0.38","sysname":"row33-1"},{"distro":"distro3","mgmt_v4_addr":"127.0.0.39","sysname":"row33-2"},{"distro":"distro3","mgmt_v4_addr":"127.0.0.40","sysname":"row35-1"},{"distro":"distro3","mgmt_v4_addr":"127.0.0.41","sysname":"row35-2"},{"distro":"distro3","mgmt_v4_addr":"127.0.0.42","sysname":"row37-1"},{"distro":"distro3","mgmt_v4_addr":"127.0.0.43","sysname":"row37-2"},{"distro":"distro3","mgmt_v4_addr":"127.0.0.44","sysname":"row39-1"},{"distro":"distro3","mgmt_v4_addr":"127.0.0.45","sysname":"row39-2"},{"distro":"core","mgmt_v4_addr":"127.0.0.46","sysname":"noc"}]' + body: '[{"mgmt_v4_addr":"127.0.0.1","sysname":"core"},{"distro_name":"core","mgmt_v4_addr":"127.0.0.2","sysname":"distro0"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.3","sysname":"row1-1"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.4","sysname":"row1-2"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.5","sysname":"row3-1"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.6","sysname":"row3-2"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.7","sysname":"row5-1"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.8","sysname":"row5-2"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.9","sysname":"row7-1"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.10","sysname":"row7-2"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.11","sysname":"row9-1"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.12","sysname":"row9-2"},{"distro_name":"core","mgmt_v4_addr":"127.0.0.13","sysname":"distro1"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.14","sysname":"row11-1"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.15","sysname":"row11-2"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.16","sysname":"row13-1"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.17","sysname":"row13-2"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.18","sysname":"row15-1"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.19","sysname":"row15-2"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.20","sysname":"row17-1"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.21","sysname":"row17-2"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.22","sysname":"row19-1"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.23","sysname":"row19-2"},{"distro_name":"core","mgmt_v4_addr":"127.0.0.24","sysname":"distro2"},{"distro_name":"distro2","mgmt_v4_addr":"127.0.0.25","sysname":"row21-1"},{"distro_name":"distro2","mgmt_v4_addr":"127.0.0.26","sysname":"row21-2"},{"distro_name":"distro2","mgmt_v4_addr":"127.0.0.27","sysname":"row23-1"},{"distro_name":"distro2","mgmt_v4_addr":"127.0.0.28","sysname":"row23-2"},{"distro_name":"distro2","mgmt_v4_addr":"127.0.0.29","sysname":"row25-1"},{"distro_name":"distro2","mgmt_v4_addr":"127.0.0.30","sysname":"row25-2"},{"distro_name":"distro2","mgmt_v4_addr":"127.0.0.31","sysname":"row27-1"},{"distro_name":"distro2","mgmt_v4_addr":"127.0.0.32","sysname":"row27-2"},{"distro_name":"distro2","mgmt_v4_addr":"127.0.0.33","sysname":"row29-1"},{"distro_name":"distro2","mgmt_v4_addr":"127.0.0.34","sysname":"row29-2"},{"distro_name":"core","mgmt_v4_addr":"127.0.0.35","sysname":"distro3"},{"distro_name":"distro3","mgmt_v4_addr":"127.0.0.36","sysname":"row31-1"},{"distro_name":"distro3","mgmt_v4_addr":"127.0.0.37","sysname":"row31-2"},{"distro_name":"distro3","mgmt_v4_addr":"127.0.0.38","sysname":"row33-1"},{"distro_name":"distro3","mgmt_v4_addr":"127.0.0.39","sysname":"row33-2"},{"distro_name":"distro3","mgmt_v4_addr":"127.0.0.40","sysname":"row35-1"},{"distro_name":"distro3","mgmt_v4_addr":"127.0.0.41","sysname":"row35-2"},{"distro_name":"distro3","mgmt_v4_addr":"127.0.0.42","sysname":"row37-1"},{"distro_name":"distro3","mgmt_v4_addr":"127.0.0.43","sysname":"row37-2"},{"distro_name":"distro3","mgmt_v4_addr":"127.0.0.44","sysname":"row39-1"},{"distro_name":"distro3","mgmt_v4_addr":"127.0.0.45","sysname":"row39-2"},{"distro_name":"core","mgmt_v4_addr":"127.0.0.46","sysname":"noc"}]' diff --git a/collectors/ping.pl b/collectors/ping.pl index c1a4af3..d5acded 100755 --- a/collectors/ping.pl +++ b/collectors/ping.pl @@ -19,10 +19,13 @@ my $q = $dbh->prepare("SELECT switch,host(mgmt_v4_addr) as ip,host(mgmt_v6_addr) my $lq = $dbh->prepare("SELECT linknet,addr1,addr2 FROM linknets WHERE addr1 is not null and addr2 is not null;"); my $last = time(); -my $target = 1.0; +my $target = 0.2; while (1) { my $now = time(); - sleep($target - ($now - $last)); + my $elapsed = ($now - $last); + if ($elapsed < $target) { + sleep($target - ($now - $last)); + } $last = time(); # ping loopbacks my $ping = Net::Oping->new; -- cgit v1.2.3 From 83cf935cc8f3064345e3a5255a91224ce9d02b9a Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Mon, 23 May 2016 20:53:04 +0200 Subject: Start tinkering with DX autoplacement. Just want to give whoever takes over a starting point. --- ansible/roles/test/tasks/main.yml | 2 +- include/nms/util.pm | 73 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 71 insertions(+), 4 deletions(-) diff --git a/ansible/roles/test/tasks/main.yml b/ansible/roles/test/tasks/main.yml index 8f105b9..92eedb1 100644 --- a/ansible/roles/test/tasks/main.yml +++ b/ansible/roles/test/tasks/main.yml @@ -28,6 +28,6 @@ body_format: json user: demo password: demo - body: '[{"mgmt_v4_addr":"127.0.0.1","sysname":"core"},{"distro_name":"core","mgmt_v4_addr":"127.0.0.2","sysname":"distro0"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.3","sysname":"row1-1"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.4","sysname":"row1-2"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.5","sysname":"row3-1"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.6","sysname":"row3-2"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.7","sysname":"row5-1"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.8","sysname":"row5-2"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.9","sysname":"row7-1"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.10","sysname":"row7-2"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.11","sysname":"row9-1"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.12","sysname":"row9-2"},{"distro_name":"core","mgmt_v4_addr":"127.0.0.13","sysname":"distro1"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.14","sysname":"row11-1"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.15","sysname":"row11-2"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.16","sysname":"row13-1"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.17","sysname":"row13-2"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.18","sysname":"row15-1"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.19","sysname":"row15-2"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.20","sysname":"row17-1"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.21","sysname":"row17-2"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.22","sysname":"row19-1"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.23","sysname":"row19-2"},{"distro_name":"core","mgmt_v4_addr":"127.0.0.24","sysname":"distro2"},{"distro_name":"distro2","mgmt_v4_addr":"127.0.0.25","sysname":"row21-1"},{"distro_name":"distro2","mgmt_v4_addr":"127.0.0.26","sysname":"row21-2"},{"distro_name":"distro2","mgmt_v4_addr":"127.0.0.27","sysname":"row23-1"},{"distro_name":"distro2","mgmt_v4_addr":"127.0.0.28","sysname":"row23-2"},{"distro_name":"distro2","mgmt_v4_addr":"127.0.0.29","sysname":"row25-1"},{"distro_name":"distro2","mgmt_v4_addr":"127.0.0.30","sysname":"row25-2"},{"distro_name":"distro2","mgmt_v4_addr":"127.0.0.31","sysname":"row27-1"},{"distro_name":"distro2","mgmt_v4_addr":"127.0.0.32","sysname":"row27-2"},{"distro_name":"distro2","mgmt_v4_addr":"127.0.0.33","sysname":"row29-1"},{"distro_name":"distro2","mgmt_v4_addr":"127.0.0.34","sysname":"row29-2"},{"distro_name":"core","mgmt_v4_addr":"127.0.0.35","sysname":"distro3"},{"distro_name":"distro3","mgmt_v4_addr":"127.0.0.36","sysname":"row31-1"},{"distro_name":"distro3","mgmt_v4_addr":"127.0.0.37","sysname":"row31-2"},{"distro_name":"distro3","mgmt_v4_addr":"127.0.0.38","sysname":"row33-1"},{"distro_name":"distro3","mgmt_v4_addr":"127.0.0.39","sysname":"row33-2"},{"distro_name":"distro3","mgmt_v4_addr":"127.0.0.40","sysname":"row35-1"},{"distro_name":"distro3","mgmt_v4_addr":"127.0.0.41","sysname":"row35-2"},{"distro_name":"distro3","mgmt_v4_addr":"127.0.0.42","sysname":"row37-1"},{"distro_name":"distro3","mgmt_v4_addr":"127.0.0.43","sysname":"row37-2"},{"distro_name":"distro3","mgmt_v4_addr":"127.0.0.44","sysname":"row39-1"},{"distro_name":"distro3","mgmt_v4_addr":"127.0.0.45","sysname":"row39-2"},{"distro_name":"core","mgmt_v4_addr":"127.0.0.46","sysname":"noc"}]' + body: '[{"mgmt_v4_addr":"127.0.0.1","sysname":"core"},{"distro_name":"core","mgmt_v4_addr":"127.0.0.2","sysname":"distro0"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.3","sysname":"row1-1"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.4","sysname":"row1-2"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.5","sysname":"row3-1"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.6","sysname":"row3-2"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.7","sysname":"row5-1"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.8","sysname":"row5-2"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.9","sysname":"row7-1"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.10","sysname":"row7-2"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.11","sysname":"row9-1"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.12","sysname":"row9-2"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.14","sysname":"row11-1"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.15","sysname":"row11-2"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.16","sysname":"row13-1"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.17","sysname":"row13-2"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.18","sysname":"row15-1"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.19","sysname":"row15-2"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.20","sysname":"row17-1"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.21","sysname":"row17-2"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.22","sysname":"row19-1"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.23","sysname":"row19-2"},{"distro_name":"core","mgmt_v4_addr":"127.0.0.24","sysname":"distro1"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.25","sysname":"row21-1"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.26","sysname":"row21-2"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.27","sysname":"row23-1"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.28","sysname":"row23-2"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.29","sysname":"row25-1"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.30","sysname":"row25-2"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.31","sysname":"row27-1"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.32","sysname":"row27-2"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.33","sysname":"row29-1"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.34","sysname":"row29-2"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.36","sysname":"row31-1"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.37","sysname":"row31-2"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.38","sysname":"row33-1"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.39","sysname":"row33-2"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.40","sysname":"row35-1"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.41","sysname":"row35-2"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.42","sysname":"row37-1"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.43","sysname":"row37-2"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.44","sysname":"row39-1"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.45","sysname":"row39-2"},{"distro_name":"core","mgmt_v4_addr":"127.0.0.46","sysname":"noc"}]' diff --git a/include/nms/util.pm b/include/nms/util.pm index 898aa9a..b71d5a2 100644 --- a/include/nms/util.pm +++ b/include/nms/util.pm @@ -49,10 +49,77 @@ sub parse_switches { return @switches; } -# Guesses placement from name to get a starting point -# -# FIXME: Move to configuration +# FIXME: Derive which function from the config/db using the shortname. +# If we care. sub guess_placement { + return guess_placement_dx($_[0]); +} +# Guesses placement from name to get a starting point +# Digitality X layout +# FIXME: Basically a stub, since MRGLASS is too slow with the map. +sub guess_placement_dx { + my ($x, $y, $xx, $yy); + + my $name = $_[0]; + my $src = "unknown"; + if ($name =~ /^row\d+-\d+$/) { + $name =~ /row(\d+)-(\d+)/; + my ($e, $s) = ($1, $2); + $src = "main"; + + $x = int(1400 - (($e-1)/2) * 60); + $y = undef; + + if ($s > 1) { + $y = 100; + } else { + $y = 500; + } + + $xx = $x + 32; + $yy = $y + 300; + + } elsif ($name =~ /^core$/) { + $src = "core"; + $x = 800; + $y = 850; + $xx = $x + 200; + $yy = $y + 100; + } elsif ($name =~ /^noc$/) { + $src = "noc"; + $x = 400; + $y = 900; + $xx = $x + 230; + $yy = $y + 40; + } elsif ($name =~ /^distro(\d)$/) { + my $d = ($1); + $src = "distro"; + $x = 1200 - $d * 900; + $y = 415; + $xx = $x + 230; + $yy = $y + 40; + } else { + # Fallback to have _some_ position + $src = "random"; + $x = int(rand(1900)); + $y = int(rand(900)); + $xx = $x + 20; + $yy = $y + 130; + }; + + + my %box = ( + 'src' => "$src", + 'x1' => $x, + 'y1' => $y, + 'xx' => $xx, + 'yy' => $yy + ); + return %box; +} + +# Last updated for TG16 +sub guess_placement_tg { my ($x, $y, $xx, $yy); my $name = $_[0]; -- cgit v1.2.3 From 58875862f3e882cdbdd04ea3129646d9e9b1e173 Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Mon, 23 May 2016 23:06:37 +0200 Subject: front: Regex searching instead of home-brew thingamajing --- web/js/nms-search.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/web/js/nms-search.js b/web/js/nms-search.js index 748c8c2..f5cfb8c 100644 --- a/web/js/nms-search.js +++ b/web/js/nms-search.js @@ -21,7 +21,8 @@ nmsSearch.helpText = [ */ nmsSearch.searchTest = function(id, sw) { try { - if(sw.toLowerCase().indexOf(id.toLowerCase()) > -1) { + var re = new RegExp(id,"i"); + if(re.test(sw)) { return true; } if (id[0] == "\"") { -- cgit v1.2.3 From 78684bd2f31a6e8bd174219d363d116e1273f6a2 Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Mon, 23 May 2016 23:38:40 +0200 Subject: front: Use RegExp all over for searches creates some interesting opportunities, as searches can be combined. E.g.: '(row\d+-2|distro0|presse) can be used to mark multiple different switches now. Or '(::1$|^noc$|127.*\.14$) etc. Could probably get rid of the ""-hack now too. It was mainly meant for the automatic oplog entry on switch-creation, which can now use "^switch$" instead. --- web/js/nms-search.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/web/js/nms-search.js b/web/js/nms-search.js index f5cfb8c..46c0571 100644 --- a/web/js/nms-search.js +++ b/web/js/nms-search.js @@ -8,6 +8,7 @@ var nmsSearch = nmsSearch || { nmsSearch.helpText = [ "The search box can be used to identify switches in several ways. The simplest is by name.", "Searching by name can be done by just entering text, or if you want to match \"foobar1\" but not \"foobar15\" you can enclose the name in quotation marks. E.g.: foobar1 matches foobar1 and foobar1123123123, while \"foobar1\" only matches exactly foobar1.", + "All text-oriented searches are regular expressions. ^row\\d-2$ matches row1-2, row2-2, etc, but not row13-2 or rowx-2.", "If you are using the non-public version of Gondul, you can also perform smart searches.", "Distro search: Type the name of a distro-switch and all access switches registered to that distro switch will also be hilighted.", 'Active ports: Type "active>x", "active30".', @@ -64,22 +65,22 @@ nmsSearch.searchTest = function(id, sw) { } } catch (e) {} try { - if (nmsData.smanagement.switches[sw].mgmt_v4_addr.match(id)) { + if (re.test(nmsData.smanagement.switches[sw].mgmt_v4_addr)) { return true; } - if (nmsData.smanagement.switches[sw].mgmt_v6_addr.match(id)) { + if (re.test(nmsData.smanagement.switches[sw].mgmt_v6_addr)) { return true; } } catch (e) {} try { - if (nmsData.smanagement.switches[sw].subnet4.match(id)) { + if (re.test(nmsData.smanagement.switches[sw].subnet4)) { return true; } - if (nmsData.smanagement.switches[sw].subnet6.match(id)) { + if (re.test(nmsData.smanagement.switches[sw].subnet6)) { return true; } } catch (e) {} - if (nmsData.snmp.snmp[sw].misc.sysDescr[0].toLowerCase().match(id)) { + if (re.test(nmsData.snmp.snmp[sw].misc.sysDescr[0])) { return true; } } catch (e) { -- cgit v1.2.3