aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ansible/roles/basics/tasks/main.yml3
-rw-r--r--ansible/roles/test/tasks/main.yml3
-rwxr-xr-xcollectors/ping.pl19
-rwxr-xr-xextras/tools/make_switches.json.sh46
-rw-r--r--include/nms/util.pm73
-rw-r--r--web/js/nms-map-handlers.js1
-rw-r--r--web/js/nms-search.js14
7 files changed, 143 insertions, 16 deletions
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..92eedb1 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":"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/collectors/ping.pl b/collectors/ping.pl
index c50ea87..d5acded 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,18 @@ 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 = 0.2;
while (1) {
- sleep(0.5);
+ my $now = time();
+ my $elapsed = ($now - $last);
+ if ($elapsed < $target) {
+ sleep($target - ($now - $last));
+ }
+ $last = time();
# ping loopbacks
my $ping = Net::Oping->new;
$ping->timeout(0.2);
@@ -58,7 +65,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};
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_
+
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];
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;
diff --git a/web/js/nms-search.js b/web/js/nms-search.js
index 748c8c2..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", "active<x" or "active=x" to identify switch with "x" amount of active gigabit ethernet (ge) ports. E.g.: "active>30".',
@@ -21,7 +22,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] == "\"") {
@@ -63,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) {