SnapMgrSPAgentandJobandPolicyDiscovery

Bostwick.SnapManager.SnapMgrSPAgentandJobandPolicyDiscovery (Discovery)

Discovers the version of the control host and the agents pointed to each control host and the storage devices

Element properties:

TargetBostwick.SnapManager.SnapMgrSPServerClass
EnabledTrue
Frequency21600
RemotableFalse

Object Discovery Details:

Discovered Classes and their attribuets:

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource Microsoft.Windows.TimedPowerShell.DiscoveryProvider Bostwick.SnapManager.SnapMgrSPSQLLogin

Source Code:

<Discovery ID="Bostwick.SnapManager.SnapMgrSPAgentandJobandPolicyDiscovery" Target="Bostwick.SnapManager.SnapMgrSPServerClass" Enabled="true" ConfirmDelivery="false" Remotable="true" Priority="Normal">
<Category>Discovery</Category>
<DiscoveryTypes>
<DiscoveryClass TypeID="Bostwick.SnapManager.SnapMgrSPServerClass">
<Property TypeID="Bostwick.SnapManager.SnapMgrSPServerClass" PropertyID="Version"/>
</DiscoveryClass>
<DiscoveryClass TypeID="Bostwick.SnapManager.SnapMgrSPAgent">
<Property TypeID="System!System.Entity" PropertyID="DisplayName"/>
</DiscoveryClass>
<DiscoveryClass TypeID="Bostwick.SnapManager.SnapMgrSPJob">
<Property TypeID="Bostwick.SnapManager.SnapMgrSPJob" PropertyID="JobID"/>
<Property TypeID="Bostwick.SnapManager.SnapMgrSPJob" PropertyID="Module"/>
<Property TypeID="Bostwick.SnapManager.SnapMgrSPJob" PropertyID="PlanName"/>
<Property TypeID="Bostwick.SnapManager.SnapMgrSPJob" PropertyID="Farm"/>
<Property TypeID="Bostwick.SnapManager.SnapMgrSPJob" PropertyID="Policy"/>
<Property TypeID="Bostwick.SnapManager.SnapMgrSPJob" PropertyID="BackupType"/>
<Property TypeID="Bostwick.SnapManager.SnapMgrSPJob" PropertyID="Status"/>
<Property TypeID="Bostwick.SnapManager.SnapMgrSPJob" PropertyID="Size"/>
<Property TypeID="System!System.Entity" PropertyID="DisplayName"/>
</DiscoveryClass>
<DiscoveryClass TypeID="Bostwick.SnapManager.SnapMgrSPStoragePolicy">
<Property TypeID="Bostwick.SnapManager.SnapMgrSPStoragePolicy" PropertyID="Name"/>
<Property TypeID="Bostwick.SnapManager.SnapMgrSPStoragePolicy" PropertyID="StorageSystem"/>
<Property TypeID="Bostwick.SnapManager.SnapMgrSPStoragePolicy" PropertyID="StorageType"/>
<Property TypeID="Bostwick.SnapManager.SnapMgrSPStoragePolicy" PropertyID="StorageUNCPath"/>
<Property TypeID="Bostwick.SnapManager.SnapMgrSPStoragePolicy" PropertyID="StorageUserName"/>
<Property TypeID="Bostwick.SnapManager.SnapMgrSPStoragePolicy" PropertyID="StorageSize"/>
<Property TypeID="Bostwick.SnapManager.SnapMgrSPStoragePolicy" PropertyID="PolicyRetention"/>
<Property TypeID="System!System.Entity" PropertyID="DisplayName"/>
</DiscoveryClass>
</DiscoveryTypes>
<DataSource ID="DS" TypeID="Windows!Microsoft.Windows.TimedPowerShell.DiscoveryProvider" RunAs="Bostwick.SnapManager.SnapMgrSPSQLLogin">
<IntervalSeconds>21600</IntervalSeconds>
<SyncTime/>
<ScriptName>SnapMgrSPAgentAndVersionDiscovery.ps1</ScriptName>
<ScriptBody><Script>
param(
$DocAveUser,
$DocAvePass,
[string]$SourceId,
[string]$ManagedEntityId)
$docavepass = ConvertTo-SecureString -String $DocAvePass -AsPlainText -Force
$oAPI = new-object -comObject "MOM.ScriptAPI"
$Discovery = $oAPI.CreateDiscoveryData(0, $SourceId, $ManagedEntityId)


