2011-01-13 23:06:31 +00:00
/ * *
* Global variables
* /
2011-01-14 20:25:14 +00:00
var gangliaTableId = 'nodesDatatable' ;
2011-01-14 05:05:06 +00:00
var gangliaNodesList ;
2011-01-13 23:06:31 +00:00
2010-11-05 22:53:47 +00:00
/ * *
* Load Ganglia monitoring tool
*
* @ return Nothing
* /
function loadGangliaMon ( ) {
// Get Ganglia tab
var gangliaTab = $ ( '#gangliamon' ) ;
2010-11-17 18:53:40 +00:00
2010-11-05 22:53:47 +00:00
// Check whether Ganglia RPMs are installed on the xCAT MN
2011-01-14 05:05:06 +00:00
$ . ajax ( {
2010-09-17 08:39:17 +00:00
url : 'lib/systemcmd.php' ,
dataType : 'json' ,
data : {
cmd : 'rpm -q rrdtool ganglia-gmetad ganglia-gmond ganglia-web'
} ,
2010-11-05 22:53:47 +00:00
success : checkGangliaRPMs
2010-09-17 08:39:17 +00:00
} ) ;
2010-11-17 18:53:40 +00:00
2010-11-05 22:53:47 +00:00
// Create groups and nodes DIV
var groups = $ ( '<div id="groups"></div>' ) ;
var nodes = $ ( '<div id="nodes"></div>' ) ;
gangliaTab . append ( groups ) ;
gangliaTab . append ( nodes ) ;
2010-09-17 08:39:17 +00:00
2010-11-05 22:53:47 +00:00
// Create info bar
var info = createInfoBar ( 'Select a group to view its nodes' ) ;
nodes . append ( info ) ;
// Get groups
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'extnoderange' ,
tgt : '/.*' ,
args : 'subgroups' ,
msg : ''
} ,
success : loadGroups4Ganglia
2010-09-17 08:39:17 +00:00
} ) ;
2010-11-05 22:53:47 +00:00
return ;
2010-09-17 08:39:17 +00:00
}
2010-11-05 22:53:47 +00:00
/ * *
* Check whether Ganglia RPMs are installed
*
* @ param data
* Data returned from HTTP request
* @ return Nothing
* /
function checkGangliaRPMs ( data ) {
var gangliaTab = $ ( '#gangliamon' ) ;
2010-11-17 18:53:40 +00:00
2010-11-05 22:53:47 +00:00
// Get the list of Ganglia RPMs installed
var status = data . rsp . split ( /\n/ ) ;
var gangliaRPMs = [ "rrdtool" , "ganglia-gmetad" , "ganglia-gmond" , "ganglia-web" ] ;
var warningMsg = 'Before continuing, please install the following packages: ' ;
var missingRPMs = false ;
for ( var i in status ) {
if ( status [ i ] . indexOf ( "not installed" ) > - 1 ) {
warningMsg += gangliaRPMs [ i ] + ' ' ;
missingRPMs = true ;
}
}
2010-11-17 18:53:40 +00:00
2010-11-05 22:53:47 +00:00
// Append Ganglia PDF
if ( missingRPMs ) {
warningMsg += ". Refer to <a href='http://xcat.svn.sourceforge.net/viewvc/xcat/xcat-core/trunk/xCAT-client/share/doc/xCAT2-Monitoring.pdf'>xCAT2-Monitoring.pdf</a> for more information." ;
2010-11-17 18:53:40 +00:00
2010-11-05 22:53:47 +00:00
var warningBar = createWarnBar ( warningMsg ) ;
warningBar . css ( 'margin-bottom' , '10px' ) ;
warningBar . prependTo ( gangliaTab ) ;
2010-11-06 00:15:13 +00:00
} else {
// Check if ganglia is running on the xCAT MN
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'monls' ,
tgt : '' ,
args : 'gangliamon' ,
msg : ''
} ,
/ * *
* Append warning message
*
* @ param data
* Data returned from HTTP request
* @ return Nothing
* /
success : function ( data ) {
if ( data . rsp [ 0 ] . indexOf ( "not-monitored" ) > - 1 ) {
// Create link to start Ganglia
2011-01-19 15:56:43 +00:00
var startLnk = $ ( '<a href="#">Click here</a>' ) ;
startLnk . css ( {
'color' : 'blue' ,
'text-decoration' : 'none'
} ) ;
startLnk . click ( function ( ) {
// Turn on Ganglia for all nodes
monitorNode ( '' , 'on' ) ;
} ) ;
// Create warning bar
var warningBar = $ ( '<div class="ui-state-error ui-corner-all"></div>' ) ;
var msg = $ ( '<p></p>' ) ;
msg . append ( '<span class="ui-icon ui-icon-alert"></span>' ) ;
msg . append ( 'Please start Ganglia Monitoring on xCAT. ' ) ;
msg . append ( startLnk ) ;
msg . append ( ' to start Ganglia Monitoring.' ) ;
warningBar . append ( msg ) ;
warningBar . css ( 'margin-bottom' , '10px' ) ;
// If there are any warning messages, append this warning after it
var curWarnings = $ ( '#gangliamon' ) . find ( '.ui-state-error' ) ;
var gangliaTab = $ ( '#gangliamon' ) ;
if ( curWarnings . length ) {
curWarnings . after ( warningBar ) ;
} else {
warningBar . prependTo ( gangliaTab ) ;
}
}
2010-11-06 00:15:13 +00:00
}
2010-11-17 18:53:40 +00:00
} ) ;
2010-11-06 00:15:13 +00:00
}
2010-11-05 22:53:47 +00:00
return ;
}
/ * *
* Load groups
*
* @ param data
* Data returned from HTTP request
* @ return
* /
function loadGroups4Ganglia ( data ) {
// Remove loader
$ ( '#groups' ) . find ( 'img' ) . remove ( ) ;
2010-11-17 18:53:40 +00:00
2010-11-05 22:53:47 +00:00
var groups = data . rsp ;
setGroupsCookies ( data ) ;
// Create a list of groups
var ul = $ ( '<ul></ul>' ) ;
var item = $ ( '<li id="root"><h3>Groups</h3></li>' ) ;
ul . append ( item ) ;
var subUL = $ ( '<ul></ul>' ) ;
item . append ( subUL ) ;
// Create a link for each group
for ( var i = groups . length ; i -- ; ) {
2010-11-12 14:01:28 +00:00
var subItem = $ ( '<li id="' + groups [ i ] + '"></li>' ) ;
var link = $ ( '<a>' + groups [ i ] + '</a>' ) ;
2010-11-05 22:53:47 +00:00
subItem . append ( link ) ;
subUL . append ( subItem ) ;
}
// Turn groups list into a tree
$ ( '#groups' ) . append ( ul ) ;
$ ( '#groups' ) . jstree ( {
2010-11-17 18:53:40 +00:00
core : {
"initially_open" : [ "root" ]
} ,
2010-11-05 22:53:47 +00:00
themes : {
"theme" : "default" ,
2010-11-17 18:53:40 +00:00
"dots" : false , // No dots
"icons" : false // No icons
2010-11-05 22:53:47 +00:00
}
2010-09-17 08:39:17 +00:00
} ) ;
2010-11-17 18:53:40 +00:00
2010-11-12 14:01:28 +00:00
// Load nodes onclick
2011-01-14 05:05:06 +00:00
$ ( '#groups' ) . bind ( 'select_node.jstree' , function ( event , data ) {
2010-11-18 00:39:27 +00:00
// If there are subgroups, remove them
data . rslt . obj . children ( 'ul' ) . remove ( ) ;
2010-11-17 18:53:40 +00:00
var thisGroup = jQuery . trim ( data . rslt . obj . text ( ) ) ;
if ( thisGroup ) {
// Clear nodes division
2010-11-12 14:01:28 +00:00
$ ( '#nodes' ) . children ( ) . remove ( ) ;
2010-11-17 18:53:40 +00:00
2010-11-12 14:01:28 +00:00
// Create link to Ganglia
var gangliaLnk = $ ( '<a href="#">click here</a>' ) ;
gangliaLnk . css ( {
'color' : 'blue' ,
'text-decoration' : 'none'
} ) ;
gangliaLnk . click ( function ( ) {
// Open a new window for Ganglia
window . open ( '../ganglia/' ) ;
} ) ;
// Create info bar
var info = $ ( '<div class="ui-state-highlight ui-corner-all"></div>' ) ;
var msg = $ ( '<p></p>' ) ;
msg . append ( '<span class="ui-icon ui-icon-info"></span>' ) ;
2010-12-21 02:47:30 +00:00
msg . append ( 'Review the nodes that are monitored by Ganglia. You can turn on Ganglia monitoring on a node by selecting it and clicking on Monitor. If you are satisfied with the nodes you want to monitor, ' ) ;
2010-11-12 14:01:28 +00:00
msg . append ( gangliaLnk ) ;
msg . append ( ' to open Ganglia page.' ) ;
info . append ( msg ) ;
info . css ( 'margin-bottom' , '10px' ) ;
$ ( '#nodes' ) . append ( info ) ;
// Create loader
var loader = $ ( '<center></center>' ) . append ( createLoader ( ) ) ;
// Create a tab for this group
var tab = new Tab ( ) ;
setNodesTab ( tab ) ;
tab . init ( ) ;
$ ( '#nodes' ) . append ( tab . object ( ) ) ;
tab . add ( 'nodesTab' , 'Nodes' , loader , false ) ;
2010-11-17 18:53:40 +00:00
2011-01-14 05:05:06 +00:00
// To improve performance, get all nodes within selected group
// Get node definitions only for first 50 nodes
2010-11-12 14:01:28 +00:00
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
2011-01-14 05:05:06 +00:00
cmd : 'nodels' ,
tgt : thisGroup ,
args : '' ,
2010-11-12 14:01:28 +00:00
msg : thisGroup
} ,
2011-01-14 05:05:06 +00:00
/ * *
* Get node definitions for first 50 nodes
*
* @ param data
* Data returned from HTTP request
* @ return Nothing
* /
success : function ( data ) {
var rsp = data . rsp ;
var group = data . msg ;
// Save nodes in a list so it can be accessed later
nodesList = new Array ( ) ;
for ( var i in rsp ) {
if ( rsp [ i ] [ 0 ] ) {
nodesList . push ( rsp [ i ] [ 0 ] ) ;
}
}
// Sort nodes list
nodesList . sort ( ) ;
// Get first 50 nodes
var nodes = '' ;
for ( var i = 0 ; i < nodesList . length ; i ++ ) {
if ( i > 49 ) {
break ;
}
nodes += nodesList [ i ] + ',' ;
}
// Remove last comma
nodes = nodes . substring ( 0 , nodes . length - 1 ) ;
// Get nodes definitions
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'lsdef' ,
tgt : '' ,
args : nodes ,
msg : group
} ,
success : loadNodes4Ganglia
} ) ;
}
2010-11-12 14:01:28 +00:00
} ) ;
2011-01-14 05:05:06 +00:00
// Get subgroups within selected group
// only when this is the parent group and not a subgroup
2010-11-12 14:01:28 +00:00
if ( data . rslt . obj . attr ( 'id' ) . indexOf ( 'Subgroup' ) < 0 ) {
2011-01-14 05:05:06 +00:00
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'extnoderange' ,
tgt : thisGroup ,
args : 'subgroups' ,
msg : thisGroup
} ,
success : loadSubgroups
} ) ;
2010-11-12 14:01:28 +00:00
}
} // End of if (thisGroup)
2010-12-21 02:47:30 +00:00
} ) ;
2010-09-17 08:39:17 +00:00
}
2010-09-24 02:27:04 +00:00
2010-11-05 22:53:47 +00:00
/ * *
* Load nodes belonging to a given group
*
* @ param data
* Data returned from HTTP request
* @ return Nothing
* /
function loadNodes4Ganglia ( data ) {
// Data returned
var rsp = data . rsp ;
// Group name
var group = data . msg ;
// Node attributes hash
var attrs = new Object ( ) ;
// Node attributes
var headers = new Object ( ) ;
2010-12-09 03:44:11 +00:00
// Variable to send command and request node status
var getNodeStatus = true ;
2011-01-19 15:56:43 +00:00
var node , args ;
2010-11-05 22:53:47 +00:00
for ( var i in rsp ) {
// Get the node
var pos = rsp [ i ] . indexOf ( 'Object name:' ) ;
if ( pos > - 1 ) {
var temp = rsp [ i ] . split ( ': ' ) ;
node = jQuery . trim ( temp [ 1 ] ) ;
// Create a hash for the node attributes
attrs [ node ] = new Object ( ) ;
i ++ ;
}
// Get key and value
2011-01-14 05:05:06 +00:00
args = rsp [ i ] . split ( '=' , 2 ) ;
2010-11-05 22:53:47 +00:00
var key = jQuery . trim ( args [ 0 ] ) ;
2011-01-14 05:05:06 +00:00
var val = jQuery . trim ( rsp [ i ] . substring ( rsp [ i ] . indexOf ( '=' ) + 1 , rsp [ i ] . length ) ) ;
2010-11-05 22:53:47 +00:00
// Create a hash table
attrs [ node ] [ key ] = val ;
headers [ key ] = 1 ;
2010-12-09 03:44:11 +00:00
// If the node status is available
if ( key == 'status' ) {
// Do not send command to request node status
getNodeStatus = false ;
}
2010-11-05 22:53:47 +00:00
}
2011-01-14 05:05:06 +00:00
// Add nodes that are not in data returned
for ( var i in nodesList ) {
if ( ! attrs [ nodesList [ i ] ] ) {
// Create attributes list and save node name
attrs [ nodesList [ i ] ] = new Object ( ) ;
attrs [ nodesList [ i ] ] [ 'node' ] = nodesList [ i ] ;
}
}
2010-11-05 22:53:47 +00:00
// Sort headers
var sorted = new Array ( ) ;
for ( var key in headers ) {
2010-12-09 03:44:11 +00:00
// Do not put comments and status in
2010-12-19 19:13:21 +00:00
if ( key != 'usercomment' && key != 'status' && key . indexOf ( 'statustime' ) < 0 ) {
2010-12-09 03:44:11 +00:00
sorted . push ( key ) ;
}
2010-11-05 22:53:47 +00:00
}
sorted . sort ( ) ;
// Add column for check box, node, ping, and power
2010-12-09 03:44:11 +00:00
sorted . unshift ( '<input type="checkbox" onclick="selectAllCheckbox(event, $(this))">' ,
'node' ,
2010-12-19 19:13:21 +00:00
'<span><a>status</a></span><img src="images/loader.gif"></img>' ,
'<span><a>power</a></span><img src="images/loader.gif" style="display: none;"></img>' ,
2010-12-09 03:44:11 +00:00
'<a>ganglia</a><img src="images/loader.gif"></img>' ) ;
2010-11-05 22:53:47 +00:00
// Create a datatable
2011-01-14 05:05:06 +00:00
var gangliaTable = new DataTable ( gangliaTableId ) ;
gangliaTable . init ( sorted ) ;
2010-11-05 22:53:47 +00:00
// Go through each node
for ( var node in attrs ) {
// Create a row
var row = new Array ( ) ;
2011-01-14 05:05:06 +00:00
// Create a check box, node link, and get node status
2010-11-05 22:53:47 +00:00
var checkBx = '<input type="checkbox" name="' + node + '"/>' ;
var nodeLink = $ ( '<a class="node" id="' + node + '">' + node + '</a>' ) . bind ( 'click' , loadNode ) ;
2010-12-09 03:44:11 +00:00
2011-01-14 05:05:06 +00:00
// If there is no status attribute for the node, do not try to access hash table
// Else the code will break
var status = '' ;
if ( attrs [ node ] [ 'status' ] ) {
status = attrs [ node ] [ 'status' ] . replace ( 'sshd' , 'ping' ) ;
}
// Push in checkbox, node, status, and power
2010-12-09 03:44:11 +00:00
row . push ( checkBx , nodeLink , status , '' , '' ) ;
2010-11-05 22:53:47 +00:00
// Go through each header
for ( var i = 5 ; i < sorted . length ; i ++ ) {
// Add the node attributes to the row
var key = sorted [ i ] ;
2010-12-09 03:44:11 +00:00
// Do not put comments and status in
2010-12-19 19:13:21 +00:00
if ( key != 'usercomment' && key != 'status' && key . indexOf ( 'statustime' ) < 0 ) {
2010-12-09 03:44:11 +00:00
var val = attrs [ node ] [ key ] ;
if ( val ) {
row . push ( val ) ;
} else {
row . push ( '' ) ;
}
2010-11-05 22:53:47 +00:00
}
2010-09-17 08:39:17 +00:00
}
2010-11-05 22:53:47 +00:00
// Add the row to the table
2011-01-14 05:05:06 +00:00
gangliaTable . add ( row ) ;
2010-09-17 08:39:17 +00:00
}
2011-01-14 05:05:06 +00:00
2010-11-05 22:53:47 +00:00
// Clear the tab before inserting the table
$ ( '#nodesTab' ) . children ( ) . remove ( ) ;
// Create action bar
var actionBar = $ ( '<div class="actionBar"></div>' ) ;
/ * *
* The following actions are available to perform against a given node :
* power and monitor
* /
/ *
* Power
* /
var powerLnk = $ ( '<a>Power</a>' ) ;
2010-11-17 18:53:40 +00:00
// Power on
2010-11-05 22:53:47 +00:00
var powerOnLnk = $ ( '<a>Power on</a>' ) ;
2011-01-14 05:05:06 +00:00
powerOnLnk . click ( function ( ) {
var tgtNodes = getNodesChecked ( gangliaTableId ) ;
2010-11-05 22:53:47 +00:00
if ( tgtNodes ) {
powerNode ( tgtNodes , 'on' ) ;
}
} ) ;
2010-11-17 18:53:40 +00:00
// Power off
2010-11-05 22:53:47 +00:00
var powerOffLnk = $ ( '<a>Power off</a>' ) ;
2011-01-14 05:05:06 +00:00
powerOffLnk . click ( function ( ) {
var tgtNodes = getNodesChecked ( gangliaTableId ) ;
2010-11-05 22:53:47 +00:00
if ( tgtNodes ) {
powerNode ( tgtNodes , 'off' ) ;
}
} ) ;
// Power actions
var powerActions = [ powerOnLnk , powerOffLnk ] ;
var powerActionMenu = createMenu ( powerActions ) ;
/ *
* Monitor
* /
var monitorLnk = $ ( '<a>Monitor</a>' ) ;
2010-11-17 18:53:40 +00:00
// Turn monitoring on
2010-11-05 22:53:47 +00:00
var monitorOnLnk = $ ( '<a>Monitor on</a>' ) ;
2011-01-14 05:05:06 +00:00
monitorOnLnk . click ( function ( ) {
var tgtNodes = getNodesChecked ( gangliaTableId ) ;
2010-11-05 22:53:47 +00:00
if ( tgtNodes ) {
monitorNode ( tgtNodes , 'on' ) ;
}
} ) ;
2010-11-17 18:53:40 +00:00
// Turn monitoring off
2010-11-05 22:53:47 +00:00
var monitorOffLnk = $ ( '<a>Monitor off</a>' ) ;
2011-01-14 05:05:06 +00:00
monitorOffLnk . click ( function ( ) {
var tgtNodes = getNodesChecked ( gangliaTableId ) ;
2010-11-05 22:53:47 +00:00
if ( tgtNodes ) {
monitorNode ( tgtNodes , 'off' ) ;
}
} ) ;
2010-11-17 18:53:40 +00:00
2010-11-05 22:53:47 +00:00
// Power actions
var monitorActions = [ monitorOnLnk , monitorOffLnk ] ;
var monitorActionMenu = createMenu ( monitorActions ) ;
2011-01-14 05:05:06 +00:00
// Create an action menu
2010-11-05 22:53:47 +00:00
var actionsDIV = $ ( '<div></div>' ) ;
var actions = [ [ powerLnk , powerActionMenu ] , [ monitorLnk , monitorActionMenu ] ] ;
var actionMenu = createMenu ( actions ) ;
actionMenu . superfish ( ) ;
actionsDIV . append ( actionMenu ) ;
actionBar . append ( actionsDIV ) ;
$ ( '#nodesTab' ) . append ( actionBar ) ;
// Insert table
2011-01-14 05:05:06 +00:00
$ ( '#nodesTab' ) . append ( gangliaTable . object ( ) ) ;
2010-11-05 22:53:47 +00:00
// Turn table into a datatable
2011-01-14 05:05:06 +00:00
var gangliaDataTable = $ ( '#' + gangliaTableId ) . dataTable ( {
'iDisplayLength' : 50
} ) ;
// Filter table when enter key is pressed
$ ( '#' + gangliaTableId + '_filter input' ) . unbind ( ) ;
$ ( '#' + gangliaTableId + '_filter input' ) . bind ( 'keyup' , function ( e ) {
if ( e . keyCode == 13 ) {
var table = $ ( '#' + gangliaTableId ) . dataTable ( ) ;
table . fnFilter ( $ ( this ) . val ( ) ) ;
// If there are nodes found, get the node attributes
if ( ! $ ( '#' + gangliaTableId + ' .dataTables_empty' ) . length ) {
getNodeAttrs4Ganglia ( group ) ;
}
}
} ) ;
// Load node definitions when next or previous buttons are clicked
$ ( '#' + gangliaTableId + '_next, #' + gangliaTableId + '_previous' ) . click ( function ( ) {
getNodeAttrs4Ganglia ( group ) ;
} ) ;
2010-11-05 22:53:47 +00:00
2011-01-14 05:05:06 +00:00
// Do not sort ping, power, and comment column
var cols = $ ( '#' + gangliaTableId + ' thead tr th' ) . click ( function ( ) {
getNodeAttrs4Ganglia ( group ) ;
} ) ;
var pingCol = $ ( '#' + gangliaTableId + ' thead tr th' ) . eq ( 2 ) ;
var powerCol = $ ( '#' + gangliaTableId + ' thead tr th' ) . eq ( 3 ) ;
var gangliaCol = $ ( '#' + gangliaTableId + ' thead tr th' ) . eq ( 4 ) ;
2010-11-05 22:53:47 +00:00
pingCol . unbind ( 'click' ) ;
powerCol . unbind ( 'click' ) ;
gangliaCol . unbind ( 'click' ) ;
// Create enough space for loader to be displayed
2010-12-03 22:09:36 +00:00
var style = { 'min-width' : '60px' , 'text-align' : 'center' } ;
2011-01-14 05:05:06 +00:00
$ ( '#' + gangliaTableId + ' tbody tr td:nth-child(3)' ) . css ( style ) ;
$ ( '#' + gangliaTableId + ' tbody tr td:nth-child(4)' ) . css ( style ) ;
$ ( '#' + gangliaTableId + ' tbody tr td:nth-child(5)' ) . css ( style ) ;
2010-11-05 22:53:47 +00:00
// Instead refresh the ping status and power status
2010-12-20 14:52:48 +00:00
pingCol . find ( 'span a' ) . bind ( 'click' , function ( event ) {
2011-01-14 20:25:14 +00:00
refreshNodeStatus ( group , gangliaTableId ) ;
2010-11-05 22:53:47 +00:00
} ) ;
2010-12-20 14:52:48 +00:00
powerCol . find ( 'span a' ) . bind ( 'click' , function ( event ) {
2011-01-14 20:25:14 +00:00
refreshPowerStatus ( group , gangliaTableId ) ;
2010-11-05 22:53:47 +00:00
} ) ;
gangliaCol . bind ( 'click' , function ( event ) {
refreshGangliaStatus ( group ) ;
} ) ;
2010-12-19 19:13:21 +00:00
// Create tooltip for status
var pingTip = createStatusToolTip ( ) ;
pingCol . find ( 'span' ) . append ( pingTip ) ;
pingCol . find ( 'span a' ) . tooltip ( {
position : "center right" ,
offset : [ - 2 , 10 ] ,
effect : "fade" ,
opacity : 0.8 ,
relative : true ,
predelay : 800
} ) ;
// Create tooltip for power
var powerTip = createPowerToolTip ( ) ;
powerCol . find ( 'span' ) . append ( powerTip ) ;
powerCol . find ( 'span a' ) . tooltip ( {
position : "center right" ,
offset : [ - 2 , 10 ] ,
effect : "fade" ,
opacity : 0.8 ,
relative : true ,
predelay : 800
} ) ;
2010-11-05 22:53:47 +00:00
/ * *
2010-12-09 03:44:11 +00:00
* Get node and ganglia status
2010-11-05 22:53:47 +00:00
* /
2010-12-09 03:44:11 +00:00
// If request to get node status is made
if ( getNodeStatus ) {
// Get the node status
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'nodestat' ,
tgt : group ,
args : '' ,
msg : ''
} ,
success : loadNodeStatus
} ) ;
} else {
// Hide status loader
2011-01-14 05:05:06 +00:00
var statCol = $ ( '#' + gangliaTableId + ' thead tr th' ) . eq ( 2 ) ;
2010-12-09 03:44:11 +00:00
statCol . find ( 'img' ) . hide ( ) ;
}
2010-11-17 18:53:40 +00:00
2010-11-05 22:53:47 +00:00
// Get the status of Ganglia
2011-01-14 05:05:06 +00:00
var nodes = getNodesShown ( gangliaTableId ) ;
2010-11-05 22:53:47 +00:00
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'webrun' ,
tgt : '' ,
2011-01-14 05:05:06 +00:00
args : 'gangliastatus;' + nodes ,
2010-11-05 22:53:47 +00:00
msg : ''
} ,
success : loadGangliaStatus
} ) ;
}
/ * *
* Load the status of Ganglia for a given group
*
* @ param data
* Data returned from HTTP request
* @ return Nothing
* /
function loadGangliaStatus ( data ) {
// Get datatable
2011-01-14 05:05:06 +00:00
var datatable = $ ( '#' + gangliaTableId ) . dataTable ( ) ;
2010-11-05 22:53:47 +00:00
var ganglia = data . rsp ;
var rowNum , node , status , args ;
for ( var i in ganglia ) {
// ganglia[0] = nodeName and ganglia[1] = state
node = jQuery . trim ( ganglia [ i ] [ 0 ] ) ;
status = jQuery . trim ( ganglia [ i ] [ 1 ] ) ;
// Get the row containing the node
2011-01-14 05:05:06 +00:00
rowNum = findRow ( node , '#' + gangliaTableId , 1 ) ;
2010-11-05 22:53:47 +00:00
// Update the power status column
2011-01-13 23:06:31 +00:00
datatable . fnUpdate ( status , rowNum , 4 ) ;
2010-09-17 08:39:17 +00:00
}
2010-11-17 18:53:40 +00:00
2010-11-05 22:53:47 +00:00
// Hide Ganglia loader
2011-01-14 05:05:06 +00:00
var gangliaCol = $ ( '#' + gangliaTableId + ' thead tr th' ) . eq ( 4 ) ;
2010-11-05 22:53:47 +00:00
gangliaCol . find ( 'img' ) . hide ( ) ;
}
/ * *
* Refresh the status of Ganglia for each node
*
* @ param group
* Group name
* @ return Nothing
* /
function refreshGangliaStatus ( group ) {
// Show ganglia loader
2011-01-14 05:05:06 +00:00
var gangliaCol = $ ( '#' + gangliaTableId + ' thead tr th' ) . eq ( 4 ) ;
2010-11-05 22:53:47 +00:00
gangliaCol . find ( 'img' ) . show ( ) ;
2011-01-14 05:05:06 +00:00
// Get power status for nodes shown
var nodes = getNodesShown ( gangliaTableId ) ;
2010-11-17 18:53:40 +00:00
2010-11-05 22:53:47 +00:00
// Get the status of Ganglia
$ . ajax ( {
2010-09-17 08:39:17 +00:00
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
2010-11-05 22:53:47 +00:00
cmd : 'webrun' ,
2010-09-17 08:39:17 +00:00
tgt : '' ,
2011-01-14 05:05:06 +00:00
args : 'gangliastatus;' + nodes ,
2010-09-17 08:39:17 +00:00
msg : ''
} ,
2010-11-05 22:53:47 +00:00
success : loadGangliaStatus
} ) ;
}
/ * *
* Turn on monitoring for a given node
*
* @ param node
* Node to monitor on or off
* @ param monitor
* Monitor state , on or off
* @ return Nothing
* /
function monitorNode ( node , monitor ) {
if ( monitor == 'on' ) {
// Append loader to warning bar
var gangliaLoader = createLoader ( '' ) ;
var warningBar = $ ( '#gangliamon' ) . find ( '.ui-state-error p' ) ;
if ( warningBar . length ) {
warningBar . append ( gangliaLoader ) ;
}
2010-11-17 18:53:40 +00:00
2010-11-05 22:53:47 +00:00
if ( node ) {
2010-11-19 20:30:21 +00:00
// Check if ganglia RPMs are installed
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'webrun' ,
tgt : '' ,
args : 'gangliacheck;' + node ,
msg : node // Node range will be passed along in data.msg
} ,
2010-11-17 18:53:40 +00:00
2010-11-19 20:30:21 +00:00
/ * *
* Start ganglia on a given node range
*
* @ param data
* Data returned from HTTP request
* @ return Nothing
* /
success : function ( data ) {
// Get response
var out = data . rsp [ 0 ] . split ( /\n/ ) ;
// Go through each line
var warn = false ;
var warningMsg = '' ;
for ( var i in out ) {
// If an RPM is not installed
if ( out [ i ] . indexOf ( 'not installed' ) > - 1 ) {
warn = true ;
2010-11-19 20:34:43 +00:00
if ( warningMsg ) {
warningMsg += '<br>' + out [ i ] ;
} else {
warningMsg = out [ i ] ;
}
2010-12-21 02:47:30 +00:00
}
}
2010-11-19 20:30:21 +00:00
// If there are warnings
if ( warn ) {
// Create warning bar
var warningBar = createWarnBar ( warningMsg ) ;
warningBar . css ( 'margin-bottom' , '10px' ) ;
warningBar . prependTo ( $ ( '#nodes' ) ) ;
} else {
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'webrun' ,
tgt : '' ,
args : 'gangliastart;' + data . msg ,
msg : ''
} ,
success : function ( data ) {
// Remove any warnings
$ ( '#nodes' ) . find ( '.ui-state-error' ) . remove ( ) ;
$ ( '#gangliamon' ) . find ( '.ui-state-error' ) . remove ( ) ;
}
} ) ;
} // End of if (warn)
} // End of function(data)
} ) ;
} else {
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'webrun' ,
tgt : '' ,
args : 'gangliastart' ,
msg : ''
} ,
2010-11-05 22:53:47 +00:00
2010-11-19 20:30:21 +00:00
success : function ( data ) {
// Remove any warnings
$ ( '#gangliamon' ) . find ( '.ui-state-error' ) . remove ( ) ;
}
} ) ;
} // End of if (node)
2010-11-05 22:53:47 +00:00
} else {
2010-11-19 20:30:21 +00:00
var args ;
2010-11-05 22:53:47 +00:00
if ( node ) {
args = 'gangliastop;' + node ;
} else {
args = 'gangliastop' ;
2010-09-17 08:39:17 +00:00
}
2010-11-17 18:53:40 +00:00
2010-11-05 22:53:47 +00:00
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'webrun' ,
tgt : '' ,
args : args ,
msg : ''
} ,
success : function ( data ) {
// Do nothing
}
} ) ;
}
2011-01-14 05:05:06 +00:00
}
/ * *
* Get attributes for nodes not yet initialized
*
* @ param group
* Group name
* @ return Nothing
* /
function getNodeAttrs4Ganglia ( group ) {
// Get datatable headers and rows
var headers = $ ( '#' + gangliaTableId + ' thead tr th' ) ;
var nodes = $ ( '#' + gangliaTableId + ' tbody tr' ) ;
// Find group column
var head , groupsCol ;
for ( var i = 0 ; i < headers . length ; i ++ ) {
head = headers . eq ( i ) . html ( ) ;
if ( head == 'groups' ) {
groupsCol = i ;
break ;
}
}
// Check if groups definition is set
var node , cols ;
var tgtNodes = '' ;
for ( var i = 0 ; i < nodes . length ; i ++ ) {
cols = nodes . eq ( i ) . find ( 'td' ) ;
if ( ! cols . eq ( groupsCol ) . html ( ) ) {
node = cols . eq ( 1 ) . text ( ) ;
tgtNodes += node + ',' ;
}
}
// If there are node definitions to load
if ( tgtNodes ) {
// Remove last comma
tgtNodes = tgtNodes . substring ( 0 , tgtNodes . length - 1 ) ;
// Get node definitions
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'lsdef' ,
tgt : '' ,
args : tgtNodes ,
msg : group
} ,
success : addNodes2GangliaTable
} ) ;
// Create dialog to indicate table is updating
var update = $ ( '<div id="updatingDialog" class="ui-state-highlight ui-corner-all">'
+ '<p><span class="ui-icon ui-icon-info"></span> Updating table <img src="images/loader.gif"/></p>'
+ '</div>' ) ;
update . dialog ( {
modal : true ,
width : 300 ,
position : 'center'
} ) ;
}
}
/ * *
* Add nodes to datatable
*
* @ param data
* Data returned from HTTP request
* @ return Nothing
* /
function addNodes2GangliaTable ( data ) {
// Data returned
var rsp = data . rsp ;
// Group name
var group = data . msg ;
// Hash of node attributes
var attrs = new Object ( ) ;
// Node attributes
var headers = $ ( '#' + gangliaTableId + ' thead tr th' ) ;
// Variable to send command and request node status
var getNodeStatus = true ;
// Go through each attribute
var node , args ;
for ( var i in rsp ) {
// Get node name
if ( rsp [ i ] . indexOf ( 'Object name:' ) > - 1 ) {
var temp = rsp [ i ] . split ( ': ' ) ;
node = jQuery . trim ( temp [ 1 ] ) ;
// Create a hash for node attributes
attrs [ node ] = new Object ( ) ;
i ++ ;
}
// Get key and value
args = rsp [ i ] . split ( '=' , 2 ) ;
var key = jQuery . trim ( args [ 0 ] ) ;
var val = jQuery . trim ( rsp [ i ] . substring ( rsp [ i ] . indexOf ( '=' ) + 1 , rsp [ i ] . length ) ) ;
// Create a hash table
attrs [ node ] [ key ] = val ;
// If node status is available
if ( key == 'status' ) {
// Do not request node status
getNodeStatus = false ;
}
}
// Set the first four headers
var headersCol = new Object ( ) ;
headersCol [ 'node' ] = 1 ;
headersCol [ 'status' ] = 2 ;
headersCol [ 'power' ] = 3 ;
headersCol [ 'ganglia' ] = 4 ;
// Go through each header
for ( var i = 5 ; i < headers . length ; i ++ ) {
// Get the column index
headersCol [ headers . eq ( i ) . html ( ) ] = i ;
}
// Go through each node
var datatable = $ ( '#' + gangliaTableId ) . dataTable ( ) ;
var rows = datatable . fnGetData ( ) ;
for ( var node in attrs ) {
// Get row containing node
var nodeRowPos ;
for ( var i in rows ) {
// If column contains node
if ( rows [ i ] [ 1 ] . indexOf ( '>' + node + '<' ) > - 1 ) {
nodeRowPos = i ;
break ;
}
}
// Get node status
var status = '' ;
if ( attrs [ node ] [ 'status' ] ) {
status = attrs [ node ] [ 'status' ] . replace ( 'sshd' , 'ping' ) ;
}
rows [ nodeRowPos ] [ headersCol [ 'status' ] ] = status ;
// Go through each header
for ( var key in headersCol ) {
// Do not put comments and status in twice
if ( key != 'usercomment' && key != 'status' && key . indexOf ( 'statustime' ) < 0 ) {
var val = attrs [ node ] [ key ] ;
if ( val ) {
rows [ nodeRowPos ] [ headersCol [ key ] ] = val ;
}
}
}
// Update row
datatable . fnUpdate ( rows [ nodeRowPos ] , nodeRowPos , 0 , false ) ;
}
// Enable node link
$ ( '.node' ) . bind ( 'click' , loadNode ) ;
// Close dialog for updating table
$ ( '.ui-dialog-content' ) . dialog ( 'close' ) ;
// If request to get node status is made
if ( getNodeStatus ) {
// Get the node status
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'nodestat' ,
tgt : group ,
args : '' ,
msg : ''
} ,
success : loadNodeStatus
} ) ;
} else {
// Hide status loader
var statCol = $ ( '#' + gangliaTableId + ' thead tr th' ) . eq ( 2 ) ;
statCol . find ( 'img' ) . hide ( ) ;
}
// Get the status of Ganglia
var nodes = getNodesShown ( gangliaTableId ) ;
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'webrun' ,
tgt : '' ,
args : 'gangliastatus;' + nodes ,
msg : ''
} ,
success : loadGangliaStatus
} ) ;
2010-09-17 08:39:17 +00:00
}