diff options
Diffstat (limited to 'web')
-rwxr-xr-x | web/api/public/distro-tree | 8 | ||||
-rwxr-xr-x | web/api/public/switches | 7 | ||||
-rwxr-xr-x | web/api/read/distro-management | 31 | ||||
-rwxr-xr-x | web/api/read/networks | 15 | ||||
-rwxr-xr-x | web/api/read/oplog | 9 | ||||
-rwxr-xr-x | web/api/read/switches-management | 27 | ||||
-rwxr-xr-x | web/api/read/template-list | 8 | ||||
-rwxr-xr-x | web/api/write/linknet-add | 32 | ||||
-rwxr-xr-x | web/api/write/network-add | 49 | ||||
-rwxr-xr-x | web/api/write/networks (renamed from web/api/write/network-update) | 21 | ||||
-rwxr-xr-x | web/api/write/switch-add | 94 | ||||
-rwxr-xr-x | web/api/write/switches (renamed from web/api/write/switch-update) | 2 | ||||
-rw-r--r-- | web/index.html | 31 | ||||
-rw-r--r-- | web/js/nms-info-box.js | 20 | ||||
-rw-r--r-- | web/js/nms-map-handlers.js | 150 | ||||
-rw-r--r-- | web/js/nms-map.js | 3 | ||||
-rw-r--r-- | web/js/nms-time.js | 6 | ||||
-rw-r--r-- | web/js/nms.js | 11 |
18 files changed, 188 insertions, 336 deletions
diff --git a/web/api/public/distro-tree b/web/api/public/distro-tree index cff35ec..49ce607 100755 --- a/web/api/public/distro-tree +++ b/web/api/public/distro-tree @@ -10,16 +10,18 @@ use strict; use warnings; use Data::Dumper; -$nms::web::cc{'max-age'} = "20"; +$nms::web::cc{'max-age'} = "5"; +$nms::web::cc{'stale-while-revalidate'} = "30"; my $q2 = $nms::web::dbh->prepare('select sysname,distro_phy_port,distro_name from switches where placement is not null and distro_name is not null and distro_phy_port is not null and deleted = false'); $q2->execute(); while (my $ref = $q2->fetchrow_hashref()) { my $sysname = $ref->{'sysname'}; - my $phy = $ref->{'distro_phy_port'}; my $distro = $ref->{'distro_name'}; - $nms::web::json{'distro-tree'}{$distro}{$phy} = $sysname; + my $phy = $ref->{'distro_phy_port'}; + $nms::web::json{'distro-tree-phy'}{$distro}{$phy} = $sysname; + $nms::web::json{'distro-tree-sys'}{$distro}{$sysname} = $phy; } finalize_output(); diff --git a/web/api/public/switches b/web/api/public/switches index 8e7f333..9bb63d8 100755 --- a/web/api/public/switches +++ b/web/api/public/switches @@ -29,11 +29,4 @@ while (my $ref = $q2->fetchrow_hashref()) { $nms::web::json{'switches'}{$ref->{'sysname'}}{'tags'} = $data; } -my $q4 = $nms::web::dbh->prepare('select linknet, (select sysname from switches where switch = switch1) as sysname1, (select sysname from switches where switch = switch2) as sysname2 from linknets'); - -$q4->execute(); -while (my $ref = $q4->fetchrow_hashref()) { - $nms::web::json{'linknets'}{$ref->{'linknet'}} = $ref; -} - finalize_output(); diff --git a/web/api/read/distro-management b/web/api/read/distro-management deleted file mode 100755 index 55ca07e..0000000 --- a/web/api/read/distro-management +++ /dev/null @@ -1,31 +0,0 @@ -#! /usr/bin/perl -# vim:ts=8:sw=8 - -use CGI qw(fatalsToBrowser); -use DBI; -use lib '/opt/gondul/include'; -use nms; -use nms::web; -use strict; -use warnings; -use Data::Dumper; - -my $target = $ENV{REQUEST_URI}; -$target =~ s/$ENV{SCRIPT_NAME}//; -$target =~ s/^\///; -my ($switch, $port) = split(/\//,$target,2); -my $q2; - -$nms::web::cc{'max-age'} = "5"; -$nms::web::cc{'stale-while-revalidate'} = "30"; - -$q2 = $nms::web::dbh->prepare('SELECT distro_name,sysname,distro_phy_port FROM switches WHERE placement is not null AND distro_name is not null AND distro_phy_port is not null and deleted = false'); - -$q2->execute(); -while (my $ref = $q2->fetchrow_hashref()) { - my $sysname = $ref->{'sysname'}; - my $distro = $ref->{'distro_name'}; - $nms::web::json{'distros'}{$distro}{$sysname} = $ref; -} - -finalize_output(); diff --git a/web/api/read/networks b/web/api/read/networks index 870ae8c..0fbdb15 100755 --- a/web/api/read/networks +++ b/web/api/read/networks @@ -13,23 +13,12 @@ use Data::Dumper; $nms::web::cc{'max-age'} = "5"; $nms::web::cc{'stale-while-revalidate'} = "30"; -my $q2 = $nms::web::dbh->prepare('select network, name, vlan, tags, routing_point, placement, last_updated, subnet4, subnet6, gw4, gw6 from networks'); +my $q2 = $nms::web::dbh->prepare('select name, vlan, networks.tags, switches.sysname as router, subnet4, subnet6, gw4, gw6 from networks left join switches on switches.switch = networks.router'); $q2->execute(); while (my $ref = $q2->fetchrow_hashref()) { - $ref->{'placement'} =~ /\((-?\d+),(-?\d+)\),\((-?\d+),(-?\d+)\)/; - my ($x1, $y1, $x2, $y2) = ($1, $2, $3, $4); my $name = $ref->{'name'}; - $nms::web::json{'networks'}{$ref->{'name'}}{'vlan'} = $ref->{'vlan'}; - $nms::web::json{'networks'}{$ref->{'name'}}{'subnet4'} = $ref->{'subnet4'}; - $nms::web::json{'networks'}{$ref->{'name'}}{'subnet6'} = $ref->{'subnet6'}; - $nms::web::json{'networks'}{$ref->{'name'}}{'gw4'} = $ref->{'gw4'}; - $nms::web::json{'networks'}{$ref->{'name'}}{'gw6'} = $ref->{'gw6'}; - $nms::web::json{'networks'}{$ref->{'name'}}{'placement'}{'x'} = $x2; - $nms::web::json{'networks'}{$ref->{'name'}}{'placement'}{'y'} = $y2; - $nms::web::json{'networks'}{$ref->{'name'}}{'placement'}{'width'} = $x1 - $x2; - $nms::web::json{'networks'}{$ref->{'name'}}{'placement'}{'height'} = $y1 - $y2; - $nms::web::json{'networks'}{$ref->{'name'}}{'routing_point'} = $ref->{'routing_point'}; + $nms::web::json{'networks'}{$ref->{'name'}} = $ref; my $data = JSON::XS::decode_json($ref->{'tags'}); $nms::web::json{'networks'}{$ref->{'name'}}{'tags'} = $data; } diff --git a/web/api/read/oplog b/web/api/read/oplog index fb187ea..f2ed3a7 100755 --- a/web/api/read/oplog +++ b/web/api/read/oplog @@ -6,7 +6,14 @@ use nms::web; use strict; use warnings; -my $query = $nms::web::dbh->prepare('select id,date_trunc(\'second\',time) as timestamp,extract(hour from time) as h, extract(minute from time) as m,systems,username,log from oplog order by id desc;'); +my $filter = ''; + +if (defined($get_params{'now'})) { + $filter = "where time < timestamp with time zone 'epoch' + " . db_safe_quote('now') . " * INTERVAL '1 second' "; +} +my $query = $nms::web::dbh->prepare('select id,date_trunc(\'second\',time) as timestamp,extract(hour from time) as h, extract(minute from time) as m,systems,username,log from oplog ' + . $filter . +'order by id desc;'); $query->execute(); while (my $ref = $query->fetchrow_hashref()) { my %meh; diff --git a/web/api/read/switches-management b/web/api/read/switches-management index b42c84b..118ea4d 100755 --- a/web/api/read/switches-management +++ b/web/api/read/switches-management @@ -25,23 +25,28 @@ my $q2; $nms::web::cc{'max-age'} = "5"; $nms::web::cc{'stale-while-revalidate'} = "30"; -if (!defined($switch)) { - $q2 = $nms::web::dbh->prepare('select switches.sysname, host(switches.mgmt_v4_addr) as mgmt_v4_addr, host(switches.mgmt_v6_addr) as mgmt_v6_addr, switches.mgmt_vlan, switches.traffic_vlan, switches.poll_frequency, switches.last_updated, switches.distro_name, switches.distro_phy_port, switches.community, traffic_net.subnet4, traffic_net.subnet6, host(mgmt_net.gw4) as mgmt_v4_gw, host(mgmt_net.gw6) as mgmt_v6_gw from switches left join networks as traffic_net on (switches.traffic_vlan = traffic_net.name) left join networks as mgmt_net on (switches.mgmt_vlan = mgmt_net.name) where switches.placement is not null and switches.deleted = false;'); -} else { - $q2 = $nms::web::dbh->prepare('select sysname,host(mgmt_v4_addr) as mgmt_v4_addr,host(mgmt_v6_addr) as mgmt_v6_addr,mgmt_vlan,traffic_vlan,poll_frequency,last_updated,distro_name,distro_phy_port,community from switches where placement is not null and sysname = ' . $nms::web::dbh->quote($switch) . ' and switches.deleted = false;'); +my $limit = ''; +if (defined($switch)) { + $limit = ' and sysname = ' . $nms::web::dbh->quote($switch); } +$q2 = $nms::web::dbh->prepare("select + switches.sysname, + host(switches.mgmt_v4_addr) as mgmt_v4_addr, + host(switches.mgmt_v6_addr) as mgmt_v6_addr, + switches.mgmt_vlan, + switches.traffic_vlan, + switches.poll_frequency, + switches.last_updated, + switches.distro_name, + switches.distro_phy_port, + switches.community + from switches where switches.placement is not null and switches.deleted = false $limit;"); + $q2->execute(); while (my $ref = $q2->fetchrow_hashref()) { my $sysname = $ref->{'sysname'}; $nms::web::json{'switches'}{$ref->{'sysname'}} = $ref; } -my $q4 = $nms::web::dbh->prepare('select linknet, (select sysname from switches where switch = switch1) as sysname1, addr1, (select sysname from switches where switch = switch2) as sysname2,addr2 from linknets'); - -$q4->execute(); -while (my $ref = $q4->fetchrow_hashref()) { - $nms::web::json{'linknets'}{$ref->{'linknet'}} = $ref; -} - finalize_output(); diff --git a/web/api/read/template-list b/web/api/read/template-list index d1c8773..81b9986 100755 --- a/web/api/read/template-list +++ b/web/api/read/template-list @@ -6,10 +6,10 @@ use nms::web; use strict; use warnings; -my $template_dir = "/opt/gondul/web/templates"; - -opendir (DIR, $template_dir) or die $!; +my @dirs = ("/opt/gondul/web/templates","/opt/gondul/data/templates"); +foreach my $template_dir (@dirs) { +opendir (DIR, $template_dir) or next; while (my $file = readdir(DIR)) { next if ($file =~ m/^\./); my %meh; @@ -17,5 +17,5 @@ while (my $file = readdir(DIR)) { push @{$nms::web::json{'templates'}},\%meh; } - +} nms::web::finalize_output(); diff --git a/web/api/write/linknet-add b/web/api/write/linknet-add deleted file mode 100755 index 13ccd17..0000000 --- a/web/api/write/linknet-add +++ /dev/null @@ -1,32 +0,0 @@ -#! /usr/bin/perl -# vim:ts=8:sw=8 -use lib '/opt/gondul/include'; -use utf8; -use nms::web qw($dbh db_safe_quote get_input finalize_output); -use strict; -use warnings; - -my $in = get_input(); -my %tmp = %{JSON::XS::decode_json($in)}; - -my $q = $nms::web::dbh->prepare("INSERT INTO linknets (switch1, switch2) VALUES((SELECT switch FROM switches WHERE sysname = ? LIMIT 1), (SELECT switch FROM switches WHERE sysname = ? LIMIT 1));"); -my $sth = $nms::web::dbh->prepare("SELECT linknet FROM linknets WHERE switch1 = (SELECT switch FROM switches WHERE sysname = ? LIMIT 1) and switch2 = (SELECT switch FROM switches WHERE sysname = ? LIMIT 1);"); - -$sth->execute($tmp{'switch1'}, $tmp{'switch2'}); -my $affected = 0; -while ( my @row = $sth->fetchrow_array ) { - $affected += 1; -} - -print "X-affected: $affected\n"; -if ($affected eq 0) { - $q->execute($tmp{'switch1'}, $tmp{'switch2'}); -} - -$dbh->commit; -$nms::web::cc{'max-age'} = '0'; -$nms::web::cc{'stale-while-revalidate'} = '0'; -$nms::web::json{'state'} = 'ok'; - -print "X-ban: /api/public/.*\n"; -finalize_output(); diff --git a/web/api/write/network-add b/web/api/write/network-add deleted file mode 100755 index d1aab4e..0000000 --- a/web/api/write/network-add +++ /dev/null @@ -1,49 +0,0 @@ -#! /usr/bin/perl -# vim:ts=8:sw=8 - -#use CGI qw(fatalsToBrowser); -use DBI; -use lib '/opt/gondul/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; -use nms::oplog qw(oplog); - -$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 name FROM networks WHERE name=?"); - -foreach my $tmp2 (@tmp) { - my %network = %{$tmp2}; - my $affected = 0; - my %template = (); - if (not defined($network{'name'})) { - next; - } - - $sth->execute( $network{'name'}); - while ( my @row = $sth->fetchrow_array ) { - $affected += 1; - } - - if ($affected == 0) { - $nms::web::dbh->do("INSERT INTO NETWORKS (name) VALUES ('$network{'name'}');"); - push @added, $network{'name'}; - oplog("\"" . $network{'name'} . "\"", "Network added: " . $network{'name'}); - } -} - -$json{'networks_addded'} = \@added; - -print "X-ban: /api/.*\n"; -finalize_output(); diff --git a/web/api/write/network-update b/web/api/write/networks index 6344c37..460a7ae 100755 --- a/web/api/write/network-update +++ b/web/api/write/networks @@ -6,7 +6,6 @@ use DBI; use lib '/opt/gondul/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; @@ -23,7 +22,7 @@ my @dups; my $sth = $nms::web::dbh->prepare("SELECT name FROM networks WHERE name=?"); -my @fields = ('name','last_updated','subnet4','subnet6','gw4','gw6','routing_point','vlan','tags'); +my @fields = ('name','subnet4','subnet6','gw4','gw6','router','vlan','tags'); foreach my $tmp2 (@tmp) { my %network = %{$tmp2}; @@ -47,8 +46,16 @@ foreach my $tmp2 (@tmp) { } } keys %network; - - $nms::web::dbh->do("INSERT INTO NETWORKS (name, last_updated, subnet4, subnet6, routing_point, gw4, gw6, vlan, tags) VALUES ($template{'name'}, $template{'last_updated'}, $template{'subnet4'}, $template{'subnet6'}, $template{'routing_point'}, $template{'gw4'}, $template{'gw6'}, $template{'vlan'}, $template{'tags'});"); + if ($template{'router'} ne 'DEFAULT') { + $template{'router'} = "(select switch from switches where sysname = $template{'router'})"; + } + if ($template{'gw4'} eq 'DEFAULT' and $template{'subnet4'} ne 'DEFAULT') { + $template{'gw4'} = "host(inet $template{'subnet4'} + 1)"; + } + if ($template{'gw6'} eq 'DEFAULT' and $template{'subnet6'} ne 'DEFAULT') { + $template{'gw6'} = "host(inet $template{'subnet6'} + 1)"; + } + $nms::web::dbh->do("INSERT INTO NETWORKS (name, subnet4, subnet6, router, gw4, gw6, vlan, tags) VALUES ($template{'name'}, $template{'subnet4'}, $template{'subnet6'}, $template{'router'}, $template{'gw4'}, $template{'gw6'}, $template{'vlan'}, $template{'tags'});"); push @added, $network{'name'}; } else { if (defined($network{'tags'})) { @@ -57,7 +64,11 @@ foreach my $tmp2 (@tmp) { my @set; map { if (defined($template{$_})) { - push @set, "$_=" . $dbh->quote($network{$_}); + if ($_ eq "router") { + push @set, "router=(select switch from switches where sysname = " . $dbh->quote($network{$_}) . ")"; + } else { + push @set, "$_=" . $dbh->quote($network{$_}); + } } } keys %network; $nms::web::dbh->do("UPDATE networks SET " . join(", ", @set) . "WHERE name=" . $dbh->quote($network{'name'}) . ";"); diff --git a/web/api/write/switch-add b/web/api/write/switch-add deleted file mode 100755 index c92cf31..0000000 --- a/web/api/write/switch-add +++ /dev/null @@ -1,94 +0,0 @@ -#! /usr/bin/perl -# vim:ts=8:sw=8 - -#use CGI qw(fatalsToBrowser); -use DBI; -use lib '/opt/gondul/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; -use nms::oplog qw(oplog); - -$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 = ( 'community', 'distro_name', 'distro_phy_port', 'mgmt_v4_addr', 'mgmt_v6_addr', 'mgmt_vlan', 'placement', 'poll_frequency', 'sysname', 'traffic_vlan'); - -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 (mgmt_v4_addr, sysname, poll_frequency, community, mgmt_v6_addr, placement, distro_name) VALUES ($template{'mgmt_v4_addr'}, $template{'sysname'}, $template{'poll_frequency'}, $template{'community'}, $template{'mgmt_v6_addr'}, $template{'placement'}, $template{'distro_name'});"); - push @added, $switch{'sysname'}; - oplog("\"" . $switch{'sysname'} . "\"", "Switch added: " . $switch{'sysname'}); - } -} - -$json{'switches_addded'} = \@added; - -print "X-ban: /api/.*\n"; -finalize_output(); diff --git a/web/api/write/switch-update b/web/api/write/switches index bcf69e1..947404d 100755 --- a/web/api/write/switch-update +++ b/web/api/write/switches @@ -11,6 +11,7 @@ use strict; use warnings; use JSON; use Data::Dumper; +use nms::oplog qw(oplog); $nms::web::cc{'max-age'} = "0"; @@ -84,6 +85,7 @@ foreach my $tmp2 (@tmp) { $nms::web::dbh->do("INSERT INTO SWITCHES (ip, sysname, last_updated, locked, poll_frequency, tags, community, secondary_ip, placement,subnet4,subnet6,distro) VALUES ($template{'ip'}, $template{'sysname'}, $template{'last_updated'}, $template{'locked'}, $template{'poll_frequency'}, $template{'tags'}, $template{'community'}, $template{'secondary_ip'}, $template{'placement'},$template{'subnet4'},$template{'subnet6'},$template{'distro'});"); push @added, $switch{'sysname'}; + oplog("\"" . $switch{'sysname'} . "\"", "Switch added: " . $switch{'sysname'}); } else { if (defined($switch{'placement'})) { my %placement; diff --git a/web/index.html b/web/index.html index 62f50df..447772f 100644 --- a/web/index.html +++ b/web/index.html @@ -46,34 +46,21 @@ <span class="caret"></span> </a> <ul class="dropdown-menu" role="menu"> - <li class="gondul-is-private"><a href="#health" onclick="setUpdater(handler_health)">Health</a></li> - <li><a href="#ping" onclick="setUpdater(handler_ping)">Ping</a></li> - <li><a href="#uplink" onclick="setUpdater(handler_uplinks)">Uplink</a></li> - <li><a href="#dhcp" onclick="setUpdater(handler_dhcp)">DHCP</a></li> - <li><a href="#temp" onclick="setUpdater(handler_temp)">Temperature</a></li> - <li><a href="#traffic" onclick="setUpdater(handler_traffic)">Traffic</a></li> - <li><a href="#traffictot" onclick="setUpdater(handler_traffic_tot)">Total switch traffic</a></li> - <li class="gondul-is-private"><a href="#snmp" onclick="setUpdater(handler_snmp)">SNMP</a></li> - <li class="gondul-is-private"><a href="#cpu" onclick="setUpdater(handler_cpu)">CPU</a></li> - <li><a href="#disco" onclick="setUpdater(handler_disco)">DISCO</a></li> + <li class="gondul-is-private dropdown-header">Switches</li> + <li class="gondul-is-private"><a href="#" onclick="nmsInfoBox.showWindow('addSwitch')">Add switch</a></li> + <li class="gondul-is-private"><a href="#" onclick="nmsInfoBox.showWindow('addNetwork')">Add network</a></li> + <li class="gondul-is-private"><a href="#" onclick="nmsInfoBox.showWindow('listNetwork')">List networks</a></li> + <li class="gondul-is-private"><a href="#" onclick="nmsMap.moveSet(true);">Enable switch moving</a></li> + <li class="gondul-is-private"><a href="#" onclick="nmsMap.moveSet(false);">Disable switch moving</a></li> + <li class="gondul-is-private divider"> </li> <li class="divider"> </li> <li class="dropdown-header">Time</li> <li><a href="#" onclick="toggleLayer('nowPickerBox');nmsTime.startNowPicker();">Travel in time</a></li> <li><a href="#" onclick="nmsTime.replayEvent();" title="Replay from opening 120 minutes per second">Replay event</a></li> <li class="divider"> </li> <li class="dropdown-header">View</li> - <li><a href="#" onclick="toggleNightMode()">Toggle Night Mode</a></li> - <li><a href="#" onclick="toggleConnect()">Toggle linknets</a></li> <li><a href="#" onclick="nmsUi.toggleVertical()">Toggle vertical mode</a></li> <li class="divider"> </li> - <li class="gondul-is-private dropdown-header">Switches</li> - <li class="gondul-is-private"><a href="#" onclick="nmsMap.moveSet(true);">Enable switch moving</a></li> - <li class="gondul-is-private"><a href="#" onclick="nmsMap.moveSet(false);">Disable switch moving</a></li> - <li class="gondul-is-private"><a href="#" onclick="nmsInfoBox.showWindow('addSwitch')">Add switch</a></li> - <li class="gondul-is-private divider"> </li> - <li class="gondul-is-private"><a href="#" onclick="nmsInfoBox.showWindow('listNetwork')">List networks</a></li> - <li class="gondul-is-private"><a href="#" onclick="nmsInfoBox.showWindow('addNetwork')">Add network</a></li> - <li class="gondul-is-private divider"> </li> <li class="gondul-is-private dropdown-header">Inventory lists</li> <li class="gondul-is-private"><a href="#" onclick="nmsInfoBox.showWindow('inventoryListing','distro_name');">Distro names</a></li> <li class="gondul-is-private"><a href="#" onclick="nmsInfoBox.showWindow('inventoryListing','sysDescr')">System description</a></li> @@ -226,6 +213,10 @@ </tr> <tr> <td>9</td> + <td>View CPU map</td> + </tr> + <tr> + <td>0</td> <td>View Disco map</td> </tr> <tr> diff --git a/web/js/nms-info-box.js b/web/js/nms-info-box.js index ba6446d..c42c7ae 100644 --- a/web/js/nms-info-box.js +++ b/web/js/nms-info-box.js @@ -832,7 +832,7 @@ var switchAddPanel = function() { var myData = JSON.stringify(myData); $.ajax({ type: "POST", - url: "/api/write/switch-add", + url: "/api/write/switches", dataType: "text", data:myData, success: function (data, textStatus, jqXHR) { @@ -1092,7 +1092,7 @@ var switchEditPanel = function () { var myData = nmsInfoBox._editStringify(this.sw); $.ajax({ type: "POST", - url: "/api/write/switch-update", + url: "/api/write/switches", dataType: "text", data:myData, success: function (data, textStatus, jqXHR) { @@ -1112,7 +1112,7 @@ var switchEditPanel = function () { myData = JSON.stringify(myData); $.ajax({ type: "POST", - url: "/api/write/switch-update", + url: "/api/write/switches", dataType: "text", data:myData, success: function (data, textStatus, jqXHR) { @@ -1317,7 +1317,7 @@ var networkAddPanel = function() { var myData = JSON.stringify(myData); $.ajax({ type: "POST", - url: "/api/write/network-add", + url: "/api/write/networks", dataType: "text", data:myData, success: function (data, textStatus, jqXHR) { @@ -1355,7 +1355,7 @@ var networkListPanel = function() { var cell3 = row.insertCell(2); cell1.innerHTML = "<a href='#' onclick='nmsInfoBox.showWindow(\"networkInfo\",\""+net+"\");'>"+net+ '</a>'; cell2.innerHTML = networks[net].vlan; - cell3.innerHTML = networks[net].routing_point; + cell3.innerHTML = networks[net].router; } this._render(table); @@ -1401,14 +1401,9 @@ var networkEditPanel = function() { var tags; for (var v in net) { /* - * Placement and tags needs to be sent and edited + * Tags needs to be sent and edited * as plain JSON... */ - if (v == "placement") { - place = JSON.stringify(net[v]); - template[v] = place; - continue; - } if (v == "tags") { tags = JSON.stringify(net[v]); template[v] = tags; @@ -1482,7 +1477,7 @@ var networkEditPanel = function() { var myData = nmsInfoBox._editStringify(this.sw,"name"); $.ajax({ type: "POST", - url: "/api/write/network-update", + url: "/api/write/networks", dataType: "text", data:myData, success: function (data, textStatus, jqXHR) { @@ -1491,6 +1486,7 @@ var networkEditPanel = function() { nmsInfoBox.hide(); } nmsData.invalidate("switches"); + nmsData.invalidate("networks"); nmsData.invalidate("smanagement"); } }); diff --git a/web/js/nms-map-handlers.js b/web/js/nms-map-handlers.js index 9f0c548..90f6922 100644 --- a/web/js/nms-map-handlers.js +++ b/web/js/nms-map-handlers.js @@ -92,6 +92,11 @@ var handler_mgmt = { tag:"mgmt", name:"Management info" }; +var handler_net = { + getInfo:networkInfo, + tag:"net", + name:"Network info" +}; var handler_snmpup = { getInfo:snmpUpInfo, tag:"snmpup", @@ -131,6 +136,7 @@ var handlerInfo = function(tag,desc) { var handlers = [ handler_health, handler_mgmt, + handler_net, handler_uplinks, handler_temp, handler_ping, @@ -160,32 +166,34 @@ function uplinkInfo(sw) ret.data[0].description = "Uplinks (live/configured)"; if (nmsData.switches.switches[sw].subnet4 == undefined || nmsData.switches.switches[sw].subnet4 == null) { - if (tagged(sw,'3up')) { - known_t = 3; - } else if (tagged(sw,'2up')) { - known_t = 2; - } else if (tagged(sw, '1up')) { - known_t = 1; - } else if (tagged(sw,'4up')) { - known_t = 4; - } - if (known_t != t) { - ret.data[0].value += "(Overridden: " + known_t + ")"; - } - - if (u == known_t) { - ret.score = 0; - ret.why = "All uplinks up"; - } else if (u == 1) { - ret.score = 800; - ret.why = "Only 1 of " + known_t + " uplinks alive"; - } else if (u < known_t) { - ret.score = 450; - ret.why = u + " of " + known_t + " uplinks alive"; - } else if (u > known_t) { - ret.score = 350; - ret.why = u + " of " + known_t + " uplinks alive"; - } + if (tagged(sw,'3up')) { + known_t = 3; + } else if (tagged(sw,'2up')) { + known_t = 2; + } else if (tagged(sw, '1up')) { + known_t = 1; + } else if (tagged(sw,'4up')) { + known_t = 4; + } + if (known_t != t) { + ret.data[0].value += "(Overridden: " + known_t + ")"; + } + if (u == known_t) { + ret.score = 0; + ret.why = "All uplinks up"; + } else if (u == 1) { + ret.score = 800; + ret.why = "Only 1 of " + known_t + " uplinks alive"; + } else if (u < known_t && !(t >= 10 && u <5)) { + ret.score = 450; + ret.why = u + " of " + known_t + " uplinks alive"; + } else if (u > known_t) { + ret.score = 350; + ret.why = u + " of " + known_t + " uplinks alive"; + } else if (u < known_t && (t >= 10 && u < 5)) { + ret.score = 150; + ret.why = u + " of " + known_t + " uplinks alive (huge diff suggests WIP - downgrading)"; + } } } if (testTree(nmsData,['switchstate','switches',sw,'clients','total'])) { @@ -479,8 +487,12 @@ function pingInfo(sw) if (!(distro == "" || phy == "" || distro == undefined || phy == undefined)) { if (testTree(nmsData,['snmp','snmp',distro, 'ports',phy,'ifOperStatus'])) { var x = nmsData['snmp']['snmp'][distro]['ports'][phy]['ifOperStatus']; - var ping = parseFloat(nmsData["ping"]["switches"][sw]["latency4"]); - var ping6 = parseFloat(nmsData["ping"]["switches"][sw]["latency6"]); + var ping = "no"; + var ping6 = "no "; + try { + ping = parseFloat(nmsData["ping"]["switches"][sw]["latency4"]); + ping6 = parseFloat(nmsData["ping"]["switches"][sw]["latency6"]); + } catch(e) {} if (x == "up") { ret.data[3] = {}; ret.data[3].description = "Distro-port"; @@ -493,7 +505,8 @@ function pingInfo(sw) } } } catch(e) { - console.log("lol"); + console.log("Lazy about errors...."); + console.log(e); } } return ret; @@ -598,7 +611,7 @@ function dhcpInfo(sw) { if (testTree(nmsData,['switchstate','switches',sw,'clients','live'])) { var tu = parseInt(nmsData.switchstate.switches[sw].clients.live); var tt = parseInt(nmsData.switchstate.switches[sw].clients.total); - if (tu - dhcpClients > 5) { + if (tu - dhcpClients > 12) { if (ret.score < 450) { ret.score = 450; ret.why = "Far more client ports than dhcp clients"; @@ -868,20 +881,69 @@ function tagged(sw, tag) { return false; } +function networkInfo(sw) { + var ret = new handlerInfo("net","Network info"); + ret.score = 0; + ret.why = "All good"; + if (testTree(nmsData,['smanagement','switches',sw])) { + var i = 0; + var mg = nmsData.smanagement.switches[sw]; + var objs = [{ + d: "Management", + v: setTree(nmsData,['networks','networks',mg.mgmt_vlan],undefined) + },{ + d: "Traffic", + v: setTree(nmsData,['networks','networks',mg.traffic_vlan],undefined) + } + ]; + for (var x in objs) { + a = objs[x]; + if (a.v == undefined) { + ret.data[i++] = { + value: 'Not set', + description: a.d + ' network' + }; + continue; + } + + ret.data[i++] = { + value: a.v.name || "Not set", + description: a.d + " network" + } + ret.data[i++] = { + value: a.v.vlan || "Not set", + description: a.d + " vlan" + } + ret.data[i++] = { + value: a.v.subnet4 || "Not set", + description: a.d + " subnet IPv4" + } + ret.data[i++] = { + value: a.v.gw4 || "Not set", + description: a.d + " gw IPv4" + } + ret.data[i++] = { + value: a.v.subnet6 || "Not set", + description: a.d + " subnet IPv6" + } + ret.data[i++] = { + value: a.v.gw6 || "Not set", + description: a.d + " gw IPv6" + } + ret.data[i++] = { + value: a.v.router || "Not set", + description: a.d + " net router" + } + } + } + return ret; +} function mgmtInfo(sw) { var ret = new handlerInfo("mgmt","Management info"); ret.score = 0; ret.why = "All good"; if (testTree(nmsData,['smanagement','switches',sw])) { var mg = nmsData.smanagement.switches[sw]; - var traffic_vlan = "N/A"; - var mgmt_vlan = "N/A"; - if (testTree(nmsData,['networks','networks',mg.traffic_vlan,"vlan"])) { - traffic_vlan = nmsData["networks"]["networks"][mg.traffic_vlan]["vlan"]; - } - if (testTree(nmsData,['networks','networks',mg.mgmt_vlan,"vlan"])) { - mgmt_vlan = nmsData["networks"]["networks"][mg.mgmt_vlan]["vlan"]; - } ret.data = [{ value: mg.mgmt_v4_addr || "N/A", @@ -890,20 +952,8 @@ function mgmtInfo(sw) { value: mg.mgmt_v6_addr || "N/A", description: "Management IP (v6)" }, { - value: mg.subnet4 || "N/A", - description: "Subnet (v4)" - }, { - value: mg.subnet6 || "N/A", - description: "Subnet (v6)" - }, { value: mg.distro_name || "N/A", description: "Distro" - }, { - value: traffic_vlan || "N/A", - description: "Client VLAN" - }, { - value: mgmt_vlan || "N/A", - description: "Management VLAN" } ]; if ((mg.mgmt_v4_addr == undefined || mg.mgmt_v4_addr == "") && (mg.mgmt_v6_addr == undefined || mg.mgmt_v6_addr == "")) { diff --git a/web/js/nms-map.js b/web/js/nms-map.js index 1ebcf92..5927324 100644 --- a/web/js/nms-map.js +++ b/web/js/nms-map.js @@ -218,7 +218,7 @@ nmsMap.drawNow = function () } else { now = new Date(nmsData.now); //Date assumes UTC } - now = now.toString().split(' ').splice(1,4).join(' '); //Date returns local time + now = now.toString().split(' ').splice(0,5).join(' '); //Date returns local time if (nmsMap._lastNow == now) { nmsMap.stats.nowDups++; return; @@ -231,6 +231,7 @@ nmsMap.drawNow = function () ctx.clearRect(0,0,800,100); ctx.fillStyle = "white"; ctx.strokeStyle = "black"; + ctx.translate(200,0); ctx.lineWidth = nms.fontLineFactor; ctx.strokeText(now, this._settings.textMargin, 25); ctx.fillText(now, this._settings.textMargin, 25); diff --git a/web/js/nms-time.js b/web/js/nms-time.js index 30604cd..482cfa7 100644 --- a/web/js/nms-time.js +++ b/web/js/nms-time.js @@ -18,7 +18,7 @@ nmsTime.replayEvent = function() { var eStart = setTree(nmsData,["config","config","data","start"],"2018-03-23T00:00:00+0200"); nmsTime._stopTime = new Date(setTree(nmsData,["config","config","data","end"],"2018-04-01T14:30:00+0200")); nmsTime.setNow(eStart); - nmsTime.startPlayback(10); + nmsTime.startPlayback(60); } nmsTime.isRealTime = function() { @@ -135,7 +135,7 @@ nmsTime.startPlayback = function(speed) { return; } nmsTime._speed = speed; - nmsTime._handle = setInterval(nmsTime._tick,1000); + nmsTime._handle = setInterval(nmsTime._tick,2000); } nmsTime.togglePause = function() { @@ -145,7 +145,7 @@ nmsTime.togglePause = function() { if (nmsTime.isRealTime()) { nmsTime.setNow(Date.now()); } else { - nmsTime.startPlayback(nmsTime._speed ? nmsTime._speed : 5); + nmsTime.startPlayback(nmsTime._speed ? nmsTime._speed : 60); } } } diff --git a/web/js/nms.js b/web/js/nms.js index 62a148c..0422f00 100644 --- a/web/js/nms.js +++ b/web/js/nms.js @@ -77,10 +77,12 @@ var nms = { '8':setMapModeFromN, '9':setMapModeFromN, 'c':toggleConnect, + 'H':moveTimeFromKey, 'h':moveTimeFromKey, 'j':moveTimeFromKey, 'k':moveTimeFromKey, 'l':moveTimeFromKey, + 'L':moveTimeFromKey, 'p':moveTimeFromKey, 'r':moveTimeFromKey, 'o':toggleOplog, @@ -502,6 +504,9 @@ function setMapModeFromN(e,key) setUpdater(handler_snmp); break; case '9': + setUpdater(handler_cpu); + break; + case '0': setUpdater(handler_disco); break; } @@ -511,6 +516,9 @@ function setMapModeFromN(e,key) function moveTimeFromKey(e,key) { switch(key) { + case 'H': + nmsTime.stepKey(-1440); + break; case 'h': nmsTime.stepKey(-60); break; @@ -523,6 +531,9 @@ function moveTimeFromKey(e,key) case 'l': nmsTime.stepKey(60); break; + case 'L': + nmsTime.stepKey(1440); + break; case 'p': nmsTime.togglePause(); break; |