Commit f69d5750 authored by Olav Kvittem's avatar Olav Kvittem
Browse files

configopplegg fra otto

parents 6abb3288 605479df
#
# Default Microdep Map config file
#
dragonlab:
# Measuremet network/variant parameters
title: "Dragonlab"
types:
# Event types for variant
gap_summary:
title: "Gap summary"
gaps:
title: "Gaps"
# Relevant data field for event type
vars:
unavail:
title: "Unavaiability"
unit: "ppm"
time:
title: "Time lost (ms)"
unit: "ms"
es_field: "tloss"
queue:
title: "Queue"
unit: "ms"
es_field: "h_ddelay"
jitter:
title: "Jitter"
unit: "ms"
min_delay:
title: "Min delay"
unit: "ms"
slope:
title: "Slope"
queues:
title: "Queues"
route_summary:
title: "Route summary"
vars:
routes_analysed:
title: "Routes failed"
es_field: "routes_failed"
routes_failed:
title: "Routes failed"
es_field: "routes_failed"
routes_reached:
title: "Routes completed"
es_field: "routes_reached"
min_length:
title: "Min length"
es_field: "min_length"
max_length:
title: "Max length"
es_field: "Max_length"
route_errors:
title: "Route errors"
uninett:
title: "Uninett"
......@@ -3,15 +3,15 @@
<head>
<!-- Bootstrap core CSS -->
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="/uninett-bootstrap-theme/css/bootstrap.min.css">
<!-- <link rel="stylesheet" href="/uninett-bootstrap-theme/css/bootstrap.min.css"> -->
<!-- Custom styles for this template -->
<link rel="stylesheet" href="/uninett-theme/css/uninett.css">
<!-- <link rel="stylesheet" href="/uninett-theme/css/uninett.css"> -->
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<!-- Bootstrap core JavaScript -->
<!-- Placed at the end of the document so the pages load faster -->
<script type="text/javascript" src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script type="text/javascript" src="/uninett-bootstrap-theme/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/uninett-bootstrap-theme/js/holder.js"></script>
<!-- <script type="text/javascript" src="/uninett-bootstrap-theme/js/bootstrap.min.js"></script> -->
<!-- <script type="text/javascript" src="/uninett-bootstrap-theme/js/holder.js"></script> -->
<!-- empty meta method in autohandler -->
......@@ -220,6 +220,8 @@ var loads=0; // number of loaded point series
var duplines=[];
var points_cache=[];
var conffile=[]; //Config file loaded initially
function fill_select(select_id, types){
var select = $("#".select_id);
select.empty();
......@@ -1665,195 +1667,223 @@ function hhmmss(d){
// initialization
$(document).ready ( function(){
parms=get_parms( );
if ( parms.net){
$("#network").val(parms.net);
} else {
parms.net = $("#network").val();
}
if (parms.event) $("#event_type").val(parms.event);
if (parms.period) $("#period").val(parms.period);
prop_names = prop_names_list[ $("#event_type").val() ];
make_prop_select("prop_select", prop_names );
$.ajaxSetup({
beforeSend:function(){
// show image here
$("#busy").show();
},
complete:function(){
// hide image here
$("#busy").hide();
}
});
// draw inital network
/* just just use trigger
show_network(parms.net);
get_connections();
links_on=true;
*/
// establish date picker
$( "#datepicker" ).datepicker({dateFormat: "yy-mm-dd", "defaultDate": -1, "firstDay": 1 });
var dato;
if ( parms.date)
dato=parms.date;
else
dato="-1d";
$("#datepicker").datepicker('setDate', dato)
.on("change", function() {
get_topology();
get_connections();
});
// OJW 2021-12-09 BEGIN CONFIG FILE LOAD
// Fetch config info and initialize page
$.getJSON( "yaml-to-json.cgi?inputfile=mapconfig.yml", function(read_conffile) {
if (Object.keys(read_conffile).length > 0) {
console.log("Config file non-empty: " + read_conffile.msg);
conffile = read_conffile.config;
// Remove default measurement variants from select list
$("#network").empty();
for (const mvar in conffile) {
// Add option for measurement variant
$("#network").append("<option value=" + mvar + ">" + conffile[mvar].title + "</option>");
}
//Select first measurement variant in list
$("#network option:eq(0)").prop("selected", true);
// $("#network").selectmenu("refresh");
}
//$("#period").select2();
$("#period").change( function(){
get_connections();
$("#period_input").val('00:00');
});
$("#period_input").change( function(){
$("#period").val(1); // hour
get_connections();
});
// OJW 2021-12-09 CONTINUES AT END OF "document ready"
parms=get_parms( );
/* does not work
$("#period_input").on('mousewheel', function(e, delta){
console.log( "delta " + delta);
});
*/
//$("#period_input").hide();
// buttons to navigate days
$("#prev").click( function(){change_date(-1); } );
$("#next").click( function(){change_date(+1)} );
$("#live").click( function(){
if ( refresh_active){
clearInterval();
refresh_active=false;
$(this).css("background-color", active_color);
if ( parms.net){
$("#network").val(parms.net);
} else {
refresh_active=true;
$("#datepicker").datepicker('setDate', new Date());
parms.net = $("#network").val();
}
if (parms.event) $("#event_type").val(parms.event);
if (parms.period) $("#period").val(parms.period);
prop_names = prop_names_list[ $("#event_type").val() ];
make_prop_select("prop_select", prop_names );
$.ajaxSetup({
beforeSend:function(){
// show image here
$("#busy").show();
},
complete:function(){
// hide image here
$("#busy").hide();
}
});
// draw inital network
/* just just use trigger
show_network(parms.net);
get_connections();
links_on=true;
*/
// establish date picker
$( "#datepicker" ).datepicker({dateFormat: "yy-mm-dd", "defaultDate": -1, "firstDay": 1 });
var dato;
if ( parms.date)
dato=parms.date;
else
dato="-1d";
$("#datepicker").datepicker('setDate', dato)
.on("change", function() {
get_topology();
get_connections();
});
//$("#period").select2();
$("#period").change( function(){
get_connections();
active_color=$(this).css("background-color");
$(this).css("background-color", refresh_color);
setInterval( function(){
$("#period_input").val('00:00');
});
$("#period_input").change( function(){
$("#period").val(1); // hour
get_connections();
});
/* does not work
$("#period_input").on('mousewheel', function(e, delta){
console.log( "delta " + delta);
});
*/
//$("#period_input").hide();
// buttons to navigate days
$("#prev").click( function(){change_date(-1); } );
$("#next").click( function(){change_date(+1)} );
$("#live").click( function(){
if ( refresh_active){
clearInterval();
refresh_active=false;
$(this).css("background-color", active_color);
} else {
refresh_active=true;
$("#datepicker").datepicker('setDate', new Date());
get_connections();
}, refresh_period );
}
} );
$("#search_input").keyup( function(){
var str = $("#search_input").val();
focus_links( str, 'flip' );
} );
// mechanism to flip network drawing
$("#draw").click( function () {
if ( links_on ){
active_color=$(this).css("background-color");
$(this).css("background-color", refresh_color);
setInterval( function(){
get_connections();
}, refresh_period );
}
} );
$("#search_input").keyup( function(){
var str = $("#search_input").val();
focus_links( str, 'flip' );
} );
// mechanism to flip network drawing
$("#draw").click( function () {
if ( links_on ){
remove_links(links);
links_on=false;
} else {
links_on=true;
focus_node="";
prop_names = prop_names_list[ $("#event_type").val() ];
make_prop_select("prop_select", prop_names );
get_connections();
// document.location.href =
removeParam( 'node');
}
});
// network change
$("#network").change( function(){
parms.net= $("#network").val();
remove_links(links);
links_on=false;
} else {
links_on=true;
focus_node="";
load_name_to_address();
show_network(parms.net);
get_topology();
update_url();
});
// event_type parameter change
$("#event_type").change( function(){
prop_names = prop_names_list[ $("#event_type").val() ];
//remove_links();
prop_names = prop_names_list[ $("#event_type").val() ];
make_prop_select("prop_select", prop_names );
get_connections();
// document.location.href =
removeParam( 'node');
update_url();
});
// select parameter change
$("#prop_select").change( function(){
// remove_links(links);
// links=[];
//draw_links(summary, $("#prop_select").val() );
taint_links(summary, $("#prop_select").val() );
update_url();
});
// select parameter change
fill_select( "stats_type", stats_types );
$("#stats_type").change( function(){
summary=digest_aggregates(aggregates, $("#stats_type").val());
taint_links(summary, $("#prop_select").val() );
update_url();
});
// draw network at startup if focus on node
if ( parms.node){
focus_node=parms.node;
get_connections();
// draw_links(summary, $("#prop_select").val() );
links_on=true;
}
});
// network change
$("#network").change( function(){
parms.net= $("#network").val();
remove_links(links);
load_name_to_address();
show_network(parms.net);
get_topology();
update_url();
});
// event_type parameter change
$("#event_type").change( function(){
prop_names = prop_names_list[ $("#event_type").val() ];
//remove_links();
prop_names = prop_names_list[ $("#event_type").val() ];
make_prop_select("prop_select", prop_names );
get_connections();
update_url();
});
// select parameter change
$("#prop_select").change( function(){
// remove_links(links);
// links=[];
//draw_links(summary, $("#prop_select").val() );
taint_links(summary, $("#prop_select").val() );
update_url();
});
// select parameter change
fill_select( "stats_type", stats_types );
$("#stats_type").change( function(){
summary=digest_aggregates(aggregates, $("#stats_type").val());
taint_links(summary, $("#prop_select").val() );
update_url();
});
// draw network at startup if focus on node
if ( parms.node){
focus_node=parms.node;
get_connections();
// draw_links(summary, $("#prop_select").val() );
links_on=true;
}
$("#check").click( function(){check_asymmetry()} );
// read coordinates
document.getElementById("mapid").addEventListener("contextmenu", function (event) {
// Prevent the browser's context menu from appearing
event.preventDefault();
// Add marker
// L.marker([lat, lng], ....).addTo(map);
alert(lat.toFixed(5) + ', ' + lng.toFixed(5));
$("#check").click( function(){check_asymmetry()} );
return false; // To disable default popup.
});
// buttons for networks
/* replaced by select network
var base = window.location.protocol + "//" + window.location.hostname + window.location.pathname;
document.getElementById('refs').innerHTML = '<button onclick=location.href="' +
fix_url( base, "net", "uninett" ) + '"> Uninett </button> '
+ '<button onclick=location.href="' +
fix_url( base, "net", "dragonlab" ) + '"> Dragonlab </button> ';
*/
$( "#missing" ).dialog({ autoOpen: false, minWidth: 800 });
// catch focus on
$("#mapid").on('click', "a.trigger", function(e){
var node=e.target.id;
focus_links( node, 'flip' )
// read coordinates
document.getElementById("mapid").addEventListener("contextmenu", function (event) {
// Prevent the browser's context menu from appearing
event.preventDefault();
// Add marker
// L.marker([lat, lng], ....).addTo(map);
alert(lat.toFixed(5) + ', ' + lng.toFixed(5));
return false; // To disable default popup.
});
// buttons for networks
/* replaced by select network
var base = window.location.protocol + "//" + window.location.hostname + window.location.pathname;
document.getElementById('refs').innerHTML = '<button onclick=location.href="' +
fix_url( base, "net", "uninett" ) + '"> Uninett </button> '
+ '<button onclick=location.href="' +
fix_url( base, "net", "dragonlab" ) + '"> Dragonlab </button> ';
*/
$( "#missing" ).dialog({ autoOpen: false, minWidth: 800 });
// catch focus on
$("#mapid").on('click', "a.trigger", function(e){
var node=e.target.id;
focus_links( node, 'flip' )
});
$("#network").trigger("change"); // draw the map
//OJW 2021-12-09 CONTINUED CONFIG FILE LOAD
})
.fail( function(e, textStatus, error ) {
// Config not avaiable
console.log("Failed to get conf.json :" + textStatus + ", " + error);
});
$("#network").trigger("change"); // draw the map
//OJW 2021-12-09 END CONFIG FILE LOAD
});
</script>
......
yaml-to-json.pl
\ No newline at end of file
#!/usr/bin/perl
#
# Return JSON object of YAML file specified
#
# yaml-to-json.cgi?file=<config-file.yml>
#
# Author: Otto J Wittner
# Email: otto.wittner@uninett.no
# Date: 2021-12-09
#
# Copyright: Uninett AS
#
use strict;
use warnings;
use Getopt::Long; # Commandline argument parser
#use Time::Piece; # Date and time string parsing
#use DateTime;
#use DateTime::Format::ISO8601;
#use Search::Elasticsearch;
use Data::Dumper;
use CGI;
use URI;
use JSON;
use YAML;
# Filter duplicate from arrays
sub uniq {
my %seen;
grep !$seen{$_}++, @_;
}
use constant {
MODE_CLI => 'cli',
MODE_CGI => 'cgi',
};
# # M A I N T H R E A D # #
# Create default timestamp as current time in current time zone but yesterday
my %params = (
help => 0, # Flag for help text
inputfile => "mapconfig.yml", # Name of in put YAML-file
verbose => 0, # Flag for more output
mode => MODE_CLI # Script input/ouput mode (default commandline mode)
);
my %output = ( msg => "", config => ""); # Output hash.
my $restq = CGI->new; # Rest/CGI query object.
# Message to user
# params: message-string, exit-flag
sub msg {
my $msg = shift @_;
my $end = shift @_;
if ($params{'mode'} eq MODE_CGI ) {
# Output json respons
$output{'msg'} = $msg;
print $restq->header( -type => 'application/json');
print encode_json \%output, "\n" if ($end);
} else {
print $msg, "\n";
print "\n", Dumper($output{"config"}), "\n";
}
exit 0 if ($end);
}
my @scriptname = split /\//, $0;
if ($scriptname[-1] =~ /.*\.cgi/) {
# Default to CGI-mode since script has cgi extention
foreach my $key (keys %params) {
#Parse params as GET input parameters
$params{$key} = $restq->param($key) if defined($restq->param($key));
}
$params{'mode'} = MODE_CGI; # Force cgi mode
} else {
# Parse commandline
GetOptions (
"verbose" => \$params{'verbose'}, # flag
"help" => \$params{'help'}) # flag for help message
or die("Error in command line arguments\n");
my $num_args = $#ARGV + 1;
if ( $params{'help'} || $params{'mode'} eq MODE_CLI && $num_args lt 1 ) {
# Show usage info
print "Usage: $scriptname[-1] [-h] input-YAML-file
-h -help This help message.
-v -verbose Show more info in addition to url
";
exit 1;
}
if ($params{'mode'} eq MODE_CGI) {
if ( $num_args ge 1) {
# Extracts params from first argument assuming HTTP GET key/value format
my $uri = URI->new("http://dummy.no/?" . $ARGV[0]);
my %query = $uri->query_form;
foreach my $key (keys %params) {
#Parse params as GET input parameters
$params{$key} = $query{$key} if defined($query{$key});
}
$params{'mode'} = MODE_CGI; # Ensure cgi mode is still set
} else {
msg ('Error: Invalid no of arguments.', 1);
}
} else {
# Store mandatory arguments
$params{'inputfile'} = $ARGV[0];
}
}
#print Dumper(%params);
if (my $yaml_hash = YAML::LoadFile($params{"inputfile"})) {