lordmilko / PrtgAPI

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

Error when I try to add a sensor #365

Open BragaGuilherme opened 10 months ago

BragaGuilherme commented 10 months ago

What's going on?

Hello Lord Milko, how are you?

I was trying to run this command:

$table = @{ "name_" = "PCT_CROMATOGRAFIANITROGENIO"; "pythonscript" = "Modbus Python.py";"params_" ="registro=17231,nome=PCT_CROMATOGRAFIANITROGENIO,tipo=32float";"sensortype" = "pythonscript";"comments"="teste"};$params = New-SensorParameters $table; Get-Device -Id 39273 | Add-sensor $params;

It was working fine earlier, but now it keeps giving me this error:

Add-sensor : Could not authenticate to PRTG; the specified username and password were invalid. No linha:1 caractere:280

Can you help me with this?

Captura de tela 2023-11-06 155200

Due Dilligance

lordmilko commented 10 months ago

Please provide the output of Get-PrtgClient -Diagnostic

BragaGuilherme commented 10 months ago

Here lord,

image
BragaGuilherme commented 10 months ago

I have another question: how can I create sensors that remain paused? The situation is that there are sensors that are not needed at the moment, but I would like to have them created but in a paused state. Is there a way to achieve this? Would it involve using the Pause-Object/Suspend-Object cmdlets? If so, could you provide an example? I tried using these cmdlets, but I wasn't successful.

xasz commented 10 months ago

What Sensor are you trying to add ? I have never added a phytonscript sensor, but i think here are some basic problems. At least on my instance the New-SensorParameters Cmdlet have not -Type phytonscript

Furthermore if you want to build hashmap for the parameters, which i see no point in that szenario, you need to use @ like New-SensorParameters @table

@BragaGuilherme This should be possible with basic powershell piping:

Get-Device -Id 148376 | Get-Sensor -Name Ping | Pause-Object -Forever -Message "You are not needed"
BragaGuilherme commented 10 months ago

Here lord, image

This issue has reappeared. What could I do to work around it?

One point, the address of this PRTG has a certificate error, and I have to use -IgnoreSSL when logging in. Could this interfere?

xasz commented 10 months ago

What issue? You should add sime information... ?

nickhoksbergen commented 10 months ago

I have the same issue when adding sensors with either the New-Sensor or Add-Sensor cmdlets.

This is the code I run:

$device = $newgroup | get-device | select -first 1 $device | new-sensor -ExeFile "NonDefaultServicesV2.ps1" -Name "Non Default Services" -ExeXml

$params = New-SensorParameters ExeXml "Non Default Services" $params.ExeFile = "NonDefaultServicesV2.ps1" $params.ExeParameters = "-FQDN %host" $device | Add-Sensor $params

This is the result

Schermafbeelding 2023-11-14 125048

Result of 'Get-PrtgClient -Diagnostic' PSVersion : 5.1.22621.2428 PSEdition : Desktop OS : Microsoft Windows 11 Enterprise PrtgAPIVersion : 0.9.18 Culture : nl-NL CLRVersion : 533320 PrtgVersion : 23.4.88.1429 PrtgLanguage : english.lng

xasz commented 10 months ago

Your prtgapi Version ist Not Up2date.

BragaGuilherme commented 10 months ago

What issue? You should add sime information... ?

Yes, I am trying to add a PythonScript sensor, which has worked before. The issue is that when I try to execute it, accessing another PRTG that is only accessible via IP and does not have a security certificate, this happens.

xasz commented 10 months ago

Does IT Work any other Sensors. I think you should Test one oneliner on which command IT Is failing. I cannot See that from you informations posted.

lordmilko commented 10 months ago

I tested PrtgAPI 0.9.19 on PRTG 23.4.90.1299

$params = New-SensorParameters ExeXml "Non Default Services"
$params.ExeFile = "NonDefaultServicesV2.ps1"
$params.ExeParameters = "-FQDN %host"
$device | Add-Sensor $params

I was able to run this code

Are you able to update to PRTG 23.4.90.1299 and advise if you're still having the issue? I didn't test on an earlier version of PRTG

If you're still having issues are you potentially able to try a ping sensor as well?

$device | New-SensorParameters -rt ping | Add-Sensor