Ação de Escrita de Fecho do Alerta de Trabalhos em Curso dos Espaços de Armazenamento Direto do Microsoft Windows Server

Microsoft.Windows.Server.10.0.Storage.StorageSpacesDirect.OngoingJobs.CloseAlertWriteAction (WriteActionModuleType)

Ação de escrita de fecho do alerta de trabalhos em curso dos Espaços de Armazenamento Direto.

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$Tempo limite (segundos)

Source Code:

<WriteActionModuleType ID="Microsoft.Windows.Server.10.0.Storage.StorageSpacesDirect.OngoingJobs.CloseAlertWriteAction" Accessibility="Internal" Batching="true" RunAs="System!System.PrivilegedMonitoringAccount">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="HealthActionId" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="SourceObjectId" 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="WAC" TypeID="System!System.CommandExecuter">
<ApplicationName />
<WorkingDirectory />
<CommandLine>powershell.exe -NoLogo -NoProfile -Noninteractive "$ep = get-executionpolicy; if ($ep -gt 'RemoteSigned') {set-executionpolicy -Scope Process remotesigned} &amp; '$$file/CloseOngoingJobsAlertScript.ps1$$' '$Config/HealthActionId$' '$Config/SourceObjectId$'</CommandLine>
<SecureInput />
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
<RequireOutput>false</RequireOutput>
<Files>
<File>
<Name>CloseOngoingJobsAlertScript.ps1</Name>
<Contents><Script>
<![CDATA[
<![CDATA[#param($HealthActionId, $SourceObjectId)


#Alert Resolution State
$resolutionStateClose = 255;

Try
{
$error.Clear();

AddTraceMessage -message "Storage monitoring script $SCRIPT_NAME started."

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

if([string]::IsNullOrEmpty($SourceObjectId))
{
Throw [System.NullReferenceException] "Null or empty SourceObjectId 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"
[void](Import-module $SCOMModulePath)
}

$managementServerName = "localhost"

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

New-SCManagementGroupConnection -ComputerName $managementServerName

AddTraceMessage -message "Connected to $managementServerName SDK."

$patternToLookForInAlertContext = ("*" + $HealthActionId +":" + $SourceObjectId + "*");

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

$all_new_alerts = @(Get-SCOMAlert -ResolutionState 0)
$alert = $all_new_alerts | Where-Object {$_.Context -like $patternToLookForInAlertContext}

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."
}
}
Catch
{
AddTraceMessage -message $_.Exception.Message
}
Finally
{
if ($error -ne $null -and $error.Count -gt 0 -and $error[0] -ne $null)
{
$momAPI.LogScriptEvent($SCRIPT_NAME, $GenericFailureEvent, 1, $error[0].ToString());
}

if ($script:traceMsg -ne $null)
{
#$momAPI.LogScriptEvent($SCRIPT_NAME, $GenericInformationEvent, 0, $script:traceMsg);
}
}
]]>
]]>
</Script></Contents>
<Unicode>true</Unicode>
</File>
</Files>
</WriteAction>-->
<WriteAction ID="WA" TypeID="Windows!Microsoft.Windows.PowerShellWriteAction">
<ScriptName>CloseOngoingJobsAlertScript.ps1</ScriptName>
<ScriptBody><Script>

param($HealthActionId, $SourceObjectId)



#general variables
#-----------------
$errorActionPreference = 'Stop'

$errEvent = [System.Diagnostics.EventLogEntryType]::Error;
$infoEvent = [System.Diagnostics.EventLogEntryType]::Information;
$GenericInformationEvent = 8671;
$GenericFailureEvent = 8672;
$script:traceMsg = "";
$msft_namespace = "root\microsoft\windows\storage"
$cluster_namespace = "root\mscluster"
$momAPI = New-Object -comObject 'MOM.ScriptAPI'

Function AddTraceMessage
{
param($message)

$errorActionPreference = 'SilentlyContinue'
$timeStamp = (get-date -format "HH:mm:ss:fff");
$script:traceMsg = $script:traceMsg + "`n[" + $timeStamp + "] " + $message;
}

AddTraceMessage -message "Start on Node: $env:COMPUTERNAME"

#param($HealthActionId, $SourceObjectId)


#Alert Resolution State
$resolutionStateClose = 255;

Try
{
$error.Clear();

AddTraceMessage -message "Storage monitoring script $SCRIPT_NAME started."

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

if([string]::IsNullOrEmpty($SourceObjectId))
{
Throw [System.NullReferenceException] "Null or empty SourceObjectId 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"
[void](Import-module $SCOMModulePath)
}

$managementServerName = "localhost"

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

New-SCManagementGroupConnection -ComputerName $managementServerName

AddTraceMessage -message "Connected to $managementServerName SDK."

$patternToLookForInAlertContext = ("*" + $HealthActionId +":" + $SourceObjectId + "*");

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

$all_new_alerts = @(Get-SCOMAlert -ResolutionState 0)
$alert = $all_new_alerts | Where-Object {$_.Context -like $patternToLookForInAlertContext}

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."
}
}
Catch
{
AddTraceMessage -message $_.Exception.Message
}
Finally
{
if ($error -ne $null -and $error.Count -gt 0 -and $error[0] -ne $null)
{
$momAPI.LogScriptEvent($SCRIPT_NAME, $GenericFailureEvent, 1, $error[0].ToString());
}

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