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")
Article Comments
Attention: This article is a record of a conversation with the Paessler support team. The information in this conversation is not updated to preserve the historical record. As a result, some of the information or recommendations in this conversation might be out of date.
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")
Feb, 2015 - Permalink
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!
Feb, 2015 - Permalink
To receive parameters from command line in your PS script, you have to declare them as parameters at the beginning of the script first.
For more information see for example https://technet.microsoft.com/en-us/magazine/jj554301.aspx
Hope I understood your question right.
Feb, 2015 - Permalink