Skip to content

Instantly share code, notes, and snippets.

@waddles
Created June 24, 2020 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waddles/103cd5ab6c727f73b71add04e8181c87 to your computer and use it in GitHub Desktop.
Save waddles/103cd5ab6c727f73b71add04e8181c87 to your computer and use it in GitHub Desktop.
PRTG EXE/XML Sensor for monitoring BIND nameserver statistics
[cmdletbinding()]
Param(
[ValidateNotNull()] [string]$NameServer
)
$curStats = New-Object System.Xml.XmlDocument
$curStats.Load( $("http://"+$NameServer+"/xml/v3/server") )
$output = "<prtg>`n"
$output += "`t<text>Config reloaded at " + $curStats.SelectSingleNode("/statistics/server/config-time").'#text' + "</text>`n"
# Incoming Requests by OpCode
$nodes = $curStats.SelectNodes("/statistics/server/counters[@type='opcode']/counter") | Where-Object {$_.name -notlike 'RESERVED*'}
foreach ($node in $nodes) {
$output += "`t<result>`n"
$output += "`t`t<channel>OpCode_$($node.name)</channel>`n"
$output += "`t`t<value>$($node.'#text')</value>`n"
$output += "`t`t<mode>difference</mode>`n"
$output += "`t</result>`n"
}
# Incoming Queries by Query Type
$nodes = $curStats.SelectNodes("/statistics/server/counters[@type='qtype']/counter")
foreach ($node in $nodes) {
$output += "`t<result>`n"
$output += "`t`t<channel>QType_$($node.name)</channel>`n"
$output += "`t`t<value>$($node.'#text')</value>`n"
$output += "`t`t<mode>difference</mode>`n"
$output += "`t</result>`n"
}
# Internal View Statistics
$nodes = $curStats.SelectNodes("/statistics/views/view[@name='internal']/counters[@type='cachestats']/counter")
foreach ($node in $nodes) {
$output += "`t<result>`n"
$output += "`t`t<channel>Cache_$($node.name)</channel>`n"
$output += "`t`t<value>$($node.'#text')</value>`n"
if ($node.name -like "*Hits" -or $node.name -like "*Misses") {
$output += "`t`t<mode>difference</mode>`n"
}
if ($node.name -like "*Mem*") {
$output += "`t`t<customunit>Bytes</customunit>`n"
}
$output += "`t</result>`n"
}
$output += '</prtg>'
# Output XML
$output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment