PrtgAPI

repository·master·Indexed 43 days ago

https://github.com/lordmilko/prtgapi

A C# and PowerShell library providing a type-safe abstraction for managing and maintaining PRTG Network Monitor. It enables automation of object creation, reporting, and environment maintenance, including the ability to manage sensors, devices, and groups via the PrtgClient class in C# or a comprehensive set of cmdlets in PowerShell.

Tokens
11K
Snippets
25
Records
28
Agent score
55%

What's inside PrtgAPI

  1. Overview of PrtgAPI capabilities

    master

    PrtgAPI is a C# and PowerShell library designed to manage and maintain PRTG Network Monitor. It abstracts the PRTG interface into type-safe methods and cmdlets.

    Key capabilities include:

    • Reporting: Generate reports based on custom queries.
    • Monitoring: Monitor the monitoring system (e.g., detecting missing sensors or new devices).
    • Object Management: Create, modify, or clone sensors, devices, and groups.
    • Automation: Deploy notification triggers, maintain standard settings across environments, and pause/resume items from external systems.
    • Batch Operations: Perform bulk actions across your PRTG environment.
  2. Manage PRTG Sensor properties with Get-ObjectProperty and Set-ObjectProperty

    master

    PrtgAPI allows you to retrieve and modify sensor settings using the Get-ObjectProperty and Set-ObjectProperty cmdlets. These cmdlets support a wide range of sensor-specific properties in a typesafe manner.

    Support Status Definitions

    When working with properties, the following status indicators describe how you can interact with them:

    • Yes: Fully supported for both Get and Set.
    • Read-Only: Supports Get, but will never support Set.
    • No: Not currently supported via typesafe methods.
    • Direct: Supports both Get and Set, but can only be retrieved via direct requests.
    • GetDirect: Supports Get via direct requests, but will never support Set.

    Using Raw Properties

    If a property is not currently supported by the typesafe API (marked as No), you can still interact with it using the -RawProperty and -RawValue parameters in the Get-ObjectProperty and Set-ObjectProperty cmdlets. This allows you to bypass the typesafe layer and interact with the underlying PRTG values directly.

    Supported Sensor Property Groups

    Properties are categorized by the type of sensor being managed. Common groups include:

    Basic Sensor Settings

    • Name (Yes/Yes): Name of the sensor.
    • Tags (Yes/No): Tags applied to this object.
    • Priority (Yes/Yes): Priority of the sensor.
    • ParentTags (Read-Only/No): Tags inherited from the parent object.

    HTTP Specific

    • Url (Yes/Yes): URL to monitor.
    • HttpRequestMethod (Yes/Yes): Request method (e.g., GET, POST).
    • PostData (Yes/Yes): Data to include in POST requests.
    • Timeout (Yes/Yes): Timeout for HTTP requests.
    • UseSNIFromUrl (Yes/Yes): Whether to use SNI from the URL or parent device.

    Ping Settings

    • Timeout (Yes/Yes): Timeout for Ping requests.
    • PingMode (Yes/Yes): Whether to send a single or multiple pings.
    • PingCount (Yes/Yes): Number of pings to send when PingMode is MultiPing.
    • PingDelay (Yes/Yes): Delay between each ping when PingMode is MultiPing.
    • PingPacketSize (Yes/Yes): Packet size (1-10,000 bytes).

    EXE/XML Settings

    • ExeFile (Yes/Yes): EXE/Script file to execute.
    • ExeParameters (Yes/Yes): Parameters to pass to the file.
    • UseWindowsAuthentication (Yes/Yes): Whether to run with credentials of the Device or the Probe Service.
    • Mutex (Yes/Yes): Mutex to execute related sensors sequentially.

    WMI Service Monitor

    • ServiceName (Read-Only/No): The name of the service being monitored.
    • StartStopped (Yes/Yes): Whether PRTG should start the target service if stopped/crashed.
    • MonitorPerformance (Yes/Yes): Whether to monitor additional performance metrics.

    Database Specific

    • Database (Yes/Yes): The name of the database to monitor.
    • SqlServerQuery (Direct/No): The SQL query file to execute (accessed via direct requests).
    • SqlInputParameter (Yes/Yes): Input parameters to the SQL query file.
    # Retrieve all properties of a sensor
    Get-Sensor -Id 1001 | Get-ObjectProperty
    
    # Modify a specific property (e.g., scanning interval)
    Get-Sensor -Id 1001 | Set-ObjectProperty Interval "00:00:30"
    
    # Use Raw properties for unsupported settings
    Get-Sensor -Id 1001 | Get-ObjectProperty -RawProperty Name
    Get-Sensor -Id 1001 | Set-ObjectProperty -RawProperty name_ -RawValue test
  3. Manage Object Properties with Get-ObjectProperty and Set-ObjectProperty

    master

    PrtgAPI provides the Get-ObjectProperty and Set-ObjectProperty cmdlets to retrieve and modify settings for PRTG Devices, Groups, Probes, and Sensors in a typesafe manner.

    Support Status Definitions

    When reviewing property tables, the following status indicators are used:

    • Yes: Fully supported for both Get and Set.
    • No: Not currently supported via typesafe cmdlets.
    • Direct: Supports both Get and Set, but can only be accessed via direct requests (e.g., for Comments or InheritTriggers).
    • N/A: Not Applicable.

    Working with Unsupported Properties

    If a property is not listed as supported (marked as No), you can still interact with it using the -RawProperty and -RawValue parameters on the Get-ObjectProperty and Set-ObjectProperty cmdlets. This allows you to bypass the typesafe layer and interact with the underlying PRTG values directly.

    # Example: Retrieve a raw property
    Get-Probe contoso | Get-ObjectProperty -RawProperty windowsloginusername_
    
    # Example: Set a raw property
    Get-Probe contoso | Set-ObjectProperty -RawProperty windowsloginusername_ -RawValue Administrator
  4. Install PrtgAPI via NuGet

    master

    You can install PrtgAPI using the Install-Package command. It is available on both NuGet.org and the PowerShell Gallery. The library provides targets for both .NET Framework and .NET Standard.

    If you are using PowerShell 5.1+ and want to install specifically from the PowerShell Gallery, use the -Source PSGallery flag.

    Note for Windows PowerShell users: Because the PowerShell Gallery requires TLS 1.2, you may need to manually enable it in your session before running the installation command.

    # Standard installation
    Install-Package PrtgAPI
    
    # Install specifically from PowerShell Gallery
    Install-Package PrtgAPI -Source PSGallery
    
    # Enable TLS 1.2 if installation fails due to security protocols
    [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
  5. Install PrtgAPI manually

    master

    If you prefer not to use a package manager, follow these steps to install PrtgAPI manually:

    1. Download the latest build ZIP file.
    2. Unblock the file: Right-click PrtgAPI.zip -> Properties -> select Unblock under the Security section on the General tab.
    3. Unzip the file.
    4. Integration:
      • C# Projects: Add a reference to PrtgAPI.dll. Use net452 for full CLR or netstandard2.0 for Core CLR.
      • PowerShell: Import the module using Import-Module C:\path\to\PrtgAPI.
      • Quick Prompt: Run the included PrtgAPI.cmd (Windows) or PrtgAPI.sh (Linux/macOS) to open a prompt that automatically imports the module for you.
    # Example PowerShell import
    Import-Module C:\path\to\PrtgAPI
  6. Connect to PrtgServer in PowerShell

    master

    To start using PrtgAPI in PowerShell, use the Connect-PrtgServer cmdlet.

    Interactive connection (prompts for credentials):

    Connect-PrtgServer prtg.mycoolsite.com

    Automated connection using credentials:

    Connect-PrtgServer prtg.mycoolsite.com (New-Credential prtgadmin supersecretpassword)

    Tip: You can define GoPrtg connections in your $Profile to automate connections in future sessions.

  7. Create a WMI Service sensor for specific services

    master

    To create a WMI Service sensor for a set of services (e.g., those matching a pattern), follow these steps:

    1. Retrieve the target device using Get-Device.
    2. Use Get-SensorTarget with the WmiService type and a wildcard pattern to find the target services.
    3. Pass those targets to New-SensorParameters using the WmiService type.
    4. Use Add-Sensor on the device to instantiate the sensor.
    $device = Get-Device -Id 1001
    $services = $device | Get-SensorTarget WmiService *exchange*
    $params = New-SensorParameters WmiService $services
    $device | Add-Sensor $params
  8. Set the UpperErrorLimit of a specific channel

    master

    To update a specific property (like UpperErrorLimit) for a named channel within a sensor, pipe the results of Get-Sensor and Get-Channel into Set-ChannelProperty.

    Example: Setting the UpperErrorLimit of the "Total" channel to 90 for all sensors tagged with wmicpuloadsensor.

    Get-Sensor -Tags wmicpuloadsensor | Get-Channel Total | Set-ChannelProperty UpperErrorLimit 90