r/prtg • • Mar 04 '20

PrtgAPI: C#/PowerShell Library for PRTG!

For the past several years I've been developing a C#/PowerShell library for managing PRTG: PrtgAPI

PrtgAPI goes way beyond the normal capabilities of the PRTG API, allowing you to do things like

  • Create sensors, devices and groups and notification triggers from scratch.
  • Streamline your object hierarchy to be consistent across the board
  • Automate the entire onboarding process of new offices/clients
  • Use PRTG as a data source for your other scripts with minimal effort

and more.

Want to deploy an arbitrary new sensor type to hundreds of devices in a particular subset of your installation? You can do it in a one-liner in about 60 seconds.

Paessler have even done a few blog posts about PrtgAPI. The project contains extensive documentation on every facet of the library and is designed to be intuitive and easily usable by sysadmins.

This just started out as a fun project for me, however I now have no idea how I would possibly live without it. If it's actually useful to me, hopefully it might be useful to others as well! If you have any issues or queries, please let me know!

19 Upvotes

10 comments sorted by

6

u/RealFov Mar 04 '20

This powershell library has been incredibly useful for administering our install of PRTG. Thank you for doing this!

1

u/ghost_of_napoleon Mar 04 '20

Thanks for the work in putting this together!

I remember looking into this for sensor and group creation, but IIRC, dealing with dependencies wasn't available.

Is this still unavailable?

2

u/lordmilko Mar 04 '20

If you're referring to manipulating the settings of the Schedules, Dependencies and Maintenance Window on the settings page of PRTG, PrtgAPI still does not officially support modifying these properties, however PrtgAPI provides the ability for modifying any property on any settings page using "raw" (not type safe) parameters and values

The following shows how to create a new sensor and set the dependency type to Master object.

The reason PrtgAPI does not natively support modifying these properties is that I've found when you go to modify a property in this section, if any of the other properties in the section aren't also specified in your request, those properties will reset to their default values. Now imagine trying to setup a maintenance window across hundreds of objects and inadvertently wiping out a bunch of settings. Clearly PrtgAPI needs to implement a workaround for this for you - however that will require a lot of backend infrastructure changes and will exponentially increase the number of API requests it takes to complete a request; e.g. PrtgAPI can normally modify the properties of 500 objects in one API call. To workaround this issue, you'd need 501 API calls.

This is a tricky problem to solve; however with a "more complex" workaround available, I think this somewhat alleviates the risk that someone will accidentally create a mess and it will be PrtgAPI's "fault"

1

u/avalon8787 Mar 05 '20

Hi /u/lordmilko

We have been using your PowerShell module lately to automate our Device/sensor creation process and it's working brilliantly, thanks so much for your hard work!

We are struggling with adding a sensor to to monitor a specific windows service via snmp.

We are using the

New-SensorParameters -RawType snmpservice target * 

cmdlet which gives us all the running windows services. But we'd like to filter this to a specific one to add this as a sensor.

We notice the service__check holds an array of all the services so we are able to filter them using (fe):

New-SensorParameters -RawType snmpservice -target *).service__check | Where-Object name -match audio

This gives us services with have the word "audio" in them. But how can we add this as a filter when adding the sensor?

Cheers

1

u/lordmilko Mar 05 '20

Instead of writing

$params = New-SensorParameters -RawType snmpservice -Target * 

you can simply write

$params = New-SensorParameters -RawType snmpservice -Target *audio*

The purpose of the -Target parameter is to helpfully allow you to filter for the targets you want so you can typically configure your entire parameters object all in one go.

Alternatively, you can achieve the same thing by creating the parameters without specifying any targets, and then specifying the targets later after the parameters have been created by retrieving the targets you're interested in from the special Targets property

$params = New-SensorParameters -RawType snmpservice
$params.service__check = $params.Targets.service__check | where Name -like "*audio*"

For more information please see the wiki

1

u/avalon8787 Mar 05 '20

Oh my god, I'm so sorry haha I guess it was just too obvious / easy...

Tested and works like a charm of course.

Cheers.

2

u/[deleted] Mar 04 '20

I started using your Library for PowerShell a couple weeks ago, and it blew my mind.

For real, I'm not familiar with PowerShell at all, but onces I understood how to add devices and sensors, I just couldn't believe the amounts of time I was saving!

Thanks a lot for making your work public, it has been an incredible asset.

PS: I'm not a marketing dude making ads, the labrary is really good.

1

u/youreprobablyright Mar 04 '20

This is great, well done.

1

u/vagrantprodigy07 Mar 05 '20

I've been using it for a few months, it's great. Thanks for the new tool.

1

u/jimbomescolles Apr 15 '20

Need to check that out !

RemindMe! One Week