Skip to content

Commit

Permalink
-Fixed a bug wherein cmdlets did not check a retry event handler had …
Browse files Browse the repository at this point in the history
…been added before attempting to remove one

-Default RetryDelay is now 0
-Implemented a check that the PassHash returned is a valid PassHash and not a system status message
  • Loading branch information
lordmilko committed Feb 15, 2017
1 parent 9b7a431 commit 8490825
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ public void PrtgClient_Constructor_RetrievesPassHash()
Assert.IsTrue(client.PassHash == "12345678");
}

[TestMethod]
[ExpectedException(typeof(PrtgRequestException))]
public void PrtgClient_Constructor_CantRetrievePassHash()
{
var webClient = new MockWebClient(new PassHashResponse("PRTG Network Monitor is starting"));

var client = new PrtgClient("prtg.example.com", "username", "password", AuthMode.Password, webClient);
}

/*private T[] CreateNullResponseItem<T>(T obj)
{
//var obj = Activator.CreateInstance(typeof (T));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@ namespace PrtgAPI.Tests.UnitTests.InfrastructureTests.Support
{
class PassHashResponse : IWebResponse
{
private string response;

public PassHashResponse(string response = "12345678")
{
this.response = response;
}

public HttpStatusCode StatusCode { get; set; }

public string GetResponseText(string address)
{
return "12345678";
return response;
}

public Task<string> GetResponseTextStream(string address)
Expand Down
2 changes: 1 addition & 1 deletion PrtgAPI/PowerShell/Base/PrtgCmdlet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private void AddEvent(Action<object, RetryRequestEventArgs> item)

private void RemoveEvent()
{
if (!retryEventRemoved)
if (!retryEventRemoved && retryEventAdded)
{
lock (lockEvents)
{
Expand Down
6 changes: 6 additions & 0 deletions PrtgAPI/PowerShell/Resources/PrtgAPI.Format.ps1xml
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,12 @@
<ListItem>
<PropertyName>PassHash</PropertyName>
</ListItem>
<ListItem>
<PropertyName>RetryCount</PropertyName>
</ListItem>
<ListItem>
<PropertyName>RetryDelay</PropertyName>
</ListItem>
</ListItems>
</ListEntry>
</ListEntries>
Expand Down
4 changes: 2 additions & 2 deletions PrtgAPI/Properties/AssemblyFileVersion.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//0
//6
//0
//13
//14
//
// This code was generated by a tool. Any changes made manually will be lost
// the next time this code is regenerated.
//

using System.Reflection;

[assembly: AssemblyFileVersion("0.6.0.13")]
[assembly: AssemblyFileVersion("0.6.0.14")]
4 changes: 0 additions & 4 deletions PrtgAPI/PrtgAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<!--<Reference Include="System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\Program Files (x86)\Reference Assemblies\Microsoft\WindowsPowerShell\3.0\System.Management.Automation.dll</HintPath>
</Reference>-->
<Reference Include="System.Management.Automation" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Web" />
Expand Down
7 changes: 5 additions & 2 deletions PrtgAPI/PrtgClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ public partial class PrtgClient
/// <summary>
/// The number of times to retry a request that times out while communicating with PRTG.
/// </summary>
public int RetryCount { get; set; } = 0;
public int RetryCount { get; set; }

/// <summary>
/// The base delay (in seconds) between retrying a timed out request. Each successive failure of a given request will wait an additional multiple of this value.
/// </summary>
public int RetryDelay { get; set; } = 1;
public int RetryDelay { get; set; }

internal EventHandler<RetryRequestEventArgs> retryRequest;

Expand Down Expand Up @@ -333,6 +333,9 @@ private string GetPassHash(string password)

var response = ExecuteRequest(JsonFunction.GetPassHash, parameters);

if(!Regex.Match(response, "^[0-9]+$").Success)
throw new PrtgRequestException($"Could not retrieve PassHash from PRTG Server. PRTG responded '{response}'");

return response;
}

Expand Down
4 changes: 0 additions & 4 deletions PrtgAPI/_Todo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ namespace PrtgAPI
Todo
----------------
//BUG: if you connect while prtg is starting your passhash might be "PRTG Network Monitor is starting"
//maybe we should verify the passhash is all digits. if not, respond with whatever message it responded with
//add a test that checks that anything that derives from prtgcmdlet does not override processrecord
Project
Expand All @@ -37,8 +35,6 @@ we can use remove-object on the root prtg object to test this
-upload our empty settings file then say dont track it
git update-index --assume-unchanged <file> and --no-assume-unchanged
-test failed pester tests generate errors in appveyor
-maybe create a "filter" alias for new-searchfilter?
-when we make a request to the ci server to do something when the core is running but the probe isnt, whats the response?
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,6 @@ C:\> Get-Sensor | Select -First 1 | Get-Channel
Name SensorId Id LastValue LimitsEnabled UpperErrorLimit LowerErrorLimit ErrorLimitMessage
---- -------- -- --------- ------------- --------------- --------------- -----------------
Downtime 3001 -4
Total 3001 0 0.32 % True 95 PANIC!! PANIC!!!
Processor 1 3001 1 <1 % False
```
Expand Down Expand Up @@ -435,7 +434,7 @@ $trigger = Get-Device | Get-NotificationTrigger *admin* -Inherited $false -Type
$parameters = $trigger | New-NotificationTriggerParameter
$parameters.Latency = 120
$parameters | Set-NotificationTrigger
$parameters | Add-NotificationTrigger
```

### Access Underlying Methods
Expand Down

0 comments on commit 8490825

Please sign in to comment.