lordmilko / PrtgAPI

C#/PowerShell interface for PRTG Network Monitor
MIT License
301 stars 37 forks source link

Tags get added with Quotes #281

Closed xasz closed 2 years ago

xasz commented 2 years ago

Describe the bug

Tags showing up in the PRTG Webinterface in Quotes.

Example: image

Steps to reproduce

$param = New-SensorParameters ExeXml
$param.ExeFile = "Get-AwesomeState.ps1"
$param.Name = $SensorName
$param.Tags += {"MyTag","A-Nother-Tag"}
$param.ExeParameters = "%host" 
$prtgDevice | Add-Sensor $param -ErrorAction SilentlyContinue

What is the output of 'Get-PrtgClient -Diagnostic'?

PSVersion      : 5.1.17763.2746
PSEdition      : Desktop
OS             : Microsoft Windows Server 2019 Standard
PrtgAPIVersion : 0.9.16
Culture        : de-DE
CLRVersion     : .NET Framework 4.7.2 (461814)
PrtgVersion    : 22.1.74.1869
PrtgLanguage   : german.lng

Additional context

I think there is a Escaping at some point, which should not happen, but i could not find it in your code.

lordmilko commented 2 years ago

Hi @xasz,

The issue is you are setting the Tags value incorrectly

$param.Tags += {"MyTag","A-Nother-Tag"}

If you do $param.Tags after doing this you will see these two tags have been interpreted by PowerShell as being a single string value with quotes and a comma in it

PS C:\> $param.Tags += {"MyTag","A-Nother-Tag"}
PS C:\> $param.Tags
xmlexesensor
"MyTag","A-Nother-Tag"

The correct way to add these two tags would be to do

$param.Tags += "MyTag","A-Nother-Tag"

Regards, lordmilko