Skip to content

Instantly share code, notes, and snippets.

@AlexAsplund
Created September 1, 2019 17:12
Show Gist options
  • Save AlexAsplund/83c8e374ed3d81d2de88767a4d9dc5e1 to your computer and use it in GitHub Desktop.
Save AlexAsplund/83c8e374ed3d81d2de88767a4d9dc5e1 to your computer and use it in GitHub Desktop.
$PRTGUrl = "http://prtg.contoso.com:5050/"
#################################
# Functions
#################################
function New-PRTGResult {
param(
[string]$Channel,
[string]$Value,
[string]$Float,
[string]$Unit,
[string]$CustomUnit,
[string]$LimitMode,
[string]$LimitMaxWarning,
[string]$LimitMaxerror,
[string]$ValueLookup,
[string]$Mode,
[string]$Text,
[string]$Warning,
[string]$Error,
[string]$LimitMinError,
[string]$LimitMinWarning
)
$Object = New-Object -TypeName psobject
$Object | Add-Member -MemberType NoteProperty -Name Channel -Value $Channel
$Object | Add-Member -MemberType NoteProperty -Name Value -Value $Value
$Object | Add-Member -MemberType NoteProperty -Name Float -Value $Float
$Object | Add-Member -MemberType NoteProperty -Name Unit -Value $Unit
$Object | Add-Member -MemberType NoteProperty -Name CustomUnit -Value $CustomUnit
$Object | Add-Member -MemberType NoteProperty -Name LimitMode -Value $LimitMode
$Object | Add-Member -MemberType NoteProperty -Name LimitMaxWarning -Value $LimitMaxWarning
$Object | Add-Member -MemberType NoteProperty -Name LimitMaxerror -Value $LimitMaxerror
$Object | Add-Member -MemberType NoteProperty -Name ValueLookup -Value $ValueLookup
$Object | Add-Member -MemberType NoteProperty -Name Mode -Value $Mode
$Object | Add-Member -MemberType NoteProperty -Name Text -Value $Text
$Object | Add-Member -MemberType NoteProperty -Name Warning -Value $Warning
$Object | Add-Member -MemberType NoteProperty -Name Error -Value $Error
$PRTGXML = ConvertTo-PRTGXML -Result $Object
Return $PRTGXML
}
Function ConvertTo-PRTGXML {
param(
$Result
)
$ResultNotNullProperties = ($Result.psobject.properties | ? {![string]::IsNullOrEmpty($_.value)}).Name
$FilteredResult = $Result | Select-Object $ResultNotNullProperties
$ToReturn = "<result>`n"
Foreach ($Property in $FilteredResult.psobject.Properties) {
$PropertyName = $Property.Name
$PropertyValue = $Property.Value
$String = "`t<$PropertyName>$PropertyValue</$PropertyName>`n"
$ToReturn += $string
}
$ToReturn += "</result>`n"
return $ToReturn
}
$Groups = $TestResults | Group Source
Foreach($Group in $Groups) {
$IdentificationToken = "$($Group.Name.ToLower())-adhealthcheck"
$Results = $Group.Group
$ValueLookup = "prtg.standardlookups.exchangedag.yesno.stateyesok"
$ResultXml = ""
Foreach($Result in $Results) {
if($Result.Pass){
$Pass = 1
}
else {
$Pass = 0
}
$ResultXml += New-PRTGResult -Channel $Result.TestName -Value $Pass -ValueLookup $ValueLookup -Text $Result.Message
}
$Output = "<prtg>"
$Output += $ResultXml
$Output += "</prtg>"
$Output = $Output -replace "[`n`t]",""
Invoke-RestMethod -Uri ($PRTGUrl + $IdentificationToken + "?content=$output") -Method Get
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment