Ejemplo n.º 1
0
        public void NotificationTrigger_LoadsAction_Lazy()
        {
            var client = Initialize_Client(new NotificationTriggerResponse(NotificationTriggerItem.StateTrigger(offNotificationAction: "302|Email to all members of group PRTG Administrator")));

            var validator = new EventValidator <string>(new[]
            {
                //First - get all triggers
                "https://prtg.example.com/api/table.xml?id=1001&content=triggers&columns=content,objid&username=username&passhash=12345678",

                //Second - touch a trigger's action's unsupported property
                "https://prtg.example.com/api/table.xml?content=notifications&columns=objid,name,baselink,tags,type,active,basetype&count=*&filter_objid=301&filter_objid=302&username=username&passhash=12345678",
                "https://prtg.example.com/controls/objectdata.htm?id=301&objecttype=notification&username=username&passhash=12345678",

                //Third - touch an unsupported property of another action
                "https://prtg.example.com/controls/objectdata.htm?id=302&objecttype=notification&username=username&passhash=12345678"
            });

            client.LogVerbose += (s, e) =>
            {
                var message = Regex.Replace(e.Message, "(.+ request )(.+)", "$2");

                Assert.AreEqual(validator.Get(message), message);
            };

            validator.MoveNext();
            var triggers = client.GetNotificationTriggers(1001);

            validator.MoveNext(2);
            var val = triggers.First().OnNotificationAction.Postpone;

            validator.MoveNext();
            var val2 = triggers.First().OffNotificationAction.Postpone;

            Assert.IsTrue(validator.Finished, "Did not process all requests");
        }
        public void NotificationTrigger_LoadsAction_Lazy()
        {
            var client = Initialize_Client(new NotificationTriggerResponse(NotificationTriggerItem.StateTrigger(offNotificationAction: "302|Email to all members of group PRTG Administrator")));

            var validator = new EventValidator <string>(new[]
            {
                //First - get all triggers
                UnitRequest.Triggers(1001),

                //Second - touch a trigger's action's unsupported property
                UnitRequest.Notifications("filter_objid=301&filter_objid=302"),
                UnitRequest.NotificationProperties(301),

                //Third - touch an unsupported property of another action
                UnitRequest.NotificationProperties(302)
            });

            client.LogVerbose += (s, e) =>
            {
                var message = Regex.Replace(e.Message, "(.+ request )(.+)", "$2");

                Assert.AreEqual(validator.Get(message), message);
            };

            validator.MoveNext();
            var triggers = client.GetNotificationTriggers(1001);

            validator.MoveNext(2);
            var val = triggers.First().OnNotificationAction.Postpone;

            validator.MoveNext();
            var val2 = triggers.First().OffNotificationAction.Postpone;

            Assert.IsTrue(validator.Finished, "Did not process all requests");
        }
