Set Event Log Search Timeframe for Discovery of Retail Components
Microsoft.Dynamics.Retail.AX2012.R2.FP.Base.WriteAction.SetDiscoveryTimeFrame (WriteActionModuleType)
Sets how many seconds in the past in the event log should be searched to discover Retail components.
Element properties: Member Modules:
Overrideable Parameters:
Source Code: <WriteActionModuleType ID="Microsoft.Dynamics.Retail.AX2012.R2.FP.Base.WriteAction.SetDiscoveryTimeFrame" Accessibility="Internal" Batching="false">
<Configuration>
<xsd:element minOccurs="1" name="TimeoutSeconds" type="xsd:integer"/>
<xsd:element minOccurs="1" name="DiscoveryName" type="xsd:string"/>
<xsd:element minOccurs="1" name="TimeFrameInSeconds" type="xsd:integer"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="TimeFrameInSeconds" Selector="$Config/TimeFrameInSeconds$" ParameterType="int"/>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<WriteAction ID="Script" TypeID="Windows!Microsoft.Windows.PowerShellWriteAction">
<ScriptName>SetDiscoveryTimeFrame.ps1</ScriptName>
<ScriptBody><Script> <#
SAMPLE CODE NOTICE
THIS SAMPLE CODE IS MADE AVAILABLE AS IS. MICROSOFT MAKES NO WARRANTIES, WHETHER EXPRESS OR IMPLIED,
OF FITNESS FOR A PARTICULAR PURPOSE, OF ACCURACY OR COMPLETENESS OF RESPONSES, OF RESULTS, OR CONDITIONS OF MERCHANTABILITY.
THE ENTIRE RISK OF THE USE OR THE RESULTS FROM THE USE OF THIS SAMPLE CODE REMAINS WITH THE USER.
NO TECHNICAL SUPPORT IS PROVIDED. YOU MAY NOT DISTRIBUTE THIS CODE UNLESS YOU HAVE A LICENSE AGREEMENT WITH MICROSOFT THAT ALLOWS YOU TO DO SO.
#>
param ([string]$DiscoveryName, [int]$TimeFrameInSeconds)
# this constant is used for logger initialization
$kScriptName = "SetDiscoveryTimeFrame.ps1"
#Logging.psm1#
## Event codes
### RetailServerInstanceDiscovery
$kRetailServerInstanceDiscoveryStartedToRun = 10000
$kRetailServerInstanceDiscoveryRegistryKeyFound = 10001
$kRetailServerInstanceDiscoveryNewInstanceAddedToDiscoveryData = 10002
$kRetailServerInstanceDiscoveryNoRegistryKeyFound = 10003
$kRetailServerInstanceDiscoveryFinishedSuccessfully = 10004
$kRetailServerInstanceDiscoveryFinishedWithError = 10005
### RealtimeServiceInstanceDiscovery
$kRealtimeServiceInstanceDiscoveryStartedToRun = 10020
$kRealtimeServiceInstanceDiscoveryRegistryKeyFound = 10021
$kRealtimeServiceInstanceDiscoveryAddedToDiscoveryData = 10022
$kRealtimeServiceInstanceDiscoveryNoRegistryKeyFound = 10023
$kRealtimeServiceInstanceDiscoveryFinishedSuccessfully = 10024
$kRealtimeServiceInstanceDiscoveryFinishedWithError = 10025
### AsyncServerReplicationJobDiscovery
$kAsyncServerReplicationJobDiscoveryReplicationJobFound = 10050
$kAsyncServerReplicationJobDiscoveryNoReplicationJobsFound = 10051
$kAsyncServerReplicationJobDiscoveryNoEventWithReplicationJobs = 10052
$kAsyncServerReplicationJobDiscoveryStartedToRun = 10053
$kAsyncServerReplicationJobDiscoveryNoAOSInstancesFound = 10054
$kAsyncServerReplicationJobDiscoveryNoAOSRegistryKeysFound = 10055
$kAsyncServerReplicationJobDiscoveryFinishedSuccessfully = 10056
$kAsyncServerReplicationJobDiscoveryFinishedWithError = 10057
$kAsyncServerReplicationJobDiscoveryReplicationJobsEventId = 10065 # This event is generated by Dynamics Server
### SharePointECommerceDiscovery
$kSharePointECommerceDiscoveryStartedToRun = 10080
$kSharePointECommerceDiscoveryFinishedSuccessfully = 10081
$kSharePointECommerceDiscoveryFinishedWithError = 10082
$kSharePointECommerceDiscoveryFarmFound = 10083
$kSharePointECommerceDiscoveryFarmNotFound = 10084
$kSharePointECommerceDiscoveryECommerceDeploymentFound = 10085
$kSharePointECommerceDiscoveryECommerceDeploymentNotFound = 10086
$kSharePointECommerceDiscoveryECommerceWebAppsFound = 10087
$kSharePointECommerceDiscoveryECommerceWebAppsNotFound = 10088
$kSharePointECommerceDiscoveryECommerceTimerJobsFound = 10089
$kSharePointECommerceDiscoveryECommerceTimerJobsNotFound = 10090
$kSharePointECommerceDiscoveryECommerceWebAppDiscoveryDataAdded = 10091
$kSharePointECommerceDiscoveryECommerceTimerJobDiscoveryDataAdded = 10091
### CdxSynchServiceClientDiscovery
$kCdxSynchServiceClientDiscoveryStartedToRun = 10100
$kCdxSynchServiceClientDiscoveryRootKeyFound = 10101
$kCdxSynchServiceClientDiscoveryFailedToEvaluateErrorCountingPeriod = 10102
$kCdxSynchServiceClientDiscoveryNewInstanceDiscovered = 10103
$kCdxSynchServiceClientDiscoveryNoRootKeyFound = 10104
$kCdxSynchServiceClientDiscoveryFinishedSuccessfully = 10105
$kCdxSynchServiceClientDiscoveryFinishedWithError = 10106
### CdxSynchServiceServerDiscovery
$kCdxSynchServiceServerDiscoveryStartedToRun = 10110
$kCdxSynchServiceServerDiscoveryRootKeyFound = 10111
$kCdxSynchServiceServerDiscoveryNewInstanceDiscovered = 10112
$kCdxSynchServiceServerDiscoveryNoRootKeyFound = 10113
$kCdxSynchServiceServerDiscoveryFinishedSuccessfully = 10114
$kCdxSynchServiceServerDiscoveryFinishedWithError = 10115
### RetailServerChannelDBConnectionDiscovery
$kRetailServerChannelDBConnectionDiscoveryStartedToRun = 10120
$kRetailServerChannelDBConnectionDiscoverySearchingSuccessEvents = 10121
$kRetailServerChannelDBConnectionDiscoverySearchingErrorEvents = 10122
$kRetailServerChannelDBConnectionDiscoveryNewInstanceFound = 10123
$kRetailServerChannelDBConnectionDiscoveryNoInstancesFound = 10124
$kRetailServerChannelDBConnectionDiscoveryFinishedSuccessfully = 10125
$kRetailServerChannelDBConnectionDiscoveryFinishedWithError = 10126
### HardwareStationDiscovery
$kHardwareStationDiscoveryStartedToRun = 10140
$kHardwareStationDiscoveryRegistryKeyFound = 10141
$kHardwareStationDiscoveryNewInstanceAddedToDiscoveryData = 10142
$kHardwareStationDiscoveryNoRegistryKeyFound = 10143
$kHardwareStationDiscoveryFinishedSuccessfully = 10144
$kHardwareStationDiscoveryFinishedWithError = 10145
$kChannelDbConnectivityFailureEventId = 10200 # This event is generated by CRT Sdk (Retail Server, POS, eCommerce)
$kChannelDbConnectivitySuccessEventId = 10201 # This event is generated by CRT Sdk (Retail Server, POS, eCommerce)
### ReplicationJobScheduleState
$kReplicationJobStateStartedToRun = 10230
$kReplicationJobStateNoMonitoringEvents = 10231
$kReplicationJobStateSucceeded = 10232
$kReplicationJobStateFailed = 10233
$kReplicationJobStateFinishedSuccessfully = 10234
$kReplicationJobStateFinishedWithError = 10235
$kReplicationJobStateEventId = 10230 # This event is generated by Dynamics Server
### IISAppPoolStatus
$kIISAppPoolStatusStartedToRun = 10300
$kIISAppPoolStatusInetsrvNotExist = 10301
$kIISAppPoolStatusAppCmdDoesntExist = 10302
$kIISAppPoolStatusNoAppPoolName = 10303
$kIISAppPoolStatusAppcmdExitedWithError = 10304
$kIISAppPoolStatusUnexpectedAppcmdOutput = 10305
$kIISAppPoolStatusLogBagContent = 10306
$kIISAppPoolStatusFinishedSuccessfully = 10307
$kIISAppPoolStatusExitedWithError = 10308
### ConnectionToChannelDbState
$kConnectionToChannelDbStateStartedToRun = 10310
$kConnectionToChannelDbStateSearchingSuccessEvents = 10311
$kConnectionToChannelDbStateSearchingErrorEvents = 10312
$kConnectionToChannelDbStateNoMonitoringEvents = 10313
$kConnectionToChannelDbStateSuccess = 10314
$kConnectionToChannelDbStateFailed = 10315
$kConnectionToChannelDbStateFinishedSuccessfully = 10316
$kConnectionToChannelDbStateFinishedWithError = 10317
### HardwareStationSmokeTest
$kHardwareStationSmokeTestStartedToRun = 10320
$kHardwareStationSmokeTestFinishedSuccessfully = 10321
$kHardwareStationSmokeTestFinishedWithError = 10322
### ChangeTraceLevelInAppConfig
$kChangeTraceLevelInAppConfigStartedToRun = 10400
$kChangeTraceLevelInAppConfigFinishedSuccessfully = 10401
$kChangeTraceLevelInAppConfigFinishedWithError = 10402
$kChangeTraceLevelInAppConfigFileSaved = 10403
$kChangeTraceLevelInAppConfigFileUnchanged = 10404
$kChangeTraceLevelInAppConfigFileParameterCheckError = 10405
### ChangeSharePointTracingLevel
$kChangeSharePointTracingLevelStartedToRun = 10600
$kChangeSharePointTracingLevelFinishedSuccessfully = 10601
$kChangeSharePointTracingLevelFinishedWithError = 10602
$kChangeSharePointTracingLevelParameterCheckError = 10603
### EnterprisePosDiscovery
$kEnterprisePosDiscoveryStartedToRun = 10700
$kEnterprisePosDiscoveryFinishedSuccessfully = 10701
$kEnterprisePosDiscoveryFinishedWithError = 10702
$kNoEnterprisePosDiscoveryDataFound = 10703
$kEnterprisePosDiscoveryEvent = 10704
### EnterprisePosOfflineDiscovery
$kRetailPosOfflineServiceDiscoveryStartedToRun = 10800
$kNoRetailPosOfflineServiceDiscoveryDataFound = 10801
$kRetailPosOfflineServiceDiscoveryFinishedSuccessfully = 10802
$kRetailPosOfflineServiceDiscoveryRootKeyFound = 10803
$kRetailPosOfflineServiceDiscoveryNotUsedByPos = 10804
$kRetailPosOfflineServiceDiscoveryFinishedSuccessfully = 10805
$kNoRetailPosOfflineServiceAdditionalDiscoveryDataFound = 10806
$kRetailPosOfflineServiceDiscoveryFinishedSuccessfully = 10807
$kRetailPosOfflineServiceDiscoveryFinishedWithError = 10808
### StartAppPool
$kStartAppPoolStartedToRun = 10900
$kStartAppPoolFinishedSuccessfully = 10901
$kStartAppPoolFinishedWithError = 10902
### CertificateStatus
$kCertificateStatusStartedToRun = 10910
$kCertificateStatusNonExistingCertificate = 10911
$kCertificateStatusLogBagContent = 10912
$kCertificateStatusFinishedSuccessfully = 10913
$kCertificateStatusExitedWithError = 10914
### SetDiscoveryTimeFrame
$kSetDiscoveryTimeFrameStartedToRun = 10920
$kSetDiscoveryTimeFrameFinishedSuccessfully = 10921
$kSetDiscoveryTimeFrameFinishedWithError = 10922
## Functions
### Function tests if logging is enabled
function Test-LoggingEnabled
{
(Get-ItemProperty -Path $LoggingAbilityItemPath -ErrorAction SilentlyContinue).EnableMonitoringScriptLogging -eq "Enabled"
}
## Constants
$LoggingAbilityItemPath = "HKLM:\SOFTWARE\Microsoft\Dynamics\6.0"
$LoggingAbilityItemPropertyName = "EnableMonitoringScriptLogging"
$kLogWidth = 200 # characters
$kLogName = "Application"
$kLogSourceName = "Microsoft Dynamics AX Retail Monitoring"
$kEnableLogging = Test-LoggingEnabled
# This is needed to mock the logger object
if ($logger -ne $null)
{
# $logger object is initialized with the MS.Dynamics.Test.Retail.Test.Monitoring.Mocks.Logger object
$logger.LogName = $kLogName;
$logger.LogSourceName = $kLogSourceName;
$logger.ScriptName = $kScriptName;
}
else
{
# this means that object $logger is not initialized
## Create logger
$logger = New-Object -TypeName System.Management.Automation.PSObject
### Add logger properties
$logger | Add-Member -MemberType ScriptProperty -Name LogName -Value { $kLogName }
$logger | Add-Member -MemberType ScriptProperty -Name LogSourceName -Value { $kLogSourceName }
$logger | Add-Member -MemberType ScriptProperty -Name ScriptName -Value { $kScriptName }
$logger | Add-Member -MemberType ScriptProperty -Name ShouldWriteToEventLog -Value { $kEnableLogging }
### Add logger methods
$logger | Add-Member -MemberType ScriptMethod -Name LogInfo -Value {
param($eventId, $message)
if ($This.ShouldWriteToEventLog)
{
try
{
Write-EventLog -LogName $This.LogName -Source $This.LogSourceName -EntryType Information -EventId $eventId -Message ($This.ScriptName + " : " + $message) -ErrorAction Stop
}
catch
{
try
{
$scomApi.LogScriptEvent($This.ScriptName, $eventId, 0, "{0}" -f $message)
}
catch
{
}
}
}
}
$logger | Add-Member -MemberType ScriptMethod -Name LogError -Value {
param($eventId, $message)
try
{
Write-EventLog -LogName $This.LogName -Source $This.LogSourceName -EntryType Error -EventId $eventId -Message ($This.ScriptName + " : " + $message) -ErrorAction Stop
}
catch
{
try
{
$scomApi.LogScriptEvent($This.ScriptName, $eventId, 2, "{0}" -f $message)
}
catch
{
}
}
}
$logger | Add-Member -MemberType ScriptMethod -Name LogScriptExecutionSucceeded -Value {
param($eventId)
$This.LogInfo($eventId, "Script execution ended successfully")
}
$logger | Add-Member -MemberType ScriptMethod -Name LogScriptExecFailed -Value {
param($eventId, $error)
$This.LogError($eventId, "Script executed with errors :`n" + ($error | Out-String -Width $kLogWidth))
}
$logger | Add-Member -MemberType ScriptMethod -Name LogScriptExecFailedWithDefaultError -Value {
param($eventId)
$This.LogError($eventId, "Script executed with errors :`n" + ($Global:Error | Out-String -Width $kLogWidth))
}
}
#RegistryHelper.psm1#
$kDynamicsRegistryKey = "HKLM:\SOFTWARE\Microsoft\Dynamics\6.0"
$kTimeFramePropertySuffix = 'TimeFrameInSeconds'
$kDefaultTimeFrameValue = [int] 86400
Function Set-DiscoveryTimeFrame
{
param(
[Parameter(Mandatory=$true)]
[string]$DiscoveryName,
[Parameter(Mandatory=$true)]
[int]$TimeFrameInSeconds
)
if (-not (Test-Path $kDynamicsRegistryKey -ErrorAction Stop))
{
[void](New-Item -Path $kDynamicsRegistryKey -Force -ErrorAction Stop)
}
[void](New-ItemProperty -Force -ErrorAction Stop `
-Path $kDynamicsRegistryKey `
-Name ($DiscoveryName + $kTimeFramePropertySuffix) `
-PropertyType 'DWord' `
-Value $TimeFrameInSeconds)
}
Function Get-DiscoveryTimeFrame
{
param(
[Parameter(Mandatory=$true)]
[string]$DiscoveryName
)
$timeFrameInSeconds = (Get-ItemProperty -Path $kDynamicsRegistryKey -ErrorAction SilentlyContinue).($DiscoveryName + $kTimeFramePropertySuffix)
if ($timeFrameInSeconds)
{
return [int]$timeFrameInSeconds
}
else
{
return $kDefaultTimeFrameValue
}
}
try
{
$logger.LogInfo($kSetDiscoveryTimeFrameStartedToRun, ("Set discovery {0} to search for events during the previous {1} seconds." -f $DiscoveryName, $TimeFrameInSeconds))
Set-DiscoveryTimeFrame -DiscoveryName $DiscoveryName -TimeFrameInSeconds $TimeFrameInSeconds
$logger.LogInfo($kSetDiscoveryTimeFrameFinishedSuccessfully, ("Successfully set discovery {0} to search for events during the previous {1} seconds." -f $DiscoveryName, $TimeFrameInSeconds))
}
catch
{
$logger.LogScriptExecFailedWithDefaultError($kSetDiscoveryTimeFrameFinishedWithError)
throw
}
</Script> </ScriptBody>
<Parameters>
<Parameter>
<Name>DiscoveryName</Name>
<Value>$Config/DiscoveryName$</Value>
</Parameter>
<Parameter>
<Name>TimeFrameInSeconds</Name>
<Value>$Config/TimeFrameInSeconds$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</WriteAction>
</MemberModules>
<Composition>
<Node ID="Script"/>
</Composition>
</Composite>
</ModuleImplementation>
<InputType>System!System.BaseData</InputType>
</WriteActionModuleType>