lordmilko / PrtgAPI

C#/PowerShell interface for PRTG Network Monitor
MIT License
301 stars 37 forks source link

PrtgAPI.PrtgClient.SetChannelProperty causes exception on 'false' or "0" values #231

Closed Lao-Tuo closed 3 years ago

Lao-Tuo commented 3 years ago

Describe the bug When trying to set the property of a channel, the correct Value of the property will raise an exception.

Steps to reproduce prtgClient.SetChannelProperty(channel, ChannelProperty.ShowInGraph, false); prtgClient.SetChannelProperty(channel, ChannelProperty.ShowInTable, false);

this will also fail: prtgClient.SetChannelProperty(channel, ChannelProperty.ShowInGraph, "0"); prtgClient.SetChannelProperty(channel, ChannelProperty.ShowInTable, "0");

What is the output of Get-PrtgClient -Diagnostic?

I don't use the PowerShell module, however:

OS: Windows Server 2019 Datacenter (1809)
PRTG Version 21.3.69.1333
PrtgAPI Version: 0.9.16

Additional context Anything else I should know to help solve the issue?

System.ArgumentException: 'False' is not a valid value for type 'PrtgAPI.AutoMode'. Please specify one of 'Automatic' or 'Manual'.
   at PrtgAPI.Parameters.Helpers.TypeConversionStateMachine.ProcessEnumValue()
   at PrtgAPI.Parameters.Helpers.TypeConversionStateMachine.ProcessNonNullable()
   at PrtgAPI.Parameters.Helpers.TypeConversionStateMachine.RunMachine()
   at PrtgAPI.Parameters.Helpers.TypeConversionStateMachine.Run()
   at PrtgAPI.Parameters.Helpers.DynamicPropertyTypeParser.ParseValue(SerializationMode mode)
   at PrtgAPI.Parameters.Helpers.DynamicPropertyTypeParser.GetParameter(Func`3 nameResolver)
   at PrtgAPI.Parameters.Helpers.ObjectPropertyParser.AddValue(DynamicPropertyTypeParser parser)
   at PrtgAPI.Parameters.Helpers.ObjectPropertyParser.ParseValueAndDependents[T](Enum property, Object value, Boolean disableDependentsOnNotReqiuiredValue)
   at PrtgAPI.Parameters.SetChannelPropertyParameters..ctor(Int32[] sensorIds, Int32 channelId, ChannelParameter[] parameters)
   at PrtgAPI.Request.VersionClient.GroupChannelsForOneSensorAndMultipleChannels(ChannelParameter[] channelParameters, IGrouping`2 sensorsChannels, List`1 groupedByChannel)
   at PrtgAPI.Request.VersionClient.GroupChannelsForOneSensor(ChannelParameter[] channelParameters, IGrouping`2 sensorsChannels)
   at PrtgAPI.Request.VersionClient.GroupChannels(ICollection`1 channels, ChannelParameter[] channelParameters)
   at PrtgAPI.Request.VersionClient.SetChannelProperty(ICollection`1 channels, ChannelParameter[] params, CancellationToken token)
   at PrtgAPI.PrtgClient.SetChannelPropertyInternal(IEnumerable`1 channels, Int32[] sensorIds, Nullable`1 channelId, ChannelParameter[] parameters, CancellationToken token)
   at PrtgAPI.PrtgClient.SetChannelProperty(IEnumerable`1 channels, ChannelParameter[] parameters, CancellationToken token)
lordmilko commented 3 years ago

Hi @Lao-Tuo,

I'm having difficulty reproducing this issue; are you able to advise if this error also occurs on the channels from sensor ID 1001 (which should be the System Health sensor on the core probe, and therefore a sensor we both have that I can test with). I also notice it appears you've actually specified multiple channels to SetChannelProperty; are you able to advise if this issue also occurs if you pass only a single channel to SetChannelProperty?

Finally, are you potentially able to provide a full minimal example of how to reproduce the issue; i.e. does the following cause any issue?

var client = new PrtgClient(<redacted>);

var channel = client.GetChannel(1001, 0);

client.SetChannelProperty(channel, ChannelProperty.ShowInTable, false);
Lao-Tuo commented 3 years ago

Hi,

yes, it also happens on single Channels. The minimal sample also throws an exception - this time that false is not a color value?!?

PrtgAPI.PrtgRequestException: PRTG was unable to complete the request. The server responded with the following error: The validation of the data you entered has failed. Color (#rrggbb): False is not a valid color value. Please use #rrggbb only, as in HTML/CSS notation! The object has not been changed.
   at PrtgAPI.Request.RequestEngine.ValidateHttpResponse(HttpResponseMessage responseMessage, PrtgResponse response)
   at PrtgAPI.Request.RequestEngine.ExecuteRequest(PrtgRequestMessage request, CancellationToken token, Func`2 responseParser)
   at PrtgAPI.Request.RequestEngine.ExecuteRequest(IHtmlParameters parameters, Func`2 responseParser, CancellationToken token)
   at PrtgAPI.PrtgClient.SetObjectProperty[T](BaseSetObjectPropertyParameters`1 parameters, Int32 numObjectIds, CancellationToken token)
   at PrtgAPI.Request.VersionClient.SetChannelProperty(ICollection`1 channels, ChannelParameter[] params, CancellationToken token)
   at PrtgAPI.PrtgClient.SetChannelPropertyInternal(IEnumerable`1 channels, Int32[] sensorIds, Nullable`1 channelId, ChannelParameter[] parameters, CancellationToken token)
   at PrtgAPI.PrtgClient.SetChannelProperty(IEnumerable`1 channels, ChannelParameter[] parameters, CancellationToken token)
   at PrtgAPI.PrtgClient.SetChannelProperty(IEnumerable`1 channels, ChannelProperty property, Object value, CancellationToken token)
   at PrtgAPI.PrtgClient.SetChannelProperty(Channel channel, ChannelProperty property, Object value, CancellationToken token)

Something is very weird. I also did a fresh git clone and a fresh app for this and got the same result.

lordmilko commented 3 years ago

Hi @Lao-Tuo,

It seems to me like its interpreting ChannelProperty.ShowInTable as ChannelProperty.LineColor or something for some reason. ChannelProperty.LineColor is 2 properties after ChannelProperty.ShowInTable in ChannelProperty.cs

Are you able to advise how you installed PrtgAPI? e.g. did you install it from NuGet, download the latest manual release or did you download and compile it yourself?

Lao-Tuo commented 3 years ago

git clone & compile myself (Microsoft Visual Studio Community 2019, Version 16.10.4)

Will try the manual build and come back in a minute.

Man, I need that weekend. PrtgAPI is all fine. my own build and the manual. It's been a very very stupid Layer-8 error that I just noticed. (I am too ashamed to give details)

lordmilko commented 3 years ago

Hi @Lao-Tuo,

So it was something in your code? Or you changed the source before you compiled it? (it's important for me that people are able to easily compile PrtgAPI should they want to)

Lao-Tuo commented 3 years ago

no code change. PrtgAPI solution compiles fine. :)

my dev machine != target machine, for some reason the background copy task of release folder failed to copy the dll to the target, so new exe old dll. Manual copy solved the problem.