Paessler support has answered this question for me. Here's response in case it helps someone else:
"
The data format you see is an internal format. For some sensors, PRTG automatically converts the internal format to a readable one.
In the case when this internal format is not converted but shown as-is, for example "-000000000000031-0.1000" please manually cut the "-0." part out and replace it with a point. For nonnegative numbers, like "0000000000000000.0000", cut "0." out and replace it with a decimal point as well.
"
I'm using JSON.NET serialization on a WCF REST service API, so my workaround is to apply this converter to the sensor channel raw data property. NOTE - my channel data is negative, so if you use this solution please double-check the positive data translation.
/// <summary>
/// Sensor channel data from request :
/// </summary>
[DataContract]
public class SensorChannelData
{
[DataMember(Name = "channels")]
public ChannelData[] ChannelData { get; private set; }
}
[DataContract]
public class ChannelData
{
[DataMember(Name = "name")]
public ChannelType ChannelType { get; private set; }
[DataMember(Name = "lastvalue")]
public string DataString { get; private set; }
[DataMember(Name = "lastvalue_raw")]
[JsonConverter(typeof(PrtgRawDataJsonConverter))]
public decimal ? Data { get; private set; }
}
/// <summary>
/// PRTG raw data has an occasional formatting problem in channel raw data.
/// This converter detects and modifies to a standard format
/// </summary>
/// <remarks>Annotate any PRTG channel raw data value property with this converter.</remarks>
internal class PrtgRawDataJsonConverter :JsonConverter
{
private static readonly Regex NegativeMatch = new Regex(@"-(?:0|[1-9]\d*)(-0\.\d+)");
private static readonly Regex PositiveMatch = new Regex(@"(0\d*)(0\.\d+)");
/// <summary>
/// Default implementation
/// </summary>
/// <param name="writer"></param>
/// <param name="value"></param>
/// <param name="serializer"></param>
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
serializer.Serialize(writer, value);
}
/// <summary>
/// Deserialize property value from PRTG formatted number string.
/// </summary>
/// <param name="reader"></param>
/// <param name="objectType"></param>
/// <param name="existingValue"></param>
/// <param name="serializer"></param>
/// <returns></returns>
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.None) return null;
if (reader.TokenType == JsonToken.None) return null;
var x = reader.Value as string;
if (!string.IsNullOrEmpty(x))
{
// match number format like -00000000000000014-0.5 which translates apparently to -14.5
if (NegativeMatch.IsMatch(x))
{
x = x.Remove(x.LastIndexOf("-0.", StringComparison.InvariantCultureIgnoreCase), 2);
}
// match number format like 000000000000000140.5 which translates apparently to 14.5
else if (PositiveMatch.IsMatch(x))
{
x = x.Remove(x.LastIndexOf("0.", StringComparison.InvariantCultureIgnoreCase), 1);
}
try
{
return JsonConvert.DeserializeObject(x, objectType);
}
catch (Exception ex)
{
ex.LogAsIgnored();
}
return null;
}
// default number parsing
return serializer.Deserialize(reader, objectType);
}
/// <summary>
/// Can convert any number ( value type assignable from int)
/// </summary>
/// <param name="objectType"></param>
/// <returns></returns>
public override bool CanConvert(Type objectType)
{
return objectType.IsValueType && objectType.IsAssignableFrom(typeof (int));
}
}
Add comment