Microsoft.SystemCenter.OperationsManager.Storage.CloseAlert.WA (WriteActionModuleType)

Element properties:

TypeWriteActionModuleType
IsolationAny
AccessibilityInternal
RunAsSystem.PrivilegedMonitoringAccount
InputTypeSystem.BaseData

Member Modules:

ID Module Type TypeId RunAs 
WA WriteAction Microsoft.Windows.PowerShellWriteAction Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
TimeoutSecondsint$Config/TimeoutSeconds$Timeout (sec)Expecting time (in seconds) that the module wait to finish the execution.

Source Code:

<WriteActionModuleType ID="Microsoft.SystemCenter.OperationsManager.Storage.CloseAlert.WA" Accessibility="Internal" Batching="true" RunAs="System!System.PrivilegedMonitoringAccount">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="FaultId" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="SourceUniqueId" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="ObjectHost" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="TimeoutSeconds" type="xsd:integer"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation>
<Composite>
<MemberModules>
<WriteAction ID="WA" TypeID="Windows!Microsoft.Windows.PowerShellWriteAction">
<ScriptName>CloseAlert.ps1</ScriptName>
<ScriptBody><Script># $faultId - faultid
# $sourceUniqueId - SourceUniqueId
# $objectHost - string indicating if the object is hosted on VMM or OM
param($faultId, $sourceUniqueId, [string] $objectHost)

$errorActionPreference = 'Stop'

$momAPI = New-Object -comObject 'MOM.ScriptAPI'

$errEvent = [System.Diagnostics.EventLogEntryType]::Error;
$infoEvent = [System.Diagnostics.EventLogEntryType]::Information;

#Storage Monitoring Event Ids
$GenericInformationEvent = 8550;
$GenericFailureEvent = 8551;

#Alert Resolution State
$resolutionStateClose = 255;

$script:traceMsg = "";

#Adds tracemessage to $Script
Function AddTraceMessage
{
param($message)
$timeStamp = (get-date -format "HH:mm:ss:fff");
$script:traceMsg = $script:traceMsg + "`n[" + $timeStamp + "] " + $message;
}

Try
{
$error.Clear();

AddTraceMessage -message "Storage monitoring script CloseAlert.ps1 started."
if([string]::IsNullOrEmpty($faultId))
{
Throw [System.NullReferenceException] "Null or empty FaultId parameter to the script.";
}

if([string]::IsNullOrEmpty($sourceUniqueId))
{
Throw [System.NullReferenceException] "Null or empty SourceUniqueId parameter to the script.";
}

#Import-Module OperationsManager
$omModule = get-module -name "OperationsManager"
if ($omModule -eq $null)
{
$SCOMPowerShellKey = "HKLM:\SOFTWARE\Microsoft\System Center Operations Manager\12\Setup\Powershell\V2"
$SCOMModulePath = Join-Path (Get-ItemProperty $SCOMPowerShellKey).InstallDirectory "OperationsManager"
Import-module $SCOMModulePath | Out-Null
}

$managementServerName = "localhost"
if($objectHost -eq "VMM")
{
#Import VMM commands
$vmmModule = get-module -name "virtualmachinemanager"
if ($vmmModule -eq $null)
{
$modulePath = get-itemproperty -path "hklm:\software\microsoft\microsoft system center virtual machine manager administrator console\Setup";
Import-Module ($modulePath.InstallPath + "bin\psModules\virtualmachinemanager\virtualmachinemanager.psd1") | Out-Null
}

#Connect to server
$vmmServer = Get-SCVMMServer -ComputerName localhost
AddTraceMessage -message "Got VMM server connection."

AddTraceMessage -message "Getting OM management server to connect to."

$mg = Get-SCOpsMgrConnection -Connect -VMMServer $vmmServer
if($mg -ne $null)
{
$managementServerName = $mg.OpsMgrServerName;
}
else
{
Throw [System.NullReferenceException] "Failed to connect get OM MG connection. This is fatal error, script will fail.";
}
}

AddTraceMessage -message "Connecting to $managementServerName OM management server."

New-SCManagementGroupConnection -ComputerName $managementServerName

AddTraceMessage -message "Connected to $managementServerName SDK."


$FaultIdpatternToLookForInAlertContext = ("*" + $faultId +":" + $sourceUniqueId + "*");

AddTraceMessage -message "Searching OM Alert with these patterns: `n $FaultIdpatternToLookForInAlertContext"

$alert = (Get-SCOMAlert) | Where-Object {$_.Context -like $FaultIdpatternToLookForInAlertContext}

if($alert -ne $null)
{
AddTraceMessage -message ("Alert found. Name = " + $alert[0].Name)
Set-SCOMAlert -Alert $alert -ResolutionState $resolutionStateClose
AddTraceMessage -message "Alert is closed."
}
else
{
AddTraceMessage -message "Could not find OM Alert with given pattern."
}

AddTraceMessage -message "Storage monitoring script CloseAlert.ps1 completed."
}
Catch
{
AddTraceMessage -message $_.Exception.Message
}
Finally
{
if($vmmServer -ne $null)
{
$vmmServer.Disconnect();
}

if ($error -ne $null -and $error.Count -gt 0 -and $error[0] -ne $null)
{
$momAPI.LogScriptEvent("CloseAlert.ps1", $GenericFailureEvent, 1, $error[0].ToString());
}

if ($script:traceMsg -ne $null)
{
$momAPI.LogScriptEvent("CloseAlert.ps1", $GenericInformationEvent, 0, $script:traceMsg);
}
}</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>FaultId</Name>
<Value>$Config/FaultId$</Value>
</Parameter>
<Parameter>
<Name>SourceUniqueId</Name>
<Value>$Config/SourceUniqueId$</Value>
</Parameter>
<Parameter>
<Name>objectHost</Name>
<Value>$Config/ObjectHost$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</WriteAction>
</MemberModules>
<Composition>
<Node ID="WA"/>
</Composition>
</Composite>
</ModuleImplementation>
<InputType>System!System.BaseData</InputType>
</WriteActionModuleType>