Veeam Backup MP Dataset writer rules are responsible for collecting raw Veeam Backup & Replication data into Ops Mgr Data Warehouse.
Information is being collected into a special Veeam Backup Dataset in the Data Warehouse database.
Target | Veeam.Backup.BackupServer |
Category | EventCollection |
Enabled | True |
Alert Generate | False |
Remotable | True |
ID | Module Type | TypeId | RunAs |
---|---|---|---|
DS | DataSource | Veeam.Backup.EventScriptDatasource | Default |
BulkWA1 | WriteAction | Veeam.Backup.DW.WA.XmlBulkInsertModule | Default |
<Rule ID="Veeam.Backup.BackupServer.DatasetWriterRule.RestoreSessionFinished" Target="VBBD!Veeam.Backup.BackupServer" Enabled="true" ConfirmDelivery="false" Remotable="true" Priority="Normal" DiscardLevel="100">
<Category>EventCollection</Category>
<DataSources>
<DataSource ID="DS" TypeID="Veeam.Backup.EventScriptDatasource">
<ComputerName>.</ComputerName>
<LogName>Veeam Backup</LogName>
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="String">EventNumber</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="String">290</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
<ScriptName>BackupRestore.js</ScriptName>
<Arguments>"$Data/Params/Param[1]$" "$Data/Params/Param[2]$" "$Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$"</Arguments>
<ScriptBody> var _argumentsCount = 3;
var _eventId = 3055;
var _momApi = new ActiveXObject("MOM.ScriptAPI");
var _dateTime = new ActiveXObject("WbemScripting.SWbemDateTime");
var _jobSessionId = null;
var _result = null;
var _bsName = null;
var _restoreSessionQueryResult = null;
var _pBag = null;
Main();
function Main()
{
try
{
SetGlobalVarsFromArguments();
_pBag = _momApi.CreatePropertyBag();
var restoreSessionQuery = "SELECT * FROM RestoreSession where InstanceUid=\"" + _jobSessionId + "\"";
_restoreSessionQueryResult = GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\VeeamBS").ExecQuery(restoreSessionQuery);
GetRestoreSessionStarted();
GetRestoreItem();
_momApi.ReturnItems();
} catch (e)
{
_momApi.LogScriptEvent("BackupRestore.Main", _eventId, 2, e.message);
}
}
function GetRestoreSessionStarted()
{
var endTimeUtc;
var restorePoint;
var startTimeUtc;
var restoreType;
var vmDisplayName;
for (var Repository = new Enumerator(_restoreSessionQueryResult); !Repository.atEnd(); Repository.moveNext())
{
_pBag = _momApi.CreatePropertyBag();
var p = GetCollectionItem(Repository, "InstanceUid");
endTimeUtc = GetCollectionItem(Repository, "EndTimeUtc");
_dateTime.Value = endTimeUtc;
SetpBagValue("EndTimeUtc", _dateTime.GetVarDate(),_pBag ); //1
var initiatorName = GetCollectionItem(Repository, "Initiator");
SetpBagValue("Initiator", initiatorName,_pBag ); //2
SetpBagValue("JobSessionId", _jobSessionId,_pBag ); //3
restorePoint = GetCollectionItem(Repository, "RestorePointDateUtc");
_dateTime.Value = restorePoint;
SetpBagValue("RestorePointDateUtc", _dateTime.GetVarDate(0),_pBag ); //4
startTimeUtc = GetCollectionItem(Repository, "StartTimeUtc");
_dateTime.Value = startTimeUtc;
SetpBagValue("StartTimeUtc", _dateTime.GetVarDate(0),_pBag ); //5
restoreType = GetCollectionItem(Repository, "Type");
SetpBagValue("Type", restoreType,_pBag ); //6
vmDisplayName = GetCollectionItem(Repository, "VmDisplayName");
SetpBagValue("VmDisplayName", vmDisplayName,_pBag ); //7
SetpBagValue("EventId", "210",_pBag ); //8
SetpBagValue("BackupServer", _bsName,_pBag ); //9
SetpBagValue("Result", _result,_pBag ); //10
_momApi.AddItem(_pBag);
break;
}
}
function GetRestoreItem()
{
var restoreItemQuery = "ASSOCIATORS OF {RestoreSession.InstanceUid=\"" + _jobSessionId + "\"} where AssocClass = RestoreSessionToRestoreItem";
var restoreItemResult = GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\VeeamBS").ExecQuery(restoreItemQuery);
var restorePointDateUtc = new Date();
for (var Repository = new Enumerator(_restoreSessionQueryResult); !Repository.atEnd(); Repository.moveNext())
{
var item = GetCollectionItem(Repository, "RestorePointDateUtc");
if (item != null)
restorePointDateUtc = item;
}
var vmDict = GetVmUid();
for (var Repository = new Enumerator(restoreItemResult); !Repository.atEnd(); Repository.moveNext())
{
_pBag = _momApi.CreatePropertyBag();
var p = GetCollectionItem(Repository, "InstanceUid");
var finishTime = GetCollectionItem(Repository, "FinishTime");
_dateTime.Value = finishTime;
SetpBagValue("FinishTime", _dateTime.GetVarDate(0),_pBag ); //1
var finishTimeUtc = GetCollectionItem(Repository, "FinishTimeUtc");
_dateTime.Value = finishTimeUtc;
SetpBagValue("FinishTimeUtc", _dateTime.GetVarDate(0),_pBag ); //2
var startTime = GetCollectionItem(Repository, "StartTime");
_dateTime.Value = startTime;
SetpBagValue("StartTime", _dateTime.GetVarDate(0),_pBag ); //3
var startTimeUtc = GetCollectionItem(Repository, "StartTimeUtc");
_dateTime.Value = startTimeUtc;
SetpBagValue("StartTimeUtc", _dateTime.GetVarDate(0),_pBag ); //4
var destination = GetCollectionItem(Repository, "Destination");
var destinationHost = GetCollectionItem(Repository, "DestinationHost");
var destinationString = "";
if (destination == null || destination == "")
destinationString = destinationHost;
else
{
if (destinationHost != null && destinationHost != "")
{
destinationString = "[" + destinationHost + "]" + destination;
}
else
{
destinationString = destination;
}
}
SetpBagValue("Destination", destinationString, _pBag); //5
var source = GetCollectionItem(Repository, "Source");
SetpBagValue("Source", source,_pBag ); //6
var destinationType = GetCollectionItem(Repository, "DestinationType");
SetpBagValue("DestinationType", destinationType,_pBag ); //7
SetpBagValue("TaskSessionId", p,_pBag ); //8
var itemName = GetCollectionItem(Repository, "ItemName");
SetpBagValue("ItemName", itemName,_pBag ); //9
var itemSize = GetCollectionItem(Repository, "ItemSize");
SetpBagValue("ItemSize", itemSize,_pBag ); //10
var itemType = GetCollectionItem(Repository, "ItemType");
SetpBagValue("ItemType", itemType,_pBag ); //11
var message = GetCollectionItem(Repository, "Message");
SetpBagValue("Message", message,_pBag ); //12
var state = GetCollectionItem(Repository, "State");
SetpBagValue("State", state,_pBag ); //13
SetpBagValue("EventId", "250",_pBag ); //14
SetpBagValue("JobSessionId", _jobSessionId,_pBag ); //15
SetpBagValue("VmMoRef", vmDict.item("vmMoRef"),_pBag ); //16
SetpBagValue("Host", vmDict.item("host"),_pBag ); //17
_dateTime.Value = restorePointDateUtc;
SetpBagValue("OibDateTime", _dateTime.GetVarDate(0),_pBag ); //18
SetpBagValue("VmName", vmDict.item("vmName"),_pBag ); //19
_momApi.AddItem(_pBag);
}
}
function GetVmUid()
{
var vmDict = new ActiveXObject("Scripting.Dictionary");
var vmQuery = "ASSOCIATORS OF {RestoreSession.InstanceUid=\"" + _jobSessionId + "\"} where AssocClass = RestoreSessionToVm";
var vmQueryResult = GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\VeeamBS").ExecQuery(vmQuery);
var vmInstanceUid = "";
for (var Repository = new Enumerator(vmQueryResult); !Repository.atEnd(); Repository.moveNext())
{
var vmInstanceUid = GetCollectionItem(Repository, "InstanceUid");
var moref = GetCollectionItem(Repository, "HierarchyRef");
if (moref != null) {
vmDict.Add("vmMoRef", moref);
}
var moref = GetCollectionItem(Repository, "Name");
if (moref != null) {
vmDict.Add("vmName", moref);
}
break;
}
var vmToHostQuery = "ASSOCIATORS OF {Vm.InstanceUid=\"" + vmInstanceUid + "\"} where AssocClass = VmToHost";
var vmToHostQueryResult = GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\VeeamBS").ExecQuery(vmToHostQuery);
for (var Repository = new Enumerator(vmToHostQueryResult); !Repository.atEnd(); Repository.moveNext())
{
var p = GetCollectionItem(Repository, "InstanceUid");
var item = GetCollectionItem(Repository, "Name");
if (item != null) {
vmDict.Add("host", item);
}
}
return vmDict;
}
function GetCollectionItem(collection_in, plropery_in)
{
var vpower = collection_in.item();
var vPowerProps = new Enumerator(vpower.Properties_);
for (; !vPowerProps.atEnd(); vPowerProps.moveNext())
{
var p = vPowerProps.item();
if (p.Name == plropery_in)
{
return p.Value;
}
}
return null;
}
function SetpBagValue(propertyName_in, propertyValue_in, pBag)
{
pBag.AddValue(propertyName_in, (propertyValue_in == null ? "" : propertyValue_in));
}
function SetGlobalVarsFromArguments()
{
if (WScript.Arguments.length != _argumentsCount)
{
_momApi.LogScriptEvent("BackupRestore", _eventId, 2, 'BackupRestore.SetGlobalVarsFromArguments error');
}
_jobSessionId = WScript.Arguments(0);
_result = WScript.Arguments(1);
_bsName = WScript.Arguments(2);
} </ScriptBody>
<TimeoutSeconds>300</TimeoutSeconds>
</DataSource>
</DataSources>
<WriteActions>
<WriteAction ID="BulkWA1" Target="MSDL!Microsoft.SystemCenter.DataWarehouseConnectorServer" TypeID="Veeam.Backup.DW.WA.XmlBulkInsertModule">
<spname>VeeamBackupMP.RestoreJob</spname>
</WriteAction>
</WriteActions>
</Rule>