Skip to content

Commit

Permalink
Add startDate parameter to PrtgClient.WatchLogs (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
lordmilko committed Mar 21, 2020
1 parent b425c16 commit ce5f677
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
10 changes: 10 additions & 0 deletions src/PrtgAPI.Tests.UnitTests/CSharp/ObjectData/LogTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@ public void Log_Watch_KeepsRequestingMoreRecords()
Assert.AreEqual(320, logs.Count);
}

[UnitTest]
[TestMethod]
public void Log_Watch_SpecifiesAStartDate()
{
Execute(
c => c.WatchLogs(startDate: new DateTime(2000, 10, 2, 12, 10, 5, DateTimeKind.Utc)).Take(1).ToList(),
UnitRequest.Logs("start=1&filter_dstart=2000-10-02-12-10-05")
);
}

[UnitTest]
[TestMethod]
public void Log_Watch_StopsWhenCallbackReturnsFalse()
Expand Down
3 changes: 2 additions & 1 deletion src/PrtgAPI/Linq/InfiniteLogGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ public InfiniteLogGenerator(
Func<LogParameters, CancellationToken, IEnumerable<Log>> getLogs,
int? objectId, LogStatus[] status,
int interval,
DateTime? startDate,
Func<int, bool> progressCallback,
CancellationToken token,
Func<IEnumerable<Log>, IEnumerable<Log>> postProcessor = null
) : this(getLogs, new LogParameters(objectId, null, DateTime.Now, null, status), interval, progressCallback, token, postProcessor)
) : this(getLogs, new LogParameters(objectId, null, startDate ?? DateTime.Now, null, status), interval, progressCallback, token, postProcessor)
{
}

