Trigger State Data

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.

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

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

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

param([string]$param1, [string[]]$
 
# Initializing PowerShell Environment
$bpKey = '
$regKey = get-Item
$strProductKey = $
$regKey = get-Item
$installPath = $
if (!(get-module -name DataCore.Executive.Cmdlets))
{
Import-Module "$installPath\DataCore.Executive.Cmdlets.dll-
}
# Connect to DataCore SANsymphony
Connect-DcsServer
sleep -seconds 1 #allows time for connecting
 
Write-Output "Starting execution"`n | Out-File "C:\ScriptOutput\Testlog.txt -append
#lists parameter and parameter array values that were input
Write-Output "Param1 is <$param1>" | Out-File "C:\ScriptOutput\Testlog.txt -appen
if ($paramArray -ne $null -and $
{
Write-Output "ParamArray values are: | Out-File C:\
foreach ($p2 in $
{
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)
{
#outputs Trigger state objects for all configured triggers
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])
{
#outputs the ID for the replication checkpoint virtual disk
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
#outputs the object for the replication checkpoint virtual disk
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])
{
#outputs the ID for the disk pool being monitored
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
#outputs the object for the replication checkpoint virtual disk
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
 #outputs each disk pool monitor
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