Manageability Test Synthetic Transaction Data Source Module

Microsoft.SystemCenter.MicrosoftAzure.Test.SyntheticTransaction.DS (DataSourceModuleType)

Microsoft Enterprise Management Manageability Test Synthetic Transaction Data Source module.

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityPublic
RunAsSystem.PrivilegedMonitoringAccount
OutputTypeSystem.PropertyBagData

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource System.SimpleScheduler Default
PA ProbeAction Microsoft.Windows.PowerShellPropertyBagProbe Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
FunctionNamestring$Config/FunctionName$Function NameFunction Name
FunctionScriptstring$Config/FunctionScript$Function ScriptFunction Script
IntervalSecondsint$Config/IntervalSeconds$Interval SecondsInterval Seconds
SyncTimestring$Config/SyncTime$Sync TimeSync Time
TimeoutSecondsint$Config/TimeoutSeconds$Timeout SecondsTimeout Seconds

Source Code:

<DataSourceModuleType ID="Microsoft.SystemCenter.MicrosoftAzure.Test.SyntheticTransaction.DS" Accessibility="Public" RunAs="System!System.PrivilegedMonitoringAccount" Batching="false">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="FunctionName" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="FunctionScript" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="IntervalSeconds" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="0" name="SyncTime" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="TimeoutSeconds" type="xsd:integer"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="FunctionName" Selector="$Config/FunctionName$" ParameterType="string"/>
<OverrideableParameter ID="FunctionScript" Selector="$Config/FunctionScript$" ParameterType="string"/>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
<OverrideableParameter ID="SyncTime" Selector="$Config/SyncTime$" ParameterType="string"/>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="DS" TypeID="System!System.SimpleScheduler">
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<SyncTime>$Config/SyncTime$</SyncTime>
</DataSource>
<ProbeAction ID="PA" TypeID="Windows!Microsoft.Windows.PowerShellPropertyBagProbe">
<ScriptName>TestSyntheticTransaction</ScriptName>
<ScriptBody><Script>
param ([String] $FunctionName, [String] $FunctionScript)

$SCRIPT_NAME = "TestSyntheticTransaction"

# -------------------------------------------------------------------------------------------------
# Begin Common.ps1
# This defines all common initialization functions and fields for all powershell scripts
# -------------------------------------------------------------------------------------------------

$ErrorActionPreference = "Stop"

# Event type constants
$EVENT_TYPE_LOG = 0
$EVENT_TYPE_ERROR = 1
$EVENT_TYPE_WARNING = 2
$EVENT_TYPE_INFORMATION = 4

# Typed property bag constants
$PROPERTY_TYPE_ALERT = 0
$PROPERTY_TYPE_EVENT = 1
$PROPERTY_TYPE_PERFORMANCE = 2
$PROPERTY_TYPE_STATE = 3

# State type constants
$STATE_SUCCESS = "Success"
$STATE_WARNING = "Warning"
$STATE_ERROR = "Error"

Function LogError($message)
{
# Write to Console
Write-Warning "ERROR: $SCRIPT_NAME: $message"
#$momAPI.LogScriptEvent($SCRIPT_NAME, 101, $EVENT_TYPE_ERROR, $message)
}

Function LogInfo($message)
{
# Write to Console
Write-Host -ForegroundColor Green "INFO: $SCRIPT_NAME: $message"
#$momAPI.LogScriptEvent($SCRIPT_NAME, 104, $EVENT_TYPE_INFORMATION, $message)
}

Function LogVerbose($message)
{
# Write to Console
Write-Verbose "VERBOSE: $SCRIPT_NAME: $message"
#$momAPI.LogScriptEvent($SCRIPT_NAME, 105, $EVENT_TYPE_INFORMATION, $message)
}

Function ThrowAndExit($message)
{
throw $message
LogError($message)

exit
}

Function CheckAndLogError($message)
{
if($Error)
{
LogError($message)
LogError($Error)

exit
}
}

# Method to resolve path.
# Resolve the local path to a full path but do not resolve the network path.
Function ResolvePath($path)
{
$resolvedPath = $path

if(!$path.StartsWith('\\'))
{
# Resolve local path
$resolvedPath = resolve-path($path)
}

CheckAndLogError("ResolvePath($path)")
return $resolvedPath
}

$Error.Clear()

$momAPI = new-object -comObject MOM.ScriptAPI

LogInfo("Executing PowerShell Script")

# -------------------------------------------------------------------------------------------------
# End of Common.ps1
# -------------------------------------------------------------------------------------------------


$StatePropertyBag = $momAPI.CreateTypedPropertyBag($PROPERTY_TYPE_STATE)
if ($StatePropertyBag -eq $null)
{
LogError("unable to create state property bag")
Exit
}

try
{
$TxResult = Invoke-Command -ScriptBlock ([scriptblock]::Create($FunctionScript))
}
catch [System.IO.IOException]
{
$StatePropertyBag.AddValue('State', "Error")
$StatePropertyBag.AddValue('Message', $_.Exception.Message)
$StatePropertyBag
Exit
}
catch
{
$StatePropertyBag.AddValue('State', "Error")
$StatePropertyBag.AddValue('Message', $_.Exception.Message)
$StatePropertyBag
Exit
}

if ($TxResult -eq $null)
{
$StatePropertyBag.AddValue('State', "Error")
$StatePropertyBag.AddValue('Message', "$FunctionName unable to retrieve result")
$StatePropertyBag

LogError("$FunctionName unable to retrieve result")
Exit
}

$StatePropertyBag.AddValue('State', "Success")
$StatePropertyBag
CheckAndLogError("Returned StatePropertyBag")

$ObjectName = "ManageabilityTest"
$CounterName = "Latency"
$InstanceName = $FunctionName
$Value = $TxResult
LogInfo("$FunctionName result is $TxResult")

$PerformancePropertyBag = $momAPI.CreateTypedPropertyBag($PROPERTY_TYPE_PERFORMANCE)
if ($PerformancePropertyBag -eq $null)
{
LogError("unable to create performance property bag")
Exit
}

$PerformancePropertyBag.AddValue('ObjectName', $ObjectName)
$PerformancePropertyBag.AddValue('CounterName', $CounterName)
$PerformancePropertyBag.AddValue('InstanceName', $InstanceName)
$PerformancePropertyBag.AddValue('Value', $Value)
$PerformancePropertyBag
CheckAndLogError("Returned PerformancePropertyBag")
</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>FunctionName</Name>
<Value>$Config/FunctionName$</Value>
</Parameter>
<Parameter>
<Name>FunctionScript</Name>
<Value>$Config/FunctionScript$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</ProbeAction>
</MemberModules>
<Composition>
<Node ID="PA">
<Node ID="DS"/>
</Node>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.PropertyBagData</OutputType>
</DataSourceModuleType>