Skip to content

Commit

Permalink
Total runtime logging (#423)
Browse files Browse the repository at this point in the history
Previously if there were no messages to processes, the event order would be (at a minimum) 0 = connected to exchange and then 5 = filtering mailbox. There was no indication that there were 0/no messages to process and/or that 5 was the "last" event one would see for a run of the connector. As such, the logging could be misinterpreted as the connector not successfully completing a run. This change removes that uncertainty as the event is now logged regardless of the number of messages to process as well as introducing event 6 which shows the total runtime of the connector for a given number of messages. Now the minimum logging order is 0, 5, 2, 6 which is more representative of a start, connect, process and finish of the connector.
  • Loading branch information
AdhocAdam authored Nov 20, 2022
1 parent 2566804 commit cb73e66
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion smletsExchangeConnector.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
$startTime = Get-Date
<#
.SYNOPSIS
Provides SCSM Exchange Connector functionality through PowerShell
Expand Down Expand Up @@ -4541,7 +4542,7 @@ $inboxFilterString = [scriptblock]::Create("$inboxFilterString")

#filter the inbox
$inbox = $exchangeService.FindItems($inboxFolder.Id,$searchFilter,$itemView) | where-object $inboxFilterString | Sort-Object DateTimeReceived
if (($loggingLevel -ge 1)-and($inbox.Count -ge 1)){New-SMEXCOEvent -Source "General" -EventId 2 -LogMessage "Messages to Process: $($inbox.Count)" -Severity "Information"; $messagesProcessed = 0}
if (($loggingLevel -ge 1)){New-SMEXCOEvent -Source "General" -EventId 2 -LogMessage "Messages to Process: $($inbox.Count)" -Severity "Information"; $messagesProcessed = 0}
# Custom Event Handler
if ($ceScripts) { Invoke-OnOpenInbox }

Expand Down Expand Up @@ -5125,3 +5126,14 @@ foreach ($message in $inbox)
#increment the number of messages processed if logging is enabled
if ($loggingLevel -ge 1){$messagesProcessed++; New-SMEXCOEvent -Source "General" -EventId 3 -LogMessage "Processed: $messagesProcessed of $($inbox.Count)" -Severity "Information"}
}

#log the total number of messages processed and the connector's total run time
if ($loggingLevel -ge 1)
{
$endTime = Get-Date
$runtime = $endTime - $startTime
New-SMExcoEvent -Source "General" -EventID 6 -Severity "Information" -LogMessage "Processed $($inbox.Count) messages in:
Minutes: $($runtime.TotalMinutes)
Seconds: $($runtime.TotalSeconds)
Milliseconds: $($runtime.TotalMilliseconds)"
}

0 comments on commit cb73e66

Please sign in to comment.