Trigger State Data

Explore this Page

Overview

This topic describes trigger state data and provides an example of how trigger state data can be used in a script file.

When a command or PowerShell script action is configured in a task with the Append the associated Task Trigger Data objects option, trigger state data objects will be appended in the script file when triggers fire in a task. The data will be returned in an array of objects called "TriggerState. The data returned from the script will depend on the type of triggers that are configured. Data can be returned for monitor triggers and checkpoint triggers. Trigger state data can be compared using other cmdlets to obtain additional information.

Trigger State Object Fields

Monitor Trigger

If a monitor trigger is configured, a “MonitorTriggerState” object will be appended with the following fields:

MonitoredObjectId

: acd50b370a6e4b8986e0fa485fabfd55

TriggerType

: MonitorTrigger

TriggerTime

: 8/12/2013 1:39:04 PM

Caption

: Critical: Host Access of Virtual disk 2 from Server Group is Access not allowed

ManualInvocation

: False

Checkpoint Trigger

If a checkpoint trigger is configured, the "CheckpointTriggerState object will be appended with the following fields:

VirtualDiskId

: 4ff6547ec8bc49f1b2ef048000d839ee

TriggerType

: MessageTrigger

TriggerTime

: 8/12/2013 1:38:26 PM

Caption

: Checkpoint marker received for replicated virtual disk

ManualInvocation

: False

In the MonitorTriggerState object, the MonitoredObjectId can be used to resolve the exact object that caused the monitor state to trigger the action and to perform additional actions in the script. In the CheckpointTriggerState object, the VirtualDiskID can be used to resolve the exact object that received the checkpoint marker and to perform additional actions in the script.

Example PowerShell Script

The following simple script is an example that demonstrates a couple ways that the trigger states can be accessed from a script file. In the example, assume that a task is created with triggers that will return both types of trigger data:

  • Configure two triggers:
    • Monitor for a change in a disk pool state

      Monitor type = Disk pools/State for selected pool object. Trigger on state "> Healthy".

    • Replication checkpoint received
  • Configure an action to run the PowerShell script file.

    Select the server and path where the script file is located (for instance C:\ScriptFiles\ExampleScript.ps1).

    Parameters are used to add script specific data from the task. Add script parameters, for example -param1 "value1" -paramarray value1, value2, value3.Select the check box toAppend the associated Task Trigger Data objects, data will not be returned without this selection.

(See Automated Tasks for more instructions and information on configuring task triggers and actions.)

When either triggers fires, the associated trigger state data objects will be appended to the script file action as a list of trigger states that caused the action to occur.

In this case, if the disk pool state changes, in the MonitorTriggerState object, theis used to resolve the exact object that caused the monitor state to trigger the action. If a replication checkpoint is received, in the

Script File

Copy
PowerShell Script
param([string]$param1, [string[]]$paramArray)

# Initializing PowerShell Environment
$bpKey = ''
$regKey = Get-Item ''
$strProductKey = ''
$installPath = ''

if (!(Get-Module -Name DataCore.Executive.Cmdlets)) {
    Import-Module "$installPath\DataCore.Executive.Cmdlets.dll"
}

# Connect to DataCore
Connect-DcsServer
Start-Sleep -Seconds 1 # Allow time to connect

Write-Output "Starting execution"`n | Out-File "C:\ScriptOutput\Testlog.txt" -Append

Write-Output "Param1 is <$param1>" | Out-File "C:\ScriptOutput\Testlog.txt" -Append

if ($paramArray -ne $null -and $paramArray.Count -gt 0) {
    Write-Output "ParamArray values are:" | Out-File "C:\ScriptOutput\Testlog.txt" -Append
    foreach ($p2 in $paramArray) {
        Write-Output $p2 | Out-File "C:\ScriptOutput\Testlog.txt" -Append
    }
    Write-Output "`n" | Out-File "C:\ScriptOutput\Testlog.txt" -Append
}

if ($TriggerStates -ne $null) {
    Write-Output "Trigger state data is appended."`n | Out-File "C:\ScriptOutput\Testlog.txt" -Append
    foreach ($trigger in $TriggerStates) {
        Write-Output "$($trigger.GetType()):" | Out-File "C:\ScriptOutput\Testlog.txt" -Append
        Write-Output $trigger | Out-File "C:\ScriptOutput\Testlog.txt" -Append

        if ($trigger -is [DataCore.Executive.CheckpointTriggerState]) {
            Write-Output "VirtualDiskId: $($trigger.VirtualDiskId)"`n | Out-File "C:\ScriptOutput\Testlog.txt" -Append
            Write-Output "VirtualDiskData object for VirtualDiskId:" | Out-File "C:\ScriptOutput\Testlog.txt" -Append
            Get-DcsVirtualDisk -VirtualDisk $trigger.VirtualDiskId | Out-File "C:\ScriptOutput\Testlog.txt" -Append
            Write-Output "`n" | Out-File "C:\ScriptOutput\Testlog.txt" -Append
        }

        if ($trigger -is [DataCore.Executive.MonitorTriggerState]) {
            Write-Output "MonitoredObjectId: $($trigger.MonitoredObjectId)"`n | Out-File "C:\ScriptOutput\Testlog.txt" -Append
            Write-Output "DiskPoolData objects for MonitoredObjectId:" | Out-File "C:\ScriptOutput\Testlog.txt" -Append
            Get-DcsPool -Pool $trigger.MonitoredObjectId | Out-File "C:\ScriptOutput\Testlog.txt" -Append
            Write-Output "MonitorData objects for the pool:" | Out-File "C:\ScriptOutput\Testlog.txt" -Append
            Get-DcsMonitor -Monitor $trigger.MonitoredObjectId | Out-File "C:\ScriptOutput\Testlog.txt" -Append
            Write-Output "`n" | Out-File "C:\ScriptOutput\Testlog.txt" -Append
        }
    }
}

Write-Output "Execution Complete"`n | Out-File "C:\ScriptOutput\Testlog.txt" -Append

Learn More