What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

PowerShell PRTG Advanced Custom Sensor JSON and XML

Votes:

2

Because i found no needful Example of a PowerShell Example of a PRTG Advanced Custom Sensor and i dislike XML. I worked out an PowerShell Example of a PRTG Advanced Custom Sensor with use of JSON Hope this helps some one else to get a faster start on it.

See also: https://www.paessler.com/manuals/prtg/custom_sensors#advanced_sensors

<#
    Sample Exe/Script Advanced sensor                              
    Returns four sensor channels with static values to standard OUT
    Predefines limits for one channel

    See: https://www.paessler.com/manuals/prtg/custom_sensors#advanced_sensors


  Output can be with the following commands

    Write-Host $XMLResult
     or
    Write-Host $JsonResult
    
    Write-Output $XMLResult
     or
    Write-Host $JsonResult

    
    # or simply return the xml / json text without any command
    
    $XMLResult

    or 

    $JsonResult

    This Example uses JSON for output at the end

#>


$XMLResult = @"
<prtg>

   <result>
       <channel>Demo Minimum Example</channel>
       <value>3</value>
   </result>

   <result>
       <channel>Demo Disk Free</channel>
       <unit>Percent</unit>
       <mode>Absolute</mode>
       <showChart>1</showChart>
       <showTable>1</showTable>
       <warning>0</warning>
       <float>1</float>
       <value>38.4487</value>
       <LimitMaxError>80</LimitMaxError>
       <LimitMaxWarning>37</LimitMaxWarning>
       <LimitWarningMsg>My custom note for warnings</LimitWarningMsg>
       <LimitErrorMsg>My custom note for errors</LimitErrorMsg>
       <LimitMode>1</LimitMode>
   </result>

   <result>
       <channel>Demo Network Speed</channel>
       <unit>SpeedNet</unit>
       <volumeSize>MegaBit</volumeSize>
       <mode>Absolute</mode>
       <showChart>1</showChart>
       <showTable>1</showTable>
       <warning>0</warning>
       <float>0</float>
       <value>124487000</value>
   </result>

   <result>
       <channel>Demo Custom</channel>
       <unit>Custom</unit>
       <customUnit>Pieces</customUnit>
       <mode>Absolute</mode>
       <showChart>1</showChart>
       <showTable>1</showTable>
       <warning>0</warning>
       <float>0</float>
       <value>855</value>
   </result>

   <text>Demo values. OS: $($env:OS)</text>
</prtg>
"@

$JsonResult = @"
{
    "prtg": {

        "result": [
            {
                "channel": "Demo Minimum Example",
                "value": "3"
            },
            {
                "channel": "Demo Disk Free",
                "unit": "Percent",
                "mode": "Absolute",
                "showChart": "1",
                "showTable": "1",
                "warning": "0",
                "float": "1",
                "value": "38.4487",
                "LimitMaxError": "80",
                "LimitMaxWarning": "37",
                "LimitWarningMsg": "My custom note for warnings",
                "LimitErrorMsg": "My custom note for errors",
                "LimitMode": "1"
            },
            {
                "channel": "Demo Network Speed",
                "unit": "SpeedNet",
                "volumeSize": "MegaBit",
                "mode": "Absolute",
                "showChart": "1",
                "showTable": "1",
                "warning": "0",
                "float": "0",
                "value": "124487000"
            },
            {
                "channel": "Demo Custom",
                "unit": "Custom",
                "customUnit": "Pieces",
                "mode": "Absolute",
                "showChart": "1",
                "showTable": "1",
                "warning": "0",
                "float": "0",
                "value": "855"
            }
        ],
    
    "text": "Demo values. OS: $($env:OS)"
    
    }
}
"@

$JsonResult



custom example powershell sensor-custom-sensor

Created on Sep 9, 2019 7:34:35 AM



1 Reply

Votes:

0

Hello there,

Thank you for your KB post.

And tank you for creating and sharing this script.


Kind regards,
Sasa Ignjatovic, Tech Support Team

Created on Sep 9, 2019 12:52:16 PM by  Sasa Ignjatovic [Paessler Support]




Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.