lordmilko / PrtgAPI

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

Cannot set devicetemplate property on a group #294

Closed kacoroski closed 2 years ago

kacoroski commented 2 years ago

Describe the bug

I am trying to change the device template on a group from Device Generic SNMP.odt to NSD-Switch.odt. I am using the Set-ObjectProperty -RawProperty command described in the wiki and cannot get it to work. Not sure what I am doing incorrectly.

Steps to reproduce

On a switch group I changed by hand:
devicetemplate : 0
devicetemplate__check : NSD-Switch.odt|NSD-Switch||

On a switch group I need to change:
devicetemplate : 0
devicetemplate__check : Device Generic SNMP.odt|Generic Device (SNMP Enabled)||

Checking on the group to change:
PS C:\Users\Administrator> get-group -Id 3014 | Get-ObjectProperty -RawProperty devicetemplate
Device Generic SNMP.odt

But no matter what I try, I cannot change it:
PS C:\Users\Administrator> get-group -Id 3014 | Set-ObjectProperty -RawProperty devicetemplate -RawValue "NSD-Switch.odt|NSD-Switch||" -Force
WARNING: Property 'devicetemplate' does not look correct. If request does not work try with 'devicetemplate_' instead. To suppress this message specify -WarningAction
SilentlyContinue.
PS C:\Users\Administrator> get-group -Id 3014 | Get-ObjectProperty -RawProperty devicetemplate
Device Generic SNMP.odt

PS C:\Users\Administrator> get-group -Id 3014 | Set-ObjectProperty -RawProperty devicetemplate_ -RawValue "NSD-Switch.odt|NSD-Switch||" -Force
PS C:\Users\Administrator> get-group -Id 3014 | Get-ObjectProperty -RawProperty devicetemplate
Device Generic SNMP.odt

PS C:\Users\Administrator> get-group -Id 3014 | Set-ObjectProperty -RawProperty devicetemplate__check -RawValue "NSD-Switch.odt|NSD-Switch||" -Force
WARNING: Property 'devicetemplate__check' does not look correct. If request does not work try with 'devicetemplate__check_' instead. To suppress this message specify
-WarningAction SilentlyContinue.
PS C:\Users\Administrator> get-group -Id 3014 | Get-ObjectProperty -RawProperty devicetemplate
Device Generic SNMP.odt

PS C:\Users\Administrator> get-group -Id 3014 | Set-ObjectProperty -RawProperty devicetemplate__check_ -RawValue "NSD-Switch.odt|NSD-Switch||" -Force
PS C:\Users\Administrator> get-group -Id 3014 | Get-ObjectProperty -RawProperty devicetemplate
Device Generic SNMP.odt

PS C:\Users\Administrator> get-group -Id 3014 | Set-ObjectProperty -RawProperty devicetemplate -RawValue "NSD-Switch.odt" -Force
WARNING: Property 'devicetemplate' does not look correct. If request does not work try with 'devicetemplate_' instead. To suppress this message specify -WarningAction
SilentlyContinue.
PS C:\Users\Administrator> get-group -Id 3014 | Get-ObjectProperty -RawProperty devicetemplate
Device Generic SNMP.odt

PS C:\Users\Administrator> get-group -Id 3014 | Set-ObjectProperty -RawProperty devicetemplate_ -RawValue "NSD-Switch.odt" -Force
PS C:\Users\Administrator> get-group -Id 3014 | Get-ObjectProperty -RawProperty devicetemplate
Device Generic SNMP.odt 

I have also tried the above sets using a variable set like this:
PS C:\Users\Administrator> $template = Get-DeviceTemplate NSD-Switch
PS C:\Users\Administrator> $template

Name       Value
----       -----
NSD-Switch NSD-Switch.odt

with no luck.

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

PS C:\Users\Administrator> Get-PrtgClient -Diagnostic

PSVersion      : 5.1.17763.2931
PSEdition      : Desktop
OS             : Microsoft Windows Server 2019 Datacenter
PrtgAPIVersion : 0.9.17
Culture        : en-US
CLRVersion     : .NET Framework 4.8 (528049)
PrtgVersion    : 22.2.77.2204
PrtgLanguage   : english.lng

Additional context

Just wondering if it is even possible to set the device template on a group. From the wiki I see that it can be done when a sensor is created.

kacoroski commented 2 years ago

So I check the html and I see:

but when I try a get property on devicetemplatecheck I get: PS C:\Users\Administrator> get-group -Id 3014 | Get-ObjectProperty -RawProperty devicetemplatecheck Get-ObjectProperty : PRTG was unable to complete the request. A value for property 'devicetemplate__check' could not be found. At line:1 char:22

lordmilko commented 2 years ago
$d = get-devicetemplate *rdp*

get-group servers|Set-ObjectProperty -RawParameters @{
    discoverytype_=2
    devicetemplate__check=$d
    ipbase_="192.168.0"
    devicetemplate_=1
} -force -verbose

If you already have the IP Base set you don't have to re-specify it, but when you first select to use device templates this value needs to be filled in

The secret property you were most likely missing is devicetemplate_=1; often you need to signify "I am modifying this this value" when there's a number of options you can possibly select from. You can find the parameters required for any request by running Fiddler Classic and tracing the web request made when you edit the settings of an object

Get-ObjectProperty -RawProperty asks PRTG for a given property directly. Not all properties can be queried directly; for them, you can view them by having PrtgAPI retrieve all properties (which it does by scraping the Settings page)

C:\> get-group servers|get-objectproperty -raw|select *devicetemplate*

devicetemplate devicetemplate__check
-------------- ---------------------
0              Server RDP.odt|RDP Server||
kacoroski commented 2 years ago

Thanks this works perfectly.

kacoroski commented 2 years ago

Thanks for your quick response and help.