From 77c172b823b64ebface655681ab0749b9d2f7081 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Benencia?= Date: Fri, 13 Apr 2018 16:30:31 -0700 Subject: First public commit --- web/js/local.js | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 web/js/local.js (limited to 'web/js/local.js') diff --git a/web/js/local.js b/web/js/local.js new file mode 100644 index 0000000..1272d0d --- /dev/null +++ b/web/js/local.js @@ -0,0 +1,117 @@ +/* + Copyright 2018 ThousandEyes Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +'use strict'; + +$(document).ready(function () { + $('#systems').hide() + updateHostnames(); + updateEventHistory(); + $('#target').on('change', scriptSelection); + + window.setTimeout(function () { + $('.alert').fadeTo(1000, 0).slideUp(1000, function () { + $(this).remove(); + }); + }, 3000); +}); + +window.setInterval(updateHostnames, 5000); +window.setInterval(updateEventHistory, 5000); + +function updateHostnames() { + $.getJSON('/ajax/servers', function (systems) { + var macs = $('#mac'); + var selection = $('select[name="mac"]').find('option:selected').text(); + macs.empty(); + + if (systems.length == 0) { + $('#systems').fadeOut(500); + $('#loading').fadeIn(500); + } else { + $('#loading').hide(500); + $('#systems').removeClass('hide'); + $('#systems').fadeIn(500); + + $.each(systems, function () { + var system_str = this.Mac + ' - ' + this.IP; + if (this.Hostname != '') { + system_str += ' - ' + this.Hostname; + } + macs.append(''); + }); + + $('#mac option').filter(function () { + //may want to use $.trim in here + return $(this).text() == selection; + }).prop('selected', true); + } + }); +} + +function scriptSelection() { + var paramsElems = $('.params-container'); + var option = $('select[name="target"]').find('option:selected'); + var script = $(option).data('script'); + var env = $(option).data('env'); + + if (!script || script.length === 0) { + paramsElems.empty(); + } else { + $.get('/ajax/script/params', { + 'script': script, + 'environment': env + }, function (params) { + paramsElems.empty(); + $.each(params, function () { + paramsElems.append('
' + + ' ' + + '
'); + }); + paramsElems.append(''); + }); + } +} + +function updateEventHistory() { + var eventLogContainer = $('.event-log'); + $.get('/ajax/events', function (events) { + if (!events) { + return; + } + eventLogContainer.empty(); + for (var mac in events) { + var title = mac; + if (events[mac][0].host != '') { + var host = events[mac][0].server.Hostname; + if (host == '') host = events[mac][0].server.IP; + title += ' (' + host + ')'; + } + var elem = eventLogContainer.append('
' + title + '
    '); + + $.each(events[mac], function () { + var date = (new Date(this.date)).toLocaleString(); + var params = ""; + for (var p in this.params) { + params += p + ':' + this.params[p] + ' '; + } + elem.append('
  • ' + date + ': ' + this.message + '
  • '); + }); + + eventLogContainer.append('
'); + } + }); +} -- cgit v1.2.3