Skip to content

attila-koteles/PrtgSharp

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

PrtgSharp

A library useful in creating well-formed XML responses for Custom Sensors in PRTG. Specifically it can be used in both the "Advanced EXE/Script Sensor" and "Advanced HTTP Data Sensors."

It's based on the PRTG API documentation for PRTG Network Monitor 16.4.x. It contains every sensor and channel property/element and does reduimentary sanity checking of values & final results.

The library allows you to feed it Channel data (and related ChannelProperties) and emits an XElement following the defined XML spec.

Obtaining

PM> Install-Package PrtgSharp.Core -Pre

Example Usages

Success

var channels = new List<IChannel>
{
    new Channel("Last Scan Duration", 
                142.5f, 
                new[] { ValueUnitProperty.TimeSeconds, SpeedValueDisplayTimeProperty.Minute }),

    new Channel("Velocity (unladen swallow)", 
                11, 
                new [] { ValueUnitProperty.Custom, new CustomValueUnitProperty("M/Sec") }),

    new Channel("Widget Size", 
                415, 
                new [] { ValueUnitProperty.BytesDisk })
};

var rpt = new PrtgSensorSuccessResult("Everything Looks Awesome!", channels);
var output = rpt.SerializeToXElement().ToString();

Produces the following XML in output

<prtg>
  <text>Everything Looks Awesome!</text>
  <result>
    <channel>Last Scan Duration</channel>
    <value>142.5</value>
    <unit>TimeSeconds</unit>
    <speedtime>Minute</speedtime>
    <float>1</float>
  </result>
  <result>
    <channel>Velocity (unladen swallow)</channel>
    <value>11</value>
    <unit>Custom</unit>
    <customunit>M/Sec</customunit>
    <float>0</float>
  </result>
  <result>
    <channel>Widget Size</channel>
    <value>415</value>
    <unit>BytesDisk</unit>
    <float>0</float>
  </result>
</prtg>

Failure

var rpt = new PrtgSensorErrorResult("It's all gone horribly wrong :(");
var output = rpt.SerializeToXElement().ToString();

Produces the following XML in output

<prtg>
  <text>It's all gone horribly wrong :(</text>
  <error>1</error>
</prtg>

Future Features

  • Logging Infrastructure to help debug/monitor
  • EXE-specific Features
    • Capturing of command line parameters
    • Capturing of environment variables
  • HTML-specific Helpers

About

PrtgSharp - A Library to help create well-formed PRTG XML responses

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%