Expand Down
10 changes: 6 additions & 4 deletions src/PrtgAPI/Request/PrtgClient.Methods.Generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1906,12 +1906,13 @@ public IQueryable<Log> QueryLogs(Expression<Func<Log, bool>> predicate, bool str
/// </summary>
/// <param name="status">Log event types to retrieve records for. If no types are specified, all record types will be retrieved.</param>
/// <param name="interval">Interval (in seconds) with which PrtgAPI should poll for new logs.</param>
/// <param name="startDate">Start date closest to now to begin streaming logs from. Specifying a value before now will show earlier logs that have already occurred. If this value is null, logs will be retrieved from the current date and time.</param>
/// <param name="progressCallback">Callback used to indicate how many records have been retrieved and whether to abort retrieving records.
/// Called between each polling attempt. Takes the number of records retrieved so far as an argument. If this method returns false, streaming will abort.</param>
/// <param name="token">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <returns>All logs that meet the specified criteria between the first log retrieved and when streaming is ended.</returns>
public IEnumerable<Log> WatchLogs(LogStatus[] status = null, int interval = 1, Func<int, bool> progressCallback = null, CancellationToken token = default(CancellationToken)) =>
new InfiniteLogGenerator(GetLogs, null, status, interval, progressCallback, token);
public IEnumerable<Log> WatchLogs(LogStatus[] status = null, int interval = 1, DateTime? startDate = null, Func<int, bool> progressCallback = null, CancellationToken token = default(CancellationToken)) =>
new InfiniteLogGenerator(GetLogs, null, status, interval, startDate, progressCallback, token);

/// <summary>
/// Continuously streams logs for a specified object from a PRTG Server. This method will not end until you stop requesting items from it,
Expand All @@ -1921,12 +1922,13 @@ public IQueryable<Log> QueryLogs(Expression<Func<Log, bool>> predicate, bool str
/// <param name="objectOrId">The object or ID of the object to retrieve logs for.</param>
/// <param name="status">Log event types to retrieve records for. If no types are specified, all record types will be retrieved.</param>
/// <param name="interval">Interval (in seconds) with which PrtgAPI should poll for new logs.</param>
/// <param name="startDate">Start date closest to now to begin streaming logs from. Specifying a value before now will show earlier logs that have already occurred. If this value is null, logs will be retrieved from the current date and time.</param>
/// <param name="progressCallback">Callback used to indicate how many records have been retrieved and whether to abort retrieving records.
/// Called between each polling attempt. Takes the number of records retrieved so far as an argument. If this method returns false, streaming will abort.</param>
/// <param name="token">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <returns>All logs that meet the specified criteria between the first log retrieved and when streaming is ended.</returns>
public IEnumerable<Log> WatchLogs(Either<IPrtgObject, int> objectOrId, LogStatus[] status = null, int interval = 1, Func<int, bool> progressCallback = null, CancellationToken token = default(CancellationToken)) =>
new InfiniteLogGenerator(GetLogs, objectOrId.GetId(), status, interval, progressCallback, token);
public IEnumerable<Log> WatchLogs(Either<IPrtgObject, int> objectOrId, LogStatus[] status = null, int interval = 1, DateTime? startDate = null, Func<int, bool> progressCallback = null, CancellationToken token = default(CancellationToken)) =>
new InfiniteLogGenerator(GetLogs, objectOrId.GetId(), status, interval, startDate, progressCallback, token);

#endregion
#region Parameters
Expand Down
6 changes: 4 additions & 2 deletions src/PrtgAPI/Request/PrtgClient.Methods.xml
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,12 @@

<Parameter name="status" type="LogStatus[]" default="null" description="Log event types to retrieve records for. If no types are specified, all record types will be retrieved."/>
<Parameter name="interval" type="int" default="1" description="Interval (in seconds) with which PrtgAPI should poll for new logs."/>
<Parameter name="startDate" type="DateTime?" default="null" description="Start date closest to now to begin streaming logs from. Specifying a value before now will show earlier logs that have already occurred. If this value is null, logs will be retrieved from the current date and time."/>
<Parameter name="progressCallback" type="Func&lt;int, bool&gt;" default="null" description="Callback used to indicate how many records have been retrieved and whether to abort retrieving records.\nCalled between each polling attempt. Takes the number of records retrieved so far as an argument. If this method returns false, streaming will abort."/>
<Parameter name="token" type="CancellationToken" default="default(CancellationToken)" description="A cancellation token that can be used by other objects or threads to receive notice of cancellation."/>

<Body expression="true">
new InfiniteLogGenerator(GetLogs, null, status, interval, progressCallback, token)
new InfiniteLogGenerator(GetLogs, null, status, interval, startDate, progressCallback, token)
</Body>
</MethodDef>
<MethodDef name="Watch{Name}s" returns="IEnumerable&lt;Log&gt;" needsAsync="false">
Expand All @@ -374,11 +375,12 @@
<Parameter name="objectOrId" type="Either&lt;IPrtgObject, int&gt;" description="The object or ID of the object to retrieve logs for."/>
<Parameter name="status" type="LogStatus[]" default="null" description="Log event types to retrieve records for. If no types are specified, all record types will be retrieved."/>
<Parameter name="interval" type="int" default="1" description="Interval (in seconds) with which PrtgAPI should poll for new logs."/>
<Parameter name="startDate" type="DateTime?" default="null" description="Start date closest to now to begin streaming logs from. Specifying a value before now will show earlier logs that have already occurred. If this value is null, logs will be retrieved from the current date and time."/>
<Parameter name="progressCallback" type="Func&lt;int, bool&gt;" default="null" description="Callback used to indicate how many records have been retrieved and whether to abort retrieving records.\nCalled between each polling attempt. Takes the number of records retrieved so far as an argument. If this method returns false, streaming will abort."/>
<Parameter name="token" type="CancellationToken" default="default(CancellationToken)" description="A cancellation token that can be used by other objects or threads to receive notice of cancellation."/>

<Body expression="true">
new InfiniteLogGenerator(GetLogs, objectOrId.GetId(), status, interval, progressCallback, token)
new InfiniteLogGenerator(GetLogs, objectOrId.GetId(), status, interval, startDate, progressCallback, token)
</Body>
</MethodDef>
</Region>
Expand Down

0 comments on commit ce5f677

Please sign in to comment.