# PRTG-O365Status # # CustomXML-Sensor to read all Office 365 Status messages and generate a PRTG-XML-File # Simply Counting "open" issues per Product without # # 20160515 Version 1.0 FC initial Version based on some other scripts # 2022xxxx Version 1.1 RH Update auf Application und Graph param ( $clientid = 'pass or enter', $ClientSecret = 'pass or enter' ) [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 write-host "PRTG-O365Status:Start" $error.clear() [bool]$errorfound = $false [string]$prtgresult="" $prtgresult+="`r`n" $prtgresult+="`r`n" if (!$errorfound) { try { write-host "PRTG-O365Status: Getting Bearer Token" $body = @{ grant_type = "client_credentials" client_id = $clientid client_secret = $ClientSecret resource = "https://graph.microsoft.com" }; $Token = Invoke-RestMethod -Uri "https://login.microsoftonline.com/netatwork.onmicrosoft.com/oauth2/token" -Method Post -Body $body } catch { write-host "Error: Unable to get Token" $prtgresult+=" 2`r`n" $prtgresult+=" Error: Unable to get Token`r`n" $errorfound = $true } } if (!$errorfound) { try { write-host "PRTG-O365Status: Retrieving Current Status" $header = New-Object "System.Collections.Generic.Dictionary[[String],[String]]" $header["authorization"] = "Bearer $($Token.access_token)" $request = Invoke-RestMethod -Uri 'https://graph.microsoft.com/v1.0/admin/serviceAnnouncement/healthOverviews?$expand=issues' -Method Get -Header $header } catch { write-host "Error: Unable to get Status" $prtgresult+=" 2`r`n" $prtgresult+=" Error: Unable to get Status`r`n" $errorfound = $true } } if (!$errorfound) { write-host "PRTG-O365Status: Generating Result" foreach ($Service in $request.value) { $prtgresult+=" `r`n" $prtgresult+=" $($service.id)`r`n" ##check since closed incidents of the las 24h are still shown $prtgresult+=" $(($Service.issues | where isresolved -eq $false).IsResolved.count)`r`n" $prtgresult+=" 0`r`n" $prtgresult+=" Absolute" $prtgresult+=" Events" $prtgresult+=" `r`n" foreach ($msg in $($Service.issues | where isresolved -eq $false)) { $text += "$($msg.id), $($msg.classification), $($msg.service) $($msg.feature), $($msg.impactDescription) ;" } } $prtgresult+=" $($text)" } $prtgresult+="" if ($errorfound) { write-host "Error Found. Ending with EXIT Code" ([xml]$prtgresult).prtg.error } write-host "PRTG-O365Status: Sending PRTGRESULT to STDOUT" $prtgresult if ($errorfound) { exit ([xml]$prtgresult).prtg.error }