New Question
 
 
PRTG Network Monitor

Intuitive to Use.
Easy to manage.

200.000 administrators have chosen PRTG to monitor their network. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free PRTG
Download >>

 

What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general. You are invited to get involved by asking and answering questions!

Learn more

 

Top Tags


View all Tags


Java Version

Votes:

0

Your Vote:

Up

Down

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 by  omcomputer (70) 2 1



Best Answer

Accepted Answer

Votes:

1

Your Vote:

Up

Down

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 by  omcomputer (70) 2 1

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



7 Replies

Votes:

0

Your Vote:

Up

Down

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]



Votes:

1

Your Vote:

Up

Down

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 by  omcomputer (70) 2 1



Votes:

0

Your Vote:

Up

Down

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]



Votes:

0

Your Vote:

Up

Down

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 by  omcomputer (70) 2 1



Votes:

0

Your Vote:

Up

Down

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]



Accepted Answer

Votes:

1

Your Vote:

Up

Down

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 by  omcomputer (70) 2 1

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



Votes:

0

Your Vote:

Up

Down

Thanks for your contribution!!

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



Please log in or register to enter your reply.


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.