This article applies to PRTG Network Monitor 16 or later
Monitoring TXT Records on Your DNS with PRTG
Update: As of PRTG 20.2.59, you can use the native DNS v2 sensor to monitor TXT records.
If you need to monitor your Domain Name Service (DNS) server, PRTG offers you a built-in DNS Sensor. It is compatible with the following record types:
- Host address IPv4 (A)
- Host address IPv6 (AAAA)
- Authoritative name server (NS)
- Start of a zone of authority marker (SOA)
- Domain name pointer (PTR)
- Mail exchange (MX)
- Canonical name for an alias (CNAME)
Currently, the DNS Sensor cannot natively query TXT DNS records. However, you can use an EXE/Script Advanced Sensor and an appropriate PowerShell script to monitor your TXT records. Just read on to see how this works.
Custom PowerShell Script for DNS Records in TXT Format
PRTG offers an API also for custom sensors. This means that you can write your own sensors and use them within PRTG. Consider, for instance, the following PowerShell script that polls and evaluates TXT DNS records:
# Monitor the content of TXT DNS records in PRTG v0.2 15/11/2016
#
# Parameters in PRTG must be: "*Text to match*"(wildcard allowed), Domain and DNS Server. Example:
# -text '*spf*' -domain 'google.com' -server '8.8.8.8'
# -text '*include*_spf.google.com*' -domain 'google.com' -server '8.8.4.4'
#
# It's recommended to use large scanning intervals for exe/xml scripts (not below 300 seconds).
# Warning: When there are multiple matches only the first record will be matched. Plan accordingly.
param(
[string]$text = "*spf*",
[string]$domain = "google.com",
[string]$server = "8.8.8.8"
)
$exectime = [System.Diagnostics.Stopwatch]::StartNew()
try {
$txtrecords = Resolve-DnsName -Name $domain -Type 'TXT' -Server $server -ErrorAction Stop
}catch{
Write-Output "<prtg>"
Write-Output "<error>1</error>"
Write-Output "<text>DNS Query Failed: $($_.Exception.Message)</text>"
Write-Output "</prtg>"
Exit
}
foreach($entry in $txtrecords){
if ($entry.Strings.ToLower() -like $text.ToLower() ){
$result = 1 #Yes
$content = "Match: "+$entry.Strings.ToLower()
break
}else{
$result = 2 #No
$content = "No Match for: "+$text.ToLower()
}
}
Write-Output "<prtg>"
Write-Output "<result>"
Write-Output "<channel>Record Matched</channel>"
Write-Output "<value>$($result)</value>"
Write-Output "<valuelookup>prtg.standardlookups.yesno.stateyesok</valuelookup>"
Write-Output "</result>"
Write-Output "<result>"
Write-Output "<channel>ExecTime</channel>"
Write-Output "<value>$($exectime.ElapsedMilliseconds)</value>"
Write-Output "<CustomUnit>msecs</CustomUnit>"
Write-Output "</result>"
Write-Output "<text>$($content)</text>"
Write-Output "</prtg>"
How to Use This TXT Records PowerShell Script
The above script essentially uses the provided parameters (text, domain and server) to perform a query for all TXT records on the given DNS address. The found records will then be checked against the provided text, thus allowing you to confirm the existence and content of TXT records used for SPF or domain verification.
Note: The script supports wildcards for the evaluation of text.
Note: If you have multiple TXT records, up to 25 of them will all be evaluated. But once there is a match, regarding the text parameter,only this first match will be evaluated, although multiple matches might be possible. Please take this into account and plan accordingly.
How to Setup Your TXT DNS Records Sensor
- If you want to use the above PowerShell script, you can either copy the script text above, paste it into a new file and create a .ps1 file from it, or you can just download it here.
- Copy your .ps1 file or the downloaded PS Query TXT Recordv2.ps1 file to the %Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML\ folder. See the Paessler Knowledge Base if you want to know more about How and Where PRTG stores its data.
- In your PRTG installation, go to your device and add a new EXE/Script Advanced Sensor.
- In the sensor settings, enter valid Parameters, for example, -text 'v=spf1 include:_spf.google.com all' -domain 'google.com' -server '8.8.4.4'. You may use Placeholders. For the text parameter, use * for wildcard match, for example '*spf*1.2.3.4*'.
Click here to enlarge.
You're done! This is how your sensor looks like:
Click here to enlarge.
Note: Please note that we cannot provide in-depth technical support for custom scripts. Scripts are provided without warranty and for use at own risk.
More
Add comment