2011-06-01 03:00:03 +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 ( ) {
2011-07-20 21:13:09 +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
2011-07-20 21:13:09 +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 ) ;
2011-09-12 16:10:53 +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 ) ;
2011-07-20 21:13:09 +00:00
//add configure div
2011-06-01 03:00:03 +00:00
rmcMonTab . append ( "<div id='rmcMonConfig'></div>" ) ;
$ ( '#rmcMonConfig' ) . hide ( ) ;
2011-07-20 21:13:09 +00:00
//load the configure div's content
2011-06-01 03:00:03 +00:00
loadRmcMonConfigure ( ) ;
2011-07-20 21:13:09 +00:00
//add the content of the rmcmon, id = 'rmcMonTab'
2011-06-01 03:00:03 +00:00
rmcMonTab . append ( "<div id='rmcMonShow'><div id='rmcmonSummary'></div><div id='rmcmonDetail'></div><div id='nodeDetail'></div></div>" ) ;
$ ( '#nodeDetail' ) . hide ( ) ;
2011-07-20 21:13:09 +00:00
//check the software work status by platform(linux and aix)
2011-09-12 16:10:53 +00:00
$ . ajax ( {
url : 'lib/systemcmd.php' ,
dataType : 'json' ,
data : {
cmd : 'ostype'
2011-06-01 03:00:03 +00:00
} ,
2011-09-12 16:10:53 +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 ( ) {
2011-07-20 21:13:09 +00:00
//get the configure div and clean its content.
2010-08-22 14:58:21 +00:00
var rmcmonCfgDiv = $ ( '#rmcMonConfig' ) ;
rmcmonCfgDiv . empty ( ) ;
2011-07-20 21:13:09 +00:00
//add the start button
2010-08-22 14:58:21 +00:00
var startButton = createButton ( 'Start' ) ;
rmcmonCfgDiv . append ( startButton ) ;
startButton . click ( function ( ) {
2011-04-27 20:28:00 +00:00
$ ( '#rmcMonStatus div' ) . empty ( ) . append ( createLoader ( ) ) ;
2010-08-22 14:58:21 +00:00
$ . ajax ( {
2011-09-12 16:10:53 +00:00
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'webrun' ,
tgt : '' ,
args : 'rmcstart;compute' ,
msg : ''
2010-08-22 14:58:21 +00:00
} ,
success : function ( data ) {
2011-04-27 20:28:00 +00:00
$ ( '#rmcMonStatus div' ) . empty ( ) . append ( data . rsp [ 0 ] ) ;
2010-08-22 14:58:21 +00:00
}
} ) ;
} ) ;
2011-07-20 21:13:09 +00:00
//add the stop button
2010-08-22 14:58:21 +00:00
var stopButton = createButton ( 'Stop' ) ;
rmcmonCfgDiv . append ( stopButton ) ;
2011-09-12 16:10:53 +00:00
stopButton . click ( function ( ) {
2011-04-27 20:28:00 +00:00
$ ( '#rmcMonStatus div' ) . empty ( ) . append ( createLoader ( ) ) ;
2010-08-22 14:58:21 +00:00
$ . ajax ( {
2011-09-12 16:10:53 +00:00
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'monstop' ,
tgt : '' ,
args : 'rmcmon' ,
msg : ''
2010-08-22 14:58:21 +00:00
} ,
2011-09-12 16:10:53 +00:00
success : function ( data ) {
2011-04-27 20:28:00 +00:00
$ ( '#rmcMonStatus div' ) . empty ( ) . append ( data . rsp [ 0 ] ) ;
2010-08-22 14:58:21 +00:00
}
} ) ;
} ) ;
//add the cancel button
var cancelButton = createButton ( 'Cancel' ) ;
rmcmonCfgDiv . append ( cancelButton ) ;
2011-09-12 16:10:53 +00:00
cancelButton . click ( function ( ) {
2010-08-22 14:58:21 +00:00
$ ( '#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 ) {
2011-07-20 21:13:09 +00:00
//linux had to check the rscp first
2011-09-12 16:10:53 +00:00
if ( 'aix' != data . rsp ) {
$ . ajax ( {
url : 'lib/systemcmd.php' ,
dataType : 'json' ,
data : {
cmd : 'rpm -q rsct.core'
2010-08-04 08:49:20 +00:00
} ,
2011-09-12 16:10:53 +00:00
success : function ( data ) {
if ( - 1 != data . rsp . indexOf ( "not" ) ) {
2011-04-27 20:28:00 +00:00
$ ( '#rmcMonStatus div' ) . empty ( ) . append (
2010-08-22 14:58:21 +00:00
'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/>' +
2010-11-05 22:53:47 +00:00
'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>' ) ;
2011-09-12 16:10:53 +00:00
} else {
2010-08-04 08:49:20 +00:00
xcatrmcRpmCheck ( ) ;
}
}
} ) ;
2011-09-12 16:10:53 +00:00
} else {
2010-08-04 08:49:20 +00:00
xcatrmcRpmCheck ( ) ;
}
}
2011-09-12 16:10:53 +00:00
function xcatrmcRpmCheck ( ) {
$ . ajax ( {
2010-08-04 08:49:20 +00:00
url : 'lib/systemcmd.php' ,
dataType : 'json' ,
data : {
2010-08-22 14:58:21 +00:00
cmd : 'rpm -q xCAT-rmc rrdtool'
2010-08-04 08:49:20 +00:00
} ,
2011-09-12 16:10:53 +00:00
success : function ( data ) {
2010-08-22 14:58:21 +00:00
var softInstallStatus = data . rsp . split ( /\n/ ) ;
var needHelp = false ;
2011-04-27 20:28:00 +00:00
$ ( '#rmcMonStatus div' ) . empty ( ) ;
2011-07-20 21:13:09 +00:00
//check the xcat-rmc
2011-09-12 16:10:53 +00:00
if ( - 1 != softInstallStatus [ 0 ] . indexOf ( "not" ) ) {
2010-08-22 14:58:21 +00:00
needHelp = true ;
2011-04-27 20:28:00 +00:00
$ ( '#rmcMonStatus div' ) . append (
2010-08-22 14:58:21 +00:00
'Please install the <a href="http://xcat.sourceforge.net/#download" target="install_window">xCAT-rmc</a> first.<br/>' ) ;
}
2011-07-20 21:13:09 +00:00
//check the rrdtool
2011-09-12 16:10:53 +00:00
if ( - 1 != softInstallStatus [ 1 ] . indexOf ( "not" ) ) {
2010-08-22 14:58:21 +00:00
needHelp = true ;
2011-04-27 20:28:00 +00:00
$ ( '#rmcMonStatus div' ) . append (
2010-08-22 14:58:21 +00:00
'Please install the <a href="http://oss.oetiker.ch/rrdtool/download.en.html" target="install_window">RRD-tool</a> first.<br/>' ) ;
}
2011-07-20 21:13:09 +00:00
//add help info or load the rmc show
2011-09-12 16:10:53 +00:00
if ( needHelp ) {
2011-04-27 20:28:00 +00:00
$ ( '#rmcMonStatus div' ) . append (
2010-08-22 14:58:21 +00:00
'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>' ) ;
2011-09-12 16:10:53 +00:00
} else {
2010-08-22 14:58:21 +00:00
rmcWorkingCheck ( ) ;
2010-08-04 08:49:20 +00:00
}
}
} ) ;
}
2011-09-12 16:10:53 +00:00
function rmcWorkingCheck ( ) {
$ ( '#rmcMonStatus div' ) . empty ( ) . append ( "Checking RMC working status" ) ;
2011-04-27 20:28:00 +00:00
$ ( '#rmcMonStatus div' ) . append ( createLoader ( ) ) ;
2010-08-22 14:58:21 +00:00
$ ( '#rmcmon button:first' ) . show ( ) ;
$ . ajax ( {
2011-09-12 16:10:53 +00:00
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'monls' ,
tgt : '' ,
args : 'rmcmon' ,
msg : ''
2010-08-22 14:58:21 +00:00
} ,
2011-09-12 16:10:53 +00:00
success : function ( data ) {
2010-08-22 14:58:21 +00:00
if ( - 1 != data . rsp [ 0 ] . indexOf ( "not-monitored" ) ) {
2011-09-12 16:10:53 +00:00
$ ( '#rmcMonStatus div' ) . empty ( ) . append ( "Please start the RMC Monitoring first" ) ;
2010-08-22 14:58:21 +00:00
return ;
}
loadRmcMonShow ( ) ;
}
} ) ;
}
2010-09-24 02:27:04 +00:00
2011-06-01 03:00:03 +00:00
function removeStatusBar ( ) {
if ( globalAllNodesNum == globalFinishNodesNum ) {
$ ( '#rmcMonStatus' ) . remove ( ) ;
}
$ ( '#rmcmonDetail [title]' ) . tooltip ( { position : [ 'center' , 'right' ] } ) ;
}
2011-07-20 21:13:09 +00:00
2010-08-04 08:49:20 +00:00
function loadRmcMonShow ( ) {
2011-09-12 16:10:53 +00:00
$ ( '#rmcMonStatus div' ) . empty ( ) . append ( "Getting summary data" ) ;
2011-04-27 20:28:00 +00:00
$ ( '#rmcMonStatus div' ) . append ( createLoader ( ) ) ;
2010-08-26 05:27:11 +00:00
2011-07-20 21:13:09 +00:00
//load the rmc status summary
2010-08-26 05:27:11 +00:00
$ . ajax ( {
2011-09-12 16:10:53 +00:00
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'webrun' ,
tgt : '' ,
args : 'rmcshow;summary;PctTotalTimeIdle,PctRealMemFree' ,
msg : ''
2010-08-26 05:27:11 +00:00
} ,
2011-09-12 16:10:53 +00:00
success : function ( data ) {
2010-08-26 05:27:11 +00:00
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
2011-06-01 03:00:03 +00:00
//update the rmc status area
2011-09-12 16:10:53 +00:00
$ ( '#rmcMonStatus div' ) . empty ( ) . append ( "Getting nodes data" ) . append ( createLoader ( ) ) ;
2011-07-20 21:13:09 +00:00
//load each nodes' status
2011-09-12 16:10:53 +00:00
$ . ajax ( {
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
2011-09-12 16:10:53 +00:00
success : function ( data ) {
2011-06-01 03:00:03 +00:00
parseRmcData ( data . rsp ) ;
}
} ) ;
2010-08-26 05:27:11 +00:00
2011-07-20 21:13:09 +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
2011-07-20 21:13:09 +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 ) ;
2011-07-28 08:29:08 +00:00
attrDiv = $ ( '<div id="monitorsumdiv' + attr + '" class="monitorsumdiv"></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 ) {
2011-06-01 03:00:03 +00:00
tempArray . push ( [ globalTimeStamp [ i ] , Number ( attrValues [ i ] ) ] ) ;
}
2010-09-13 08:44:19 +00:00
2011-06-01 03:00:03 +00:00
$ . jqplot ( 'monitorsumdiv' + attr , [ tempArray ] , {
2011-09-12 16:10:53 +00:00
series : [ {
2011-06-01 03:00:03 +00:00
showMarker : false
2011-09-12 16:10:53 +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
}
} ,
2011-09-12 16:10:53 +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 ;
$ ( '#rmcmonDetail' ) . empty ( ) . append ( '<h3>Detail</h3><hr/>' ) ;
//add the table for show nodes
var detailUl = $ ( '<ul style="margin:0px;padding:0px;"></ul>' ) ;
//update the table area
$ ( '#rmcmonDetail ul' ) . remove ( ) ;
$ ( '#rmcmonDetail' ) . append ( detailUl ) ;
globalAllNodesNum = returnData . length ;
globalFinishNodesNum = 0 ;
2011-09-12 16:10:53 +00:00
for ( var i in returnData ) {
2011-06-01 03:00:03 +00:00
var temp = returnData [ i ] . indexOf ( ':' ) ; ;
nodeName = returnData [ i ] . substr ( 0 , temp ) ;
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 : '' ,
args : 'rmcshow;' + nodeName + ';PctTotalTimeIdle,PctRealMemFree' ,
msg : nodeName
} ,
success : function ( data ) {
showRmcNodes ( data . rsp , data . msg ) ;
}
} ) ;
}
2010-09-13 08:44:19 +00:00
}
2011-09-12 16:10:53 +00:00
function createUnkownNode ( nodeName ) {
2011-07-28 08:29:08 +00:00
var tempLi = '<li class="monitorunknown ui-corner-all monitornodeli" id="' + nodeName + '" ' +
2011-06-01 03:00:03 +00:00
'title="Name:' + nodeName + '<br/>Unknown"></li>' ;
return tempLi ;
2010-09-13 08:44:19 +00:00
}
2011-09-12 16:10:53 +00:00
function createErrorNode ( nodeName ) {
2011-07-28 08:29:08 +00:00
var tempLi = '<li class="monitorerror ui-corner-all monitornodeli id="' + nodeName + '" ' +
2011-06-01 03:00:03 +00:00
'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 = { } ;
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 ) ;
//error node, can not 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 ] ) {
2011-06-01 03:00:03 +00:00
delete ( globalNodesDetail [ nodename ] ) ;
}
return ;
}
//normal node, save the values
tempObj [ attrname ] = values ;
}
globalNodesDetail [ nodename ] = tempObj ;
//get each average
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 ) ;
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 ) ;
if ( cpuAvg >= 10 && memAvg <= 90 ) {
2011-07-28 08:29:08 +00:00
classname = 'monitornormal' ;
2011-09-12 16:10:53 +00:00
} else {
2011-07-28 08:29:08 +00:00
classname = 'mornitorwarning' ;
2011-06-01 03:00:03 +00:00
}
2011-07-28 08:29:08 +00:00
var normalLi = $ ( '<li class="' + classname + ' ui-corner-all monitornodeli" id="' + nodename + '" title="' +
2011-06-01 03:00:03 +00:00
'Name:' + nodename + '<br/> CpuIdle: ' + cpuAvg + '%<br/> MemFree: ' + memAvg + '%"></li>' ) ;
$ ( '#rmcmonDetail ul' ) . append ( normalLi ) ;
normalLi . bind ( 'click' , function ( ) {
showNode ( $ ( this ) . attr ( 'id' ) ) ;
} ) ;
//check if the process finished
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 ) ;
for ( var attr in globalNodesDetail [ nodeName ] ) {
var tempTd = $ ( '<td style="border:0px;padding:1px 1px;"></td>' ) ;
var attrChat = $ ( '<div id="monitornodediv' + nodeName + attr
2011-07-28 08:29:08 +00:00
+ '" class="monitornodediv"></div>' ) ;
2011-06-01 03:00:03 +00:00
if ( 0 == parseNum % 4 ) {
nodeRow = $ ( '<tr></tr>' ) ;
nodeTable . append ( nodeRow ) ;
}
nodeRow . append ( tempTd ) ;
parseNum ++ ;
// data
tempTd . append ( attrChat ) ;
var tempData = globalNodesDetail [ nodeName ] [ attr ] . split ( ',' ) ;
var tempArray = [ ] ;
for ( var i in tempData ) {
tempArray . push ( [ globalTimeStamp [ i ] , Number ( tempData [ i ] ) ] ) ;
}
$ . jqplot ( 'monitornodediv' + nodeName + attr , [ tempArray ] , {
2011-09-12 16:10:53 +00:00
series : [ {
2011-06-01 03:00:03 +00:00
showMarker : false
2011-09-12 16:10:53 +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
}
/ * *
2011-09-12 16:10:53 +00:00
* load the rmc event tab
2011-06-01 03:00:03 +00:00
*
2011-09-12 16:10:53 +00:00
* @ return nothing
2010-12-16 03:14:55 +00:00
* /
function loadRmcEvent ( ) {
2011-07-20 21:13:09 +00:00
//find the rmcevent tab
2010-12-16 03:14:55 +00:00
2011-07-20 21:13:09 +00:00
//add the stauts bar first. id = 'rmcMonStatus'
2010-12-16 14:28:49 +00:00
var rmcStatusBar = createStatusBar ( 'rmcEventStatus' ) ;
2011-04-27 20:28:00 +00:00
rmcStatusBar . find ( 'div' ) . append ( createLoader ( ) ) ;
2010-12-16 03:14:55 +00:00
$ ( '#rmcevent' ) . append ( rmcStatusBar ) ;
$ ( '#rmcevent' ) . append ( '<div id="rmcEventDiv"></div>' ) ;
2011-09-12 16:10:53 +00:00
$ . ajax ( {
2010-12-16 03:14:55 +00:00
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'webrun' ,
tgt : '' ,
2010-12-16 14:28:49 +00:00
args : 'lsevent;-O;1000' ,
2010-12-16 03:14:55 +00:00
msg : ''
} ,
success : showEventLog
} ) ;
}
2010-12-25 02:17:00 +00:00
/ * *
2011-06-01 03:00:03 +00:00
* get all conditions
2010-12-25 02:17:00 +00:00
*
2011-09-12 16:10:53 +00:00
* @ return nothing
2010-12-25 02:17:00 +00:00
* /
function getConditions ( ) {
2011-09-12 16:10:53 +00:00
if ( ! globalCondition ) {
2011-04-27 20:28:00 +00:00
$ ( '#rmcEventStatus div' ) . empty ( ) . append ( 'Getting predefined conditions' ) . append ( createLoader ( ) ) ;
2010-12-25 02:17:00 +00:00
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'webrun' ,
tgt : '' ,
args : 'lscondition' ,
msg : ''
} ,
2011-04-16 14:40:15 +00:00
success : function ( data ) {
2011-04-27 20:28:00 +00:00
$ ( '#rmcEventStatus div' ) . empty ( ) ;
2011-01-11 09:22:45 +00:00
$ ( '#rmcEventButtons' ) . show ( ) ;
2010-12-25 02:17:00 +00:00
globalCondition = data . rsp [ 0 ] ;
}
} ) ;
2011-09-12 16:10:53 +00:00
} else {
2011-01-11 09:22:45 +00:00
$ ( '#rmcEventButtons' ) . show ( ) ;
}
2010-12-25 02:17:00 +00:00
}
/ * *
2011-06-01 03:00:03 +00:00
* get all response
2010-12-25 02:17:00 +00:00
*
2011-09-12 16:10:53 +00:00
* @ return nothing
2010-12-25 02:17:00 +00:00
* /
2011-09-12 16:10:53 +00:00
function getResponse ( ) {
2010-12-25 02:17:00 +00:00
var tempFlag = false ;
2011-07-20 21:13:09 +00:00
//get all response first
2011-09-12 16:10:53 +00:00
for ( var i in globalResponse ) {
2010-12-25 02:17:00 +00:00
tempFlag = true ;
break ;
}
2011-04-16 14:40:15 +00:00
2011-09-12 16:10:53 +00:00
if ( ! tempFlag ) {
2010-12-25 02:17:00 +00:00
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'webrun' ,
tgt : '' ,
args : 'lsresponse' ,
msg : ''
} ,
2011-09-12 16:10:53 +00:00
success : function ( data ) {
2010-12-25 02:17:00 +00:00
var resps = data . rsp [ 0 ] . split ( ';' ) ;
2011-09-12 16:10:53 +00:00
for ( var i in resps ) {
2010-12-25 02:17:00 +00:00
var name = resps [ i ] ;
name = name . substr ( 1 , ( name . length - 2 ) ) ;
globalResponse [ name ] = 1 ;
}
}
} ) ;
}
}
2010-12-16 03:14:55 +00:00
/ * *
2011-06-01 03:00:03 +00:00
* show all the event in the rmc event tab
2010-12-16 03:14:55 +00:00
*
2011-09-12 16:10:53 +00:00
* @ param data
* response from the xcat server
* @ return nothing
2010-12-16 03:14:55 +00:00
* /
2011-09-12 16:10:53 +00:00
function showEventLog ( data ) {
2011-04-27 20:28:00 +00:00
$ ( '#rmcEventStatus div' ) . empty ( ) ;
2011-06-01 03:00:03 +00:00
// rsct not installed.
2011-09-12 16:10:53 +00:00
if ( data . rsp [ 0 ] && ( - 1 != data . rsp [ 0 ] . indexOf ( 'lsevent' ) ) ) {
2011-04-27 20:28:00 +00:00
$ ( '#rmcEventStatus div' ) . append ( 'Please install RSCT first!' ) ;
2010-12-16 14:28:49 +00:00
return ;
}
2010-12-16 03:14:55 +00:00
var eventDiv = $ ( '#rmcEventDiv' ) ;
eventDiv . empty ( ) ;
2011-09-12 16:10:53 +00:00
2011-07-20 21:13:09 +00:00
//get conditions and responses, save in the global
2010-12-25 02:17:00 +00:00
getConditions ( ) ;
getResponse ( ) ;
2010-12-16 03:14:55 +00:00
var eventTable = new DataTable ( 'lsEventTable' ) ;
eventTable . init ( [ 'Time' , 'Type' , 'Content' ] ) ;
2011-09-12 16:10:53 +00:00
for ( var i in data . rsp ) {
2010-12-16 03:14:55 +00:00
var row = data . rsp [ i ] . split ( ';' ) ;
eventTable . add ( row ) ;
}
eventDiv . append ( eventTable . object ( ) ) ;
$ ( '#lsEventTable' ) . dataTable ( {
2011-09-12 16:10:53 +00:00
'iDisplayLength' : 50 ,
'bLengthChange' : false ,
"sScrollX" : "100%" ,
"bAutoWidth" : true
2010-12-16 03:14:55 +00:00
} ) ;
2011-09-12 16:10:53 +00:00
//add the configure button
loadRmcEventConfig ( ) ;
2011-07-20 21:13:09 +00:00
//unsort on the content column
2010-12-16 03:14:55 +00:00
$ ( '#lsEventTable thead tr th' ) . eq ( 2 ) . unbind ( 'click' ) ;
2010-12-16 14:28:49 +00:00
}
/ * *
* Add the configure button into rmc event tab
2011-09-12 16:10:53 +00:00
*
* @ return nothing
2010-12-16 14:28:49 +00:00
* /
function loadRmcEventConfig ( ) {
2011-09-12 16:10:53 +00:00
//create action bar
var actionBar = $ ( '<div class="actionBar"></div>' ) ;
var chCondScopeLnk = $ ( '<a>Change condition scope</a>' ) ;
chCondScopeLnk . bind ( 'click' , function ( ) {
2010-12-23 03:03:19 +00:00
chCondScopeDia ( ) ;
} ) ;
2011-09-12 16:10:53 +00:00
var mkCondRespLnk = $ ( '<a>Make/remove associatione</a>' ) ;
mkCondRespLnk . bind ( 'click' , function ( ) {
2010-12-28 09:34:44 +00:00
mkCondRespDia ( ) ;
2010-12-23 03:03:19 +00:00
} ) ;
2011-09-12 16:10:53 +00:00
var startCondRespLnk = $ ( '<a>Start/stop association</a>' ) ;
startCondRespLnk . bind ( 'click' , function ( ) {
2011-01-11 09:22:45 +00:00
startStopCondRespDia ( ) ;
2010-12-28 09:34:44 +00:00
} ) ;
2011-09-12 16:10:53 +00:00
//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
}
/ * *
* show the make association dialogue
*
2011-09-12 16:10:53 +00:00
* @ return nothing
2010-12-16 14:28:49 +00:00
* /
function mkCondRespDia ( ) {
2011-01-11 09:22:45 +00:00
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">' ;
2011-07-20 21:13:09 +00:00
//add the conditions into fieldset
2011-09-12 16:10:53 +00:00
if ( ! globalCondition ) {
mkAssociationTable += 'Getting predefined conditions, open this dislogue later' ;
} else {
2011-01-11 09:22:45 +00:00
mkAssociationTable += createConditionTd ( globalCondition ) ;
2010-12-25 02:17:00 +00:00
}
2011-09-12 16:10:53 +00:00
mkAssociationTable += '</td><td id="mkAssResp">Please select condition first</td></tr></tbody></table></center>' ;
2011-01-11 09:22:45 +00:00
diaDiv . append ( mkAssociationTable ) ;
diaDiv . append ( '<div id="selectedResp" style="display: none;" ><div>' ) ;
2011-07-20 21:13:09 +00:00
//change the response field when click the condition
2011-09-12 16:10:53 +00:00
diaDiv . find ( 'input:radio' ) . bind ( 'click' , function ( ) {
2011-01-11 09:22:45 +00:00
diaDiv . find ( '#mkAssResp' ) . empty ( ) . append ( 'Getting response' ) . append ( createLoader ( ) ) ;
2010-12-25 02:17:00 +00:00
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'webrun' ,
tgt : '' ,
args : 'lscondresp;"' + $ ( this ) . attr ( 'value' ) + '"' ,
msg : ''
} ,
2011-09-12 16:10:53 +00:00
success : function ( data ) {
2010-12-25 02:17:00 +00:00
var tempHash = new Object ( ) ;
2010-12-27 09:02:40 +00:00
var oldSelectedResp = '' ;
2010-12-25 02:17:00 +00:00
var showStr = '' ;
if ( data . rsp [ 0 ] ) {
var names = data . rsp [ 0 ] . split ( ';' ) ;
2011-09-12 16:10:53 +00:00
for ( var i in names ) {
2010-12-25 02:17:00 +00:00
var name = names [ i ] ;
name = name . substr ( 1 , name . length - 2 ) ;
tempHash [ name ] = 1 ;
}
}
2011-09-12 16:10:53 +00:00
for ( var name in globalResponse ) {
if ( tempHash [ name ] ) {
2011-01-11 09:22:45 +00:00
showStr += '<input type="checkbox" checked="checked" value="' + name + '">' + name + '<br/>' ;
2010-12-27 09:02:40 +00:00
oldSelectedResp += ';' + name ;
2011-09-12 16:10:53 +00:00
} else {
2011-01-11 09:22:45 +00:00
showStr += '<input type="checkbox" value="' + name + '">' + name + '<br/>' ;
2010-12-25 02:17:00 +00:00
}
}
2011-01-11 09:22:45 +00:00
diaDiv . find ( '#mkAssResp' ) . empty ( ) . append ( showStr ) ;
2010-12-27 09:02:40 +00:00
diaDiv . find ( '#selectedResp' ) . empty ( ) . append ( oldSelectedResp ) ;
2010-12-25 02:17:00 +00:00
}
} ) ;
} ) ;
2010-12-16 14:28:49 +00:00
diaDiv . dialog ( {
modal : true ,
2011-01-11 09:22:45 +00:00
width : 620 ,
height : 600 ,
2011-09-12 16:10:53 +00:00
close : function ( event , ui ) {
2010-12-16 14:28:49 +00:00
$ ( this ) . remove ( ) ;
} ,
buttons : {
2011-09-12 16:10:53 +00:00
'Ok' : function ( ) {
2010-12-27 09:02:40 +00:00
var newResp = new Object ( ) ;
var oldResp = new Object ( ) ;
var oldString = '' ;
var newString = '' ;
2011-07-20 21:13:09 +00:00
//get the old seelected responses
2010-12-27 09:02:40 +00:00
var conditionName = $ ( this ) . find ( '#mkAssCond :checked' ) . attr ( 'value' ) ;
2011-09-12 16:10:53 +00:00
if ( ! conditionName ) {
2010-12-27 09:02:40 +00:00
return ;
}
var temp = $ ( this ) . find ( '#selectedResp' ) . html ( ) ;
2011-09-12 16:10:53 +00:00
if ( ! temp ) {
2010-12-27 09:02:40 +00:00
return ;
}
var tempArray = temp . substr ( 1 ) . split ( ';' ) ;
2011-09-12 16:10:53 +00:00
for ( var i in tempArray ) {
2010-12-27 09:02:40 +00:00
oldResp [ tempArray [ i ] ] = 1 ;
}
2011-07-20 21:13:09 +00:00
//get the new selected responses
2010-12-27 09:02:40 +00:00
$ ( this ) . find ( '#mkAssResp input:checked' ) . each ( function ( ) {
var respName = $ ( this ) . attr ( 'value' ) ;
newResp [ respName ] = 1 ;
} ) ;
2011-09-12 16:10:53 +00:00
for ( var i in newResp ) {
if ( oldResp [ i ] ) {
2010-12-27 09:02:40 +00:00
delete oldResp [ i ] ;
delete newResp [ i ] ;
}
}
2011-07-20 21:13:09 +00:00
//add the response which are delete.
2011-09-12 16:10:53 +00:00
for ( var i in oldResp ) {
2010-12-27 09:02:40 +00:00
oldString += ',"' + i + '"' ;
}
2011-09-12 16:10:53 +00:00
if ( '' != oldString ) {
2010-12-27 09:02:40 +00:00
oldString = oldString . substr ( 1 ) ;
}
2011-07-20 21:13:09 +00:00
//add the response which are new add
2011-09-12 16:10:53 +00:00
for ( var i in newResp ) {
2010-12-27 09:02:40 +00:00
newString += ',"' + i + '"' ;
}
2011-09-12 16:10:53 +00:00
if ( '' != newString ) {
2010-12-27 09:02:40 +00:00
newString = newString . substr ( 1 ) ;
}
2011-09-12 16:10:53 +00:00
if ( ( '' != oldString ) || ( '' != newString ) ) {
$ ( '#rmcEventStatus div' ) . empty ( ) . append ( 'Create/remove associations ' ) . append ( createLoader ( ) ) ;
2010-12-27 09:02:40 +00:00
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'webrun' ,
tgt : '' ,
args : 'mkcondresp;"' + conditionName + '";+' + newString + ':-' + oldString ,
msg : ''
} ,
2011-09-12 16:10:53 +00:00
success : function ( data ) {
2011-04-27 20:28:00 +00:00
$ ( '#rmcEventStatus div' ) . empty ( ) . append ( data . rsp [ 0 ] ) ; ;
2010-12-27 09:02:40 +00:00
}
} ) ;
}
2010-12-16 14:28:49 +00:00
$ ( this ) . dialog ( 'close' ) ;
2011-09-12 16:10:53 +00:00
} ,
'Cancel' : function ( ) {
$ ( this ) . dialog ( 'close' ) ;
2010-12-16 14:28:49 +00:00
}
}
} ) ;
}
2010-12-23 03:03:19 +00:00
/ * *
* show the make condition dialogue
2011-09-12 16:10:53 +00:00
*
* @ return nothing
2010-12-23 03:03:19 +00:00
* /
2011-09-12 16:10:53 +00:00
function chCondScopeDia ( ) {
2011-01-11 09:22:45 +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>' ;
2010-12-25 02:17:00 +00:00
2011-01-11 09:22:45 +00:00
tableContent += '<tbody><tr><td id="changePreCond">' ;
2011-07-20 21:13:09 +00:00
//add the conditions into fieldset
2011-09-12 16:10:53 +00:00
if ( '' == globalCondition ) {
tableContent += 'Getting predefined conditions, open this dialogue later' ;
} else {
2011-01-11 09:22:45 +00:00
tableContent += createConditionTd ( globalCondition ) ;
}
tableContent += '</td><td id="changeGroup">' ;
2011-07-20 21:13:09 +00:00
//add the groups into table
2011-01-11 09:22:45 +00:00
var groups = $ . cookie ( 'groups' ) . split ( ',' ) ;
2011-09-12 16:10:53 +00:00
for ( var i in groups ) {
2011-01-11 09:22:45 +00:00
tableContent += '<input type="checkbox" value="' + groups [ i ] + '">' + groups [ i ] + '<br/>' ;
2010-12-25 02:17:00 +00:00
}
2011-01-11 09:22:45 +00:00
tableContent += '</td></tr></tbody></table></center>' ;
diaDiv . append ( tableContent ) ;
2011-07-20 21:13:09 +00:00
//fieldset to show status
2011-01-11 09:22:45 +00:00
diaDiv . append ( '<fieldset id="changeStatus"></fieldset>' ) ;
2011-07-20 21:13:09 +00:00
//create the dislogue
2010-12-23 03:03:19 +00:00
diaDiv . dialog ( {
2011-01-11 09:22:45 +00:00
modal : true ,
width : 500 ,
height : 600 ,
2011-09-12 16:10:53 +00:00
close : function ( event , ui ) {
2010-12-23 03:03:19 +00:00
$ ( this ) . remove ( ) ;
} ,
buttons : {
2011-09-12 16:10:53 +00:00
'Ok' : function ( ) {
2010-12-23 03:03:19 +00:00
$ ( '#changeStatus' ) . empty ( ) . append ( '<legend>Status</legend>' ) ;
var conditionName = $ ( '#changePreCond :checked' ) . attr ( 'value' ) ;
var groupName = '' ;
2011-09-12 16:10:53 +00:00
$ ( '#changeGroup :checked' ) . each ( function ( ) {
if ( '' == groupName ) {
2010-12-23 03:03:19 +00:00
groupName += $ ( this ) . attr ( 'value' ) ;
2011-09-12 16:10:53 +00:00
} else {
2010-12-23 03:03:19 +00:00
groupName += ',' + $ ( this ) . attr ( 'value' ) ;
}
} ) ;
2011-09-12 16:10:53 +00:00
if ( undefined == conditionName ) {
$ ( '#changeStatus' ) . append ( 'Please select conditon' ) ;
2010-12-23 03:03:19 +00:00
return ;
}
2011-09-12 16:10:53 +00:00
if ( '' == groupName ) {
$ ( '#changeStatus' ) . append ( 'Please select group' ) ;
2010-12-23 03:03:19 +00:00
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 ( ) ;
2011-09-12 16:10:53 +00:00
if ( - 1 != data . rsp [ 0 ] . indexOf ( 'Error' ) ) {
2010-12-23 03:03:19 +00:00
$ ( '#changeStatus' ) . append ( data . rsp [ 0 ] ) ;
2011-09-12 16:10:53 +00:00
} else {
2011-04-27 20:28:00 +00:00
$ ( '#rmcEventStatus div' ) . empty ( ) . append ( data . rsp [ 0 ] ) ;
2010-12-23 03:03:19 +00:00
$ ( '#chScopeDiaDiv' ) . remove ( ) ;
}
}
} ) ;
2011-09-12 16:10:53 +00:00
} ,
'Cancel' : function ( ) {
$ ( this ) . dialog ( 'close' ) ;
2010-12-23 03:03:19 +00:00
}
}
} ) ;
}
/ * *
* show the make response dialogue
*
2011-09-12 16:10:53 +00:00
* @ return nothing
2010-12-23 03:03:19 +00:00
* /
2011-09-12 16:10:53 +00:00
function mkResponseDia ( ) {
2010-12-23 03:03:19 +00:00
var diaDiv = $ ( '<div title="Make Response"><div>' ) ;
diaDiv . append ( 'under construction.' ) ;
diaDiv . dialog ( {
modal : true ,
width : 400 ,
2011-09-12 16:10:53 +00:00
close : function ( event , ui ) {
2010-12-23 03:03:19 +00:00
$ ( this ) . remove ( ) ;
} ,
buttons : {
2011-09-12 16:10:53 +00:00
'Ok' : function ( ) {
2010-12-23 03:03:19 +00:00
$ ( this ) . dialog ( 'close' ) ;
} ,
2011-09-12 16:10:53 +00:00
'Cancel' : function ( ) {
2010-12-23 03:03:19 +00:00
$ ( this ) . dialog ( 'close' ) ;
}
}
} ) ;
2010-12-25 02:17:00 +00:00
}
2010-12-28 09:34:44 +00:00
/ * *
* start the condition and response associations
*
2011-09-12 16:10:53 +00:00
* @ return nothing
2010-12-28 09:34:44 +00:00
* /
2011-09-12 16:10:53 +00:00
function startStopCondRespDia ( ) {
2011-01-11 09:22:45 +00:00
var diaDiv = $ ( '<div title="Start/Stop Association" id="divStartStopAss" class="tab"><div>' ) ;
2010-12-28 09:34:44 +00:00
diaDiv . append ( 'Getting conditions' ) . append ( createLoader ( ) ) ;
2011-09-12 16:10:53 +00:00
if ( ! globalCondition ) {
2011-01-11 09:22:45 +00:00
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'webrun' ,
tgt : '' ,
args : 'lscondition' ,
msg : ''
} ,
2011-09-12 16:10:53 +00:00
success : function ( data ) {
2011-01-11 09:22:45 +00:00
if ( data . rsp [ 0 ] ) {
globalcondition = data . rsp [ 0 ] ;
$ ( '#divStartStopAss' ) . empty ( ) . append ( createAssociationTable ( globalCondition ) ) ;
$ ( '#divStartStopAss' ) . dialog ( "option" , "position" , 'center' ) ;
2011-09-12 16:10:53 +00:00
} else {
$ ( '#divStartStopAss' ) . empty ( ) . append ( 'There are no conditions' ) ;
2011-01-11 09:22:45 +00:00
}
2010-12-28 09:34:44 +00:00
}
2011-01-11 09:22:45 +00:00
} ) ;
2011-09-12 16:10:53 +00:00
} else {
2011-01-11 09:22:45 +00:00
diaDiv . empty ( ) . append ( createAssociationTable ( globalCondition ) ) ;
}
2010-12-28 09:34:44 +00:00
diaDiv . dialog ( {
modal : true ,
width : 570 ,
2011-01-11 09:22:45 +00:00
height : 600 ,
2010-12-28 09:34:44 +00:00
close : function ( event , ui ) {
$ ( this ) . remove ( ) ;
} ,
buttons : {
2011-09-12 16:10:53 +00:00
'Close' : function ( ) {
2010-12-28 09:34:44 +00:00
$ ( this ) . dialog ( 'close' ) ;
2011-01-12 05:54:46 +00:00
}
}
} ) ;
2011-09-12 16:10:53 +00:00
$ ( '#divStartStopAss button' ) . bind ( 'click' , function ( ) {
2011-01-12 05:54:46 +00:00
var operationType = '' ;
var conditionName = $ ( this ) . attr ( 'name' ) ;
2011-09-12 16:10:53 +00:00
if ( 'Start' == $ ( this ) . html ( ) ) {
2011-01-12 05:54:46 +00:00
operationType = 'start' ;
2011-09-12 16:10:53 +00:00
} else {
2011-01-12 05:54:46 +00:00
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 = '' ;
2011-09-12 16:10:53 +00:00
if ( 'start' == data . msg . substr ( 0 , 5 ) ) {
2011-01-12 05:54:46 +00:00
newOperationType = 'Stop' ;
conditionName = data . msg . substr ( 6 ) ;
associationStatus = 'Monitored' ;
backgroudColor = '#ffffff' ;
2011-09-12 16:10:53 +00:00
} else {
2011-01-12 05:54:46 +00:00
newOperationType = 'Start' ;
conditionName = data . msg . substr ( 5 ) ;
associationStatus = 'Not Monitored' ;
backgroudColor = '#fffacd' ;
}
var button = $ ( '#divStartStopAss button[name="' + conditionName + '"]' ) ;
2011-09-12 16:10:53 +00:00
if ( data . rsp [ 0 ] ) {
2011-04-27 20:28:00 +00:00
$ ( '#rmcEventStatus div' ) . empty ( ) . append ( 'Getting associations\' status' ) . append ( createLoader ( ) ) ;
2011-01-12 05:54:46 +00:00
$ ( '#rmcEventButtons' ) . hide ( ) ;
button . html ( newOperationType ) ;
button . parent ( ) . prev ( ) . html ( associationStatus ) ;
button . parent ( ) . parent ( ) . css ( 'background-color' , backgroudColor ) ;
globalCondition = '' ;
getConditions ( ) ;
2011-09-12 16:10:53 +00:00
} else {
2011-01-12 05:54:46 +00:00
button . html ( 'Error' ) ;
}
$ ( '#divStartStopAss' ) . dialog ( 'option' , 'disabled' , false ) ;
}
} ) ;
2010-12-28 09:34:44 +00:00
} ) ;
}
/ * *
* stop the condition and response associations
*
2011-09-12 16:10:53 +00:00
* @ return nothing
2010-12-28 09:34:44 +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 : ''
} ,
2011-09-12 16:10:53 +00:00
success : function ( data ) {
if ( data . rsp [ 0 ] ) {
2010-12-28 09:34:44 +00:00
$ ( '#stopAss' ) . empty ( ) . append ( createConditionTable ( data . rsp [ 0 ] ) ) ;
$ ( '#stopAss' ) . dialog ( "option" , "position" , 'center' ) ;
2011-09-12 16:10:53 +00:00
} else {
2010-12-28 09:34:44 +00:00
$ ( '#stopAss' ) . empty ( ) . append ( 'There is not monitored condition.' ) ;
}
}
} ) ;
diaDiv . dialog ( {
modal : true ,
width : 570 ,
2011-09-12 16:10:53 +00:00
close : function ( event , ui ) {
2010-12-28 09:34:44 +00:00
$ ( this ) . remove ( ) ;
} ,
buttons : {
2011-09-12 16:10:53 +00:00
'Stop' : function ( ) {
2010-12-28 09:34:44 +00:00
var conditionName = $ ( '#stopAss :checked' ) . attr ( 'value' ) ;
2011-09-12 16:10:53 +00:00
if ( ! conditionName ) {
2010-12-28 09:34:44 +00:00
alert ( 'Select condition name please.' ) ;
return ;
}
2011-04-27 20:28:00 +00:00
$ ( '#rmcEventStatus div' ) . empty ( ) . append ( 'Stoping monitor on ' + conditionName ) . append ( createLoader ( ) ) ;
2010-12-28 09:34:44 +00:00
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'webrun' ,
tgt : '' ,
args : 'stopcondresp;' + conditionName ,
msg : ''
} ,
2011-09-12 16:10:53 +00:00
success : function ( data ) {
2011-04-27 20:28:00 +00:00
$ ( '#rmcEventStatus div' ) . empty ( ) . append ( data . rsp [ 0 ] ) ;
2010-12-28 09:34:44 +00:00
}
} ) ;
$ ( this ) . dialog ( 'close' ) ;
2011-09-12 16:10:53 +00:00
} ,
'Cancel' : function ( ) {
$ ( this ) . dialog ( 'close' ) ;
2010-12-28 09:34:44 +00:00
}
}
} ) ;
}
2010-12-25 02:17:00 +00:00
/ * *
* create the condition table for dialogue
2011-09-12 16:10:53 +00:00
*
* @ param cond
* condition
* @ return nothing
2010-12-25 02:17:00 +00:00
* /
2011-01-11 09:22:45 +00:00
function createConditionTd ( cond ) {
2010-12-25 02:17:00 +00:00
var conditions = cond . split ( ';' ) ;
var name = '' ;
2011-01-11 09:22:45 +00:00
var showStr = '' ;
2011-09-12 16:10:53 +00:00
for ( var i in conditions ) {
2010-12-25 02:17:00 +00:00
name = conditions [ i ] ;
2011-01-11 09:22:45 +00:00
//because there is status and quotation marks in name, so 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 ;
}
/ * *
* create the association table for dialogue , which show the status
* and start / stop associations
*
2011-09-12 16:10:53 +00:00
* @ param cond
* Condition
* @ return nothing
2011-01-11 09:22:45 +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>' ;
2011-09-12 16:10:53 +00:00
for ( var i in conditions ) {
2011-01-11 09:22:45 +00:00
name = conditions [ i ] ;
tempLength = name . length ;
tempStatus = name . substr ( tempLength - 3 ) ;
name = name . substr ( 1 , tempLength - 6 ) ;
2011-09-12 16:10:53 +00:00
if ( 'Not' == tempStatus ) {
2011-01-12 05:54:46 +00:00
showStr += '<tr style="background-color:#fffacd;"><td>' + name + '</td><td>Not Monitored</td>' ;
showStr += '<td><button id="button" name="' + name + '">Start</button></td>' ;
2011-09-12 16:10:53 +00:00
} else {
2011-01-12 05:54:46 +00:00
showStr += '<tr><td>' + name + '</td><td>Monitored</td>' ;
showStr += '<td><button id="button" name="' + name + '">Stop</button></td>' ;
2010-12-25 02:17:00 +00:00
}
2011-01-11 09:22:45 +00:00
showStr += '</tr>' ;
2010-12-25 02:17:00 +00:00
}
2011-01-11 09:22:45 +00:00
showStr += '<tbody></table></center>' ;
2010-12-25 02:17:00 +00:00
return showStr ;
2010-08-04 08:49:20 +00:00
}