Hi,

Ok, I've created .bat file:

@echo off
for /F "tokens=2" %%a in ('nslookup bbc.co.uk 8.8.8.8') do (
  set value=%%a 
)
echo 0:%value%

This is stored on the PRTG server.

I've then created an EXE/Script sensor using the .bat. It works perfectly and shows the correct IP of bbc.co.uk

What I want to do is use the Parameters field on the PRTG sensor so I can use this multiple times for many DNS entries / URLs.

What should I use in the sensor and how should the .bat be amended to add a variable in to be passed by the sensor?

Thanks

Chris


Article Comments

Please stop using batch, you're only making your life harder :) Do yourself a favor and use PowerShell:

# the parameters of the script
param([string[]]$hosts = @("www.google.de","bbc.co.uk"), $DNS = "8.8.8.8")

# create a new list object where the hosts are added 
$list = New-Object System.Collections.ArrayList($null)

# Foreach Domain in the $hosts array...
Foreach($Domain in $hosts){

    # Resolve the DNS name using the given DNS server. Only select the A records
    $Results = (Resolve-DnsName -Server $DNS -NoHostsFile $Domain | Select Name,IPAddress,Type | Where {$_.Type -eq "A"})
    
    # Now add every result to the lists. Since one domain can have multiple A-records or IPs, we need to split this. 
    foreach($Result in $Results)
    { $list.add("[$($Result.Name) - $($Result.IPAddress)]") | Out-Null; }
}

# Output it to PRTG. Example output: 
# 0:[www.google.de - 172.217.21.195] [bbc.co.uk - 212.58.244.22] [bbc.co.uk - 212.58.244.23] [bbc.co.uk - 212.58.246.79] [bbc.co.uk - 212.58.246.78]
Write-Host "0:$($list -join " ")";

A quick introduction to PowerShell Sensors in PRTG can be found here.


Sep, 2016 - Permalink

Haha. I agree. I found that batch file code from a previous KB on here, but it didn't pass parameters.

All sorted with the PS script

Many thanks

C


Sep, 2016 - Permalink