Hey,
APRIL 2018 – VERSION 18.2.39 Note: The fix required changes to the handling of command line parameters. In certain cases, it will be necessary to adapt quoting with backticks (``) in the parameters field because PRTG will process quotes more accurately. Please use single or double quotes to escape special characters and whitespaces in the parameters fields.
Any Idea how to reformat the below
-Commands "text1","text2","cat /proc/analog/value4" -RemoteHost "172.20.1.188"
Problem seem to be that I cant escape the SPACE between the multiple quote sets
Thanks,
Article Comments
Not sure what the best answer to that is
they are separate values, used one after another as they are piped to a telnet device, however when i wrote the script it was easier to write it as above
do you have an example of passing a array to powershell? and parsing ?
Thanks,
Apr, 2018 - Permalink
Hi there,
It would be interesting to see what happens within the script. Is the actual variable ""text1","text2","cat /proc/analog/value4""?
In the meantime please try the following:
-Commands '"text1","text2","cat /proc/analog/value4"' -RemoteHost "172.20.1.188" |
Does that work?
Best regards.
Apr, 2018 - Permalink
I will test now however script is below
purpose is to retrieve a value from a linux device via telnet
I know password and username in a script are bad practice but leaving as is
- Example
- -RemoteHost "192.168.0.55" -Commands "username","password","cat /proc/analog/value1"
Param ( [Parameter(ValueFromPipeline=$true)] [String[]]$Commands = @("username","password","disable clipaging","sh config"), [string]$RemoteHost = "HostnameOrIPAddress", [string]$Port = "23", [int]$WaitTime = 1200 ) #Attach to the remote device, setup streaming requirements $Socket = New-Object System.Net.Sockets.TcpClient($RemoteHost, $Port) If ($Socket) { $Stream = $Socket.GetStream() $Writer = New-Object System.IO.StreamWriter($Stream) $Buffer = New-Object System.Byte[] 1024 $Encoding = New-Object System.Text.AsciiEncoding #wait for session to stablize Start-Sleep -Milliseconds $WaitTime #Now start issuing the commands ForEach ($Command in $Commands) { $Writer.WriteLine($Command) $Writer.Flush() Start-Sleep -Milliseconds $WaitTime } #All commands issued, but since the last command is usually going to be #the longest let's wait a little longer for it to finish Start-Sleep -Milliseconds ($WaitTime * 4) $Result = "" #Save all the results While($Stream.DataAvailable) { $Read = $Stream.Read($Buffer, 0, 1024) $Result += ($Encoding.GetString($Buffer, 0, $Read)) } } Else { $Result = "Unable to connect to host: $($RemoteHost):$Port" } $next = 0 foreach ($line in $Result.Split("`n") ){ if ($next -eq 1){ $final= [double]$line $far = ($final * 1.8)+32 $x=[string]$far+":The Current Value is "+$far+" thanks." write-host $x exit 0 } if ($line.Contains("# cat /proc/")){ $next = 1 } } exit 0
Apr, 2018 - Permalink
Nope
External EXE/Script did not return a response (code: PE087)
what i suspect is happening is that the unix box is running
cat without the value that is meant to be returned
FYI
I have tried ' " \
and various combinations unsuccessfully before reaching out
Thanks,
Apr, 2018 - Permalink
Hi there,
I am able to output the data properly that is transmitted as a parameter. Parameters within PRTG:
-Commands '"text1","text2","cat /proc/analog/value4"' |
Test-Script:
param( [String[]]$Commands = @("username","password","disable clipaging","sh config") ) Write-Host @" <PRTG> <result> <channel>Test</channel> <value>1234</value> </result> <text> $($Commands) </text> </PRTG> "@
The sensor will then output the following in the message:
"text1","text2","cat /proc/analog/value4" |
Therefore I suspect that something is wrong with the script itself or that some kind of issue happens within the script. Please activate the "Write EXE result to disk" option in the sensor's settings and post the log files (Result of Sensor XXX.Data.txt and Result of Sensor XXX.txt) located on the corresponding probe under "C:\ProgramData\Paessler\PRTG Network Monitor\Logs (Sensors)".
Best regards.
Apr, 2018 - Permalink
FYI
Test Script
Write-Host $Commands[0] #exit 0
Test Input
.\TelnetMFIcatvalue.ps1 -Commands '\"ubnt\",\"ubnt\",\"cat /proc/analog/value4\"' -RemoteHost 172.20.1.188 Result \"ubnt\",\"ubnt\",\"cat /proc/analog/value4\"
Expected Result single first variable - ubnt
Apr, 2018 - Permalink
Hi there,
I think I got it. Can you try the following instead:
'text1','text2','cat /proc/analog/value4' |
So basically I switched all double-quotes with single-quotes and the test script only outputs "text1".
Best regards.
Apr, 2018 - Permalink
it seems to confuse which parameter is which here
Data['environment'].asString := ''; Data['exefile'].asString := 'TelnetMFIcatvalue.ps1'; Data['exeparams'].asString := '-Commands 'ubnt','ubnt','cat /proc/analog/value4' -RemoteHost '172.20.1.188''; Data['exeparamscache'].asString := '-Commands 'ubnt'`,'ubnt'`,'cat /proc/analog/value4' -RemoteHost '172.20.1.188''; Data['exeparamshash'].asString := '0be9715e67aeaae989eb16e4205b2d88b92792c9'; Data['fastcount'].asString := '0'; Data['host'].asString := '172.20.0.23'; Data['hostv6'].asString := ''; Data['inerror'].asString := '1'; Data['interfacenumber'].asString := ''; Data['inum'].asString := ''; Data['ipversion'].asString := '0'; Data['isexesensor'].asString := '1'; Data['lastmsg'].asString := '#O132 (New-Object : Cannot convert argument "1", with value: ",ubnt,cat /proc/analog/value4", for "TcpClient" to type "System.Int32": "Cannot convert value ",ubnt,cat /proc/analog/value4" to type "System.Int32". Error: "Input string was not in a correct format."" At C:\Program Files (x86)\PRTG Network Monitor\custom sensors\EXE\TelnetMFIcatvalue.ps1:22 char:15 + ... $Socket = New-Object System.Net.Sockets.TcpClient($RemoteHost, $Por ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [New-Object], MethodExcept ion + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.Power Shell.Commands.NewObjectCommand )'; Data['lastuptime'].asString := '0';
Apr, 2018 - Permalink
Hi there,
I can't reproduce this, the parameters are correctly transmitted to the script. Parameters within PRTG:
-Commands 'ubnt','ubnt','cat /proc/analog/value4' -RemoteHost '172.20.1.188' |
PowerShell Test Script:
param( [String[]]$Commands = @("username","password","disable clipaging","sh config"), $RemoteHost = "" ) Write-Host @" <PRTG> <result> <channel>Test</channel> <value>1234</value> </result> <text> $($Commands[0]) - $($RemoteHost) </text> </PRTG> "@
Can you output the variable "Commands" and "RemoteHost" in the script that is executed by PRTG to see what values they hold?
Best regards.
Apr, 2018 - Permalink
sure see below
seperately are you running the same PRTG verison as this issues only started when i did the latest update
Thanks,
script ======================= #Example #-RemoteHost "192.168.0.55" -Commands "username","password","cat /proc/analog/value1" Param ( [Parameter(ValueFromPipeline=$true)] [String[]]$Commands = @("username","password","disable clipaging","sh config"), [string]$RemoteHost = "HostnameOrIPAddress", [string]$Port = "23", [int]$WaitTime = 1200 ) #Write-Host $Commands[1] Write-Host $Commands Write-Host $RemoteHost #exit 0
log =================================
Data['exefile'].asString := 'TelnetMFIcatvalue.ps1'; Data['exeparams'].asString := '-Commands 'ubnt','ubnt','cat /proc/analog/value4' -RemoteHost '172.20.1.188''; Data['exeparamscache'].asString := '-Commands 'ubnt'`,'ubnt'`,'cat /proc/analog/value4' -RemoteHost '172.20.1.188''; Data['exeparamshash'].asString := '0be9715e67aeaae989eb16e4205b2d88b92792c9'; Data['fastcount'].asString := '0'; Data['host'].asString := '172.20.0.23'; Data['hostv6'].asString := ''; Data['inerror'].asString := '1'; Data['interfacenumber'].asString := ''; Data['inum'].asString := ''; Data['ipversion'].asString := '0'; Data['isexesensor'].asString := '1'; Data['lastmsg'].asString := '#O132 (ubnt 172.20.1.188 New-Object : Cannot convert argument "1", with value: ",ubnt,cat /proc/analog/value4", for "TcpClient" to type "System.Int32": "Cannot convert value ",ubnt,cat /proc/analog/value4" to type "System.Int32". Error: "Input string was not in a correct format."" At C:\Program Files (x86)\PRTG Network Monitor\custom sensors\EXE\TelnetMFIcatvalue.ps1:23 char:15 + ... $Socket = New-Object System.Net.Sockets.TcpClient($RemoteHost, $Por ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [New-Object], MethodExcept ion + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.Power Shell.Commands.NewObjectCommand )'; Data['lastuptime'].asString := '0';
Apr, 2018 - Permalink
Hi there,
The log does not seem to have changed. However you should see the result after one scan in the other log file as the Data File only shows the used options.
Yes I am also using the same version I am aware of that change. :)
Best regards.
Apr, 2018 - Permalink
Thanks had to check :)
ubnt
172.20.1.188
New-Object : Cannot convert argument "1", with value: ",ubnt,cat
/proc/analog/value4", for "TcpClient" to type "System.Int32": "Cannot convert
value ",ubnt,cat /proc/analog/value4" to type "System.Int32". Error: "Input
string was not in a correct format.""
At C:\Program Files (x86)\PRTG Network Monitor\custom
sensors\EXE\TelnetMFIcatvalue.ps1:23 char:15
+ ... $Socket = New-Object System.Net.Sockets.TcpClient($RemoteHost, $Por ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [New-Object], MethodExcept
ion
+ FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.Power
Shell.Commands.NewObjectCommand
Apr, 2018 - Permalink
Hi there,
I am afraid that we run in circles. :(
Please contact us, with referring to this thread, under "support@paessler.com". Please forward us the used Script file, both log files and screenshots of the sensor settings so we can check this further.
Best regards.
Apr, 2018 - Permalink
Hi Timo,
Due to the recent update and security additions to the parameter exchange, it is no longer possible to fill arrays via the parameters. This means that each value needs its own parameter. Before:
-parameter "Value1","Value2" |
Now:
-value1 "Value1" -value2 "Value2" |
Another possibility is to use "Split" within the script to split the parameter:
-parameter "Value1,Value2,Value3" |
In the script it then will look like this:
$parameter.split(",") |
Best regards.
Apr, 2018 - Permalink
Hi there,
Should the following be an array or is this entire string one command?
Please note that this is not the correct way to save values into an array within PowerShell.
Best regards.
Apr, 2018 - Permalink