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");
        }
Пример #2
0
        protected override IWebResponse GetResponse(string address)
        {
            switch (requestNum)
            {
            case 1:
                Assert.AreEqual(UnitRequest.Objects("filter_objid=1001"), address);
                return(new ProbeResponse(new ProbeItem(objid: "1001")));

            case 2:
                Assert.AreEqual(UnitRequest.Probes("filter_objid=1001&filter_parentid=0"), address);
                return(new ProbeResponse(new ProbeItem(objid: "1001", notifiesx: "Inherited 1 State")));

            case 3:
                Assert.AreEqual(UnitRequest.Triggers(1001), address);
                return(new NotificationTriggerResponse(NotificationTriggerItem.StateTrigger(parentId: "1001")));

            case 4:
                if (!async)
                {
                    goto default;
                }
                Assert.AreEqual(UnitRequest.Notifications("filter_objid=301"), address);
                return(new NotificationActionResponse(new NotificationActionItem()));

            case 5:
                if (!async)
                {
                    goto default;
                }
                Assert.AreEqual(UnitRequest.NotificationProperties(301), address);
                return(new NotificationActionResponse(new NotificationActionItem()));

            case 6:
                if (!async)
                {
                    goto default;
                }
                Assert.AreEqual(UnitRequest.Schedules(), address);
                return(new ScheduleResponse(new ScheduleItem()));

            case 7:
                if (!async)
                {
                    goto default;
                }
                Assert.AreEqual(UnitRequest.ScheduleProperties(623), address);
                return(new ScheduleResponse(new ScheduleItem()));

            default:
                throw UnknownRequest(address);
            }
        }
        public async Task NotificationAction_FiltersByPropertyAsync()
        {
            var urls = new[]
            {
                UnitRequest.Notifications("filter_name=ticket"),
                UnitRequest.NotificationProperties(300),
                UnitRequest.Schedules("filter_objid=623"),
                UnitRequest.ScheduleProperties(623)
            };

            var countOverride = new Dictionary <Content, int>
            {
                [Content.Notifications] = 1,
                [Content.Schedules]     = 1
            };

            await ExecuteAsync(
                async c => await c.GetNotificationActionsAsync(Property.Name, "ticket"),
                urls,
                countOverride,
                additionalItems : r => r.HasSchedule = new[] { 300 }
                );
        }
        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");
        }
Пример #6
0
        protected override IWebResponse GetResponse(string address)
        {
            switch (requestNum)
            {
            case 1:
                Assert.AreEqual(UnitRequest.Probes("filter_parentid=0"), address);
                return(new ProbeResponse(new ProbeItem(objid: "1001", groupnum: "2", groupnumRaw: "2", devicenum: "3", devicenumRaw: "3")));

            case 2:
                Assert.AreEqual(UnitRequest.Groups(), address);
                return(new GroupResponse(
                           new GroupItem(objid: "0", parentId: "-1000", name: "Root"),
                           new GroupItem(objid: "2001", parentId: "1001", groupnum: "1", groupnumRaw: "1", devicenum: "2", devicenumRaw: "2"),
                           new GroupItem(objid: "2002", parentId: "2001", name: "VMware", groupnum: "0", groupnumRaw: "0", devicenum: "1", devicenumRaw: "1")
                           ));

            case 3:
                Assert.AreEqual(UnitRequest.Devices(), address);
                return(new DeviceResponse(
                           new DeviceItem(objid: "3001", parentId: "1001", totalsens: "2", totalsensRaw: "2"),
                           new DeviceItem(objid: "3002", parentId: "2001", totalsens: "2", totalsensRaw: "2"),
                           new DeviceItem(objid: "3003", parentId: "2002", totalsens: "2", totalsensRaw: "2")
                           ));

            case 4:
                Assert.AreEqual(UnitRequest.Sensors(), address);
                return(new SensorResponse(
                           new SensorItem(objid: "4001", parentId: "3001"),
                           new SensorItem(objid: "4002", parentId: "3002"),
                           new SensorItem(objid: "4003", parentId: "3003")
                           ));

            case 5:
                Assert.AreEqual(UnitRequest.Triggers(1001), address);
                return(new NotificationTriggerResponse(NotificationTriggerItem.StateTrigger(parentId: "1001")));

            case 6:
                if (!async)
                {
                    goto default;
                }
                Assert.AreEqual(UnitRequest.Notifications("filter_objid=301"), address);
                return(new NotificationActionResponse(new NotificationActionItem()));

            case 7:
                if (!async)
                {
                    goto default;
                }
                Assert.AreEqual(UnitRequest.NotificationProperties(301), address);
                return(new NotificationActionResponse(new NotificationActionItem()));

            case 8:
                if (!async)
                {
                    goto default;
                }
                Assert.AreEqual(UnitRequest.Schedules(), address);
                return(new ScheduleResponse(new ScheduleItem()));

            case 9:
                if (!async)
                {
                    goto default;
                }
                Assert.AreEqual(UnitRequest.ScheduleProperties(623), address);
                return(new ScheduleResponse(new ScheduleItem()));

            default:
                throw UnknownRequest(address);
            }
        }
