DataProtector Device Status Provider Probe Action

HP.DataProtector.PA.Device.Status.Provider (ProbeActionModuleType)

Element properties:

TypeProbeActionModuleType
IsolationAny
AccessibilityPublic
RunAsDefault
InputTypeSystem.BaseData
OutputTypeSystem.PropertyBagData

Member Modules:

ID Module Type TypeId RunAs 
Script ProbeAction Microsoft.Windows.ScriptPropertyBagProbe Default
Filter ConditionDetection System.ExpressionFilter Default

Source Code:

<ProbeActionModuleType ID="HP.DataProtector.PA.Device.Status.Provider" Accessibility="Public" Batching="false" PassThrough="false">
<Configuration>
<xsd:element minOccurs="1" name="ComputerName" type="xsd:string"/>
<xsd:element minOccurs="1" name="DeviceName" type="xsd:string"/>
</Configuration>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<ProbeAction ID="Script" TypeID="Windows!Microsoft.Windows.ScriptPropertyBagProbe">
<ScriptName>MPDPDeviceStatusProvider.js</ScriptName>
<Arguments>$Config/ComputerName$ $Config/DeviceName$</Arguments>
<ScriptBody><Script>/* ============================================================================
|
| Copyright (c) 2013 ComTrade d.o.o. All rights reserved.
|
| Possession of this software does not grant any rights to use, reproduce,
| modify or distribute it or to use any concept it may contain.
|
| Licensed under ComTrade d.o.o. license ("the License"); you may not use
| this software unless in compliance with the License. Any use of the software
| without such license is a violation of copyright laws and may be subject to
| legal actions (remedies and/or criminal prosecution).
|
| NOTE:
| If you receive this content in error, please let us know by contacting
| ComTrade d.o.o. legal department ([email protected]) and destroy any
| copy you may have.
|
+=============================================================================*/

/* ======================================================================

NAME: MPDPDeviceStatusProvider.js

AUTHOR: AMS Team , Comtrade d.o.o.
DATE : 11/14/2013

COMMENT:

========================================================================= */

Main();

WScript.Quit(0);

function MPDPInstalledOnNode() {}

function Main() {
var oArgs = WScript.Arguments;
var oAPI,
oDiscoveryData,
oInst;
try {
oAPI = WScript.CreateObject("MOM.ScriptAPI");
} catch (e) {
WScript.Echo(e.message);
returnDummyPB();
WScript.Quit(0);
}

if (oArgs.Count() &lt; 2) {
oAPI.LogScriptEvent("MPDPDeviceStatusProvider.js", 101, 1, "Too few script arguments. Quit(-1).");
WScript.Quit(-1);
}

var TargetComputer, TargetDevice;
TargetComputer = oArgs(0);
TargetDevice = oArgs(1);

// Debug info.
oAPI.LogScriptEvent("MPDPDeviceStatusProvider.js", 201, 0, "Running health check on host " + TargetComputer + ", on device " + TargetDevice);

var dataFound = false;
var utility = new MPDPUtility();

//check if MPDP agent is installed on node!
var MPDPInstalled = false;
agtPath = utility.readFromRegistry(utility.agentPathRegistryKey, "");
if (agtPath.length &gt; 0) {
MPDPInstalled = true;
}

var xmlDoc;
try {
xmlDoc = utility.getXmlDataDoc();
} catch (e) {

oAPI.LogScriptEvent("MPDPDeviceStatusProvider.js", 101, 1, "utility.getXmlDataDoc(): " + e.message);
returnDummyPB();
WScript.Quit(0);
}

try {
var currentDT = new Date();
var discoveryTag = xmlDoc.getElementsByTagName("discovery")[0];
var validDiscoveryDate = parseDate(discoveryTag.getAttribute("valid"));
// TODO Enable time validity check !!
/*
if(currentDT.getTime() &gt; validDiscoveryDate.getTime()) // old xml, service not running
{
returnDummyPB();
WScript.Quit(0);
}
*/
} catch (e) {}

var cell_node, cellserver_node, bLicensed, devices_node, dc_nodes, dc_node;
bLicensed = false;

cell_node = xmlDoc.getElementsByTagName("cell")[0];

if (typeof(cell_node) != "undefined" &amp;&amp; cell_node != null) {

devices_node = cell_node.getElementsByTagName("devices")[0];
if (typeof(devices_node) != "undefined" &amp;&amp; devices_node != null) {
dc_nodes = devices_node.childNodes;

while (dc_node = dc_nodes.nextNode()) {

if (dc_node.nodeName == "device") {

var v_result = "Error";
v_result = (dc_node.getAttribute("status") == "OK") ? "Good" : v_result;
v_result = (dc_node.getAttribute("status") == "Mount Request") ? "Warning" : v_result;

var v_status = (dc_node.getAttribute("status") != null) ? dc_node.getAttribute("status") : "N/A";

var v_Host, v_Name, v_Policy, v_Pool, v_Library, v_Type;
v_Host = (dc_node.getAttribute("host") != null) ? dc_node.getAttribute("host") : "N/A";
v_Name = (dc_node.getAttribute("name") != null) ? dc_node.getAttribute("name") : "N/A";
v_Policy = (dc_node.getAttribute("policy") != null) ? dc_node.getAttribute("policy") : "N/A";
v_Pool = (dc_node.getAttribute("pool") != null) ? dc_node.getAttribute("pool") : "N/A";
v_Library = (dc_node.getAttribute("library") != null) ? dc_node.getAttribute("library") : "N/A";
v_Type = (dc_node.getAttribute("type") != null) ? dc_node.getAttribute("type") : "N/A";

oBag = oAPI.CreatePropertyBag();
oBag.AddValue("ComputerName", v_Host)
oBag.AddValue("DeviceName", v_Name)
oBag.AddValue("Result", v_result);
oBag.AddValue("Policy", v_Policy);
oBag.AddValue("Pool", v_Pool);
oBag.AddValue("Library", v_Library);
oBag.AddValue("Type", v_Type);
oBag.AddValue("Status", v_status);
oBag.AddValue("DataFound", true);
oAPI.AddItem(oBag);

dataFound = true;
}
}
}
}
if (dataFound == false) {
returnDummyPB();
} else {
oAPI.ReturnItems();
}
}

