Status Monitor Data Source Type

Microsoft.SystemCenter.ApplicationInsights.StatusMonitorDataSourceType (DataSourceModuleType)

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityInternal
RunAsSystem.PrivilegedMonitoringAccount
OutputTypeSystem.PropertyBagData

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource System.CommandExecuterPropertyBagSource Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
IntervalSecondsint$Config/IntervalSeconds$Run interval (seconds)The recurring interval of time in seconds in which to run the workflow.
TimeoutSecondsint$Config/TimeoutSeconds$Timeout (seconds)Specifies the time the workflow is allowed to run before being closed and marked as failed.

Source Code:

<DataSourceModuleType ID="Microsoft.SystemCenter.ApplicationInsights.StatusMonitorDataSourceType" Accessibility="Internal" RunAs="System!System.PrivilegedMonitoringAccount">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="IntervalSeconds" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="TimeoutSeconds" type="xsd:int"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" ParameterType="int" Selector="$Config/IntervalSeconds$"/>
<OverrideableParameter ID="TimeoutSeconds" ParameterType="int" Selector="$Config/TimeoutSeconds$"/>
</OverrideableParameters>
<ModuleImplementation>
<Composite>
<MemberModules>
<DataSource ID="DS" TypeID="System!System.CommandExecuterPropertyBagSource">
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<ApplicationName/>
<WorkingDirectory/>
<CommandLine>powershell.exe -NoLogo -NoProfile -Noninteractive "$ep = get-executionpolicy; if ($ep -gt 'RemoteSigned') {set-executionpolicy -Scope Process remotesigned} &amp; '$$file/GetStatusMonitorData.ps1$$' '$FileResource[Name="Microsoft.SystemCenter.ApplicationInsights.Resources.InstallationFile"]/Path$'</CommandLine>
<SecureInput/>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
<RequireOutput>true</RequireOutput>
<Files>
<File>
<Name>GetStatusMonitorData.ps1</Name>
<Contents><Script>param($MsiPath)

$SCRIPT_EVENT_ID = 4444

#Event Severity values
$INFORMATION_EVENT_TYPE = 0
$ERROR_EVENT_TYPE = 1

function Main {
param (
[IO.FileInfo] $FilePath
)

# Prepare MOM API and property bag object
$api = New-Object -comObject "MOM.ScriptAPI"

try {
$key = 'HKLM:\SOFTWARE\Microsoft\Application Insights Agent\Setup\v1.0'
$pathExist = Test-Path $key
if ($pathExist) {
$regkey = Get-Item -LiteralPath $key
$installedVersion = $regkey.GetValue('Version', '')

$windowsInstaller = New-Object -com WindowsInstaller.Installer

$database = $windowsInstaller.GetType().InvokeMember(
"OpenDatabase", "InvokeMethod", $Null,
$windowsInstaller, @($FilePath.FullName, 0)
)

$q = "SELECT Value FROM Property WHERE Property = 'ProductVersion'"
$View = $database.GetType().InvokeMember(
"OpenView", "InvokeMethod", $Null, $database, ($q)
)

$View.GetType().InvokeMember("Execute", "InvokeMethod", $Null, $View, $Null)

$record = $View.GetType().InvokeMember(
"Fetch", "InvokeMethod", $Null, $View, $Null
)

$productVersion = $record.GetType().InvokeMember(
"StringData", "GetProperty", $Null, $record, 1
)

$View.GetType().InvokeMember("Close", "InvokeMethod", $Null, $View, $Null)

$bag = $api.CreatePropertyBag()
try {
if ( [System.Version]$installedVersion -ge [System.Version]$productVersion)
{
$bag.AddValue("VersionUpToDate", 1)
}
else
{
$bag.AddValue("VersionUpToDate", 0)
}
} catch {
$bag.AddValue("VersionUpToDate", 1)
}

$api.Return($bag)
}
}
catch {
$header = "Application Insights Status Monitor datasource"
$msg = $_.Exception.Message;
$msg = "Error occured in the Application Insights Status Monitor datasource. Reason: $msg"
$api.LogScriptEvent($header, $SCRIPT_EVENT_ID, $ERROR_EVENT_TYPE, $msg)
}

}

Main $MsiPath</Script></Contents>
<Unicode>true</Unicode>
</File>
</Files>
</DataSource>
</MemberModules>
<Composition>
<Node ID="DS"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.PropertyBagData</OutputType>
</DataSourceModuleType>