Veeam vSphere Host Sensors Write Action

Veeam.Virt.Extensions.VMware.ListHostSensors.WriteAction (WriteActionModuleType)

Veeam vSphere Host Sensors Write Action Module

Element properties:

TypeWriteActionModuleType
IsolationAny
AccessibilityInternal
RunAsSystem.PrivilegedMonitoringAccount
InputTypeSystem.BaseData
OutputTypeSystem.CommandOutput

Member Modules:

ID Module Type TypeId RunAs 
ListSensors WriteAction System.CommandExecuter Default

Source Code:

<WriteActionModuleType ID="Veeam.Virt.Extensions.VMware.ListHostSensors.WriteAction" Accessibility="Internal" RunAs="System!System.PrivilegedMonitoringAccount" Batching="false">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="hostName" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="sensorType" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="typeDisplayName" type="xsd:string"/>
</Configuration>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<WriteAction ID="ListSensors" TypeID="System!System.CommandExecuter">
<ApplicationName>%windir%\system32\cscript.exe</ApplicationName>
<WorkingDirectory/>
<CommandLine>/nologo $File/ListHostSensors.js$ $Config/hostName$ $Config/sensorType$ "$Config/typeDisplayName$"</CommandLine>
<TimeoutSeconds>300</TimeoutSeconds>
<RequireOutput>true</RequireOutput>
<Files>
<File>
<Name>ListHostSensors.js</Name>
<Contents><Script><![CDATA[//ListHostSensors.js
var ARGUMENT_COUNT = 3;

if (WScript.Arguments.length != ARGUMENT_COUNT) {
WScript.Quit(0);
}

var hostName = WScript.Arguments(0);
var sensorType = WScript.Arguments(1);
var typeDisplayName = WScript.Arguments(2);

var sensorsByTypeDict = new ActiveXObject("Scripting.Dictionary");

var wql = "";
if (sensorType == "power") {
wql = "SELECT sensorName, sensorType, healthState FROM SensorStats WHERE hostName = '" + hostName + "' AND (sensorType = 'power' OR sensorType = 'voltage')";
} else if (sensorType == "SENSOR") {
wql = "SELECT sensorName, sensorType, healthState FROM SensorStats WHERE hostName = '" + hostName + "' AND sensorType <> 'power' AND sensorType <> 'voltage' AND sensorType <> 'fan' AND sensorType <> 'Memory' AND sensorType <> 'Processors' AND sensorType <> 'Storage' AND sensorType <> 'temperature'";
} else if (sensorType == "ALL") {
wql = "SELECT sensorName, sensorType, healthState FROM SensorStats WHERE hostName = '" + hostName + "'";
} else {
wql = "SELECT sensorName, sensorType, healthState FROM SensorStats WHERE hostName = '" + hostName + "' AND sensorType = '" + sensorType + "'";
}

var items = GetObject("winmgmts:\\\\.\\root\\nworks").ExecQuery(wql);
for (enumItems = new Enumerator(items); !enumItems.atEnd(); enumItems.moveNext()) {
var item = enumItems.item();
var colProps = new Enumerator(item.Properties_);
var sName = "";
var sHealthState = "";
var sType = "";
for (; !colProps.atEnd(); colProps.moveNext()) {
var p = colProps.item();
if (p.Name == "sensorName")
sName = p.Value + "";
if (p.Name == "healthState")
sHealthState = p.Value + "";
if (p.Name == "sensorType")
sType = p.Value + "";
}

if (!sensorsByTypeDict.Exists(sType)) {
sensorsByTypeDict.Item(sType) = new ActiveXObject("Scripting.Dictionary");
}

if (!sensorsByTypeDict.Item(sType).Exists(sHealthState)) {
sensorsByTypeDict.Item(sType).Item(sHealthState) = new Array();
}

sensorsByTypeDict.Item(sType).Item(sHealthState).push(sName);
}

var msg = "";
for (var i = 0; i < sensorsByTypeDict.Keys().toArray().length; i++) {
var statuses = sensorsByTypeDict.Item(sensorsByTypeDict.Keys().toArray()[i]);
var typePart = "Sensors in RED state:\r\n";
var k = 0;
var sensors = new Array();
if (statuses.Exists("red")) {
sensors = statuses.Item("red");
for (k = 0; k < sensors.length; k++) {
typePart += sensors[k] + "\r\n";
}
typePart += "\r\n";
} else {
typePart += "NONE\r\n\r\n";
}

typePart += "Sensors in YELLOW state:\r\n";
if (statuses.Exists("yellow")) {
sensors = statuses.Item("yellow");
for (k = 0; k < sensors.length; k++) {
typePart += sensors[k] + "\r\n";
}
typePart += "\r\n";
} else {
typePart += "NONE\r\n\r\n";
}

typePart += "Sensors in GREEN state:\r\n";
if (statuses.Exists("green")) {
sensors = statuses.Item("green");
for (k = 0; k < sensors.length; k++) {
typePart += sensors[k] + "\r\n";
}
typePart += "\r\n";
} else {
typePart += "NONE\r\n\r\n";
}

for (var j = 0; j < statuses.Keys().toArray().length; j++) {
var currState = statuses.Keys().toArray()[j];
if (currState == "red" || currState == "yellow" || currState == "green")
continue;
typePart += "\r\n";
typePart += "Sensors in '" + currState + "' state:\r\n";

sensors = statuses.Item(currState);
for (k = 0; k < sensors.length; k++) {
typePart += sensors[k] + "\r\n";
}
}

if (sensorType == "SENSOR" || sensorType == "ALL" || sensorType == "power")
msg += "Sensors of type '" + sensorsByTypeDict.Keys().toArray()[i] + "' are listed below:\r\n";
msg += typePart + "\r\n\r\n";
}

var header = "";
switch (sensorType) {
case "SENSOR":
header = "All other hardware sensors on this Host are listed below, with their type and status:\r\n\r\n";
break;
case "ALL":
header = "All hardware sensors on this Host are listed below, with their type and status:\r\n\r\n";
break;
default:
header = "All hardware sensors of class '" + typeDisplayName + "' on this Host are listed below, with their status:\r\n\r\n";
}

WScript.echo(header);
WScript.echo(msg);
]]></Script></Contents>
<Unicode>false</Unicode>
</File>
</Files>
</WriteAction>
</MemberModules>
<Composition>
<Node ID="ListSensors"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.CommandOutput</OutputType>
<InputType>System!System.BaseData</InputType>
</WriteActionModuleType>