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"); }
private IWebResponse GetTableResponse(string address) { var components = UrlHelpers.CrackUrl(address); Content content = components["content"].ToEnum <Content>(); switch (content) { case Content.Sensors: if (components["filter_objid"] == "1") { return(new SensorResponse()); } if (countOverride != null && countOverride[Content.Sensors] == 0) { return(new SensorResponse()); } return(new SensorResponse(new SensorItem())); case Content.Channels: return(new ChannelResponse(new ChannelItem())); case Content.Triggers: return(new NotificationTriggerResponse(NotificationTriggerItem.StateTrigger())); case Content.Notifications: return(new NotificationActionResponse(new NotificationActionItem("301"))); default: throw new NotImplementedException($"Unknown content '{content}' requested from {nameof(SetNotificationTriggerResponse)}"); } }
public async Task SetTriggerProperty_ChannelAsync() { var triggerItem = NotificationTriggerItem.ThresholdTrigger(channel: "Backup State", parentId: "4000"); var channelItem = new ChannelItem(name: "Backup State"); var response = new NotificationTriggerResponse(new[] { triggerItem }, new[] { channelItem }); var client = Initialize_Client(response); var trigger = client.GetNotificationTriggers(4000).First(t => t.Type == TriggerType.Threshold); await ExecuteAsync( async c => { var channel = await c.GetChannelAsync(4000, 1); await c.SetTriggerPropertyAsync(trigger, TriggerProperty.Channel, channel); }, new[] { UnitRequest.Channels(4000), UnitRequest.ChannelProperties(4000, 1), UnitRequest.Sensors("filter_objid=4000"), UnitRequest.Channels(4000), UnitRequest.ChannelProperties(4000, 1), UnitRequest.EditSettings("id=4000&subid=7&channel_7=1") } ); }
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"); }
public async Task NotificationTrigger_LoadsAction_Efficiently() { 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 "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=baselink,type,tags,active,objid,name&count=*&filter_objid=301&filter_objid=302&username=username&passhash=12345678", "https://prtg.example.com/controls/editnotification.htm?id=301&username=username&passhash=12345678", "https://prtg.example.com/controls/editnotification.htm?id=302&username=username&passhash=12345678" }); client.LogVerbose += (s, e) => { var message = Regex.Replace(e.Message, "(.+ request )(.+)", "$2"); Assert.AreEqual(validator.Get(message), message); }; validator.MoveNext(4); var triggers = await client.GetNotificationTriggersAsync(1001); var val = triggers.First().OnNotificationAction.Postpone; Assert.IsTrue(validator.Finished, "Did not process all requests"); }
public void Tree_Factory_AllTypes_Single() { var client = BaseTest.Initialize_Client(new MultiTypeResponse()); var factory = new PrtgNodeFactory(client); var node = factory.Probe(1000, factory.Group(2000, factory.Device(3000, factory.Sensor(4000, factory.Property(3000, ObjectProperty.Name) ) ) ) ); var response = new NotificationTriggerResponse( NotificationTriggerItem.StateTrigger(parentId: "3000"), NotificationTriggerItem.SpeedTrigger(parentId: "3000") ); var triggerClient = BaseTest.Initialize_Client(response); var triggerFactory = new PrtgNodeFactory(triggerClient); Assert.IsNotNull(triggerFactory.Trigger(3000, "Email and push notification to admin")); }
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 TriggerTranslation(NotificationTriggerItem englishXml, NotificationTriggerItem japaneseXml, NotificationTriggerJsonItem englishJson, NotificationTriggerJsonItem japaneseJson) { EnglishXml = englishXml; JapaneseXml = japaneseXml; EnglishJson = englishJson; JapaneseJson = japaneseJson; }
public async Task NotificationTrigger_Throws_WhenChannelCantBeResolvedAsync() { var client = Initialize_Client(new NotificationTriggerResponse(NotificationTriggerItem.ThresholdTrigger(channel: "Backup State"))); await AssertEx.ThrowsAsync <InvalidStateException>( async() => (await client.GetNotificationTriggersAsync(1001)).First(), "Object may be in a corrupted state" ); }
public void NotificationTrigger_Throws_WhenChannelCantBeResolved() { var client = Initialize_Client(new NotificationTriggerResponse(NotificationTriggerItem.ThresholdTrigger(channel: "Backup State"))); AssertEx.Throws <InvalidStateException>( () => client.GetNotificationTriggers(1001).First(), "Object may be in a corrupted state" ); }
public async Task NotificationTrigger_CanRemoveAsync() { var triggerClient = Initialize_Client(new NotificationTriggerResponse(NotificationTriggerItem.StateTrigger())); var trigger = (await triggerClient.GetNotificationTriggersAsync(0)).First(); var client = Initialize_Client(new AddressValidatorResponse("deletesub.htm?id=0&subid=1")); await client.RemoveNotificationTriggerAsync(trigger); }
private PrtgClient GetCustomClient(MethodInfo method, PrtgClient defaultClient) { if (method.Name == "GetNotificationTriggers" || method.Name == "GetNotificationTriggersAsync") { return(BaseTest.Initialize_Client(new NotificationTriggerResponse(NotificationTriggerItem.StateTrigger()))); } return(defaultClient); }
public void NotificationTrigger_CanRemove() { var triggerClient = Initialize_Client(new NotificationTriggerResponse(NotificationTriggerItem.StateTrigger())); var trigger = triggerClient.GetNotificationTriggers(0).First(); var client = Initialize_Client(new AddressValidatorResponse("deletesub.htm?id=0&subid=1")); client.RemoveNotificationTrigger(trigger); }
public void NotificationTrigger_LoadsAction_Lazy_AllPropertiesAreSet() { var client = Initialize_Client(new NotificationTriggerResponse(NotificationTriggerItem.StateTrigger(offNotificationAction: "302|Email to all members of group PRTG Administrator"))); var triggers = client.GetNotificationTriggers(1001); var val = triggers.First().OnNotificationAction; AssertEx.AllPropertiesAreNotDefault(val); }
private PrtgClient GetResolvesASensorChannelResponseClient() { var notificationItem = NotificationTriggerItem.ThresholdTrigger(channel: "Backup State"); var channelItem = new ChannelItem(name: "Backup State"); var client = Initialize_Client(new NotificationTriggerResponse(new[] { notificationItem }, new[] { channelItem })); return(client); }
public void NotificationTrigger_CanRemove() { var triggerClient = Initialize_Client(new NotificationTriggerResponse(NotificationTriggerItem.StateTrigger())); var trigger = triggerClient.GetNotificationTriggers(0).First(); Execute( c => c.RemoveNotificationTrigger(trigger), "deletesub.htm?id=0&subid=1" ); }
private NotificationTrigger GetTrigger() { var notificationItem = NotificationTriggerItem.ThresholdTrigger(channel: "Primary"); var client = Initialize_Client(new NotificationTriggerResponse(new[] { notificationItem })); var trigger = client.GetNotificationTriggers(1).First(t => t.Type == TriggerType.Threshold); return(trigger); }
public async Task NotificationTrigger_CanRemoveAsync() { var triggerClient = Initialize_Client(new NotificationTriggerResponse(NotificationTriggerItem.StateTrigger())); var trigger = (await triggerClient.GetNotificationTriggersAsync(0)).First(); await ExecuteAsync( async c => await c.RemoveNotificationTriggerAsync(trigger), "deletesub.htm?id=0&subid=1" ); }
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"); }
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); } }
private IWebResponse GetTableResponse(string address) { var content = GetContent(address); if (content == Content.Sensors) { return(new SensorResponse()); } if (content == Content.Triggers) { return(new NotificationTriggerResponse(NotificationTriggerItem.StateTrigger(parentId: "5678"))); } else { throw new NotSupportedException($"Content type {content} is not supported by {nameof(CloneResponse)}"); } }
public void Tree_Factory_AllTypes_Multiple() { var client = BaseTest.Initialize_Client(new MultiTypeResponse()); var factory = new PrtgNodeFactory(client); var probes = factory.Probes(Property.Name, "Local Probe"); var groups = factory.Groups(Property.Name, "Windows Infrastructure"); var devices = factory.Devices(Property.Name, "dc-1"); var sensors = factory.Sensors(Property.Name, "Ping"); var properties = factory.Properties(3000); var response = new NotificationTriggerResponse( NotificationTriggerItem.StateTrigger(parentId: "3000"), NotificationTriggerItem.SpeedTrigger(parentId: "3000") ); var triggerClient = BaseTest.Initialize_Client(response); var triggerFactory = new PrtgNodeFactory(triggerClient); var triggers = triggerFactory.Triggers(3000); }
public void NotificationTrigger_LoadsSchedule_Lazy_AllPropertiesAreSet() { var client = Initialize_Client(new NotificationTriggerResponse( NotificationTriggerItem.StateTrigger(offNotificationAction: "302|Email to all members of group PRTG Administrator")) { HasSchedule = new[] { 301 } } ); var triggers = client.GetNotificationTriggers(1001); var action = triggers.First().OnNotificationAction; var schedule = action.Schedule; AssertEx.AllPropertiesAreNotDefault(schedule, p => { if (p.Name == "Tags") { return(true); } return(false); }); }
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"); }
private IWebResponse GetTableResponse(string address, string function, bool async) { var components = UrlUtilities.CrackUrl(address); Content?content; try { content = components["content"].DescriptionToEnum <Content>(); } catch { content = null; } var count = GetCount(components, content); //Hack to make test "forces streaming with a date filter and returns no results" work if (content == Content.Logs && count == 0 && components["columns"] == "objid,name") { count = 501; address = address.Replace("count=1", "count=501"); } if (function == nameof(XmlFunction.HistoricData)) { return(new SensorHistoryResponse(GetItems(i => new SensorHistoryItem(), count))); } var columns = components["columns"]?.Split(','); switch (content) { case Content.Sensors: return(Sensors(CreateSensor, count, columns, address, async)); case Content.Devices: return(Devices(CreateDevice, count, columns, address, async)); case Content.Groups: return(Groups(CreateGroup, count, columns, address, async)); case Content.Probes: return(Probes(CreateProbe, count, columns, address, async)); case Content.Logs: if (IsGetTotalLogs(address)) { return(TotalLogsResponse()); } return(Messages(i => new MessageItem($"WMI Remote Ping{i}"), count)); case Content.History: return(new ModificationHistoryResponse(new ModificationHistoryItem())); case Content.Notifications: return(Notifications(CreateNotification, count)); case Content.Schedules: return(Schedules(CreateSchedule, count)); case Content.Channels: return(new ChannelResponse(GetItems(Content.Channels, i => new ChannelItem(), 1))); case Content.Objects: return(Objects(address, function, components)); case Content.Triggers: return(new NotificationTriggerResponse( NotificationTriggerItem.StateTrigger(onNotificationAction: "300|Email to all members of group PRTG Users Group"), NotificationTriggerItem.ThresholdTrigger(onNotificationAction: "300|Email to all members of group PRTG Users Group", offNotificationAction: "300|Email to all members of group PRTG Users Group"), NotificationTriggerItem.SpeedTrigger(onNotificationAction: "300|Email to all members of group PRTG Users Group", offNotificationAction: "300|Email to all members of group PRTG Users Group"), NotificationTriggerItem.VolumeTrigger(onNotificationAction: "300|Email to all members of group PRTG Users Group"), NotificationTriggerItem.ChangeTrigger(onNotificationAction: "300|Email to all members of group PRTG Users Group") )); case Content.SysInfo: return(new SystemInfoResponse( SystemInfoItem.SystemItem(), SystemInfoItem.HardwareItem(), SystemInfoItem.SoftwareItem(), SystemInfoItem.ProcessItem(), SystemInfoItem.ServiceItem(), SystemInfoItem.UserItem() )); default: throw new NotImplementedException($"Unknown content '{content}' requested from {nameof(MultiTypeResponse)}"); } }
private IWebResponse GetTableResponse(ref string address, string function) { var components = UrlHelpers.CrackUrl(address); Content content = components["content"].DescriptionToEnum <Content>(); totalRequestCount++; if (skip != null) { if (skip.Any(i => i == totalRequestCount)) { return(base.GetResponse(ref address, function)); } } else { if (start > 1) { start--; return(base.GetResponse(ref address, function)); } } requestCount++; var leading = LeadingSpace ? " " : ""; int count; //1: Before //2: After //3: Before //4: After //5: Before //6: After //Every odd request (the first request) returns 2; the second request returns 2 if (requestCount % 2 != 0) { count = 2; if (flip) { LeadingSpace = true; flip = false; } } else { count = multiple ? 4 : 3; if (LeadingSpace) { flip = true; LeadingSpace = false; } } switch (content) { case Content.Sensors: return(new SensorResponse(GetItems(i => new SensorItem(name: $"{leading}Volume IO _Total{i}", objid: (1000 + i).ToString()), count))); case Content.Devices: return(new DeviceResponse(GetItems(i => new DeviceItem(name: $"Probe Device{i}", objid: (1000 + i).ToString()), count))); case Content.Groups: return(new GroupResponse(GetItems(i => new GroupItem(name: $"Windows Infrastructure{i}", objid: (1000 + i).ToString()), count))); case Content.Notifications: totalRequestCount--; requestCount--; return(new NotificationActionResponse(new NotificationActionItem("301"))); case Content.Triggers: return(new NotificationTriggerResponse( GetItems( i => NotificationTriggerItem.StateTrigger(onNotificationAction: $"301|Email to all members of group PRTG Users Group {i}", subId: i.ToString(), parentId: "1001"), count ) )); case Content.Schedules: totalRequestCount--; requestCount--; return(new ScheduleResponse(new ScheduleItem())); default: throw new NotImplementedException($"Unknown content '{content}' requested from {nameof(DiffBasedResolveResponse)}"); } }
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); } }
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); } }
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"); }