2012-05-04 00:54:58 +00:00
var globalNodesDetail = new Object ( ) ;
2010-08-26 05:27:11 +00:00
var globalAllNodesNum = 0 ;
var globalFinishNodesNum = 0 ;
2010-12-14 08:11:08 +00:00
var globalTimeStamp ;
2010-12-25 02:17:00 +00:00
var globalCondition = '' ;
var globalResponse = new Object ( ) ;
2010-08-26 05:27:11 +00:00
2011-06-01 03:00:03 +00:00
function loadRmcMon ( ) {
2012-05-04 00:54:58 +00:00
// Find the rmcmon tab
2011-06-01 03:00:03 +00:00
var rmcMonTab = $ ( '#rmcmon' ) ;
2010-08-04 08:49:20 +00:00
2012-05-04 00:54:58 +00:00
// Add the stauts bar first. id = 'rmcMonStatus'
2011-06-01 03:00:03 +00:00
var rmcStatusBar = createStatusBar ( 'rmcMonStatus' ) ;
rmcStatusBar . find ( 'div' ) . append ( createLoader ( ) ) ;
rmcMonTab . append ( rmcStatusBar ) ;
2012-05-04 00:54:58 +00:00
// Add the configure button
2011-06-01 03:00:03 +00:00
var configButton = createButton ( 'Configure' ) ;
configButton . hide ( ) ;
configButton . click ( function ( ) {
if ( $ ( '#rmcMonConfig' ) . is ( ':hidden' ) ) {
$ ( '#rmcMonConfig' ) . show ( ) ;
2011-09-12 16:10:53 +00:00
} else {
2011-06-01 03:00:03 +00:00
$ ( '#rmcMonConfig' ) . hide ( ) ;
}
} ) ;
rmcMonTab . append ( configButton ) ;
2012-05-04 00:54:58 +00:00
// Add configure div
2011-06-01 03:00:03 +00:00
rmcMonTab . append ( "<div id='rmcMonConfig'></div>" ) ;
$ ( '#rmcMonConfig' ) . hide ( ) ;
2012-05-04 00:54:58 +00:00
// Load the configure div's content
2011-06-01 03:00:03 +00:00
loadRmcMonConfigure ( ) ;
2012-05-04 00:54:58 +00:00
// Add the content of the rmcmon
rmcMonTab
. append ( "<div id='rmcMonShow'><div id='rmcmonSummary'></div><div id='rmcmonDetail'></div><div id='nodeDetail'></div></div>" ) ;
2011-06-01 03:00:03 +00:00
$ ( '#nodeDetail' ) . hide ( ) ;
2012-05-04 00:54:58 +00:00
// Check the software work status by platform (Linux and AIX)
2011-09-12 16:10:53 +00:00
$ . ajax ( {
2012-05-04 00:54:58 +00:00
url : 'lib/systemcmd.php' ,
dataType : 'json' ,
data : {
cmd : 'ostype'
2011-06-01 03:00:03 +00:00
} ,
2012-05-04 00:54:58 +00:00
success : rsctRpmCheck
2011-06-01 03:00:03 +00:00
} ) ;
2010-08-04 08:49:20 +00:00
}
2011-09-12 16:10:53 +00:00
function loadRmcMonConfigure ( ) {
2012-05-04 00:54:58 +00:00
// Get the configure div and clean its content
var rmcmonCfgDiv = $ ( '#rmcMonConfig' ) ;
rmcmonCfgDiv . empty ( ) ;
// Add the start button
var startButton = createButton ( 'Start' ) ;
rmcmonCfgDiv . append ( startButton ) ;
startButton . click ( function ( ) {
$ ( '#rmcMonStatus div' ) . empty ( ) . append ( createLoader ( ) ) ;
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'webrun' ,
tgt : '' ,
args : 'rmcstart;compute' ,
msg : ''
} ,
success : function ( data ) {
$ ( '#rmcMonStatus div' ) . empty ( ) . append ( data . rsp [ 0 ] ) ;
}
} ) ;
} ) ;
// Add the stop button
var stopButton = createButton ( 'Stop' ) ;
rmcmonCfgDiv . append ( stopButton ) ;
stopButton . click ( function ( ) {
$ ( '#rmcMonStatus div' ) . empty ( ) . append ( createLoader ( ) ) ;
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'monstop' ,
tgt : '' ,
args : 'rmcmon' ,
msg : ''
} ,
success : function ( data ) {
$ ( '#rmcMonStatus div' ) . empty ( ) . append ( data . rsp [ 0 ] ) ;
}
} ) ;
} ) ;
// Add the cancel button
var cancelButton = createButton ( 'Cancel' ) ;
rmcmonCfgDiv . append ( cancelButton ) ;
cancelButton . click ( function ( ) {
$ ( '#rmcMonConfig' ) . hide ( ) ;
} ) ;
2010-08-04 08:49:20 +00:00
}
2010-08-26 05:27:11 +00:00
2011-09-12 16:10:53 +00:00
function rsctRpmCheck ( data ) {
2012-05-04 00:54:58 +00:00
// Linux has to check the rscp first
if ( 'aix' != data . rsp ) {
$ . ajax ( {
url : 'lib/systemcmd.php' ,
dataType : 'json' ,
data : {
cmd : 'rpm -q rsct.core'
} ,
success : function ( data ) {
if ( - 1 != data . rsp . indexOf ( "not" ) ) {
$ ( '#rmcMonStatus div' )
. empty ( )
. append (
'Please install the <a href="http://www14.software.ibm.com/webapp/set2/sas/f/rsct/rmc/download/home.html" target="install_window">RSCT</a> first.<br/>'
+ 'You can find more support from <a href="http://xcat.svn.sourceforge.net/viewvc/xcat/xcat-core/trunk/xCAT-client/share/doc/xCAT2-Monitoring.pdf" target="pdf_window">xCAT2-Monitoring.pdf</a>' ) ;
} else {
xcatrmcRpmCheck ( ) ;
}
}
} ) ;
} else {
xcatrmcRpmCheck ( ) ;
}
2010-08-04 08:49:20 +00:00
}
2011-09-12 16:10:53 +00:00
function xcatrmcRpmCheck ( ) {
2012-05-04 00:54:58 +00:00
$ . ajax ( {
url : 'lib/systemcmd.php' ,
dataType : 'json' ,
data : {
cmd : 'rpm -q xCAT-rmc rrdtool'
} ,
success : function ( data ) {
var softInstallStatus = data . rsp . split ( /\n/ ) ;
var needHelp = false ;
$ ( '#rmcMonStatus div' ) . empty ( ) ;
// Check the xcat-rmc
if ( - 1 != softInstallStatus [ 0 ] . indexOf ( "not" ) ) {
needHelp = true ;
$ ( '#rmcMonStatus div' )
. append (
'Please install the <a href="http://xcat.sourceforge.net/#download" target="install_window">xCAT-rmc</a> first.<br/>' ) ;
}
// Check the rrdtool
if ( - 1 != softInstallStatus [ 1 ] . indexOf ( "not" ) ) {
needHelp = true ;
$ ( '#rmcMonStatus div' )
. append (
'Please install the <a href="http://oss.oetiker.ch/rrdtool/download.en.html" target="install_window">RRD-tool</a> first.<br/>' ) ;
}
// Add help info or load the rmc show
if ( n eedHelp ) {
$ ( '#rmcMonStatus div' )
. append (
'You can find more support form <a href="http://xcat.svn.sourceforge.net/viewvc/xcat/xcat-core/trunk/xCAT-client/share/doc/xCAT2-Monitoring.pdf" target="pdf_window">xCAT2-Monitoring.pdf</a>' ) ;
} else {
rmcWorkingCheck ( ) ;
}
}
} ) ;
2010-08-04 08:49:20 +00:00
}
2011-09-12 16:10:53 +00:00
function rmcWorkingCheck ( ) {
2012-05-04 00:54:58 +00:00
$ ( '#rmcMonStatus div' ) . empty ( ) . append ( "Checking RMC working status" ) ;
$ ( '#rmcMonStatus div' ) . append ( createLoader ( ) ) ;
$ ( '#rmcmon button:first' ) . show ( ) ;
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'monls' ,
tgt : '' ,
args : 'rmcmon' ,
msg : ''
} ,
success : function ( data ) {
if ( - 1 != data . rsp [ 0 ] . indexOf ( "not-monitored" ) ) {
$ ( '#rmcMonStatus div' ) . empty ( ) . append (
"Please start the RMC Monitoring first" ) ;
return ;
}
loadRmcMonShow ( ) ;
}
} ) ;
2010-08-22 14:58:21 +00:00
}
2010-09-24 02:27:04 +00:00
2012-05-04 00:54:58 +00:00
function removeStatusBar ( ) {
if ( globalAllNodesNum == globalFinishNodesNum ) {
2011-06-01 03:00:03 +00:00
$ ( '#rmcMonStatus' ) . remove ( ) ;
}
2012-05-04 00:54:58 +00:00
$ ( '#rmcmonDetail [title]' ) . tooltip ( {
position : [ 'center' , 'right' ]
} ) ;
2011-06-01 03:00:03 +00:00
}
2011-07-20 21:13:09 +00:00
2012-05-04 00:54:58 +00:00
function loadRmcMonShow ( ) {
$ ( '#rmcMonStatus div' ) . empty ( ) . append ( "Getting summary data" ) ;
$ ( '#rmcMonStatus div' ) . append ( createLoader ( ) ) ;
// Load the rmc status summary
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'webrun' ,
tgt : '' ,
args : 'rmcshow;summary;PctTotalTimeIdle,PctRealMemFree' ,
msg : ''
} ,
success : function ( data ) {
showRmcSummary ( data . rsp [ 0 ] ) ;
}
} ) ;
2010-12-09 05:09:01 +00:00
}
2011-06-01 03:00:03 +00:00
function showRmcSummary ( returnData ) {
var attributes = returnData . split ( ';' ) ;
var attr ;
var attrName ;
var attrValues ;
var attrDiv ;
var summaryTable = $ ( '<table><tbody></tbody></table>' ) ;
var summaryRow ;
globalTimeStamp = new Array ( ) ;
2010-08-26 05:27:11 +00:00
2012-05-04 00:54:58 +00:00
// Update the rmc status area
$ ( '#rmcMonStatus div' ) . empty ( ) . append ( "Getting nodes data" ) . append (
createLoader ( ) ) ;
// Load each nodes' status
2011-09-12 16:10:53 +00:00
$ . ajax ( {
2012-05-04 00:54:58 +00:00
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'webrun' ,
tgt : '' ,
args : 'rmcshow;compute;PctTotalTimeIdle,PctRealMemFree' ,
msg : ''
2011-06-01 03:00:03 +00:00
} ,
2010-08-26 05:27:11 +00:00
2012-05-04 00:54:58 +00:00
success : function ( data ) {
2011-06-01 03:00:03 +00:00
parseRmcData ( data . rsp ) ;
}
} ) ;
2010-08-26 05:27:11 +00:00
2012-05-04 00:54:58 +00:00
// Create the timestamp, the flot only use the UTC time, so had to change the value, to show the right time
2011-06-01 03:00:03 +00:00
var tempDate = new Date ( ) ;
var tempOffset = tempDate . getTimezoneOffset ( ) ;
var tempTime = tempDate . getTime ( ) - 3600000 ;
2011-09-12 16:10:53 +00:00
for ( var i = 0 ; i < 60 ; i ++ ) {
2011-06-01 03:00:03 +00:00
tempDate . setTime ( tempTime + i * 60000 ) ;
globalTimeStamp . push ( tempDate . getTime ( ) ) ;
}
2010-09-13 08:44:19 +00:00
2012-05-04 00:54:58 +00:00
// Show the summary data
2011-06-01 03:00:03 +00:00
$ ( '#rmcmonSummary' ) . empty ( ) . append ( '<h3>Overview</h3><hr />' ) ;
$ ( '#rmcmonSummary' ) . append ( summaryTable ) ;
2010-09-13 08:44:19 +00:00
2011-06-01 03:00:03 +00:00
for ( attr in attributes ) {
var tempTd = $ ( '<td style="border:0px;padding:15px 5px;"></td>' ) ;
var tempArray = [ ] ;
var temp = attributes [ attr ] . indexOf ( ':' ) ;
attrName = attributes [ attr ] . substr ( 0 , temp ) ;
attrValues = attributes [ attr ] . substr ( temp + 1 ) . split ( ',' ) ;
2010-09-13 08:44:19 +00:00
2011-06-01 03:00:03 +00:00
if ( 0 == ( attr % 3 ) ) {
summaryRow = $ ( '<tr></tr>' ) ;
summaryTable . append ( summaryRow ) ;
}
summaryRow . append ( tempTd ) ;
2012-05-04 00:54:58 +00:00
attrDiv = $ ( '<div id="monitor-sum-div' + attr
+ '" class="monitor-sum-div"></div>' ) ;
2011-06-01 03:00:03 +00:00
tempTd . append ( attrDiv ) ;
2011-09-12 16:10:53 +00:00
for ( var i in attrValues ) {
2012-05-04 00:54:58 +00:00
tempArray . push ( [ globalTimeStamp [ i ] , Number ( attrValues [ i ] ) ] ) ;
2011-06-01 03:00:03 +00:00
}
2010-09-13 08:44:19 +00:00
2012-05-01 23:43:11 +00:00
$ . jqplot ( 'monitor-sum-div' + attr , [ tempArray ] , {
2012-05-04 00:54:58 +00:00
series : [ {
2011-06-01 03:00:03 +00:00
showMarker : false
2012-05-04 00:54:58 +00:00
} ] ,
axes : {
xaxis : {
label : attrName ,
renderer : $ . jqplot . DateAxisRenderer ,
numberTicks : 5 ,
tickOptions : {
formatString : '%R' ,
show : true ,
fontSize : '10px'
2011-06-01 03:00:03 +00:00
}
} ,
2012-05-04 00:54:58 +00:00
yaxis : {
tickOptions : {
formatString : '%.2f' ,
fontSize : '10px'
2011-06-01 03:00:03 +00:00
}
}
}
} ) ;
}
2010-09-14 08:06:50 +00:00
}
2011-09-12 16:10:53 +00:00
function parseRmcData ( returnData ) {
2011-06-01 03:00:03 +00:00
var nodeName ;
var nodeStatus ;
2012-05-04 00:54:58 +00:00
2011-06-01 03:00:03 +00:00
$ ( '#rmcmonDetail' ) . empty ( ) . append ( '<h3>Detail</h3><hr/>' ) ;
2012-05-04 00:54:58 +00:00
// Add the table for show nodes
2011-06-01 03:00:03 +00:00
var detailUl = $ ( '<ul style="margin:0px;padding:0px;"></ul>' ) ;
2012-05-04 00:54:58 +00:00
// Update the table area
2011-06-01 03:00:03 +00:00
$ ( '#rmcmonDetail ul' ) . remove ( ) ;
$ ( '#rmcmonDetail' ) . append ( detailUl ) ;
2012-05-04 00:54:58 +00:00
2011-06-01 03:00:03 +00:00
globalAllNodesNum = returnData . length ;
globalFinishNodesNum = 0 ;
2011-09-12 16:10:53 +00:00
for ( var i in returnData ) {
2012-05-04 00:54:58 +00:00
var temp = returnData [ i ] . indexOf ( ':' ) ;
;
2011-06-01 03:00:03 +00:00
nodeName = returnData [ i ] . substr ( 0 , temp ) ;
2012-05-04 00:54:58 +00:00
nodeStatus = returnData [ i ] . substr ( temp + 1 ) . replace ( /(^\s*)|(\s*$)/g ,
'' ) ;
2011-09-12 16:10:53 +00:00
if ( 'OK' != nodeStatus ) {
2011-06-01 03:00:03 +00:00
globalFinishNodesNum ++ ;
detailUl . append ( createUnkownNode ( nodeName ) ) ;
removeStatusBar ( ) ;
continue ;
}
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'webrun' ,
tgt : '' ,
2012-05-04 00:54:58 +00:00
args : 'rmcshow;' + nodeName
+ ';PctTotalTimeIdle,PctRealMemFree' ,
2011-06-01 03:00:03 +00:00
msg : nodeName
} ,
2012-05-04 00:54:58 +00:00
success : function ( data ) {
2011-06-01 03:00:03 +00:00
showRmcNodes ( data . rsp , data . msg ) ;
}
} ) ;
}
2010-09-13 08:44:19 +00:00
}
2011-09-12 16:10:53 +00:00
function createUnkownNode ( nodeName ) {
2012-05-04 00:54:58 +00:00
var tempLi = '<li class="monitor-unknown ui-corner-all monitor-node-li" id="'
+ nodeName
+ '" '
+ 'title="Name:'
+ nodeName
+ '<br/>Unknown"></li>' ;
2011-06-01 03:00:03 +00:00
return tempLi ;
2010-09-13 08:44:19 +00:00
}
2011-09-12 16:10:53 +00:00
function createErrorNode ( nodeName ) {
2012-05-04 00:54:58 +00:00
var tempLi = '<li class="monitor-error ui-corner-all monitor-node-li id="'
+ nodeName + '" ' + 'title="Name:' + nodeName + '<br/>Error"></li>' ;
2010-09-13 08:44:19 +00:00
}
2011-06-01 03:00:03 +00:00
function showRmcNodes ( data , nodename ) {
var attrname = '' ;
var values = '' ;
var position = 0 ;
var index = 0 ;
var classname = '' ;
var tempObj = { } ;
2012-05-04 00:54:58 +00:00
2011-09-12 16:10:53 +00:00
for ( index in data ) {
2011-06-01 03:00:03 +00:00
position = data [ index ] . indexOf ( ':' ) ;
attrname = data [ index ] . substr ( 0 , position ) ;
values = data [ index ] . substr ( position + 1 ) ;
2012-05-04 00:54:58 +00:00
// Error node, cannot get the last hour's data
2011-09-12 16:10:53 +00:00
if ( ! values ) {
2011-06-01 03:00:03 +00:00
$ ( '#rmcmonDetail ul' ) . append ( createErrorNode ( nodename ) ) ;
2011-09-12 16:10:53 +00:00
if ( globalNodesDetail [ nodename ] ) {
2012-05-04 00:54:58 +00:00
delete ( globalNodesDetail [ nodename ] ) ;
2011-06-01 03:00:03 +00:00
}
return ;
}
2012-05-04 00:54:58 +00:00
// Normal node, save the values
2011-06-01 03:00:03 +00:00
tempObj [ attrname ] = values ;
}
2012-05-04 00:54:58 +00:00
2011-06-01 03:00:03 +00:00
globalNodesDetail [ nodename ] = tempObj ;
2012-05-04 00:54:58 +00:00
// Get each average
2011-06-01 03:00:03 +00:00
var cpuAvg = 0 ;
var memAvg = 0 ;
var tempSum = 0 ;
var tempArray = globalNodesDetail [ nodename ] [ 'PctTotalTimeIdle' ] . split ( ',' ) ;
2011-09-12 16:10:53 +00:00
for ( index = 0 ; index < tempArray . length ; index ++ ) {
2011-06-01 03:00:03 +00:00
tempSum += Number ( tempArray [ index ] ) ;
}
cpuAvg = parseInt ( tempSum / index ) ;
2012-05-04 00:54:58 +00:00
2011-06-01 03:00:03 +00:00
tempArray = globalNodesDetail [ nodename ] [ 'PctRealMemFree' ] . split ( ',' ) ;
tempSum = 0 ;
2011-09-12 16:10:53 +00:00
for ( index = 0 ; index < tempArray . length ; index ++ ) {
2011-06-01 03:00:03 +00:00
tempSum += Number ( tempArray [ index ] ) ;
}
memAvg = parseInt ( tempSum / index ) ;
2012-05-04 00:54:58 +00:00
if ( cpuAvg >= 10 && memAvg <= 90 ) {
2012-05-01 23:43:11 +00:00
classname = 'monitor-normal' ;
2011-09-12 16:10:53 +00:00
} else {
2012-05-01 23:43:11 +00:00
classname = 'mornitor-warning' ;
2011-06-01 03:00:03 +00:00
}
2012-05-04 00:54:58 +00:00
var normalLi = $ ( '<li class="' + classname
+ ' ui-corner-all monitor-node-li" id="' + nodename + '" title="'
+ 'Name:' + nodename + '<br/> CpuIdle: ' + cpuAvg
+ '%<br/> MemFree: ' + memAvg + '%"></li>' ) ;
2011-06-01 03:00:03 +00:00
$ ( '#rmcmonDetail ul' ) . append ( normalLi ) ;
normalLi . bind ( 'click' , function ( ) {
showNode ( $ ( this ) . attr ( 'id' ) ) ;
} ) ;
2012-05-04 00:54:58 +00:00
// Check if the process finished
2011-06-01 03:00:03 +00:00
globalFinishNodesNum ++ ;
removeStatusBar ( ) ;
2010-09-13 08:44:19 +00:00
}
2011-06-01 03:00:03 +00:00
function showNode ( nodeName ) {
var nodeTable = $ ( '<table><tbody></tbody></table>' ) ;
var backButton = createButton ( 'Go back to all nodes' ) ;
var nodeRow ;
var parseNum = 0 ;
2010-12-01 06:14:44 +00:00
2011-06-01 03:00:03 +00:00
$ ( '#rmcmonDetail' ) . hide ( ) ;
$ ( '#nodeDetail' ) . empty ( ) . show ( ) ;
$ ( '#nodeDetail' ) . append ( '<h3>' + nodeName + ' Detail</h3><hr />' ) ;
$ ( '#nodeDetail' ) . append ( backButton ) ;
backButton . bind ( 'click' , function ( ) {
$ ( '#nodeDetail' ) . hide ( ) ;
$ ( '#rmcmonDetail' ) . show ( ) ;
} ) ;
$ ( '#nodeDetail' ) . append ( nodeTable ) ;
2012-05-04 00:54:58 +00:00
for ( var attr in globalNodesDetail [ nodeName ] ) {
2011-06-01 03:00:03 +00:00
var tempTd = $ ( '<td style="border:0px;padding:1px 1px;"></td>' ) ;
2012-05-01 23:43:11 +00:00
var attrChat = $ ( '<div id="monitor-node-div' + nodeName + attr
+ '" class="monitor-node-div"></div>' ) ;
2011-06-01 03:00:03 +00:00
if ( 0 == parseNum % 4 ) {
nodeRow = $ ( '<tr></tr>' ) ;
nodeTable . append ( nodeRow ) ;
}
nodeRow . append ( tempTd ) ;
parseNum ++ ;
tempTd . append ( attrChat ) ;
var tempData = globalNodesDetail [ nodeName ] [ attr ] . split ( ',' ) ;
var tempArray = [ ] ;
2012-05-04 00:54:58 +00:00
for ( var i in tempData ) {
tempArray . push ( [ globalTimeStamp [ i ] , Number ( tempData [ i ] ) ] ) ;
2011-06-01 03:00:03 +00:00
}
2012-05-01 23:43:11 +00:00
$ . jqplot ( 'monitor-node-div' + nodeName + attr , [ tempArray ] , {
2012-05-04 00:54:58 +00:00
series : [ {
2011-06-01 03:00:03 +00:00
showMarker : false
2012-05-04 00:54:58 +00:00
} ] ,
2011-06-01 03:00:03 +00:00
axes : {
xaxis : {
label : attr ,
renderer : $ . jqplot . DateAxisRenderer ,
numberTicks : 5 ,
tickOptions : {
formatString : '%R' ,
show : true ,
fontSize : '10px'
}
} ,
yaxis : {
tickOptions : {
formatString : '%.2f' ,
fontSize : '10px'
}
}
}
} ) ;
}
2010-12-16 03:14:55 +00:00
}
/ * *
2012-05-04 00:54:58 +00:00
* Load the rmc event tab
2010-12-16 03:14:55 +00:00
* /
2012-05-04 00:54:58 +00:00
function loadRmcEvent ( ) {
// Find the rmcevent tab
// Add the stauts bar first
var rmcStatusBar = createStatusBar ( 'rmcEventStatus' ) ;
rmcStatusBar . find ( 'div' ) . append ( createLoader ( ) ) ;
$ ( '#rmcevent' ) . append ( rmcStatusBar ) ;
$ ( '#rmcevent' ) . append ( '<div id="rmcEventDiv"></div>' ) ;
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'webrun' ,
tgt : '' ,
args : 'lsevent;-O;1000' ,
msg : ''
} ,
success : showEventLog
} ) ;
2010-12-16 03:14:55 +00:00
}
2010-12-25 02:17:00 +00:00
/ * *
2012-05-04 00:54:58 +00:00
* Get all conditions
2010-12-25 02:17:00 +00:00
* /
2012-05-04 00:54:58 +00:00
function getConditions ( ) {
if ( ! globalCondition ) {
$ ( '#rmcEventStatus div' ) . empty ( )
. append ( 'Getting predefined conditions' ) . append ( createLoader ( ) ) ;
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'webrun' ,
tgt : '' ,
args : 'lscondition' ,
msg : ''
} ,
success : function ( data ) {
$ ( '#rmcEventStatus div' ) . empty ( ) ;
$ ( '#rmcEventButtons' ) . show ( ) ;
globalCondition = data . rsp [ 0 ] ;
}
} ) ;
} else {
$ ( '#rmcEventButtons' ) . show ( ) ;
}
2010-12-25 02:17:00 +00:00
}
/ * *
2012-05-04 00:54:58 +00:00
* Get all response
2010-12-25 02:17:00 +00:00
* /
2011-09-12 16:10:53 +00:00
function getResponse ( ) {
2012-05-04 00:54:58 +00:00
var tempFlag = false ;
// Get all response first
for ( var i in globalResponse ) {
tempFlag = true ;
break ;
}
if ( ! tempFlag ) {
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'webrun' ,
tgt : '' ,
args : 'lsresponse' ,
msg : ''
} ,
success : function ( data ) {
var resps = data . rsp [ 0 ] . split ( ';' ) ;
for ( var i in resps ) {
var name = resps [ i ] ;
name = name . substr ( 1 , ( name . length - 2 ) ) ;
globalResponse [ name ] = 1 ;
}
}
} ) ;
}
2010-12-25 02:17:00 +00:00
}
2010-12-16 03:14:55 +00:00
/ * *
2012-05-04 00:54:58 +00:00
* Show all the event in the rmc event tab
2010-12-16 03:14:55 +00:00
*
2012-05-04 00:54:58 +00:00
* @ param data Response from the xcat server
2010-12-16 03:14:55 +00:00
* /
2011-09-12 16:10:53 +00:00
function showEventLog ( data ) {
2012-05-04 00:54:58 +00:00
$ ( '#rmcEventStatus div' ) . empty ( ) ;
// rsct not installed
if ( data . rsp [ 0 ] && ( - 1 != data . rsp [ 0 ] . indexOf ( 'lsevent' ) ) ) {
$ ( '#rmcEventStatus div' ) . append ( 'Please install RSCT first!' ) ;
return ;
}
var eventDiv = $ ( '#rmcEventDiv' ) ;
eventDiv . empty ( ) ;
// Get conditions and responses, save in the global
getConditions ( ) ;
getResponse ( ) ;
var eventTable = new DataTable ( 'lsEventTable' ) ;
eventTable . init ( [ 'Time' , 'Type' , 'Content' ] ) ;
for ( var i in data . rsp ) {
var row = data . rsp [ i ] . split ( ';' ) ;
eventTable . add ( row ) ;
}
eventDiv . append ( eventTable . object ( ) ) ;
2013-02-05 15:43:57 +00:00
$ ( '#lsEventTable' ) . dataTable ( {
'iDisplayLength' : 50 ,
'bLengthChange' : false ,
"bScrollCollapse" : true ,
"sScrollY" : "400px" ,
"sScrollX" : "110%" ,
"bAutoWidth" : true ,
"oLanguage" : {
"oPaginate" : {
"sNext" : "" ,
"sPrevious" : ""
}
}
2012-05-04 00:54:58 +00:00
} ) ;
// Add the configure button
loadRmcEventConfig ( ) ;
// Unsort on the content column
$ ( '#lsEventTable thead tr th' ) . eq ( 2 ) . unbind ( 'click' ) ;
2010-12-16 14:28:49 +00:00
}
/ * *
* Add the configure button into rmc event tab
* /
2012-05-04 00:54:58 +00:00
function loadRmcEventConfig ( ) {
// Create action bar
var actionBar = $ ( '<div class="actionBar"></div>' ) ;
var chCondScopeLnk = $ ( '<a>Change condition scope</a>' ) ;
chCondScopeLnk . bind ( 'click' , function ( ) {
chCondScopeDia ( ) ;
} ) ;
var mkCondRespLnk = $ ( '<a>Make/remove associatione</a>' ) ;
mkCondRespLnk . bind ( 'click' , function ( ) {
mkCondRespDia ( ) ;
} ) ;
var startCondRespLnk = $ ( '<a>Start/stop association</a>' ) ;
startCondRespLnk . bind ( 'click' , function ( ) {
startStopCondRespDia ( ) ;
} ) ;
// Actions
var actionsLnk = '<a>Actions</a>' ;
var actsMenu = createMenu ( [ chCondScopeLnk , mkCondRespLnk , startCondRespLnk ] ) ;
// Create an action menu
var actionsMenu = createMenu ( [ [ actionsLnk , actsMenu ] ] ) ;
actionsMenu . superfish ( ) ;
actionsMenu . css ( 'display' , 'inline-block' ) ;
actionBar . append ( actionsMenu ) ;
// Create a division to hold actions menu
var menuDiv = $ ( '<div id="lsEventTable_menuDiv" class="menuDiv"></div>' ) ;
$ ( '#lsEventTable_wrapper' ) . prepend ( menuDiv ) ;
menuDiv . append ( actionBar ) ;
$ ( '#lsEventTable_filter' ) . appendTo ( menuDiv ) ;
2010-12-16 14:28:49 +00:00
}
/ * *
2012-05-04 00:54:58 +00:00
* Show the make association dialogue
2010-12-16 14:28:49 +00:00
* /
2012-05-04 00:54:58 +00:00
function mkCondRespDia ( ) {
var diaDiv = $ ( '<div title="Configure Association" id="mkAssociation" class="tab"></div>' ) ;
var mkAssociationTable = '<center><table><thead><tr><th>Condition Name</th><th>Response Name</th></tr></thead>' ;
mkAssociationTable += '<tbody><tr><td id="mkAssCond">' ;
// Add the conditions into fieldset
if ( ! globalCondition ) {
mkAssociationTable += 'Getting predefined conditions, open this dislogue later' ;
} else {
mkAssociationTable += createConditionTd ( globalCondition ) ;
}
mkAssociationTable += '</td><td id="mkAssResp">Please select condition first</td></tr></tbody></table></center>' ;
diaDiv . append ( mkAssociationTable ) ;
diaDiv . append ( '<div id="selectedResp" style="display: none;" ><div>' ) ;
// Change the response field when click the condition
diaDiv . find ( 'input:radio' ) . bind ( 'click' ,
function ( ) {
diaDiv . find ( '#mkAssResp' ) . empty ( ) . append ( 'Getting response' ) . append ( createLoader ( ) ) ;
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'webrun' ,
tgt : '' ,
args : 'lscondresp;"'
+ $ ( this ) . attr ( 'value' ) + '"' ,
msg : ''
} ,
success : function ( data ) {
var tempHash = new Object ( ) ;
var oldSelectedResp = '' ;
var showStr = '' ;
if ( data . rsp [ 0 ] ) {
var names = data . rsp [ 0 ] . split ( ';' ) ;
for ( var i in names ) {
var name = names [ i ] ;
name = name . substr ( 1 ,
name . length - 2 ) ;
tempHash [ name ] = 1 ;
}
}
for ( var name in globalResponse ) {
if ( tempHash [ name ] ) {
showStr += '<input type="checkbox" checked="checked" value="'
+ name
+ '">'
+ name
+ '<br/>' ;
oldSelectedResp += ';' + name ;
} else {
showStr += '<input type="checkbox" value="'
+ name
+ '">'
+ name
+ '<br/>' ;
}
}
diaDiv . find ( '#mkAssResp' ) . empty ( )
. append ( showStr ) ;
diaDiv . find ( '#selectedResp' ) . empty ( )
. append ( oldSelectedResp ) ;
}
} ) ;
} ) ;
diaDiv . dialog ( {
modal : true ,
width : 620 ,
height : 600 ,
close : function ( event , ui ) {
$ ( this ) . remove ( ) ;
} ,
buttons : {
'Ok' : function ( ) {
var newResp = new Object ( ) ;
var oldResp = new Object ( ) ;
var oldString = '' ;
var newString = '' ;
// Get the old seelected responses
var conditionName = $ ( this ) . find ( '#mkAssCond :checked' ) . attr (
'value' ) ;
if ( ! conditionName ) {
return ;
}
var temp = $ ( this ) . find ( '#selectedResp' ) . html ( ) ;
if ( ! temp ) {
return ;
}
var tempArray = temp . substr ( 1 ) . split ( ';' ) ;
for ( var i in tempArray ) {
oldResp [ tempArray [ i ] ] = 1 ;
}
// Get the new selected responses
$ ( this ) . find ( '#mkAssResp input:checked' ) . each ( function ( ) {
var respName = $ ( this ) . attr ( 'value' ) ;
newResp [ respName ] = 1 ;
} ) ;
for ( var i in newResp ) {
if ( oldResp [ i ] ) {
delete oldResp [ i ] ;
delete newResp [ i ] ;
}
}
// Add the response which are delete
for ( var i in oldResp ) {
oldString += ',"' + i + '"' ;
}
if ( '' != oldString ) {
oldString = oldString . substr ( 1 ) ;
}
// Add the response which are new add
for ( var i in newResp ) {
newString += ',"' + i + '"' ;
}
if ( '' != newString ) {
newString = newString . substr ( 1 ) ;
}
if ( ( '' != oldString ) || ( '' != newString ) ) {
$ ( '#rmcEventStatus div' ) . empty ( ) . append (
'Create/remove associations ' ) . append (
createLoader ( ) ) ;
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'webrun' ,
tgt : '' ,
args : 'mkcondresp;"' + conditionName + '";+'
+ newString + ':-' + oldString ,
msg : ''
} ,
success : function ( data ) {
$ ( '#rmcEventStatus div' ) . empty ( )
. append ( data . rsp [ 0 ] ) ;
;
}
} ) ;
}
$ ( this ) . dialog ( 'close' ) ;
} ,
'Cancel' : function ( ) {
$ ( this ) . dialog ( 'close' ) ;
}
}
} ) ;
2010-12-16 14:28:49 +00:00
}
2010-12-23 03:03:19 +00:00
/ * *
2012-05-04 00:54:58 +00:00
* Show the make condition dialogue
2010-12-23 03:03:19 +00:00
* /
2011-09-12 16:10:53 +00:00
function chCondScopeDia ( ) {
2012-05-04 00:54:58 +00:00
var diaDiv = $ ( '<div title="Change Condition Scope" id="chScopeDiaDiv" class="tab"></div>' ) ;
var tableContent = '<center><table id="changeScopeTable" ><thead><tr><th>Condition Name</th><th>Group Name</th></tr></thead>' ;
tableContent += '<tbody><tr><td id="changePreCond">' ;
// Add the conditions into fieldset
if ( '' == globalCondition ) {
tableContent += 'Getting predefined conditions, open this dialogue later' ;
} else {
tableContent += createConditionTd ( globalCondition ) ;
}
tableContent += '</td><td id="changeGroup">' ;
// Add the groups into table
var groups = $ . cookie ( 'groups' ) . split ( ',' ) ;
for ( var i in groups ) {
tableContent += '<input type="checkbox" value="' + groups [ i ] + '">'
+ groups [ i ] + '<br/>' ;
}
tableContent += '</td></tr></tbody></table></center>' ;
diaDiv . append ( tableContent ) ;
// Fieldset to show status
diaDiv . append ( '<fieldset id="changeStatus"></fieldset>' ) ;
// Create the dislogue
diaDiv . dialog ( {
modal : true ,
width : 500 ,
2011-01-11 09:22:45 +00:00
height : 600 ,
2012-05-04 00:54:58 +00:00
close : function ( event , ui ) {
$ ( this ) . remove ( ) ;
} ,
buttons : {
'Ok' : function ( ) {
$ ( '#changeStatus' ) . empty ( ) . append ( '<legend>Status</legend>' ) ;
var conditionName = $ ( '#changePreCond :checked' ) . attr ( 'value' ) ;
var groupName = '' ;
$ ( '#changeGroup :checked' ) . each ( function ( ) {
if ( '' == groupName ) {
groupName += $ ( this ) . attr ( 'value' ) ;
} else {
groupName += ',' + $ ( this ) . attr ( 'value' ) ;
}
} ) ;
if ( undefined == conditionName ) {
$ ( '#changeStatus' ) . append ( 'Please select conditon' ) ;
return ;
}
if ( '' == groupName ) {
$ ( '#changeStatus' ) . append ( 'Please select group' ) ;
return ;
}
$ ( '#changeStatus' ) . append ( createLoader ( ) ) ;
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'webrun' ,
tgt : '' ,
args : 'mkcondition;change;' + conditionName + ';'
+ groupName ,
msg : ''
} ,
success : function ( data ) {
$ ( '#changeStatus img' ) . remove ( ) ;
if ( - 1 != data . rsp [ 0 ] . indexOf ( 'Error' ) ) {
$ ( '#changeStatus' ) . append ( data . rsp [ 0 ] ) ;
} else {
$ ( '#rmcEventStatus div' ) . empty ( )
. append ( data . rsp [ 0 ] ) ;
$ ( '#chScopeDiaDiv' ) . remove ( ) ;
}
}
} ) ;
} ,
'Cancel' : function ( ) {
$ ( this ) . dialog ( 'close' ) ;
}
}
} ) ;
2010-12-23 03:03:19 +00:00
}
/ * *
2012-05-04 00:54:58 +00:00
* Show the make response dialogue
2010-12-23 03:03:19 +00:00
* /
2011-09-12 16:10:53 +00:00
function mkResponseDia ( ) {
2012-05-04 00:54:58 +00:00
var diaDiv = $ ( '<div title="Make Response"><div>' ) ;
diaDiv . append ( 'Not yet supported.' ) ;
2010-12-28 09:34:44 +00:00
2012-05-04 00:54:58 +00:00
diaDiv . dialog ( {
modal : true ,
width : 400 ,
close : function ( event , ui ) {
$ ( this ) . remove ( ) ;
} ,
buttons : {
'Ok' : function ( ) {
$ ( this ) . dialog ( 'close' ) ;
} ,
'Cancel' : function ( ) {
$ ( this ) . dialog ( 'close' ) ;
}
}
} ) ;
}
2010-12-28 09:34:44 +00:00
/ * *
2012-05-04 00:54:58 +00:00
* Start the condition and response associations
2010-12-28 09:34:44 +00:00
* /
2011-09-12 16:10:53 +00:00
function startStopCondRespDia ( ) {
2012-05-04 00:54:58 +00:00
var diaDiv = $ ( '<div title="Start/Stop Association" id="divStartStopAss" class="tab"><div>' ) ;
diaDiv . append ( 'Getting conditions' ) . append ( createLoader ( ) ) ;
if ( ! globalCondition ) {
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'webrun' ,
tgt : '' ,
args : 'lscondition' ,
msg : ''
} ,
success : function ( data ) {
if ( data . rsp [ 0 ] ) {
globalcondition = data . rsp [ 0 ] ;
$ ( '#divStartStopAss' ) . empty ( ) . append (
createAssociationTable ( globalCondition ) ) ;
$ ( '#divStartStopAss' )
. dialog ( "option" , "position" , 'center' ) ;
} else {
$ ( '#divStartStopAss' ) . empty ( ) . append (
'There are no conditions' ) ;
}
}
} ) ;
} else {
diaDiv . empty ( ) . append ( createAssociationTable ( globalCondition ) ) ;
}
diaDiv . dialog ( {
modal : true ,
width : 570 ,
height : 600 ,
close : function ( event , ui ) {
$ ( this ) . remove ( ) ;
} ,
buttons : {
'Close' : function ( ) {
$ ( this ) . dialog ( 'close' ) ;
}
}
} ) ;
$ ( '#divStartStopAss button' ) . bind (
'click' ,
function ( ) {
var operationType = '' ;
var conditionName = $ ( this ) . attr ( 'name' ) ;
if ( 'Start' == $ ( this ) . html ( ) ) {
operationType = 'start' ;
} else {
operationType = 'stop' ;
}
$ ( this ) . parent ( ) . prev ( ) . empty ( ) . append ( createLoader ( ) ) ;
$ ( '#divStartStopAss' ) . dialog ( 'option' , 'disabled' , true ) ;
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'webrun' ,
tgt : '' ,
args : operationType + 'condresp;' + conditionName ,
msg : operationType + ';' + conditionName
} ,
success : function ( data ) {
var conditionName = '' ;
var newOperationType = '' ;
var associationStatus = '' ;
var backgroudColor = '' ;
if ( 'start' == data . msg . substr ( 0 , 5 ) ) {
newOperationType = 'Stop' ;
conditionName = data . msg . substr ( 6 ) ;
associationStatus = 'Monitored' ;
backgroudColor = '#ffffff' ;
} else {
newOperationType = 'Start' ;
conditionName = data . msg . substr ( 5 ) ;
associationStatus = 'Not Monitored' ;
backgroudColor = '#fffacd' ;
}
var button = $ ( '#divStartStopAss button[name="'
+ conditionName + '"]' ) ;
if ( data . rsp [ 0 ] ) {
$ ( '#rmcEventStatus div' ) . empty ( ) . append (
'Getting associations\' status' ) . append (
createLoader ( ) ) ;
$ ( '#rmcEventButtons' ) . hide ( ) ;
button . html ( newOperationType ) ;
button . parent ( ) . prev ( ) . html ( associationStatus ) ;
button . parent ( ) . parent ( ) . css ( 'background-color' ,
backgroudColor ) ;
globalCondition = '' ;
getConditions ( ) ;
} else {
button . html ( 'Error' ) ;
}
$ ( '#divStartStopAss' ) . dialog ( 'option' , 'disabled' ,
false ) ;
}
} ) ;
} ) ;
2010-12-28 09:34:44 +00:00
}
/ * *
2012-05-04 00:54:58 +00:00
* Stop the condition and response associations
2010-12-28 09:34:44 +00:00
* /
2012-05-04 00:54:58 +00:00
function stopCondRespDia ( ) {
var diaDiv = $ ( '<div title="Stop Association" id="stopAss"><div>' ) ;
diaDiv . append ( 'Getting conditions' ) . append ( createLoader ( ) ) ;
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'webrun' ,
tgt : '' ,
args : 'lscondition;-m' ,
msg : ''
} ,
success : function ( data ) {
if ( data . rsp [ 0 ] ) {
$ ( '#stopAss' ) . empty ( ) . append (
createConditionTable ( data . rsp [ 0 ] ) ) ;
$ ( '#stopAss' ) . dialog ( "option" , "position" , 'center' ) ;
} else {
$ ( '#stopAss' ) . empty ( ) . append (
'There is not monitored condition.' ) ;
}
}
} ) ;
diaDiv . dialog ( {
modal : true ,
width : 570 ,
close : function ( event , ui ) {
$ ( this ) . remove ( ) ;
} ,
buttons : {
'Stop' : function ( ) {
var conditionName = $ ( '#stopAss :checked' ) . attr ( 'value' ) ;
if ( ! conditionName ) {
alert ( 'Select condition name please.' ) ;
return ;
}
$ ( '#rmcEventStatus div' ) . empty ( ) . append (
'Stoping monitor on ' + conditionName ) . append (
createLoader ( ) ) ;
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'webrun' ,
tgt : '' ,
args : 'stopcondresp;' + conditionName ,
msg : ''
} ,
success : function ( data ) {
$ ( '#rmcEventStatus div' ) . empty ( ) . append ( data . rsp [ 0 ] ) ;
}
} ) ;
$ ( this ) . dialog ( 'close' ) ;
} ,
'Cancel' : function ( ) {
$ ( this ) . dialog ( 'close' ) ;
}
}
} ) ;
2010-12-28 09:34:44 +00:00
}
2010-12-25 02:17:00 +00:00
/ * *
2012-05-04 00:54:58 +00:00
* Create the condition table for dialogue
*
* @ param cond Condition
2010-12-25 02:17:00 +00:00
* /
2012-05-04 00:54:58 +00:00
function createConditionTd ( cond ) {
var conditions = cond . split ( ';' ) ;
var name = '' ;
var showStr = '' ;
for ( var i in conditions ) {
name = conditions [ i ] ;
// Because there is status and quotation marks in name,
// we must delete the status and quotation marks
name = name . substr ( 1 , name . length - 6 ) ;
showStr += '<input type="radio" name="preCond" value="' + name + '">' + name + '<br/>' ;
}
return showStr ;
2011-01-11 09:22:45 +00:00
}
/ * *
2012-05-04 00:54:58 +00:00
* Create the association table for dialogue , which show the status and start / stop associations
2011-01-11 09:22:45 +00:00
*
2012-05-04 00:54:58 +00:00
* @ param cond Condition
2011-01-11 09:22:45 +00:00
* /
2012-05-04 00:54:58 +00:00
function createAssociationTable ( cond ) {
var conditions = cond . split ( ';' ) ;
var name = '' ;
var tempLength = '' ;
var tempStatus = '' ;
var showStr = '<center><table><thead><tr><th>Condition Name</th><th>Status</th><th>Start/Stop</th></tr></thead>' ;
showStr += '<tbody>' ;
for ( var i in conditions ) {
name = conditions [ i ] ;
tempLength = name . length ;
tempStatus = name . substr ( tempLength - 3 ) ;
name = name . substr ( 1 , tempLength - 6 ) ;
if ( 'Not' == tempStatus ) {
showStr += '<tr style="background-color:#fffacd;"><td>' + name
+ '</td><td>Not Monitored</td>' ;
showStr += '<td><button id="button" name="' + name
+ '">Start</button></td>' ;
} else {
showStr += '<tr><td>' + name + '</td><td>Monitored</td>' ;
showStr += '<td><button id="button" name="' + name
+ '">Stop</button></td>' ;
}
showStr += '</tr>' ;
}
showStr += '<tbody></table></center>' ;
return showStr ;
2010-08-04 08:49:20 +00:00
}