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

What is my powershell parameters

Votes:

0

Hi, Dear.

i Have a powershell file (.ps1) i already added but i can not running on prtg because what is my parameters i dont know.

This is a PS1 file Code;

function signtest ($vkn, $port=4444, $server="SERVER_IP_ADRESS") { $client = New-Object System.Net.Sockets.TcpClient $server, $port $stream = $client.GetStream() $writer = New-Object System.IO.StreamWriter $stream $writer.AutoFlush = $TRUE $writer.WriteLine("This_is_windows_service " + $vkn)

$reader = New-Object System.IO.StreamReader $stream $line = $reader.ReadLine()

If($line.equals("OK")){ write-host $line -fore cyan } Else { write-host $line -fore red }

$reader.Dispose() $writer.Dispose() $stream.Dispose() }

signtest("our_code_is_here")

custom-script-exe custom-sensor parameters powershell

Created on Feb 10, 2015 9:49:59 AM

Last change on Mar 19, 2015 3:47:07 PM by  Martina Wittmann [Paessler Support]



Best Answer

Accepted Answer

Votes:

0

Should work like this:

param(
       $vkn,
       $port=4444,
       $server="192.168.1.5"
)

function signtest(){
    $client = New-Object System.Net.Sockets.TcpClient $server, $port
    $stream = $client.GetStream()
    $writer = New-Object System.IO.StreamWriter $stream
    $writer.AutoFlush = $TRUE
    $writer.WriteLine("Efat SIGNTEST " + $vkn)

    $reader = New-Object System.IO.StreamReader $stream
    $line = $reader.ReadLine()

    $reader.Dispose()
    $writer.Dispose()
    $stream.Dispose()

    If($line.equals("OK")){
     write-host "0:$($line)" -foregroundcolor cyan; exit 0; }
    Else {
     write-host "0:$($line)" -foregroundcolor red; exit 2; }
}

signtest;

Parameter field for the sensor has to look like this: -VKN "your vkn variable" -Port "1234" -Server "192.168.1.5"

Note that I've added the proper exit codes to the script, otherwise PRTG wouldn't know what result has to be considered ok or error :) If it doesn't work, please provide a sample output of the script. Thanks!

Created on Feb 10, 2015 8:35:01 PM by  Stephan Linke [Paessler Support]

Last change on Nov 13, 2018 4:06:30 PM by  Birk Guttmann [Paessler Support]



4 Replies

Votes:

0

To receive parameters from command line in your PS script, you have to declare them as parameters at the beginning of the script first.

param (
  $vkn,
  $port=4444,
  $server="SERVER_IP_ADDRESS"
)

For more information see for example https://technet.microsoft.com/en-us/magazine/jj554301.aspx

Hope I understood your question right.

Created on Feb 10, 2015 12:32:09 PM



Votes:

0

Everyting is true its working correctly. Just i need PARAMETERS on PRTG (sensor settings) What is my parameters ?

This is our code;

function signtest ($vkn, $port=4444, $server="192.168.1.5") {
    $client = New-Object System.Net.Sockets.TcpClient $server, $port
    $stream = $client.GetStream()
    $writer = New-Object System.IO.StreamWriter $stream
    $writer.AutoFlush = $TRUE
    $writer.WriteLine("Efat SIGNTEST " + $vkn)

    $reader = New-Object System.IO.StreamReader $stream
    $line = $reader.ReadLine()

    If($line.equals("OK")){
     write-host $line -fore cyan }
    Else {
write-host $line -fore red }

    $reader.Dispose()
    $writer.Dispose()
    $stream.Dispose()
}

signtest("XXXXXXXX")

Created on Feb 10, 2015 12:52:01 PM

Last change on Feb 10, 2015 1:04:35 PM by  Torsten Lindner [Paessler Support]



Accepted Answer

Votes:

0

Should work like this:

param(
       $vkn,
       $port=4444,
       $server="192.168.1.5"
)

function signtest(){
    $client = New-Object System.Net.Sockets.TcpClient $server, $port
    $stream = $client.GetStream()
    $writer = New-Object System.IO.StreamWriter $stream
    $writer.AutoFlush = $TRUE
    $writer.WriteLine("Efat SIGNTEST " + $vkn)

    $reader = New-Object System.IO.StreamReader $stream
    $line = $reader.ReadLine()

    $reader.Dispose()
    $writer.Dispose()
    $stream.Dispose()

    If($line.equals("OK")){
     write-host "0:$($line)" -foregroundcolor cyan; exit 0; }
    Else {
     write-host "0:$($line)" -foregroundcolor red; exit 2; }
}

signtest;

Parameter field for the sensor has to look like this: -VKN "your vkn variable" -Port "1234" -Server "192.168.1.5"

Note that I've added the proper exit codes to the script, otherwise PRTG wouldn't know what result has to be considered ok or error :) If it doesn't work, please provide a sample output of the script. Thanks!

Created on Feb 10, 2015 8:35:01 PM by  Stephan Linke [Paessler Support]

Last change on Nov 13, 2018 4:06:30 PM by  Birk Guttmann [Paessler Support]



Votes:

0

Thank you Stephan. It's perfectly work :)

Created on Feb 11, 2015 8:43:04 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.