PrtgAPI icon indicating copy to clipboard operation
PrtgAPI copied to clipboard

Error when I try to add a sensor

Open BragaGuilherme opened this issue 2 years ago • 11 comments

What's going on?

Hello Lord Milko, how are you?

I was trying to run this command:

$table = @{ "name_" = "PCT_CROMATOGRAFIA_NITROGENIO"; "pythonscript_" = "Modbus Python.py";"params_" ="registro=17231,nome=PCT_CROMATOGRAFIA_NITROGENIO,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

  • ... w-SensorParameters $table; Get-Device -Id 39273 | Add-sensor $params;
  •                                                   ~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : NotSpecified: (:) [Add-Sensor], HttpRequestException
    • FullyQualifiedErrorId : System.Net.Http.HttpRequestException,PrtgAPI.PowerShell.Cmdlets.AddSensor

Can you help me with this?

Captura de tela 2023-11-06 155200

Due Dilligance

  • [X] It wasn't covered by the wiki, I swear!
  • [X] I have tried doing some basic research on this issue but haven't been able to come up with anything. Please help!

BragaGuilherme avatar Nov 06 '23 18:11 BragaGuilherme

Please provide the output of Get-PrtgClient -Diagnostic

lordmilko avatar Nov 07 '23 03:11 lordmilko

Here lord, image

BragaGuilherme avatar Nov 07 '23 15:11 BragaGuilherme

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.

BragaGuilherme avatar Nov 07 '23 17:11 BragaGuilherme

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"

xasz avatar Nov 09 '23 09:11 xasz

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?

BragaGuilherme avatar Nov 13 '23 21:11 BragaGuilherme

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

xasz avatar Nov 13 '23 21:11 xasz

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

nickhoksbergen avatar Nov 14 '23 11:11 nickhoksbergen

Your prtgapi Version ist Not Up2date.

xasz avatar Nov 14 '23 12:11 xasz

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.

BragaGuilherme avatar Nov 14 '23 12:11 BragaGuilherme

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.

xasz avatar Nov 14 '23 12:11 xasz

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

lordmilko avatar Nov 16 '23 09:11 lordmilko