function get-dbdata {
[CmdletBinding()]
param (
[string]$connectionString,
[string]$query,
[switch]$isSQLServer
)
#Credit for Function goes to Don Jones
if ($isSQLServer) {
Write-Verbose 'in SQL Server mode'
$connection = New-Object -TypeName System.Data.SqlClient.SqlConnection
} else {
Write-Verbose 'in OleDB mode'
$connection = New-Object -TypeName System.Data.OleDb.OleDbConnection
}
$connection.ConnectionString = $connectionString
$command = $connection.CreateCommand()
$command.CommandText = $query
if ($isSQLServer) {
$adapter = New-Object -TypeName System.Data.SqlClient.SqlDataAdapter $command
} else {
$adapter = New-Object -TypeName System.Data.OleDb.OleDbDataAdapter $command
}
$SQLdataset = New-Object -TypeName 'System.Data.DataSet'
$adapter.Fill($SQLdataset)|out-null
$SQLdataset.Tables[0]
}

function Create-AgentDiscoveryData{
param($agent)

$Instance2 = $Discovery.CreateClassInstance("$MPElement[Name='Bostwick.SnapManager.SnapMgrSPAgent']$")
$Instance2.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", $agent.name)
$instance2.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $agent.fqdn)
$instance2.AddProperty("$MPElement[Name='Bostwick.SnapManager.SnapMgrSPAgent']/Farm$", $agent.farm)
$instance2.AddProperty("$MPElement[Name='Bostwick.SnapManager.SnapMgrSPAgent']/Account$", $agent.account)
$instance2.AddProperty("$MPElement[Name='Bostwick.SnapManager.SnapMgrSPAgent']/Mode$", $agent.mode)
$Discovery.AddInstance($Instance2)
}

function Create-JobDiscoveryData{
param($job)
$Instance3 = $Discovery.CreateClassInstance("$MPElement[Name='Bostwick.SnapManager.SnapMgrSPJob']$")
$Instance3.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", [string]$job.id)
$Instance3.AddProperty("$MPElement[Name='Bostwick.SnapManager.SnapMgrSPJob']/JobID$", [string]$job.id)
$Instance3.AddProperty("$MPElement[Name='Bostwick.SnapManager.SnapMgrSPJob']/DateTime$", [datetime]$job.datetime)
$Instance3.AddProperty("$MPElement[Name='Bostwick.SnapManager.SnapMgrSPJob']/Module$", [string]$job.Module )
$Instance3.AddProperty("$MPElement[Name='Bostwick.SnapManager.SnapMgrSPJob']/Status$", [string]$job.Status)
$Instance3.AddProperty("$MPElement[Name='Bostwick.SnapManager.SnapMgrSPJob']/Size$", [string]$job.Size)
$Instance3.AddProperty("$MPElement[Name='Bostwick.SnapManager.SnapMgrSPJob']/BackupType$", [string]$job.Type)
$Instance3.AddProperty("$MPElement[Name='Bostwick.SnapManager.SnapMgrSPJob']/PlanName$", [string]$job.Plan)
$Instance3.AddProperty("$MPElement[Name='Bostwick.SnapManager.SnapMgrSPJob']/Farm$", [string]$job.Farm)
$Instance3.AddProperty("$MPElement[Name='Bostwick.SnapManager.SnapMgrSPJob']/Policy$", [string]$job.Policy)
$Discovery.AddInstance($Instance3)
}

function Create-StoragePolicyDiscoveryData {
param($policy)

$Instance4 = $Discovery.CreateClassInstance("$MPElement[Name='Bostwick.SnapManager.SnapMgrSPStoragePolicy']$")
$Instance4.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", [string]$policy.name)
$instance4.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$",$localServername)
$Instance4.AddProperty("$MPElement[Name='Bostwick.SnapManager.SnapMgrSPStoragePolicy']/Name$", [string]$policy.PolicyName)
$Instance4.AddProperty("$MPElement[Name='Bostwick.SnapManager.SnapMgrSPStoragePolicy']/StorageUNCPath$", [string]$policy.UNCPath)
$Instance4.AddProperty("$MPElement[Name='Bostwick.SnapManager.SnapMgrSPStoragePolicy']/StorageUserName$", [string]$policy.UserName)
$Instance4.AddProperty("$MPElement[Name='Bostwick.SnapManager.SnapMgrSPStoragePolicy']/StorageSize$", [string]$policy.Size)
$Instance4.AddProperty("$MPElement[Name='Bostwick.SnapManager.SnapMgrSPStoragePolicy']/StorageSystem$", [string]$policy.StorageSystemProfile)
$Instance4.AddProperty("$MPElement[Name='Bostwick.SnapManager.SnapMgrSPStoragePolicy']/StorageType$", [string]$policy.StorageType)
$Instance4.AddProperty("$MPElement[Name='Bostwick.SnapManager.SnapMgrSPStoragePolicy']/PolicyRetention$", [string]$policy.PolicyRetention)
$Discovery.AddInstance($Instance4)
}



