lordmilko / PrtgAPI

C#/PowerShell interface for PRTG Network Monitor
MIT License
305 stars 38 forks source link

Help identifying property values returned by New-SensorParameters #378

Closed markgu-coast closed 10 months ago

markgu-coast commented 10 months ago

What's going on?

I'm creating a new sensor using the following method:

$params = Get-Device "Device" | New-SensorParameters -RawType paessler.rest.rest_custom_v2_sensor

Get-Device "Device" | Add-Sensor $params

Before I actually create the device, I update the mandatory parameters using:

$params.<Property> = "value"

This works as expected. However, the sensor is not created correctly. This is I believe because I am not correctly defining the following property:

$params.paessler-rest-channel_section-channel_group-channel1_type

This property is populated with the value "integer_value" by default, when New-SensorParameters is used. I speculatively changed this to "string_value" although this did not work; no error although the sensor is not created as required.

Having no terms of reference here for valid values I decided to check the properties of an existing sensor as follows:

Get-Sensor -Id <Manually Created REST API v2 Sensor> | Get-ObjectProperty -Raw

Alas, the property of interest, channel 1 type, is not returned:

Get-Sensor -Id 69755 | Get-ObjectProperty -Raw | findstr channel1_
paessler-rest-channel_section-channel_group-channel1_jsonpath                  : $.data.0.isActive
paessler-rest-channel_section-channel_group-channel1_name                      : Cloud connection
paessler-rest-channel_section-channel_group-channel1_up_states                 : true
paessler-rest-channel_section-channel_group-channel1_warning_states            :
paessler-rest-channel_section-channel_group-channel1_down_states               : false
paessler-rest-channel_section-channel_group-channel1_unlisted_string_handling  : down
paessler-rest-channel_section-channel_group-channel1_lookup_name               :
paessler-rest-channel_section-channel_group-channel1_unit_kind                 : custom
paessler-rest-channel_section-channel_group-channel1_unit

Based on objects returned by New-SensorParameters below, I was hoping that the desired property would also be returned above:

$params | findstr channel1_
paessler-rest-channel_section-channel_group-channel1_jsonpath                  :
paessler-rest-channel_section-channel_group-channel1_name                      :
paessler-rest-channel_section-channel_group-channel1_type                      : integer_type
paessler-rest-channel_section-channel_group-channel1_up_states                 :
paessler-rest-channel_section-channel_group-channel1_warning_states            :
paessler-rest-channel_section-channel_group-channel1_down_states               :
paessler-rest-channel_section-channel_group-channel1_unlisted_string_handling  : down
paessler-rest-channel_section-channel_group-channel1_lookup_name               :
paessler-rest-channel_section-channel_group-channel1_unit                      :
paessler-rest-channel_section-channel_group-channel1_unit_kind                 : custom

Any thoughts on how I can correctly identify correct values for paessler-rest-channel_section-channel_group-channel1_type?

Thanks in advance!

Due Dilligance

lordmilko commented 10 months ago

Are you able to open the add sensor page in the PRTG UI for this sensor type, and then (assuming using Google Chrome) press Ctrl+Shift+J to open the inspector. Locate the area on the screen that contains the setting that you would modify that contains integer_type, etc. Then, select this icon

image

Click on the setting for integer_type. This will bring up the HTML that backs this setting. By comparing this backing value of this setting to the settings next to it, you'll be able to find the value of the other settings too.

I couldn't see this sensor type in my PRTG install (23.4.90.1299+). Please let me know if you have any issues with the above

markgu-coast commented 10 months ago

We have beta sensors enabled, perhaps that's the difference (23.4.90.1299+).

Get-SensorType *"REST Custom V2"*

Id                                  Name                  Description
--                                  ----                  -----------
paessler.rest.rest_custom_v2_sensor REST Custom v2 (BETA) Monitors JSON or XML REST APIs

Thanks so much for the browser tip, I was quickly able to identify the correct value:

paessler-rest-channel_section-channel_group-channel1_type : string_as_state_type

Sensor now created exactly as required.

Sincere thanks again!