Ejemplo n.º 3
0
        public async Task NotificationTrigger_LoadsSchedule_LazyAsync()
        {
            var client = Initialize_Client(new NotificationTriggerResponse(
                                               NotificationTriggerItem.StateTrigger(offNotificationAction: "302|Email to all members of group PRTG Administrator"),
                                               NotificationTriggerItem.ChangeTrigger("303|Ticket Notification"))
            {
                HasSchedule = new[] { 301, 302, 303 }
            }
                                           );

            var validator = new EventValidator <string>(new[]
            {
                //First - get all triggers. Automatically retrieves all notifications, and their properties.
                //All of the schedules of the notifications are retrieved, as well as each schedule's properties
                "https://prtg.example.com/api/table.xml?id=1001&content=triggers&columns=content,objid&username=username&passhash=12345678",

                "https://prtg.example.com/api/table.xml?content=notifications&columns=objid,name,baselink,tags,type,active,basetype&count=*&filter_objid=301&filter_objid=302&filter_objid=303&username=username&passhash=12345678",
                "https://prtg.example.com/controls/objectdata.htm?id=301&objecttype=notification&username=username&passhash=12345678",
                "https://prtg.example.com/controls/objectdata.htm?id=302&objecttype=notification&username=username&passhash=12345678",
                "https://prtg.example.com/controls/objectdata.htm?id=303&objecttype=notification&username=username&passhash=12345678",

                "https://prtg.example.com/api/table.xml?content=schedules&columns=objid,name,baselink,tags,type,active,basetype&count=*&filter_objid=623&username=username&passhash=12345678",
                "https://prtg.example.com/controls/objectdata.htm?id=623&objecttype=schedule&username=username&passhash=12345678",
            });

            client.LogVerbose += (s, e) =>
            {
                var message = Regex.Replace(e.Message, "(.+ request )(.+)", "$2");

                Assert.AreEqual(validator.Get(message), message);
            };

            validator.MoveNext(7);
            var triggers = await client.GetNotificationTriggersAsync(1001);

            var val = triggers.First().OnNotificationAction.Schedule;

            var val2 = triggers.First().OffNotificationAction.Schedule;

            var val3 = triggers.First().EscalationNotificationAction.Schedule; //should be action "None"

            Assert.AreEqual(null, val3);

            var trueVal3 = triggers.Skip(1).First().OnNotificationAction.Schedule;

            var firstAgain     = triggers.First().OnNotificationAction.Schedule;
            var secondAgain    = triggers.First().OffNotificationAction.Schedule;
            var thirdFakeAgain = triggers.First().EscalationNotificationAction.Schedule;
            var thirdRealAgain = triggers.Skip(1).First().OnNotificationAction.Schedule;

            Assert.IsTrue(validator.Finished, "Did not process all requests");

            Assert.IsTrue(validator.Finished, "Did not process all requests");
        }
        public async Task NotificationTrigger_LoadsSchedule_LazyAsync()
        {
            var client = Initialize_Client(new NotificationTriggerResponse(
                                               NotificationTriggerItem.StateTrigger(offNotificationAction: "302|Email to all members of group PRTG Administrator"),
                                               NotificationTriggerItem.ChangeTrigger("303|Ticket Notification"))
            {
                HasSchedule = new[] { 301, 302, 303 }
            }
                                           );

            var validator = new EventValidator <string>(new[]
            {
                //First - get all triggers. Automatically retrieves all notifications, and their properties.
                //All of the schedules of the notifications are retrieved, as well as each schedule's properties
                UnitRequest.Triggers(1001),

                UnitRequest.Notifications("filter_objid=301&filter_objid=302&filter_objid=303"),
                UnitRequest.NotificationProperties(301),
                UnitRequest.NotificationProperties(302),
                UnitRequest.NotificationProperties(303),

                UnitRequest.Schedules("filter_objid=623"),
                UnitRequest.ScheduleProperties(623),
            });

            client.LogVerbose += (s, e) =>
            {
                var message = Regex.Replace(e.Message, "(.+ request )(.+)", "$2");

                Assert.AreEqual(validator.Get(message), message);
            };

            validator.MoveNext(7);
            var triggers = await client.GetNotificationTriggersAsync(1001);

            var val = triggers.First().OnNotificationAction.Schedule;

            var val2 = triggers.First().OffNotificationAction.Schedule;

            var val3 = triggers.First().EscalationNotificationAction.Schedule; //should be action "None"

            Assert.AreEqual(null, val3);

            var trueVal3 = triggers.Skip(1).First().OnNotificationAction.Schedule;

            var firstAgain     = triggers.First().OnNotificationAction.Schedule;
            var secondAgain    = triggers.First().OffNotificationAction.Schedule;
            var thirdFakeAgain = triggers.First().EscalationNotificationAction.Schedule;
            var thirdRealAgain = triggers.Skip(1).First().OnNotificationAction.Schedule;

            Assert.IsTrue(validator.Finished, "Did not process all requests");

            Assert.IsTrue(validator.Finished, "Did not process all requests");
        }
