Hello again!
Before I saw you response I had gotten "SensorTree" to work perfectly. It gave me full information about everything I need, Group, Devices and Sensors.
I'm guessing that your last answer would give me approximately the same things, but that I only could get the device-name from the sensor, and group-name from that device etc.
With SensorTree I can go the other way around with Group as base and access the devices and sensors through the group. It's a more natural class structure for what I'm trying to do IMO.
I used the query that's used in the API-demo:
/api/table.xml?content=sensortree&output=xml&&id=$GroupId$
You must of course add your authorization after this.
I'm doing this in C# and the class structure that I created to deserialize the response too looks like this (It's a rather large response with multiple XmlRoots):
using System.Collections.Generic;
using System.Xml.Serialization;
namespace YourOwnNamespace
{
[XmlRoot(ElementName = "usertimezone")]
public class Usertimezone
{
[XmlElement(ElementName = "bias")]
public string Bias { get; set; }
[XmlElement(ElementName = "standardbias")]
public string StandardBias { get; set; }
[XmlElement(ElementName = "daylightbias")]
public string DaylightBias { get; set; }
[XmlElement(ElementName = "standarddatemonth")]
public string StandardDateMonth { get; set; }
[XmlElement(ElementName = "standarddatedayofweek")]
public string StandardDateDayOfWeek { get; set; }
[XmlElement(ElementName = "standarddateday")]
public string StandardDateDay { get; set; }
[XmlElement(ElementName = "standarddatehour")]
public string StandardDateHour { get; set; }
[XmlElement(ElementName = "standarddateminute")]
public string StandardDateMinute { get; set; }
[XmlElement(ElementName = "daylightdatemonth")]
public string DaylightDateMonth { get; set; }
[XmlElement(ElementName = "daylightdatedayofweek")]
public string DaylightDateDayOfWeek { get; set; }
[XmlElement(ElementName = "daylightdateday")]
public string DaylightDateDay { get; set; }
[XmlElement(ElementName = "daylightdatehour")]
public string DaylightDateHour { get; set; }
[XmlElement(ElementName = "daylightdateminute")]
public string DaylightDateMinute { get; set; }
}
[XmlRoot(ElementName = "userdatesettings")]
public class Userdatesettings
{
[XmlElement(ElementName = "shorttimeformat")]
public string ShortTimeformat { get; set; }
[XmlElement(ElementName = "longtimeformat")]
public string LongTimeformat { get; set; }
[XmlElement(ElementName = "shortdateformat")]
public string ShortDateformat { get; set; }
[XmlElement(ElementName = "longdateformat")]
public string LongDateformat { get; set; }
[XmlElement(ElementName = "dateseparator")]
public string DateSeparator { get; set; }
[XmlElement(ElementName = "timeseparator")]
public string TimeSeparator { get; set; }
}
[XmlRoot(ElementName = "graphs")]
public class Graphs
{
[XmlElement(ElementName = "live")]
public string Live { get; set; }
[XmlElement(ElementName = "graph1")]
public string Graph1 { get; set; }
[XmlElement(ElementName = "graph2")]
public string Graph2 { get; set; }
[XmlElement(ElementName = "graph3")]
public string Graph3 { get; set; }
}
[XmlRoot(ElementName = "tasks")]
public class Tasks
{
[XmlElement(ElementName = "autodisco")]
public string Autodisco { get; set; }
[XmlElement(ElementName = "histcalc")]
public string Histcalc { get; set; }
[XmlElement(ElementName = "correlationstatus")]
public string CorrelationStatus { get; set; }
[XmlElement(ElementName = "correlationrunning")]
public string CorrelationRunning { get; set; }
[XmlElement(ElementName = "autoupdate")]
public string AutoUpdate { get; set; }
[XmlElement(ElementName = "maintenance")]
public string Maintenance { get; set; }
[XmlElement(ElementName = "trialdaysleft")]
public string TrialDaysLeft { get; set; }
[XmlElement(ElementName = "showchanneltab")]
public string ShowChannelTab { get; set; }
[XmlElement(ElementName = "showfollowlinks")]
public string ShowFollowLinks { get; set; }
[XmlElement(ElementName = "showfeedbacklinks")]
public string ShowFeedbackLinks { get; set; }
[XmlElement(ElementName = "probeerrors")]
public string ProbeErrors { get; set; }
[XmlElement(ElementName = "recommenderrunning")]
public string RecommenderRunning { get; set; }
}
[XmlRoot(ElementName = "options")]
public class PrtgOptions
{
[XmlElement(ElementName = "usertimezone")]
public Usertimezone UserTimezone { get; set; }
[XmlElement(ElementName = "userdatesettings")]
public Userdatesettings UserdateSettings { get; set; }
[XmlElement(ElementName = "graphs")]
public Graphs Graphs { get; set; }
[XmlElement(ElementName = "sensortypes")]
public string SensorTypes { get; set; }
[XmlElement(ElementName = "usedtags")]
public string UsedTags { get; set; }
[XmlElement(ElementName = "tasks")]
public Tasks Tasks { get; set; }
}
[XmlRoot(ElementName = "sensor")]
public class Sensor
{
[XmlElement(ElementName = "name")]
public string Name { get; set; }
[XmlElement(ElementName = "id")]
public string Id { get; set; }
[XmlAttribute(AttributeName = "id")]
public string _Id { get; set; }
[XmlElement(ElementName = "url")]
public string Url { get; set; }
[XmlElement(ElementName = "tags")]
public string Tags { get; set; }
[XmlElement(ElementName = "priority")]
public string Priority { get; set; }
[XmlElement(ElementName = "fixed")]
public string Fixed { get; set; }
[XmlElement(ElementName = "hascomment")]
public string Hascomment { get; set; }
[XmlElement(ElementName = "sensortype")]
public string Sensortype { get; set; }
[XmlElement(ElementName = "sensorkind")]
public string Sensorkind { get; set; }
[XmlElement(ElementName = "interval")]
public string Interval { get; set; }
[XmlElement(ElementName = "status_raw")]
public string StatusRaw { get; set; }
[XmlElement(ElementName = "status")]
public string Status { get; set; }
[XmlElement(ElementName = "datamode")]
public string Datamode { get; set; }
[XmlElement(ElementName = "lastvalue")]
public string LastValue { get; set; }
[XmlElement(ElementName = "lastvalue_raw")]
public string LastValueRaw { get; set; }
[XmlElement(ElementName = "statusmessage")]
public string StatusMessage { get; set; }
[XmlElement(ElementName = "statussince_raw_utc")]
public string StatusSinceRawUtc { get; set; }
[XmlElement(ElementName = "lasttime_raw_utc")]
public string LastTimeRawUtc { get; set; }
[XmlElement(ElementName = "lastok_raw_utc")]
public string LastOkRawUtc { get; set; }
[XmlElement(ElementName = "lasterror_raw_utc")]
public string LastErrorRawUtc { get; set; }
[XmlElement(ElementName = "lastup_raw_utc")]
public string LastUpRawUtc { get; set; }
[XmlElement(ElementName = "lastdown_raw_utc")]
public string LastDownRawUtc { get; set; }
[XmlElement(ElementName = "cumulateddowntime_raw")]
public string CumulateDownimeRaw { get; set; }
[XmlElement(ElementName = "cumulateduptime_raw")]
public string CumulatedUptimeRaw { get; set; }
[XmlElement(ElementName = "cumulatedsince_raw")]
public string CumulatedSinceRaw { get; set; }
[XmlElement(ElementName = "active")]
public string Active { get; set; }
}
[XmlRoot(ElementName = "device")]
public class Device
{
[XmlElement(ElementName = "summary")]
public string Summary { get; set; }
[XmlElement(ElementName = "name")]
public string Name { get; set; }
[XmlElement(ElementName = "deviceicon")]
public string DeviceIcon { get; set; }
[XmlElement(ElementName = "id")]
public string Id { get; set; }
[XmlAttribute(AttributeName = "id")]
public string _Id { get; set; }
[XmlElement(ElementName = "url")]
public string Url { get; set; }
[XmlElement(ElementName = "tags")]
public string Tags { get; set; }
[XmlElement(ElementName = "priority")]
public string Priority { get; set; }
[XmlElement(ElementName = "fixed")]
public string Fixed { get; set; }
[XmlElement(ElementName = "hascomment")]
public string HasComment { get; set; }
[XmlElement(ElementName = "host")]
public string Host { get; set; }
[XmlElement(ElementName = "status_raw")]
public string StatusRaw { get; set; }
[XmlElement(ElementName = "active")]
public string Active { get; set; }
[XmlElement(ElementName = "sensor")]
public List<Sensor> Sensor { get; set; }
}
[XmlRoot(ElementName = "group")]
public class Group
{
[XmlElement(ElementName = "name")]
public string Name { get; set; }
[XmlElement(ElementName = "id")]
public string Id { get; set; }
[XmlAttribute(AttributeName = "id")]
public string _Id { get; set; }
[XmlElement(ElementName = "url")]
public string Url { get; set; }
[XmlElement(ElementName = "tags")]
public string Tags { get; set; }
[XmlElement(ElementName = "priority")]
public string Priority { get; set; }
[XmlElement(ElementName = "fixed")]
public string Fixed { get; set; }
[XmlElement(ElementName = "hascomment")]
public string HasComment { get; set; }
[XmlElement(ElementName = "status_raw")]
public string StatusRaw { get; set; }
[XmlElement(ElementName = "active")]
public string Active { get; set; }
[XmlElement(ElementName = "device")]
public List<Device> Device { get; set; }
}
[XmlRoot(ElementName = "nodes")]
public class Nodes
{
[XmlElement(ElementName = "group")]
public Group Group { get; set; }
}
[XmlRoot(ElementName = "sensortree")]
public class Sensortree
{
[XmlElement(ElementName = "nodes")]
public Nodes Nodes { get; set; }
}
[XmlRoot(ElementName = "prtg")]
public class BasePrtgSensorTree
{
[XmlElement(ElementName = "prtg-version")]
public string Prtgversion { get; set; }
[XmlElement(ElementName = "options")]
public PrtgOptions Options { get; set; }
[XmlElement(ElementName = "sensortree")]
public Sensortree Sensortree { get; set; }
}
}
You should be able to just copy and paste this code into a .cs file. The base-class you deserialize against is BasePrtgSensorTree.
Here's some examples on how to handle this structure (base-class is here called base:
Get Group:
var group = base.SensorTree.Nodes.Group;
Loop through each Device in Group:
foreach(var device in base.SensorTree.Nodes.Group.Device){ //Perform actions here}
Inside this foreach loop you can loop through each Sensor that's in the current Device.
I hope this will help someone that's trying to do the same thing.
Thanks again!
Martin Johansson
Add comment