diff --git a/amtmanager.js b/amtmanager.js index 812b755f..602f800f 100644 --- a/amtmanager.js +++ b/amtmanager.js @@ -59,6 +59,11 @@ module.exports.CreateAmtManager = function(parent) { // React to node being removed if (event.action == 'removenode') { removeDevice(event.nodeid); } + + // React to node wakeup command, perform Intel AMT wake if possible + if ((event.action == 'wakedevices') && (Array.isArray(event.nodeids))) { + for (var i in event.nodeids) { performPowerAction(event.nodeids[i], 2); } + } } // Remove a device @@ -69,6 +74,18 @@ module.exports.CreateAmtManager = function(parent) { delete obj.amtDevices[nodeid]; } + // Perform a power action: 2 = Power up, 5 = Power cycle, 8 = Power down, 10 = Reset + function performPowerAction(nodeid, action) { + var dev = obj.amtDevices[nodeid]; + if ((dev == null) || (dev.amtstack == null)) return; + try { dev.amtstack.RequestPowerStateChange(action, performPowerActionResponse); } catch (ex) { } + } + + // Response to Intel AMT power action + function performPowerActionResponse(stack, name, responses, status) { + //console.log('performPowerActionResponse', status); + } + // Update information about a device function fetchIntelAmtInformation(nodeid) { parent.db.Get(nodeid, function (err, nodes) { diff --git a/meshuser.js b/meshuser.js index b48b0655..10848761 100644 --- a/meshuser.js +++ b/meshuser.js @@ -3539,6 +3539,11 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use // - We should get a full list of all MAC's to wake first. // - We should try to only have one agent per subnet (using Gateway MAC) send a wake-on-lan. if (common.validateArray(command.nodeids, 1) == false) break; // Check nodeid's + + // Event wakeup, this will cause Intel AMT wake operations on this and other servers. + parent.parent.DispatchEvent('*', obj, { action: 'wakedevices', userid: user._id, username: user.name, nodeids: command.nodeids, domain: domain.id, nolog: 1 }); + + // Perform wake-on-lan for (i in command.nodeids) { // Get the node and the rights for this node parent.GetNodeWithRights(domain, user, command.nodeids[i], function (node, rights, visible) {