From 4dccdb55e6999db79a7cedd46cd1a94e7582998d Mon Sep 17 00:00:00 2001 From: phamt Date: Thu, 14 Apr 2011 16:07:25 +0000 Subject: [PATCH] Enable monitoring plugin to be turned on or off, 1-click monitoring. git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@9314 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-UI/js/monitor/monitor.js | 65 ++++++++++++++++++++++++++++++++--- 1 file changed, 61 insertions(+), 4 deletions(-) diff --git a/xCAT-UI/js/monitor/monitor.js b/xCAT-UI/js/monitor/monitor.js index d161b14df..4e2405701 100644 --- a/xCAT-UI/js/monitor/monitor.js +++ b/xCAT-UI/js/monitor/monitor.js @@ -100,11 +100,11 @@ function loadMonitorPage() { // Set button to correct status if (statusHash[name] == 'On') { - statusButton.append($('')); - statusButton.append($('')); + statusButton.append($('')); + statusButton.append($('')); } else { - statusButton.append($('')); - statusButton.append($('')); + statusButton.append($('')); + statusButton.append($('')); } statusButton.find('label').css({ @@ -114,6 +114,9 @@ function loadMonitorPage() { 'width': 'auto' }); statusButton.buttonset(); + + // Turn on or off monitoring tool when clicked + statusButton.find('input["' + name + '"]:radio').change(toggleMonitor); } var monTable = $('
'); @@ -279,4 +282,58 @@ function loadUnfinish(monitorName, tab) { var unfinishPage = $('
'); unfinishPage.append(createInfoBar('Under construction')); tab.add(monitorName, 'Unfinished', unfinishPage, true); +} + +/** + * Turn on or off monitoring tool + * + * @return Nothing + */ +function toggleMonitor() { + // Get the name of the monitoring tool + var name = $(this).attr('name'); + // Get the status to toggle to, either on or off + var status = $(this).val(); + + // Start or stop monitoring plugin + var command = 'monstart'; + if (status == 'Off') { + command = 'monstop' ; + } + + $.ajax( { + url : 'lib/cmd.php', + dataType : 'json', + data : { + cmd : command, + tgt : '', + args : name + ';-r', + msg : name + ' switched ' + status + }, + success : updateMonStatus + }); +} + +/** + * Update the monitoring status on Monitor tab + * + * @param data + * Data returned from HTTP request + * @return Nothing + */ +function updateMonStatus(data) { + var rsp = data.rsp[data.rsp.length-1]; + var msg = data.msg; + + // Create appropriate info or warning bar + var bar = ''; + if (rsp.indexOf('started') > -1 || rsp.indexOf('stopped') > -1) { + bar = createInfoBar(msg); + } else { + var bar = createWarnBar('Failed to ' + msg + '. ' + rsp); + } + + // Prepend info or warning bar to tab + bar.prependTo($('#monitorTab .form')); + bar.delay(4000).slideUp(); } \ No newline at end of file