r/PowerShell
•
u/NewfagDesTodes
•
Jul 20 '26
•
1
Script Sharing PrtgSensorKit - a PowerShell framework for writing custom PRTG sensors without the boilerplate
Hey r/powershell,
This is mostly helpful for people in the EU but nevertheless 😄 :
I've been building custom sensors for PRTG Network Monitor often for my job and got tired of handling all the prtg specific plumbing boilerplate every time - so I wrote PrtgSensorKit, an open-source module that abstracts away all the specifics of PRTG so you can focus on your task = writing a goddamn monitoring sensor.
What it handles for you:
- JSON output formatting - builds valid PRTG sensor JSON so you don't hand-craft it yourself
- PRTG's constraints enforced automatically - channel limits, string length caps, escaping, valid value types, blah blah blah...
- Powershell Versions - helpers to run your sensor logic in 64-bit PowerShell or PS7+ when you need modules/dependencies that don't play nice with the 32-bit host PRTG normally uses
- DPAPI-encrypted secret storage - store API tokens/credentials without leaving them in plaintext in your script or passing them as Plaintext from PRTG
- Full built-in help -
Get-Helpworks like you'd expect on every cmdlet and pretty much has all the docs Prtg offers on their website
Basically: you write the metric-gathering logic, the module handles everyting else
Install from the Gallery:
Install-Module PrtgSensorKitRepo: https://github.com/ArchitektApx/PrtgSensorKit
Would love feedback, bug reports, or feature requests if anyone here monitors stuff with PRTG and writes custom sensors. Contributions welcome too.
EDIT: v1.1.0:
- Sensor state between runs -
Save/Get-PrtgSensorStatefor rates, deltas, and caching expensive lookups. Safe under overlapping scans (file locking so two runs don't corrupt each other) - Retries -
-RetryCountre-runs your block when the API hiccups instead of instantly alerting, PRTG shows how many retries it took - -DryRun - debug your sensor in a normal console and inspect channels as objects instead of squinting at JSON
- -ForceModernTls - fixes the classic TLS 1.2 problem on 5.1 with one switch
- Sensor doctor -
Invoke-PrtgSensorDoctorstatically checks your script for classic mistakes before PRTG cryptically fails on them
v1.2.0 (out now):
- File logging that can't break your sensor -
-EnableLoggingwrites one log file per run with full error details (stack trace. script line). Never touches stdout, never throws - Shared collection cache - 8 sensors hitting the same API every interval?
Use-PrtgCachedResultmakes them share one call per interval, race-free. Your rate-limited API will thank you - More doctor checks - including the sneaky one where a BOM-less UTF-8 script works everywhere except in what PRTG displays (5.1 reads it as ANSI, your umlauts turn into mojibake)
- Docs got restructured into proper per-topic pages instead of one endless README
UPDATE (October 2026): 1.5 is out with credential masking, crash-safe state and stricter error handling. Update post here
2
u/LemurTech Jul 20 '26
Great idea! Going to try this!
2
u/jazzy095 Jul 20 '26
This is dope. Can't wait to try
2
u/chipchipjack Jul 21 '26
What a total G! Thank u
1
u/MonkeyNin Jul 21 '26
If you use
List[Object]instead of ArrayList, you don't have to catch the output on adds like this line Add-PrtgChannel.ps1then
The left-hand-side syntax for using
type constraintsworks correctly even with an initial value like:If the module is meant to be thread safe, these might need to be a threadsafe type : https://github.com/ArchitektApx/PrtgSensorKit/blob/28c6d15f62965c66b95abf1762b767ac197ad62d/Source/Private/PrtgState.ps1#L4
1
u/surfingoldelephant Jul 22 '26
When you specify a parameter like this:
You aren't actually constraining it to custom objects since
[pscustomobject]in that context is equivalent to[psobject]. And[psobject]accepts anything.Whereas if you decorate it with a
PSTypeNameattribute, you can at least restrict it to your own objects:You already give your custom objects a
PSTypeName, so for better input validation:3
u/BlackV Jul 20 '26
I do miss prtg some times
2
u/gadgetboi88 Jul 20 '26
Great idea! Thank you for sharing your work.