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

Does REST API support JSON formatting for Historic Data

Votes:

0

XML data formatted with properties doesn't deserialize using the .NET DataContract serializer, so it would be advantageous to have correctly formatted JSON historic data.

When requesting historic data via REST api in JSON format, e.g:

http://10.10.222.101/api/historicdata.xml?output=json&id=2420&avg=3600&sdate=2014-08-14&edate=2014-08-15

Response data seems to be missing channel property information (name/ID):

{"prtg-version":"14.2.9.1690","treesize":24,"histdata":[{"datetime":"8/14/2014 12:00:00 AM - 1:00:00 AM","datetime_raw":41865.2083333333,"value":-31.03,"value_raw":-31.0275,"value":-62.05,"value_raw":-62.0550,"value":0.00,"value_raw":0.0000,"coverage":"100 %","coverage_raw":10000},{"datetime":"8/14/2014 1:00:00 AM - 2:00:00 AM","datetime_raw":41865.2500000000,"value":-31.03,"value_raw":-31.0300,"value":-62.06,"value_raw":-62.0600,"value":0.00,"value_raw":0.0000,"coverage":"100 %","coverage_raw":10000}, 

... ]}

XML response content for similar request is :

<?xml version="1.0" encoding="UTF-8"?>
  <histdata>
   <prtg-version>14.2.9.1690</prtg-version>
   <item>
    <datetime>8/14/2014 12:00:00 AM - 1:00:00 AM</datetime>
    <datetime_raw>41865.2083333333</datetime_raw>
    <value channel="Avg" channelid="1">-31.03 </value>
    <value_raw channel="Avg" channelid="1">-31.0275</value_raw>
    <value channel="Min" channelid="2">-62.05 </value>
    <value_raw channel="Min" channelid="2">-62.0550</value_raw>
    <value channel="Max" channelid="3">0.00 </value>
    <value_raw channel="Max" channelid="3">0.0000</value_raw>
    <coverage>100 %</coverage>
    <coverage_raw>0000010000</coverage_raw>
   </item>
   <item>
    <datetime>8/14/2014 1:00:00 AM - 2:00:00 AM</datetime>
    <datetime_raw>41865.2500000000</datetime_raw>
    <value channel="Avg" channelid="1">-31.03 </value>
    <value_raw channel="Avg" channelid="1">-31.0300</value_raw>
    <value channel="Min" channelid="2">-62.06 </value>
    <value_raw channel="Min" channelid="2">-62.0600</value_raw>
    <value channel="Max" channelid="3">0.00 </value>
    <value_raw channel="Max" channelid="3">0.0000</value_raw>
    <coverage>100 %</coverage>
    <coverage_raw>0000010000</coverage_raw>
   </item>
...

I'm currently using a hack to deserialize the JSON, if anyone is interested it looks like this (ChannelType is a custom enum - could use an integer channel ID instead, depends on channel numbering 1 .. n matching order of raw data in the JSON response)

    [DataContract]
    public class SensorHistoricData
    {
        [DataMember(Name = "histdata")]
        public HistoricDataPoint[] DataPoints { get; set; }
    }

    [DataContract]
    public class HistoricDataPoint
    {

        ... (other properties - coverage, datetime)

        [IgnoreDataMember]
        private ChannelType _channelType = ChannelType.None;

        /// <summary>
        /// HACK to accumulate channel data from badly formatted JSON
        /// </summary>
        [DataMember(Name = "value_raw")]
        public decimal? AddRawData
        {
            get { return null; }
            private set
            {
                
                _channelType += 1;
                if (value.HasValue)
                {
                    ChannelData  = new List<HistoricChannelData>(ChannelData ?? new HistoricChannelData [] {})
                        {
                            new HistoricChannelData {ChannelType = _channelType, Data = value.Value}
                        }.ToArray();
                }
            }
        }

        [IgnoreDataMember]
        public HistoricChannelData[] ChannelData { get; set; }
}

api histdata historic-data historicdata rest

Created on Aug 18, 2014 5:06:53 PM

Last change on Aug 19, 2014 7:57:49 AM by  Konstantin Wolff [Paessler Support]



1 Reply

Votes:

0

Dear Lisa

It is correct that the JSON query provides a slightly different set of data. We have no current plans to change this, as each query works for almost any case.

Created on Aug 21, 2014 2:05:32 PM by  Arne Seifert [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.