Search code examples
powershellsolarwinds-orion

Powershell integration with Office365


I would like some comments on the integration code that I am developing... trying to integrate Office365 to Solarwinds:

import-Module Office365Alerts


$Username = '[email protected]'
$Password = 'XXXXXXXXXXXXXXXX'


$credential = New-Object -TypeName pscredential -ArgumentList $Username, ($Password | ConvertTo-SecureString -AsPlainText -Force) -ErrorAction Stop


$alerts = Get-Office365ServiceHealth -Credential $credential -ErrorAction Stop  | Select-Object -Property * | Where-Object Service -like '*Exchange*'


foreach($a in $alerts){
[regex]$regex = '\bCurrent status:\s?.*\s' 
$Mess = $a.LatestMessage 

if($Mess -match $regex){
foreach($m in $mess){
Write-Host "Message:Title: $($a.Title)"

Write-Host "Message:Impact: $($a.UserImpact)"

Write-Host "Message:Start Time: $($a.StartTime)"

Write-Host "Message:Last Update: $($a.LastUpdate)"

Write-Host "Message: $($Matches.Values)"


}
Write-Host "Statistic: 1"
}



}

if($a -eq $null){

Write-Host "Message: Service is Healthy"
Write-Host "Statistic: 0"

Solution

  • The SolarWinds Powershell monitors are limited to 10 returned metric pairs (message and statistic), if there are more than 10 alerts returned, it will break. AS you are returning 5 messages, which appear to be identical in foreach($a in $alerts) loop, they won't have unique names, also probably causing you problems.

    Are you running the script in Local Host or Remote Host execution mode? IF you are running it on a host without the Office365 commandlets, it'll fail.

    Have you enabled debug logging, within the template? It's under Advanced at the top of the template editing view. Logs can be found in ProgramData\SolarWinds\Logs\APM, take note of your templateID or its componentIDs, as the logs will be referenced by them.