$server = $env:computername
$SMSP8_directory = (get-itemproperty 'hklm:\software\network appliance\snapmanager for sharepoint 8').installpath

[xml]$webconfig = Get-Content $smsp8_directory\control\web.config
$port = $WEBCONFIG.CONFIGURATION.APPSETTINGS.ADD|?{$_.KEY -EQ 'controlserviceport'}|%{$_.value}
$sqldatabase = $webconfig.configuration.appSettings.add|?{$_.key -eq 'configdatabasename'}|%{$_.value}
$SERVERinstance = $webconfig.configuration.appSettings.add|?{$_.key -eq 'ConfigDatabaseInstance'}|%{$_.value}
$sqlconnectionstring = "Server=$serverinstance;Integrated Security=SSPI"


$agentquery = @"
SELECT [$($sqldatabase)].[dbo].[Farm].[DisplayName] as [Farm], [$($sqldatabase)].[dbo].[Service].[Name],
case [$($sqldatabase)].[dbo].[Service].[Mode]
when 0 then 'active'
else 'down'
end as [Mode]
FROM [$($sqldatabase)].[dbo].[Farm] Right JOIN
[$($sqldatabase)].[dbo].[Service] ON [$($sqldatabase)].[dbo].[Farm].[FarmId] = [$($sqldatabase)].[dbo].[Service].[Farm]
"@


$retentionquery = @"
SELECT [$($sqldatabase)].[dbo].[StoragePolicy].[Name], [$($sqldatabase)].[dbo].[StoragePolicy].[Retention], [$($sqldatabase)].[dbo].[LogicalDrive].[Name] AS [LogicalDrive]
FROM [$($sqldatabase)].[dbo].[LogicalDrive] INNER JOIN
[$($sqldatabase)].[dbo].[StoragePolicy] ON [$($sqldatabase)].[dbo].[LogicalDrive].[Id] = [$($sqldatabase)].[dbo].[StoragePolicy].[LogicalDrive]
WHERE ([$($sqldatabase)].[dbo].[StoragePolicy].[IsOldRecord] = 0)
"@


[xml]$verconfig = Get-Content $smsp8_directory\control\bin\serviceversion.config
$version = $verconfig.configuration.properties.displayversion