function MPDPUtility() {
this.agentPathRegistryKey = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Hewlett-Packard\\DataProtector MP Agent\\DataDir";
this.dataFileLock = "mpdp-data.lock";
this.dataFile = "mpdp-data.xml";
this.agentPath = "";

this.getXmlDataDoc = function () {
var xmlDoc = WScript.CreateObject("Microsoft.XMLDOM")
xmlDoc.async = false;

datFilePath = this.getDataFilePath();
agtPath = this.getAgentPath();

// lock data file and load the content
var fs = WScript.CreateObject("Scripting.FileSystemObject");

var fileLock,
lockFileName;
var repeatCount = 100; // the number of tries for retreiving the lock
lockFileName = agtPath + "\\" + this.dataFileLock;
do {
try {
fileLock = fs.OpenTextFile(lockFileName, 2, true);
break;
} catch (e) {
repeatCount--;
WScript.Sleep(100);
}
} while (repeatCount &gt; 0);

if (repeatCount == 0) {
throw new Error("Could not acquire lock for reading MPDP MP data file '" + lockFileName + "'.");
}

if (!xmlDoc.load(datFilePath)) {
// before throwing exception close the lock
fileLock.Close();
throw new Error("Error loading MPDP MP data file '" + datFilePath + "'. Error code: " + xmlDoc.parseError.reason);
}

// afther we read the data file contnent we can unlock it
fileLock.Close();

// return the xml doc object
return xmlDoc;
}

this.getAgentPath = function () {
if (this.agentPath.length == 0) {
agtPath = this.readFromRegistry(this.agentPathRegistryKey, "");
if (agtPath.length &lt;= 0) {
throw new Error("Cannot resolve MPDP Agent path. No registry key '" + this.agentPathRegistryKey + "'.");
}
this.agentPath = agtPath;
}

return this.agentPath;
}

this.getDataFilePath = function () {
agtPath = this.getAgentPath();
return agtPath + "\\" + this.dataFile;
}

this.readFromRegistry = function (strRegistryKey, strDefault) {
try {
var value;
var WSHShell = WScript.CreateObject("WScript.Shell");
value = WSHShell.RegRead(strRegistryKey);
valueReadFromRegistry = value;
WSHShell = null;
} catch (err) {
valueReadFromRegistry = strDefault;
}
return valueReadFromRegistry;
}

//parses ISO 8601 formated timestamps ("yyyy'-'MM'-'dd'T'HH':'mm':'ss")
parseDate = function (date) {
var timestamp,
dtParams;
// 1 YYYY 2 MM 3 DD 4 HH 5 mm 6 ss 7 msec
if ((dtParams = /^(\d{4}|[+\-]\d{6})(?:-(\d{2})(?:-(\d{2}))?)?(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{3}))?)?)?$/.exec(date))) {
var dtParamsIdx = [1, 4, 5, 6, 7];
// avoid NaN timestamps
for (var i = 0, k; (k = dtParamsIdx[i]); ++i) {
dtParams[k] = +dtParams[k] || 0;
}
// allow undefined days and months
dtParams[2] = (+dtParams[2] || 1) - 1;
dtParams[3] = +dtParams[3] || 1;
timestamp = new Date(dtParams[1], dtParams[2], dtParams[3], dtParams[4], dtParams[5], dtParams[6], dtParams[7]);
} else
timestamp = new Date(date);

return timestamp;
}
}

function returnDummyPB() {
var oAPI = WScript.CreateObject("MOM.ScriptAPI");
var oBag = oAPI.CreatePropertyBag();
oBag.AddValue("ComputerName", "N/A");
oBag.AddValue("DeviceName", "N/A");
oBag.AddValue("Result", "N/A");
oBag.AddValue("Policy", "N/A");
oBag.AddValue("Pool", "N/A");
oBag.AddValue("Library", "N/A");
oBag.AddValue("Type", "N/A");
oBag.AddValue("Status", "N/A");
oBag.AddValue("DataFound", false);
oAPI.AddItem(oBag);
oAPI.ReturnItems();
}</Script></ScriptBody>
<TimeoutSeconds>300</TimeoutSeconds>
</ProbeAction>
<ConditionDetection ID="Filter" TypeID="System!System.ExpressionFilter">
<Expression>
<And>
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="String">Property[@Name='ComputerName']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="String">$Config/ComputerName$</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="String">Property[@Name='DeviceName']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="String">$Config/DeviceName$</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
</And>
</Expression>
</ConditionDetection>
</MemberModules>
<Composition>
<Node ID="Filter">
<Node ID="Script"/>
</Node>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.PropertyBagData</OutputType>
<InputType>System!System.BaseData</InputType>
</ProbeActionModuleType>