Skip to content

Commit

Permalink
Fixed an issue wherein ErrorLimitMessage, WarningLimitMessage cannot …
Browse files Browse the repository at this point in the history
…be modified and LimitsEnabled cannot be set to true when using SetObjectProperty / Set-ChannelProperty against PRTG 18.1.38
  • Loading branch information
lordmilko committed Mar 11, 2018
1 parent 2b36abe commit 4104bcd
Show file tree
Hide file tree
Showing 26 changed files with 1,515 additions and 159 deletions.
32 changes: 31 additions & 1 deletion PrtgAPI.Tests.IntegrationTests/ActionTests/ChannelTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace PrtgAPI.Tests.IntegrationTests
Expand All @@ -9,9 +10,24 @@ public class ChannelTests : BasePrtgClientTest
{
[TestMethod]
[TestCategory("IntegrationTest")]
public void Action_Channel_SetChannelProperty_UpperErrorLimit()
public void Action_Channel_SetChannelProperty_Limits()
{
SetAndRevertChannelProperty(3000, ChannelProperty.UpperErrorLimit, c => c.UpperErrorLimit);
SetAndRevertChannelProperty(4000, ChannelProperty.LowerErrorLimit, c => c.LowerErrorLimit);
SetAndRevertChannelProperty(5000, ChannelProperty.UpperWarningLimit, c => c.UpperWarningLimit);
SetAndRevertChannelProperty(6000, ChannelProperty.LowerWarningLimit, c => c.LowerWarningLimit);
SetAndRevertChannelProperty("testMessage", ChannelProperty.ErrorLimitMessage, c => c.ErrorLimitMessage);
}

[TestMethod]
[TestCategory("IntegrationTest")]
public async Task Action_Channel_SetChannelProperty_LimitsAsync()
{
await SetAndRevertChannelPropertyAsync(3000, ChannelProperty.UpperErrorLimit, c => c.UpperErrorLimit);
await SetAndRevertChannelPropertyAsync(4000, ChannelProperty.LowerErrorLimit, c => c.LowerErrorLimit);
await SetAndRevertChannelPropertyAsync(5000, ChannelProperty.UpperWarningLimit, c => c.UpperWarningLimit);
await SetAndRevertChannelPropertyAsync(6000, ChannelProperty.LowerWarningLimit, c => c.LowerWarningLimit);
await SetAndRevertChannelPropertyAsync("testMessage", ChannelProperty.ErrorLimitMessage, c => c.ErrorLimitMessage);
}

private void SetAndRevertChannelProperty<T>(T newValue, ChannelProperty property, Func<Channel, T> getProperty)
Expand All @@ -27,5 +43,19 @@ private void SetAndRevertChannelProperty<T>(T newValue, ChannelProperty property
var finalChannel = client.GetChannels(Settings.ChannelSensor).First(c => c.Id == Settings.Channel);
AssertEx.AreEqual(getProperty(initialChannel), getProperty(finalChannel), "Channel value did not revert properly");
}

private async Task SetAndRevertChannelPropertyAsync<T>(T newValue, ChannelProperty property, Func<Channel, T> getProperty)
{
var initialChannel = (await client.GetChannelsAsync(Settings.ChannelSensor)).First(c => c.Id == Settings.Channel);
AssertEx.AreNotEqual(getProperty(initialChannel), newValue, "Initial channel value was not expected value");

await client.SetObjectPropertyAsync(Settings.ChannelSensor, Settings.Channel, property, newValue);
var newChannel = (await client.GetChannelsAsync(Settings.ChannelSensor)).First(c => c.Id == Settings.Channel);
AssertEx.AreEqual(newValue, getProperty(newChannel), "New channel value did not apply properly");

await client.SetObjectPropertyAsync(Settings.ChannelSensor, Settings.Channel, property, getProperty(initialChannel));
var finalChannel = (await client.GetChannelsAsync(Settings.ChannelSensor)).First(c => c.Id == Settings.Channel);
AssertEx.AreEqual(getProperty(initialChannel), getProperty(finalChannel), "Channel value did not revert properly");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Describe "Set-ChannelProperty_IT" {
$newValue | Should Not BeNullOrEmpty

$newValue | Should Be $value

(& $channel) | Set-ChannelProperty $property $initialValue
}

function SetChild($property, $value, $dependentProperty, $dependentValue)
Expand All @@ -47,6 +49,35 @@ Describe "Set-ChannelProperty_IT" {
(& $channel) | Set-ChannelProperty $dependentProperty $initialDependent
}

function SetLimit
{
$client = Get-PrtgClient

$c1 = & $channel

$c1.UpperErrorLimit | Assert-Equal $null -Message "Initial channel UpperErrorLimit was not null"

Invoke-WebRequest "$($client.Server)/editsettings?id=$($c1.SensorId)&limitmaxerror_$($c1.Id)=1&username=$($client.UserName)&passhash=$($client.PassHash)"

$c2 = & $channel

$c2.UpperErrorLimit | Assert-Equal 1 -Message "Initial channel UpperErrorLimit was not 1"
}

function SetValueWithLimit($property, $value)
{
SetLimit

SetValue $property $value
}

function SetChildWithLimit($property, $value, $dependentProperty, $dependentValue)
{
SetLimit

SetChild $property $value $dependentProperty $dependentValue
}

function ClearDependents($property, $value, $dependents)
{
LogTestDetail "Clearing dependents of property $property"
Expand Down Expand Up @@ -201,9 +232,14 @@ Describe "Set-ChannelProperty_IT" {
SetChild "UpperWarningLimit" 200 "LimitsEnabled" $true
SetChild "LowerErrorLimit" -200 "LimitsEnabled" $true
SetChild "LowerWarningLimit" -300 "LimitsEnabled" $true
SetChild "ErrorLimitMessage" "error! error!" "LimitsEnabled" $true
SetChild "WarningLimitMessage" "warning! warning!" "LimitsEnabled" $true
SetValue "LimitsEnabled" $true

{ SetChild "ErrorLimitMessage" "error! error!" "LimitsEnabled" $true } | Should Throw "does not have a limit value defined on it"
{ SetChild "WarningLimitMessage" "warning! warning!" "LimitsEnabled" $true } | Should Throw "does not have a limit value defined on it"
{ SetValue "LimitsEnabled" $true } | Should Throw "does not have a limit value defined on it"

SetValueWithLimit "LimitsEnabled" $true
SetChildWithLimit "ErrorLimitMessage" "error! error!" "LimitsEnabled" $true
SetChildWithLimit "WarningLimitMessage" "warning! warning!" "LimitsEnabled" $true
}

It "can set the properties of multiple in a single request" {
Expand All @@ -218,7 +254,7 @@ Describe "Set-ChannelProperty_IT" {
$channels[0].LimitsEnabled | Should Be $false
$channels[1].LimitsEnabled | Should Be $false

$channels | Set-ChannelProperty LimitsEnabled $true
$channels | Set-ChannelProperty LowerWarningLimit 20

$newChannels = $sensor | Get-Channel -Id $ids

Expand Down
Loading

0 comments on commit 4104bcd

Please sign in to comment.