Hello,
PRTG have not a specific sensor for count the number of received email in specific mailbox for analyse the statistics by day.
I want a total number to incoming emails on specific mailbox, by day.
(I already use the sensor for count the number of email in folder inbox but it'is different to know the number of received emails by day)
I do not expect a prtg/Paessler response because I know there is no sensor for this, but I'm looking for an answer from other PRTG users.
The need is to simply know the number of mail received per day on a specific mailbox, and to have the number 1 times a day.
thank you
Article Comments
Dear DIMITRI,
Thank you very much for your KB-post.
My colleague Dieter wrote a script which should help you with your request. Using this script you can use PRTG´s native EXE/Script Advanced Sensor.
- Please save this script as Get-MailcountReceivedYesterdayTodayForUser.ps1 under C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXE
- Deploy a EXE/Script Advanced Sensor to your Exchange device
- Please use the following syntax for the parameter-setting within PRTG:
- -server <fqdn of the server> -user <loginname> -pass <password> -recipient <smtp-address to check for mails>
- Save the settings.
Please let us know if this works fine for you.
Kind regards,
Sven
Param(
$server,
$user,
$pass,
$recipient
)
<# use the following syntax for the parameter-setting within PRTG:
-server <fqdn of the server> -user <loginname> -pass <password> -recipient <smtp-address to check for mails>
or simple to use presets within the device:
-server %host -user %windowsdomain\%windowsuser -pass %windowspassword -recipient <smtp-address to check for mails>
#>
$prtg = ‘<?xml version="1.0" encoding="utf-8" ?>
<prtg>
‘
try {
$secPw = ConvertTo-SecureString $pass -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential ($user, $secPw)
$Session = New-PSSession -ConfigurationName Microsoft.Exchange `
-ConnectionUri http://$server/PowerShell/ `
-credential $credential
Import-PSSession $session -AllowClobber
$msgsSinceYesterday = Get-MessageTrackingLog -ResultSize Unlimited -Start (get-date (get-date).AddDays(-1) -f ((New-Object System.Globalization.CultureInfo(“en-US”)).DateTimeFormat.ShortDatePattern)) -Recipients $recipient -EventId Receive
$msgsSinceYesterdayGrouped = $msgsSinceYesterday | select timestamp | Group-Object {$_.timestamp.date}
if ($msgsSinceYesterdayGrouped.count -eq 2) {
$mailsYesterday = $msgsSinceYesterdayGrouped[0].count
$mailsToday = $msgsSinceYesterdayGrouped[1].count
} elseif ($msgsSinceYesterdayGrouped.count -eq 1) { # this may happen if there is NO mail within one day for example during night or at the weekend
if ((get-date($msgsSinceYesterday[0].name)).Date -lt (get-date).Date) {
$mailsYesterday = $msgsSinceYesterdayGrouped[0].count
$mailsToday = 0
} else {
$mailsYesterday = 0
$mailsToday = $msgsSinceYesterdayGrouped[0].count
}
} else {
$mailsYesterday = 0
$mailsToday = 0
}
$prtg +=" <result>
<channel>Mails Today</channel>
<value>$mailstoday</value>
<unit>custom</unit>
<customunit>emails</customunit>
<showChart>1</showChart>
<showTable>1</showTable>
</result>
<result>
<channel>Mails Yesterday</channel>
<value>$mailsyesterday</value>
<unit>custom</unit>
<customunit>emails</customunit>
<showChart>1</showChart>
<showTable>1</showTable>
</result>
"
$prtg +=" <text>OK</text>
</prtg>"
} catch {
$errormessage = $_.Exception.Message
$prtg +=" <error>1</error>"
$prtg +=" <text>$errormessage</text>
</prtg>"
} finally {
if ($Session -ne $null) { Remove-PSSession $Session; }
}
$prtg
Dec, 2016 - Permalink
Hello,
thank you for this response:
This is the result of sensor
Réponse non correcte : "( ModuleType Version Name ExportedCommands ---------- ------- ---- ---------------- Script 1.0 tmp_12hib4vw.oub {Add-DistributionG... <?xml version="1.0" encoding="utf-8" ?> <prtg> <error>1</error> <text>Le terme « Get-MessageTrackingLog » n'est pas reconnu comme nom d'applet de comande, fonction, fichier de script ou programme exécutable. Vérifiez l'orthographe du nom, ou si un chemin d'accès existe, vérifiez que le chemin d'accès est correct et réessayez.</text> </prtg> )" (code : PE132) |
On the Exchange Server, if I send the powershell command "get-MessageTrackingLog" the server return the informations normally
Have you an idea?
Dec, 2016 - Permalink
Dear DIMITRI,
Thank you very much for your response.
Please use the same user/password in the sensor-settings of PRTG as you use when you run the command directly on the Exchange Server. This is needed because the related CMDlets won´t be available on the Probe if you are not use a suitable user.
Best regards,
Sven
Dec, 2016 - Permalink
Hello
In my case, the user logon is "domain\logon"
I test it with parameter only "logon" but not working
and test it with parameter domain\logon with backslash not working either
thank you
Dec, 2016 - Permalink
Dear DIMITRI,
Thank you very much for your response.
Have you used the following syntax for the parameter-setting within PRTG?
-server <fqdn of the server> -user <loginname> -pass <password> -recipient <smtp-address to check for mails>
or simple to use presets within the device:
-server %host -user %windowsdomain\%windowsuser -pass %windowspassword -recipient <smtp-address to check for mails>
Please use " " before/after loginname and password and try it once again.
If this still does not work, please open a support ticket, and send us screenshots of the sensor-settings.
Thank you very much in advance.
Best regards,
Sven
Dec, 2016 - Permalink
Dear DIMITRI,
Thank you very much for your KB-post.
My colleague Dieter wrote a script which should help you with your request. Using this script you can use PRTG´s native EXE/Script Advanced Sensor.
Please let us know if this works fine for you.
Kind regards,
Sven
Dec, 2016 - Permalink