aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristian Lyngstol <kly@kly@.no>2016-03-21 12:26:19 +0100
committerKristian Lyngstol <kly@kly@.no>2016-03-21 12:26:19 +0100
commit0eb9e5b5e2c6f6ac34bc5119f0e4011e0dbf79e6 (patch)
tree922a19e11f38028c737f90bd25ff0867df96859d
parente2c018a18d972679160220b6cf76fa1a337e0a08 (diff)
parent7a1eea87c3cffd208f66e93c04a73e40045f3ef2 (diff)
Merge branch 'master' of github.com:tech-server/tgmanage
-rwxr-xr-xinclude/nms/web.pm2
-rw-r--r--nms/.bashrc16
-rw-r--r--nms/README.md26
-rwxr-xr-xnms/config.pm4
-rwxr-xr-xweb/nms.gathering.org/api/private/snmp3
-rwxr-xr-xweb/nms.gathering.org/api/private/which-switch-am-i-on40
-rwxr-xr-xweb/nms.gathering.org/api/public/dhcp-summary2
-rwxr-xr-xweb/nms.gathering.org/api/public/ping32
-rwxr-xr-xweb/nms.gathering.org/api/public/switch-state6
-rw-r--r--web/nms.gathering.org/js/nms-map-handlers.js49
10 files changed, 130 insertions, 50 deletions
diff --git a/include/nms/web.pm b/include/nms/web.pm
index 2a5e132..b36d692 100755
--- a/include/nms/web.pm
+++ b/include/nms/web.pm
@@ -81,7 +81,7 @@ sub finalize_output {
printcc;
print "Etag: $hash\n";
- print "Content-Type: text/jso; charset=utf-8\n\n";
+ print "Content-Type: text/json; charset=utf-8\n\n";
print JSON::XS::encode_json(\%json);
print "\n";
}
diff --git a/nms/.bashrc b/nms/.bashrc
new file mode 100644
index 0000000..06072e3
--- /dev/null
+++ b/nms/.bashrc
@@ -0,0 +1,16 @@
+NAME='NMS Docker'
+
+
+ln -s /srv/tgmanage/web/etc/apache2/nms.tg16.gathering.org.conf /etc/apache2/sites-enabled/
+ln -s /srv/tgmanage/nms/config.pm /srv/tgmanage/include/
+echo 'demo:$apr1$IKrQYF6x$0zmRciLR7Clc2tEEosyHV.' > /srv/tgmanage/web/.htpasswd
+
+/etc/init.d/apache2 restart
+echo "go here to look at nms: http://172.17.0.2:8080/"
+
+# Aliases
+alias h="history"
+alias l="ls -lAhoF --color --show-control-chars"
+alias ll="ls -lash --color --show-control-chars"
+alias cd..="cd .."
+
diff --git a/nms/README.md b/nms/README.md
index 107b630..7be3f14 100644
--- a/nms/README.md
+++ b/nms/README.md
@@ -4,21 +4,29 @@
- fetch data from tg server: `scp ${USER}@wat.gathering.org:/root/nms-2015.sql.gz .`
- Rename the nms dump so we can use it later: `mv nms-2015.sql.gz nms-dump.sql.gz`
-- Do the Debian install(or whatever OS you're on.): https://docs.docker.com/engine/installation/linux/debian/ And make sure that your user is in the docker group, so that you can run docker without sudo.
+- Do the Debian install(or whatever OS you're on.):
+https://docs.docker.com/engine/installation/linux/debian/
+And make sure that your user is in the docker group, so that you can run docker without sudo.
- Clone repository: `git clone git@github.com:tech-server/tgmanage.git`
-
- run `./makedockerfiles.sh`, which creates the docker image files, and builds
them.
-- Start database node: `docker run -v /sys/fs/cgroup:/sys/fs/cgroup:ro --privileged --rm -ti --name=db nms-db`
-- Start front end node: ` docker run -v /sys/fs/cgroup:/sys/fs/cgroup:ro --privileged --rm -ti --name=front --link=db:db nms-front `
-- Find IP's: `docker inspect front`, `docker inspect db`
-- Start a shell in a container: `docker exec front /bin/bash`
-- Open localhost:PORT in browser to start testing.
+- Start database node:
+`docker run -v /sys/fs/cgroup:/sys/fs/cgroup:ro --privileged --rm -ti --name=db nms-db`
+
+- Start front end node:
+-- with cgroup: `docker run -v /sys/fs/cgroup:/sys/fs/cgroup:ro --privileged --rm -ti --name=front --link=db:db nms-front`
+
+-- getting to prompt(without cgroup):
+`docker run -v "/home/kiro/repos/tgmanage:/srv/tgmanage" -v "/home/kiro/repos/tgmanage/nms/.bashrc:/root/.bashrc" -w "/srv/tgmanage/web/nms.gathering.org" \
+-rm=true -ti --name=front --privileged nms-front /bin/bash`
+- Find IP's:
+`docker inspect nms-db | grep "IPAddress\":"`
+`docker inspect nms-front | grep "IPAddress\":"`
+- Open the nms-front ip in the web browser.
+http://172.17.0.2:8080/
-## TODO
-- finish the installation guide above.
diff --git a/nms/config.pm b/nms/config.pm
index faaeaa1..db9775f 100755
--- a/nms/config.pm
+++ b/nms/config.pm
@@ -6,9 +6,9 @@ package nms::config;
# DB
our $db_name = "nms";
-our $db_host = "db";
+our $db_host = "nms-dev-db.gathering.org";
our $db_username = "nms";
-our $db_password = "foobar";
+our $db_password = "nms-lol";
# NMS hash used for public NMS obfuscation of interface names
our $nms_hash = "<removed>";
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()) {
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..0d3f2b4
--- /dev/null
+++ b/web/nms.gathering.org/api/private/which-switch-am-i-on
@@ -0,0 +1,40 @@
+#! /usr/bin/perl
+# vim:ts=8:sw=8
+
+use lib '../../../../include';
+use nms::web;
+use strict;
+use warnings;
+use Data::Dumper;
+
+#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();
+
+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};
+
+# add start html: header + body etc.
+print "
+<html>
+ <body style=\"text-align: center; font-size: 50pt;\">
+";
+
+# print address
+print "" . $addr ."<br \>";
+
+# print switch name and distroname.
+while ( my $ref = $query->fetchrow_hashref() ) {
+ print $ref->{sysname}. " @ " . $ref->{distro};
+}
+
+# add end html
+print "
+ </body>
+</html>
+";
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');
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";
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();
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()