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"); }
protected override IWebResponse GetResponse(string address) { switch (requestNum) { case 1: Assert.AreEqual(address, UnitRequest.Objects("filter_objid=1001")); return(new ProbeResponse(new ProbeItem(objid: "1001", name: "Local Probe"))); case 2: Assert.AreEqual(address, UnitRequest.Probes("filter_objid=1001&filter_parentid=0")); return(new ProbeResponse(new ProbeItem(objid: "1001", name: "Local Probe"))); //Probe -> Devices case 3: Assert.AreEqual(address, UnitRequest.Devices("filter_parentid=1001")); return(new DeviceResponse( new DeviceItem(objid: "3001", name: "dc-1", position: "10", positionRaw: "10"), new DeviceItem(objid: "3002", name: "dc-2", position: "20", positionRaw: "20") )); //Probe -> Groups case 4: Assert.AreEqual(address, UnitRequest.Groups("filter_parentid=1001")); return(new GroupResponse(new GroupItem(objid: "2001", name: "Servers", position: "30", positionRaw: "30"))); //Probe -> Triggers case 5: Assert.AreEqual(address, UnitRequest.Triggers(1001)); return(new NotificationTriggerResponse( NotificationTriggerItem.StateTrigger(onNotificationAction: "300|Trigger1", parentId: "1001"), NotificationTriggerItem.StateTrigger(onNotificationAction: "301|Trigger2", parentId: "1001"), NotificationTriggerItem.StateTrigger(onNotificationAction: "302|Trigger3", parentId: "1001") )); //Probe -> Devices -> Sensors case 6: Assert.AreEqual(address, UnitRequest.Sensors("filter_parentid=3001")); return(new SensorResponse( new SensorItem(name: "Sensor2", objid: "4002", position: "20", positionRaw: "20"), new SensorItem(name: "Sensor1", objid: "4001", position: "10", positionRaw: "10") )); case 7: Assert.AreEqual(address, UnitRequest.Sensors("filter_parentid=3002")); return(new SensorResponse()); //Probe -> Groups -> Devices case 8: Assert.AreEqual(address, UnitRequest.Devices("filter_parentid=2001")); return(new DeviceResponse()); //Probe -> Groups -> Groups case 9: Assert.AreEqual(address, UnitRequest.Groups("filter_parentid=2001")); return(new GroupResponse()); default: throw UnknownRequest(address); } }
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"); }
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 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"); }
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); } }
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); } }