Пример #7
0
        protected override IWebResponse GetResponse(string address)
        {
            switch (requestNum)
            {
            case 1:     //Resolve Object
                Assert.AreEqual(UnitRequest.Objects("filter_objid=1001"), address);
                return(new ProbeResponse(new ProbeItem(objid: "1001", groupnum: "2", groupnumRaw: "2", devicenum: "3", devicenumRaw: "3")));

            case 2:     //Probes
                Assert.AreEqual(UnitRequest.Probes("filter_objid=1001&filter_parentid=0"), address);
                return(new ProbeResponse(new ProbeItem(objid: "1001", groupnum: "2", groupnumRaw: "2", devicenum: "3", devicenumRaw: "3", notifiesx: "Inherited 1 State")));

            case 3:     //Probe -> Device
                Assert.AreEqual(UnitRequest.Devices("filter_parentid=1001"), address);
                return(new DeviceResponse(new DeviceItem(objid: "3001", totalsens: "2", totalsensRaw: "2")));

            case 4:     //Probe -> Group
                Assert.AreEqual(UnitRequest.Groups("filter_parentid=1001"), address);
                return(new GroupResponse(new GroupItem(objid: "2001", groupnum: "1", groupnumRaw: "1", devicenum: "2", devicenumRaw: "2")));

            case 5:     //Probe -> Device -> Sensor
                Assert.AreEqual(UnitRequest.Sensors("filter_parentid=3001"), address);
                return(new SensorResponse(new SensorItem(objid: "4001")));

            case 6:     //Probe -> Group -> Device
                Assert.AreEqual(UnitRequest.Devices("filter_parentid=2001"), address);
                return(new DeviceResponse(new DeviceItem(objid: "3002", totalsens: "2", totalsensRaw: "2")));

            case 7:     //Probe -> Group -> Group
                Assert.AreEqual(UnitRequest.Groups("filter_parentid=2001"), address);
                return(new GroupResponse(new GroupItem(objid: "2002", name: "VMware", groupnum: "0", groupnumRaw: "0", devicenum: "1", devicenumRaw: "1")));

            case 8:     //Probe -> Group -> Device -> Sensor
                Assert.AreEqual(UnitRequest.Sensors("filter_parentid=3002"), address);
                return(new SensorResponse(new SensorItem(objid: "4002")));

            case 9:     //Probe -> Group -> Group -> Device
                Assert.AreEqual(UnitRequest.Devices("filter_parentid=2002"), address);
                return(new DeviceResponse(new DeviceItem(objid: "3003", totalsens: "2", totalsensRaw: "2")));

            case 10:     //Probe -> Group -> Group -> Sensor
                Assert.AreEqual(UnitRequest.Sensors("filter_parentid=3003"), address);
                return(new SensorResponse(new SensorItem(objid: "4003")));

            case 11:
                Assert.AreEqual(UnitRequest.Triggers(1001), address);
                return(new NotificationTriggerResponse(NotificationTriggerItem.StateTrigger(parentId: "1001")));

            case 12:
                if (!async)
                {
                    goto default;
                }
                Assert.AreEqual(UnitRequest.Notifications("filter_objid=301"), address);
                return(new NotificationActionResponse(new NotificationActionItem()));

            case 13:
                if (!async)
                {
                    goto default;
                }
                Assert.AreEqual(UnitRequest.NotificationProperties(301), address);
                return(new NotificationActionResponse(new NotificationActionItem()));

            case 14:
                if (!async)
                {
                    goto default;
                }
                Assert.AreEqual(UnitRequest.Schedules(), address);
                return(new ScheduleResponse(new ScheduleItem()));

            case 15:
                if (!async)
                {
                    goto default;
                }
                Assert.AreEqual(UnitRequest.ScheduleProperties(623), address);
                return(new ScheduleResponse(new ScheduleItem()));

            default:
                throw UnknownRequest(address);
            }
        }