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

Java Version

Votes:

0

I'd like to check the installed Java Version on different Windows Server. There is a simple way to do it in a batch file:

java -version

To be able to use the output in PRTG I have a .bat file with the following content:

for /f "tokens=3" %%g in ('java -version 2^>^&1 ^| findstr /i "version"') do ( set JAVAVER=%%g ) set JAVAVER=%JAVAVER:"=% set JAVAVER=%JAVAVER:_=% set JAVAVER=%JAVAVER:.=% echo %JAVAVER%:%JAVAVER%

This works fine for me on local or remote probes. How can I use the .bat file on other Servers where no probe is installed?

I had no success with PsExec. WMI doesn't work for us as well, as we installed Java through Server JRE.

batch java version

Created on Oct 23, 2017 1:59:27 PM



Best Answer

Accepted Answer

Votes:

1

finally I've got the solution, to extract the Java version with PowerShell on a remote machine:

#Get PRTG Sensor Parameter '%device'
param(
    [string]$device = "N/A"
    )

#Scriptblock
$javaversion = {

#Gets output from "java -version" and filters to just one line
#containing version information
function getJavaVersionOutput(){
	$ret = java -version 2>&1 | Select-String "version"
	return $ret
}

#Removes any non-digit character in the argument given as
# "$str", and returns the new string with only digits
function filterDigits([string] $str){
    return (($str) -Replace '\D', '')
}

#get filtered java version output
$version = getJavaVersionOutput

#filter digits from the variable, only digits will remain in it
$version = filterDigits $version

#output for prtg monitor
Write-Host ${version}:"OK"

}

#Run Scriptblock
Invoke-Command -ComputerName $device -ScriptBlock $javaversion

Works only with Parameter '%device' in the Sensor settings and enough rights on the PRTG Probe Service to run PowerShell scripts on the remote machine.

On Windows 10 Clients I had to start the service "Windows-Remoteverwaltung" WinRM automatically and the Windows Firewall inbound rule "Windows-Remoteverwaltung (HTTP eingehend)" for the Domain through GPO.

Created on Dec 6, 2017 8:32:32 AM

Last change on Dec 7, 2017 6:09:28 AM by  Luciano Lingnau [Paessler]



7 Replies

Votes:

0

Hi!

You are looking for our Custom/EXE Script Sensor.

https://www.paessler.com/manuals/prtg/exe_script_sensor

This will allow you to run this batch file you've created on any target host with any credentials you need to use for said host.

If you're looking to get notified of a change to the version, you can put a Change Trigger on the sensor, and get alerted anytime the result returned is different than it was in the previous check.

Thanks!

Created on Oct 24, 2017 8:28:51 AM by  Benjamin Day [Paessler Support] (1,441) 2 1



Votes:

1

Hi Benjamin

Thank you for your answer. I already tried the Custom / EXE Script Sensor. As I've seen, the batch file is only working on systems where a probe is installed.

My Scenario:

Server A: where PRTG is installed but no Java Server B: in the same domain, no probe is installed but Java

In PRTG I add a Custom / EXE Script Sensor on the Device "Server B" with the batch mentioned. As output I get "= . This is the case when no Java is installed. It seems that I get the answer for Server A instead of B.

Created on Oct 24, 2017 11:28:56 AM



Votes:

0

Ahhh, I forgot to mention. You will need to modify your code to accept a parameter. The parameter should be the host name of the device, and in the sensor settings there should be a field for 'Parameters'. Put in '%hostname', and it will send the target host name to the script. Then the script should remotely execute on the target host.

Thanks!

Created on Oct 24, 2017 12:21:01 PM by  Benjamin Day [Paessler Support] (1,441) 2 1



Votes:

0

Thank you. In the meantime I have a PowerShell script to extract the Java version on a remote machine. I tried to implement the following script to a custom sensor in PRTG:

Enter-PSSession %hostname

#Gets output from "java -version" and filters to just one line
#containing version information
function getJavaVersionOutput(){
	$ret = java -version 2>&1 | Select-String "version"
	return $ret
}

#Removes any non-digit character in the argument given as
# "$str", and returns the new string with only digits
function filterDigits([string] $str){
    return (($str) -Replace '\D', '')
}

#get filtered java version output
$version = getJavaVersionOutput

#filter digits from the variable, only digits will remain in it
$version = filterDigits $version

#output for prtg monitor
Write-Host $version":OK"

In PRTG the sensor with this script is up and I get the message "OK". But the version in the primary channel is "0". This should be "180151" as example.

Do you have an idea what's wrong in my script?

Created on Dec 5, 2017 7:54:56 AM



Votes:

0

We can't handle a String as a channel value. Can you return it as an integer or float?

Created on Dec 5, 2017 11:45:09 PM by  Benjamin Day [Paessler Support] (1,441) 2 1



Accepted Answer

Votes:

1

finally I've got the solution, to extract the Java version with PowerShell on a remote machine:

#Get PRTG Sensor Parameter '%device'
param(
    [string]$device = "N/A"
    )

#Scriptblock
$javaversion = {

#Gets output from "java -version" and filters to just one line
#containing version information
function getJavaVersionOutput(){
	$ret = java -version 2>&1 | Select-String "version"
	return $ret
}

#Removes any non-digit character in the argument given as
# "$str", and returns the new string with only digits
function filterDigits([string] $str){
    return (($str) -Replace '\D', '')
}

#get filtered java version output
$version = getJavaVersionOutput

#filter digits from the variable, only digits will remain in it
$version = filterDigits $version

#output for prtg monitor
Write-Host ${version}:"OK"

}

#Run Scriptblock
Invoke-Command -ComputerName $device -ScriptBlock $javaversion

Works only with Parameter '%device' in the Sensor settings and enough rights on the PRTG Probe Service to run PowerShell scripts on the remote machine.

On Windows 10 Clients I had to start the service "Windows-Remoteverwaltung" WinRM automatically and the Windows Firewall inbound rule "Windows-Remoteverwaltung (HTTP eingehend)" for the Domain through GPO.

Created on Dec 6, 2017 8:32:32 AM

Last change on Dec 7, 2017 6:09:28 AM by  Luciano Lingnau [Paessler]



Votes:

0

Thanks for your contribution!!

Created on Dec 7, 2017 2:00:14 AM by  Benjamin Day [Paessler Support] (1,441) 2 1




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.