PrtgAPI icon indicating copy to clipboard operation
PrtgAPI copied to clipboard

Library,LibraryNode,Notification Templates

Open schoenm1 opened this issue 3 years ago • 3 comments

What's going on?

Hi @lordmilko I try in a first step, to get data from a library, check if library node with tag filtering exist and check if NotificationTemplate is linked to Library. If this is successfull, the 2nd would be to create this three types witch PRTGApi. At moment, getting library and library node data is working. Even the Rawdata Property "libtagfilter_"

$AllLibrariesAndNodes = Get-Object -Type Library
$AllLibraries = $AllLibrariesAndNodes | Where-Object {$_.ParentID -le 0}
$AllLibrariesNodes = $AllLibrariesAndNodes | Where-Object {$_.ParentID -gt 0}
[...]
$ThisLibraryNode | Get-ObjectProperty -RawProperty "libtagfilter_"

All Notification Action I can parse Get-NotificationAction. But I would not get the data, if a Notification is linked to a library. Even with Development View in Firefox i could not see the POST data to find out the rawparam. Is there a way to get the data screenshot)? https://myserver.domain.com/library.htm?id=50475&tabid=4 image

PS C:\Users\user> Get-PrtgClient  -Diagnostic
PSVersion      : 5.1.17763.2931
PSEdition      : Desktop
OS             : Microsoft Windows 10 Enterprise LTSC
PrtgAPIVersion : 0.9.17
Culture        : de-CH
CLRVersion     : .NET Framework 4.8 (528049)
PrtgVersion    : 22.3.78.1873
PrtgLanguage   : english.lng

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!

schoenm1 avatar Oct 06 '22 05:10 schoenm1

Libraries aren't really supported by PrtgAPI, but you can try using the Get-NotificationTrigger cmdlet against the library. You should be able to do Get-Trigger -Id <libraryId> or something

lordmilko avatar Oct 06 '22 07:10 lordmilko

unfortunately, the Get-NotificationTrigger (Get-Trigger) ist not working with Get-Object (which I have to use for 'Library' and 'LibraryNode' Object). Get-NotificationTrigger is working well for Devices (Get-Devices) Working (with Get-Device):

PS C:\Users\user> Get-Device -id 40 | Get-Trigger * -verbose
VERBOSE: Get-NotificationTrigger: Synchronously executing request https://myserver.domain.com/api/table.xml?id=40&content=triggers&columns=content,objid&username=prtgadmin&passhash=***********

Type      ObjectId SubId Inherited ParentId Latency Condition Threshold Unit       OnNotificationAction
----      -------- ----- --------- -------- ------- --------- --------- ----       --------------------
State     40       1     False     40       60      Equals    Down                 None
State     40       2     False     40       36256   Equals    Down                 None
State     40       1     True      0        600     Equals    Warning              E-Mail [email protected]
State     40       2     True      0        600     Equals    Down                 E-Mail [email protected]

But for inherit from Library, the command to get Trigger from Library is not working, independent if the id is a 'Device' or 'Library'.

PS C:\Users\user> Get-Object -id 50475 | Get-NotificationTrigger * -verbose
Get-NotificationTrigger : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters
that take pipeline input.
At line:1 char:24
+ Get-Object -id 50475 | Get-NotificationTrigger * -verbose
+                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (TEST-Library:PSObject) [Get-NotificationTrigger], ParameterBindingException
    + FullyQualifiedErrorId : InputObjectNotBound,PrtgAPI.PowerShell.Cmdlets.GetNotificationTrigger

schoenm1 avatar Oct 07 '22 05:10 schoenm1

As stated you need to do Get-NotificationTrigger -Id 50475 as the Get-NotificationTrigger cmdlet does not have a parameter set that allows specifying a simple PrtgObject as pipeline input

lordmilko avatar Oct 07 '22 06:10 lordmilko

Get-NotificationTrigger -Id 50475 is not working. ID 50475 is a Library and not a Sensor/Device/Group/Probe Even if I add 50475 as param, the Get-NotificationTrigger ask again for Object Input.

Get-NotificationTrigger -Id 50475
cmdlet Get-NotificationTrigger at command pipeline position 1
Supply values for the following parameters:
(Type !? for Help.)
Object: 50475
Get-NotificationTrigger : Cannot bind parameter 'Object'. Cannot convert the "50475" value of type "System.String" to type "PrtgAPI.SensorOrDeviceOrGroupOrProbe".
At line:1 char:1
+ Get-NotificationTrigger -Id 50475
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-NotificationTrigger], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,PrtgAPI.PowerShell.Cmdlets.GetNotificationTrigger

Get-Object -id 50475
Name         Id    Type
----         --    ----
TEST-Library 50475 Library

schoenm1 avatar Nov 03 '22 14:11 schoenm1

Apologies, I believe the correct command should actually be

Get-NotificationTrigger -ObjectId 50475

lordmilko avatar Nov 03 '22 19:11 lordmilko

I can not get any NotificationTrigger for a Library.

Get-Object -id 50475 | fl *

Id          : 50475
ParentId    : -6
Name        : TEST-Library
Tags        :
DisplayType : Library
Type        : Library
Active      : True

Get-NotificationTrigger -ObjectId 50475 -verbose
VERBOSE: Get-NotificationTrigger: Synchronously executing request
https://prtg.domain.com/api/table.xml?id=50475&content=triggers&columns=content,objid&username=username&passhash=***

With Get-Help Get-NotificationTrigger -full I see, that the parameter 'Object' should be <SensorOrDeviceOrGroupOrProbe>. As far as I understand, I can give 'Object' or 'ObjectID' as parameter. But when 'Object' is not allowed to be the type 'Library', should this be possible for 'ObjectID'?

schoenm1 avatar Nov 04 '22 05:11 schoenm1

It's executing the correct API call so based on this it would appear it's not possible to retrieve notification triggers using the normal notification trigger API

lordmilko avatar Nov 04 '22 06:11 lordmilko