Ejemplo n.º 5
0
        public async Task NotificationTrigger_LoadsAction_Efficiently_WhenAsync()
        {
            var client = Initialize_Client(new NotificationTriggerResponse(
                                               NotificationTriggerItem.StateTrigger(offNotificationAction: "302|Email to all members of group PRTG Administrator")
                                               )
            {
                HasSchedule = new[] { 302 }
            });

            var validator = new EventValidator <string>(new[]
            {
                //First
                "https://prtg.example.com/api/table.xml?id=1001&content=triggers&columns=content,objid&username=username&passhash=12345678",
                "https://prtg.example.com/api/table.xml?content=notifications&columns=objid,name,baselink,tags,type,active,basetype&count=*&filter_objid=301&filter_objid=302&username=username&passhash=12345678",
                "https://prtg.example.com/controls/objectdata.htm?id=301&objecttype=notification&username=username&passhash=12345678",
                "https://prtg.example.com/controls/objectdata.htm?id=302&objecttype=notification&username=username&passhash=12345678",
                "https://prtg.example.com/api/table.xml?content=schedules&columns=objid,name,baselink,tags,type,active,basetype&count=*&filter_objid=623&username=username&passhash=12345678",
                "https://prtg.example.com/controls/objectdata.htm?id=623&objecttype=schedule&username=username&passhash=12345678"
            });

            client.LogVerbose += (s, e) =>
            {
                var message = Regex.Replace(e.Message, "(.+ request )(.+)", "$2");

                Assert.AreEqual(validator.Get(message), message);
            };

            validator.MoveNext(6);
            var triggers = await client.GetNotificationTriggersAsync(1001);

            var val = triggers.First().OnNotificationAction.Postpone;

            Assert.AreEqual("Weekdays [GMT+0800]", triggers.First().OffNotificationAction.Schedule.Name);

            Assert.IsTrue(validator.Finished, "Did not process all requests");
        }
        public async Task NotificationTrigger_LoadsAction_Efficiently_WhenAsync()
        {
            var client = Initialize_Client(new NotificationTriggerResponse(
                                               NotificationTriggerItem.StateTrigger(offNotificationAction: "302|Email to all members of group PRTG Administrator")
                                               )
            {
                HasSchedule = new[] { 302 }
            });

            var validator = new EventValidator <string>(new[]
            {
                //First
                UnitRequest.Triggers(1001),
                UnitRequest.Notifications("filter_objid=301&filter_objid=302"),
                UnitRequest.NotificationProperties(301),
                UnitRequest.NotificationProperties(302),
                UnitRequest.Schedules("filter_objid=623"),
                UnitRequest.ScheduleProperties(623)
            });

            client.LogVerbose += (s, e) =>
            {
                var message = Regex.Replace(e.Message, "(.+ request )(.+)", "$2");

                Assert.AreEqual(validator.Get(message), message);
            };

            validator.MoveNext(6);
            var triggers = await client.GetNotificationTriggersAsync(1001);

            var val = triggers.First().OnNotificationAction.Postpone;

            Assert.AreEqual("Weekdays [GMT+0800]", triggers.First().OffNotificationAction.Schedule.Name);

            Assert.IsTrue(validator.Finished, "Did not process all requests");
        }
        public void NotificationTrigger_LoadsSchedule_Lazy()
        {
            var client = Initialize_Client(new NotificationTriggerResponse(
                                               NotificationTriggerItem.StateTrigger(offNotificationAction: "302|Email to all members of group PRTG Administrator"),
                                               NotificationTriggerItem.ChangeTrigger("303|Ticket Notification"))
            {
                HasSchedule = new[] { 301, 302, 303 }
            }
                                           );

            var validator = new EventValidator <string>(new[]
            {
                //First - get all triggers
                UnitRequest.Triggers(1001),

                //Second - touch a trigger's action's schedule
                UnitRequest.Notifications("filter_objid=301&filter_objid=302&filter_objid=303"),
                UnitRequest.NotificationProperties(301),
                UnitRequest.Schedules("filter_objid=623"),
                UnitRequest.ScheduleProperties(623),

                //Third - touch the same schedule on another action
                UnitRequest.NotificationProperties(302),
                UnitRequest.Schedules("filter_objid=623"),
                UnitRequest.ScheduleProperties(623),

                //Fourth - touch a different schedule on another action
                UnitRequest.NotificationProperties(303),
                UnitRequest.Schedules("filter_objid=623"),
                UnitRequest.ScheduleProperties(623),
            });

            client.LogVerbose += (s, e) =>
            {
                var message = Regex.Replace(e.Message, "(.+ request )(.+)", "$2");

                Assert.AreEqual(validator.Get(message), message);
            };

            validator.MoveNext();
            var triggers = client.GetNotificationTriggers(1001);

            validator.MoveNext(4);
            var val = triggers.First().OnNotificationAction.Schedule;

            validator.MoveNext(3);
            var val2 = triggers.First().OffNotificationAction.Schedule;

            var val3 = triggers.First().EscalationNotificationAction.Schedule; //should be action "None"

            Assert.AreEqual(null, val3);

            validator.MoveNext(3);
            var trueVal3 = triggers.Skip(1).First().OnNotificationAction.Schedule;

            var firstAgain     = triggers.First().OnNotificationAction.Schedule;
            var secondAgain    = triggers.First().OffNotificationAction.Schedule;
            var thirdFakeAgain = triggers.First().EscalationNotificationAction.Schedule;
            var thirdRealAgain = triggers.Skip(1).First().OnNotificationAction.Schedule;

            Assert.IsTrue(validator.Finished, "Did not process all requests");
        }