$D ="."+ [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain().name
$localServername = $SERVER+$d


import-module docavemodule
login-damanager -controlhost $server -controlport $port -username $DocAveuser -password $DocAvePass

$agentservicedata = get-daagentservice
$agentqueryResults = get-dbdata -connectionString $sqlconnectionstring -query $agentquery -isSQLServer
$agents = @()
foreach($agent in $agentservicedata){
$agentobj = new-object psobject -Property @{
name = $agent.name
fqdn = $agent.name + $d
farm = ($agentqueryResults |?{$_.name -eq $agent.name}).farm
mode = ($agentqueryResults |?{$_.name -eq $agent.name}).mode
account = $agent.accountname
}
if($agentobj.farm.gettype().name -eq 'dbnull'){$agentobj.farm = "None"}
$agents += $agentobj
}




#Create Agent Discovery Data
foreach($agent in $agents){
Create-AgentDiscoveryData -agent $agent
}


$modules = 'retention','platformbackup'
$jobs = @()
foreach($module in $modules){
$jobs +=get-dajob -module $module -StartTimeRangeBeginning (get-date).adddays(-14)
}

$job_objects = @()
foreach($job in $jobs){
$obj = new-object psobject
$jobsummary = get-dajobsummary -id $job.id
$obj|add-member noteproperty ID $job.id
$obj|add-member noteproperty module ($job.module|out-string).trim()
$obj|add-member noteproperty Size $jobsummary.item('Statistics-Total Size')
$obj|add-member noteproperty Status ($job.status|out-string).trim()
$obj|add-member noteproperty Datetime $job.starttime
switch($job.module){
retention{
$obj|add-member noteproperty Type $jobsummary.item('Job Information-Type')
$obj|add-member noteproperty Plan ''
$obj|add-member noteproperty Farm ''
$obj|add-member noteproperty Policy $jobsummary.item('Job Information-Storage Policy')
}
platformbackup{
$obj|add-member noteproperty Type ($jobsummary.item('Job Information-Backup Option')+' '+$jobsummary.item('Job Information-Restore Granularity Level'))
$obj|add-member noteproperty Plan $jobsummary.item('Job Information-Plan Name')
$obj|add-member noteproperty Farm (($jobsummary.item('Environment Information-Source Farm') -split 'farm\(')[1] -replace '\)')
$obj|add-member noteproperty Policy ''
}
}
$job_objects += $obj
}

#Create Job Discovery Data
foreach($job in $job_objects){
create-jobdiscoverydata -job $job
}


$physicaldevices = get-daphysicaldevice
$Retention_Query_results = get-dbdata -connectionString $sqlconnectionstring -query $retentionquery -isSQLServer
$dapolicies = get-dastoragepolicy
$dalogicaldevices = get-dalogicaldevice

$policies = @()
foreach($pol in $dapolicies){
$dev = $physicaldevices |?{$_.name -eq ($dalogicaldevices|?{$_.name -eq $pol.primarystorage}).physicaldevicelist[0].name}
$retentionxml = ([xml]($Retention_Query_results|?{$_.name -eq $pol.name -and $_.logicaldrive -eq $pol.primarystorage}).retention).storagepolicyxml.backupretentionrules.backupretentionrulexml
$retentionstring = "Delete:$($retentionxml.Removethejob);"
if($retentionxml.ischeckkeepbackupvalue -eq 'true'){$type = 'backups'}
if($retentionxml.IsCheckKeepCycles -eq 'true'){$type = 'cycles'}
if($retentionxml.IsCheckKeepDate -eq 'true'){$type = 'date'}
if($retentionxml.IsCheckKeepDatevalue -eq 'true'){$type = 'datevalue'}
$retentionstring += "BackupGroup:$($retentionxml.backupmanagementgroup);"
switch($type){
backups{$retentionstring += "KeepLast:$($retentionxml.keepbackupvalue) Backups"}
cycles{$retentionstring += "KeepLast:$($retentionxml.keepCyclesValue) $($retentionxml.CycleDateUnit)s"}
date{$retentionstring += "KeepLast:$($retentionxml.keepcyclesdatevalue) $($retentionxml.CycleDateUnit)s"}
datevalue{$retentionstring += "KeepLast:$($retentionxml.keepbackupdatevalue) $($retentionxml.BackupDateUnit)s"}
}
$pol_obj = new-object psobject -property @{
PolicyName = $pol.name
UNCPath = $dev.uncpath
username= $dev.username
Size= $dev.totalsize
StorageSystemProfile = $dev.StorageSystemProfile
StorageType= $dev.StorageType
policyretention = $retentionstring
}
$policies += $pol_obj
}


#Create Policy Discovery Data
foreach($policy in $policies){
create-StoragePolicyDiscoveryData -policy $policy
}

$Instance = $Discovery.CreateClassInstance("$MPElement[Name='Bostwick.SnapManager.SnapMgrSPServerClass']$")
$Instance.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", $server)
$Instance.AddProperty("$MPElement[Name='Bostwick.SnapManager.SnapMgrSPServerClass']/Version$", [string]$version)
$instance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$",$localServername)
$Discovery.AddInstance($Instance)

$discovery
</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>DocAveUser</Name>
<Value>$RunAs[Name="Bostwick.SnapManager.SnapMgrSPDocAveLogin"]/UserName$</Value>
</Parameter>
<Parameter>
<Name>DocAvePass</Name>
<Value>$RunAs[Name="Bostwick.SnapManager.SnapMgrSPDocAveLogin"]/Password$</Value>
</Parameter>
<Parameter>
<Name>SourceId</Name>
<Value>$MPElement$</Value>
</Parameter>
<Parameter>
<Name>ManagedEntityId</Name>
<Value>$Target/Id$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>500</TimeoutSeconds>
</DataSource>
</Discovery>