#function to get divider for the various metrics
function GetDivider
{
param([string] $metName)
switch ($metName)
{
MemoryAvailable {return "1GB"}
MemoryTotal {return "1GB"}
if (0 -ne $error.Count)
{
AddTraceMessage -message "Cannot get storage subsystem for storage object."
$exception = $error[0].Exception
LogErrors -exception $exception
return $null
}
return $storageSubSystem
}
function GetHealthReport($storageSubSystem,$storageObject)
{
$ErrorActionPreference = "SilentlyContinue"
$cimReportMethod = "GetReport"
####################################
# Check Object Type and valid values
# Don't get data on null objects
###################################
if ($null -eq $storageObject)
{
return $null
}
if ($null -eq $storageSubSystem)
{
return $null
}
if ($null -eq $storageSubSystem.GetType)
{
AddTraceMessage -message "S2D capable storage subsystem is not found."
return $null
}
##########################################
#Getting Object requireg for Health Report
# Don't get data on null objects
##########################################
#Trying to get Storage Health Object
AddTraceMessage -message "Trying to get storage health object."
if ($error.Count -ne 0)
{
$exception = $error[0].Exception
$message = $exception.Message
AddTraceMessage -message "Cannot get S2D storage subsystem health report data. `nError details:$message"
}
if ($null -eq $HealthReportObject)
{
AddTraceMessage -message "S2D storage subsystem doesn't have any health report available. Exiting..."
return $null
}
return $HealthReportObject.ItemValue
}
#add propertyBag
function AddBag([HashTable]$valuenameDictionary)
{
$ErrorActionPreference = "Stop"
if ([string]::IsNullOrEmpty($storageObject))
{
$message = "File Share with Id: $targetInstanceUniqueID is not found. Exiting.."
AddTraceMessage -message $message
LogErrors -exception $null
exit
}
$message = "Trying to get storage volume from File Share with Id: $targetInstanceUniqueID"
AddTraceMessage -message $message
if ($volume -eq $null -or $volume.OperationalStatus -ne "OK")
{
$message = "Volume for File Share with Id: $targetInstanceUniqueID is not found or in offline state. Exiting.."
AddTraceMessage -message $message
LogErrors -exception $null
exit
}
$storageObject = $volume
}
if ($null -eq $storageObject)
{
$message = "Storage Object with Id: $targetInstanceUniqueID is empty. Exiting.."
AddTraceMessage -message $message
LogErrors -exception $null
exit
}
if ($storageObject.OperationalStatus -ne "OK" -and $storageObject.OperationalStatus -ne "Online")
{
$message = "Storage Object with Id: $targetInstanceUniqueID is in $($storageObject.OperationalStatus) state. Exiting.."
AddTraceMessage -message $message
LogErrors -exception $null
exit
}
if ($true -eq $IsStorageSubSystem)
{
$message = "Trying to get Health Report for storage object with Id: $targetInstanceUniqueID"
AddTraceMessage -message $message
$healthreport = GetHealthReport -storageSubSystem $storageObject -storageObject $storageObject
}
else
{
$message = "Trying to get S2D storage subsystem for storage object with Id: $targetInstanceUniqueID"
AddTraceMessage -message $message
$storagesubsystem = GetS2DStorageSubsystem -storageobject $storageObject
$message = "Trying to get Health Report for storage object with Id: $targetInstanceUniqueID"
AddTraceMessage -message $message
$healthreport = GetHealthReport -storageSubSystem $storagesubsystem -storageObject $storageObject
}
$message = "Finish processing Health Report for storage object with Id: $targetInstanceUniqueID"
AddTraceMessage -message $message
if ($null -eq $healthreport -or $healthreport.Count -eq 0)
{
$message = "Metrics for Storage Object with UniqueID: $targetInstanceUniqueID, were not found. Health report is empty."
AddTraceMessage -message $message
LogErrors -exception $null
exit
}
$valuenameDictionary = @{}
$recordsList = @()
$recordsList += $healthreport.Records | select
if($recordsList -eq $null -or $recordsList.Count -eq 0)
{
$message = "Metrics records for Storage Object with UniqueID: $targetInstanceUniqueID, were not found in health report."
AddTraceMessage -message $message
LogErrors -exception $null
exit
}
foreach ($record in $recordsList)
{
if ($null -eq $record.Value -or [string]::IsNullOrEmpty($record.Name)) {continue;}
if ($valuenameDictionary.ContainsKey($record.Name)) {continue;}
$divider = GetDivider($record.Name)
$calculatedValue = [Math]::Round($record.Value/$divider,3);
$valuenameDictionary.Add($record.Name, $calculatedValue);
}
AddBag -valuenameDictionary $valuenameDictionary
}
Catch
{
#If storage object doesn't exist SCOM may have lag in discovery so ignore this case
$exception = Get-FaultException -exception $_.Exception -IsObjectExist $IsStorageObjectExist
AddTraceMessage -message $exception.Message
}
Finally
{
LogErrors -exception $exception