Update SDK Version

Microsoft.SystemCenter.ApplicationInsights.Monitor.SDKVersion.Recovery (Recovery)

Recovery task to update SDK automatically.

Element properties:

TargetMicrosoft.SystemCenter.ApplicationInsights.Application
MonitorMicrosoft.SystemCenter.ApplicationInsights.Monitor.SDKVersion
Reset MonitorTrue
RemotableTrue
Timeout300
CategoryCustom
Enabledfalse
AccessibilityPublic

Member Modules:

ID Module Type TypeId RunAs 
Microsoft.SystemCenter.ApplicationInsights.Monitor.SDKVersion.Recovery.WriteAction WriteAction System.CommandExecuter System.PrivilegedMonitoringAccount

Source Code:

<Recovery ID="Microsoft.SystemCenter.ApplicationInsights.Monitor.SDKVersion.Recovery" Accessibility="Public" Enabled="false" Target="Microsoft.SystemCenter.ApplicationInsights.Application" Monitor="Microsoft.SystemCenter.ApplicationInsights.Monitor.SDKVersion" ResetMonitor="true" ExecuteOnState="Warning" Remotable="true" Timeout="300">
<Category>Custom</Category>
<WriteAction ID="Microsoft.SystemCenter.ApplicationInsights.Monitor.SDKVersion.Recovery.WriteAction" TypeID="System!System.CommandExecuter" RunAs="System!System.PrivilegedMonitoringAccount">
<ApplicationName/>
<WorkingDirectory/>
<CommandLine>powershell.exe -NoLogo -NoProfile -Noninteractive "$ep = get-executionpolicy; if ($ep -gt 'RemoteSigned') {set-executionpolicy -Scope Process remotesigned} &amp; '$$file/UpdateSDK.ps1$$' '$Target/Property[Type='Microsoft.SystemCenter.ApplicationInsights.Application']/IISApplicationPath$' '$Target/Property[Type='Microsoft.SystemCenter.ApplicationInsights.Application']/InstrumentationKey$'</CommandLine>
<SecureInput/>
<TimeoutSeconds>180</TimeoutSeconds>
<RequireOutput>true</RequireOutput>
<Files>
<File>
<Name>UpdateSDK.ps1</Name>
<Contents><Script>param($AppName, $IKey)

$SCRIPT_EVENT_ID = 4444

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

function Main($name, $iKey)
{

# 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
$filepath = $regkey.GetValue('Path', $null)

if ($filepath -ne $null) {
$filepath = Split-Path $filepath
$filepath += '\PowerShell\Microsoft.Diagnostics.Agent.StatusMonitor.PowerShell.dll'
Import-Module $filepath
Update-ApplicationInsightsVersion
Update-ApplicationInsightsMonitoring $name $iKey
}
}
}
catch {
$header = "Application Insights application SDK update task"
$msg = $_.Exception.Message;
$msg = "Error occured in the Application Insights application SDK update task. Reason: $msg"
$api.LogScriptEvent($header, $SCRIPT_EVENT_ID, $ERROR_EVENT_TYPE, $msg)
}

}

Main $AppName $IKey</Script></Contents>
<Unicode>true</Unicode>
</File>
</Files>
</WriteAction>
</Recovery>