Data Protector Client Group Status Provider Probe Action

HP.DataProtector.PA.ClientGroup.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

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
WarningThresholdint$Config/WarningThreshold$Warning Threshold
ErrorThresholdint$Config/ErrorThreshold$Error Threshold
AcceptFaultyBackupsbool$Config/AcceptFaultyBackups$Accept Faulty Backups

Source Code:

<ProbeActionModuleType ID="HP.DataProtector.PA.ClientGroup.Status.Provider" Accessibility="Public" Batching="false" PassThrough="false">
<Configuration>
<xsd:element minOccurs="1" name="ComputerName" type="xsd:string"/>
<xsd:element minOccurs="1" name="WarningThreshold" type="xsd:integer"/>
<xsd:element minOccurs="1" name="ErrorThreshold" type="xsd:integer"/>
<xsd:element minOccurs="0" name="AcceptFaultyBackups" type="xsd:boolean"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="WarningThreshold" Selector="$Config/WarningThreshold$" ParameterType="int"/>
<OverrideableParameter ID="ErrorThreshold" Selector="$Config/ErrorThreshold$" ParameterType="int"/>
<OverrideableParameter ID="AcceptFaultyBackups" Selector="$Config/AcceptFaultyBackups$" ParameterType="bool"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<ProbeAction ID="Script" TypeID="Windows!Microsoft.Windows.ScriptPropertyBagProbe">
<ScriptName>MPDPClientGroupStatusProvider.js</ScriptName>
<Arguments>$Config/ComputerName$ $Config/WarningThreshold$ $Config/ErrorThreshold$ $Config/AcceptFaultyBackups$</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: MPDPClientGroupStatusProvider.js

AUTHOR: AMS Team , Comtrade d.o.o.
DATE : 10/10/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; 4) {
oAPI.LogScriptEvent("MPDPClientGroupStatusProvider.js", 101, 1, "Too few script arguments. Quit(-1).");
WScript.Quit(-1);
}

var TargetComputer, sErrorThreshold, sWarningThreshold;
var sAcceptFaulty = false;

TargetComputer = oArgs(0);
sWarningThreshold = parseInt(oArgs(1));
sErrorThreshold = parseInt(oArgs(2));
sAcceptFaultyBackups = (oArgs(3) === "true") ? true : false;


// Debug info.
oAPI.LogScriptEvent("MPDPClientGroupStatusProvider.js", 201, 0, "Running health check on target " + TargetComputer);

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("MPDPClientGroupStatusProvider.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;
bLicensed = false;

var vFaultyClients = 0;
var vOKClients = 0;
var vTotalClients = 0;
var vFolderStatus = "Good";

// Prep the search array
var aAcceptableBackupStates = new Array();
aAcceptableBackupStates.push("Completed");

if (sAcceptFaultyBackups) {
aAcceptableBackupStates.push("Completed/Errors");
}

cell_node = xmlDoc.getElementsByTagName("cell")[0];
if (typeof (cell_node) != "undefined" &amp;&amp; cell_node != null) {
cellserver_node = cell_node.getElementsByTagName("cellserver")[0];
if (typeof (cellserver_node) != "undefined" &amp;&amp; cellserver_node != null) {
var v_cellName = cellserver_node.getAttribute("hostname");
var clients_node, cf_nodes, cf_node;
clients_node = cell_node.getElementsByTagName("clients")[0];
if (typeof (clients_node) != "undefined" &amp;&amp; clients_node != null) {
cf_nodes = clients_node.childNodes;
while (cf_node = cf_nodes.nextNode()){
if (cf_node.nodeName == "client") {
for (var i = 0; i &lt; aAcceptableBackupStates.length; i++) {
if (aAcceptableBackupStates[i] === cf_node.getAttribute("status")) {
vOKClients++;
break;
}
}
vTotalClients++;
}
}
}
}

vFaultyClients = vTotalClients - vOKClients;

if (vTotalClients &gt; 0) {
var vFaultyPerc = 100 * vFaultyClients / vTotalClients;

// Good, Warning, Error
var v_folderStatus = "Good";
v_folderStatus = (vFaultyPerc &gt; sWarningThreshold) ? "Warning" : v_folderStatus;
v_folderStatus = (vFaultyPerc &gt; sErrorThreshold) ? "Error" : v_folderStatus;

oBag = oAPI.CreatePropertyBag();
oBag.AddValue("Result", v_folderStatus);
oBag.AddValue("DataFound", true);
oAPI.AddItem(oBag);
dataFound = true;
}else{
dataFound = false;
}
}
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("Result", "N/A");
oBag.AddValue("DataFound", false);
oAPI.AddItem(oBag);
oAPI.ReturnItems();
}</Script></ScriptBody>
<TimeoutSeconds>300</TimeoutSeconds>
</ProbeAction>
</MemberModules>
<Composition>
<Node ID="Script"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.PropertyBagData</OutputType>
<InputType>System!System.BaseData</InputType>
</ProbeActionModuleType>