What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

nslookup Pass Parameter from EXE Sensor to .bat file

Votes:

0

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

batch custom-script-exe prtg

Created on Sep 22, 2016 1:17:07 PM

Last change on Sep 23, 2016 10:26:24 AM by  Stephan Linke [Paessler Support]



2 Replies

Votes:

0

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.

Created on Sep 23, 2016 10:49:02 AM by  Stephan Linke [Paessler Support]



Votes:

0

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

Created on Sep 23, 2016 11:19:46 AM




Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.