Skip to content

Schedules

lordmilko edited this page Aug 25, 2018 · 16 revisions

Contents

C#

Basic Requests

Schedules supported by PRTG can be retrieved via the GetSchedules method

var schedules = client.GetSchedules();

When retrieving Schedules, one or more SearchFilter objects can be specified to limit the returned results. Note however that not all Property values supported by PRTG are compatible with notification action queries. As such, if you find your specified filter does not work, you may want to filter within your application instead of within PRTG.

//Get the schedule with ID 630
var schedule = client.GetSchedules(Property.Id, 301).FirstOrDefault();

When retrieving a particular notification action you insist should exist, it is possible to use the singular GetSchedule method, returning a single Schedule rather than a List<Schedule> as with GetSchedules.

GetSchedule supports filtering by either the object name or object ID

var schedule = client.GetSchedule(300);
var schedule = client.GetSchedule("Weekdays [GMT+0800]");

If exactly one schedule with the specified ID or name is not returned, GetSchedule will throw an InvalidOperationException. If you are not sure whether exactly one schedule with the specified ID or name exists, you should use GetSchedules instead and check for the presence of any results.

var schedule = client.GetSchedules(Property.Id, 630).SingleOrDefault();

if (schedule != null)
    Console.WriteLine($"Found exactly one schedule: '{schedule}'!");

When synchronously retrieving Schedule objects via the GetSchedules method, PrtgAPI will automatically populate all enhanced object properties (including the details of each notification type - i.e. Email, SMS, Ticket, etc). When retrieving schedules via any other method (for example GetNotificationTriggers or GetNotificationActions) PrtgAPI will defer loading these properties (and invoking a web request) until these properties are actually accessed.

Schedule objects retrieved via asynchronous requests (including GetSchedulesAsync / GetNotificationActionsAsync / GetNotificationTriggersAsync) are always loaded immediately so that any secondary requests can be executed in parallel for multiple objects.

TimeTables

The weekly timetable of a Schedule can be accessed via the TimeTable property

var schedule = client.GetSchedules().First();

Console.WriteLine($"Schedule {schedule} is active at these times: {schedule.TimeTable}");

The schedule TimeTable provides a variety of different views which can be used to interrogate the times the schedule is active:

  • Indexers: retrieves the TimeSlot object(s) for a specified hour and/or day of the week
  • Rows: provides a custom view representing the days the timetable is active for a specified hour of the day. Provides a high simplified overview of the schedule.
  • Grid: provides access to the underlying cells of the TimeTable, storing the 24 hours of each day for each day of the week. Allows iteration over all levels of the timetable
// Indexers
var tuesday = timetable[DayOfWeek.Tuesday];

var wednesday1am = timetable[1, DayOfWeek.Wednesday];

var oneAM = timetable[1];
//Rows
foreach (var row in timetable.Rows)
{
    if (row.Tuesday)
        Console.WriteLine($"{row.Time} is active Tuesday");
    else
    {
        var days = row.ToString().Replace($"{row.Time} ", "");
        Console.WriteLine($"{row.Time} is not active Tuesday, but is active {days}");
    }
}
//Grid
foreach (var day in timetable.Grid)
{
    foreach (var slot in day.Value)
    {
        Console.WriteLine($"{slot.Hour} ({slot.Day}): {slot.Active}");
    }
}

PowerShell

Clone this wiki locally