Is there any way to monitor Office365 Mailbox?

I’m trying to find a way to monitor office365 emails. It turns out that OAuth2 is now a requirement for login. I’ve found check_mailbox.sh which still passes along a username:password combination but this is now, disabled by Office365. Are there any current ways to monitor the contents of an Office365 mailbox?

  • Icinga2 Version: r2.6.0-1
  • Operating System: Debian 9
  • Enabled features: api checker command ido-mysql mainlog notification
  • Icinga Web 2 version and modules 2.4.1; doc - 2.4.1, monitoring - 2.4.1
  • Config validation (icinga2 daemon -C)
    information/cli: Icinga application loader (version: r2.6.0-1)
    information/cli: Loading configuration file(s).
    information/ConfigItem: Committing config item(s).
    information/ApiListener: My API identity: icinga2.phytec
    warning/ApplyRule: Apply rule ‘auto_reroute_status’ (in /etc/icinga2/conf.d/services.conf: 100:1-100:35) for type ‘Service’ does not match anywhere!
    warning/ApplyRule: Apply rule ‘check-speedtest’ (in /etc/icinga2/conf.d/services.conf: 198:1-198:31) for type ‘Service’ does not match anywhere!
    warning/ApplyRule: Apply rule ‘ilo’ (in /etc/icinga2/conf.d/services.conf: 226:1-226:19) for type ‘Service’ does not match anywhere!
    information/ConfigItem: Instantiated 2 ApiUsers.
    information/ConfigItem: Instantiated 1 ApiListener.
    information/ConfigItem: Instantiated 1 Zone.
    information/ConfigItem: Instantiated 1 FileLogger.
    information/ConfigItem: Instantiated 1 Endpoint.
    information/ConfigItem: Instantiated 2 NotificationCommands.
    information/ConfigItem: Instantiated 49 Notifications.
    information/ConfigItem: Instantiated 205 CheckCommands.
    information/ConfigItem: Instantiated 1 Downtime.
    information/ConfigItem: Instantiated 47 Hosts.
    information/ConfigItem: Instantiated 1 IcingaApplication.
    information/ConfigItem: Instantiated 2 HostGroups.
    information/ConfigItem: Instantiated 3 Comments.
    information/ConfigItem: Instantiated 3 UserGroups.
    information/ConfigItem: Instantiated 5 Users.
    information/ConfigItem: Instantiated 49 Services.
    information/ConfigItem: Instantiated 3 TimePeriods.
    information/ConfigItem: Instantiated 3 ServiceGroups.
    information/ConfigItem: Instantiated 1 ScheduledDowntime.
    information/ConfigItem: Instantiated 1 ExternalCommandListener.
    information/ConfigItem: Instantiated 1 CheckerComponent.
    information/ConfigItem: Instantiated 1 IdoMysqlConnection.
    information/ConfigItem: Instantiated 1 NotificationComponent.
    information/ScriptGlobal: Dumping variables to file ‘/var/cache/icinga2/icinga2.vars’
    information/cli: Finished validating the configuration file(s).

I can recommend you Microsoft Graph API to monitor Microsoft 365 services.

Funny that you are asking as just last week somebody wanted me to monitor a mailbox as well and I told them, that I would prefer to monitor the source of the report and not the resulting mail.

If I end up writing the check I will use the python lib I already use to work with Exchange and it also supports Office365.

But if you’re faster, I welcome reading about it on the Icinga Exchange :wink:

I’m tyring to implement this as a solution for myself. I’m running into errors where:

exchangelib.errors.ErrorInvalidExchangeImpersonationHeaderData: ExchangeImpersonation SOAP header must be present for this type of OAuth token.

Do you know how I might solve this? I’ve tried numerous solutions that I’ve seen online to no avail.

Do you know how I might use the Graph API? I’ve created the App registration as per the below exchangelib documentation. I’ve not been able to successfully implement this solution though.

Finally got it working using powershell. The following was the useful bit:

Get-EXOMailboxFolderStatistics -Identity support -FolderScope inbox | ?{$_.folderpath -eq "/inbox"} | select visibleItemsInFolder
1 Like

I think I needed a technical account for my app with full rights set by the Exchange Admin (not just delegate) on the mailbox for it to work.
Also a search tells me access_type=IMPERSONATION needs to be set.

But you got your solution and there no need except that PowerShell hat bad startup times (at least on our hosts) and use a lot of CPU :wink: