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


What is my powershell parameters

Votes:

0

Your Vote:

Up

Down

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 by  Ortadoğu Grup (0) 1

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



Best Answer

Accepted Answer

Votes:

0

Your Vote:

Up

Down

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

Your Vote:

Up

Down

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 by  ages (977) 5 1



Votes:

0

Your Vote:

Up

Down

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 by  Ortadoğu Grup (0) 1

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



Accepted Answer

Votes:

0

Your Vote:

Up

Down

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

Your Vote:

Up

Down

Thank you Stephan. It's perfectly work :)

Created on Feb 11, 2015 8:43:04 AM by  Ortadoğu Grup (0) 1



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.