private string GetTableText(string address) { var components = UrlUtilities.CrackUrl(address); var content = MultiTypeResponse.GetContent(address); switch (content) { case Content.Triggers: return(base.GetResponseText(ref address)); case Content.Channels: if (Convert.ToInt32(components["id"]) >= 4000) { return(new ChannelResponse(channels).GetResponseText(ref address)); } return(new ChannelResponse().GetResponseText(ref address)); case Content.Notifications: return(new NotificationActionResponse(new NotificationActionItem("301"), new NotificationActionItem("302"), new NotificationActionItem("303")).GetResponseText(ref address)); case Content.Schedules: return(new ScheduleResponse(new ScheduleItem()).GetResponseText(ref address)); default: throw new NotImplementedException($"Unknown content '{content}' requested from {nameof(NotificationTriggerResponse)}"); } }
private IWebResponse GetObjectDataResponse(string address) { var components = UrlUtilities.CrackUrl(address); var objectType = components["objecttype"]?.ToEnum <ObjectType>() ?? ObjectType.Sensor; switch (objectType) { case ObjectType.Sensor: return(new SensorSettingsResponse()); case ObjectType.Device: return(new DeviceSettingsResponse()); case ObjectType.Notification: return(new NotificationActionResponse(new NotificationActionItem()) { HasSchedule = HasSchedule }); case ObjectType.Schedule: return(new ScheduleResponse()); default: throw new NotImplementedException($"Unknown object type '{objectType}' requested from {nameof(MultiTypeResponse)}"); } }
private IWebResponse GetObjectDataResponse(string address) { var components = UrlUtilities.CrackUrl(address); var objectType = components["objecttype"]?.DescriptionToEnum <ObjectType>(); if (objectType == null && components["id"] == "810") { objectType = ObjectType.WebServerOptions; } switch (objectType) { case ObjectType.Notification: return(new NotificationActionResponse(new NotificationActionItem())); case ObjectType.Schedule: return(new ScheduleResponse()); case ObjectType.WebServerOptions: return(new WebServerOptionsResponse()); default: throw new NotImplementedException($"Unknown object type '{objectType}' requested from {nameof(MultiTypeResponse)}"); } }
private IWebResponse GetTableResponse(string address) { var components = UrlUtilities.CrackUrl(address); Content content = components["content"].DescriptionToEnum <Content>(); var count = 1; var objIds = components.GetValues("filter_objid"); if (objIds != null) { count = objIds.Length; } switch (content) { case Content.Sensors: var type = components["filter_type"] ?? "aggregation"; if (type.StartsWith("@sub(")) { type = type.Substring(5, type.Length - 6); } return(new SensorResponse(Enumerable.Range(0, count).Select(i => new SensorItem(typeRaw: type)).ToArray())); case Content.Channels: return(new ChannelResponse(new ChannelItem())); default: throw new NotImplementedException($"Unknown content '{content}' requested from {nameof(SensorFactorySourceResponse)}"); } }
private IWebResponse GetTableResponse(string address) { var components = UrlUtilities.CrackUrl(address); Content content = components["content"].DescriptionToEnum <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"))); case Content.Schedules: return(new ScheduleResponse(new ScheduleItem())); default: throw new NotImplementedException($"Unknown content '{content}' requested from {nameof(SetNotificationTriggerResponse)}"); } }
protected override IWebResponse GetResponse(ref string address, string function) { if (function == nameof(XmlFunction.TableData)) { var components = UrlUtilities.CrackUrl(address); Content content = components["content"].DescriptionToEnum <Content>(); if (content == Content.Logs) { if (components["columns"] != "objid,name") { components.Remove("content"); components.Remove("columns"); components.Remove("username"); components.Remove("passhash"); if (components["start"] != null) { components.Remove("start"); } var filtered = WebUtility.UrlDecode(UrlUtilities.QueryCollectionToString(components)); if (filtered != str) { Assert.Fail($"Address was '{filtered}' instead of '{str}'"); } } } } return(base.GetResponse(ref address, function)); }
protected override IWebResponse GetResponse(ref string address, string function) { switch (function) { case nameof(XmlFunction.TableData): return(GetTableResponse(address)); case nameof(HtmlFunction.ObjectData): return(new SensorSettingsResponse(propertyChanger)); case nameof(XmlFunction.GetObjectProperty): var components = UrlUtilities.CrackUrl(address); if (components["name"] == "aggregationchannel") { var text = new SensorSettingsResponse(propertyChanger).GetResponseText(ref address); var xml = HtmlParser.Default.GetXml(text); var value = xml.Descendants("injected_aggregationchannel").First().Value; return(new RawPropertyResponse(value)); } throw new NotImplementedException($"Don't know how to handle object property '{components["name"]}'"); case nameof(HtmlFunction.ChannelEdit): return(new ChannelResponse(new ChannelItem())); default: throw GetUnknownFunctionException(function); } }
private string GetSystemInfo(string address) { var components = UrlUtilities.CrackUrl(address); switch (components["category"].DescriptionToEnum <SystemInfoType>()) { case SystemInfoType.System: return(GetResponse(SystemInfoType.System)); case SystemInfoType.Hardware: return(GetResponse(SystemInfoType.Hardware)); case SystemInfoType.Software: return(GetResponse(SystemInfoType.Software)); case SystemInfoType.Processes: return(GetResponse(SystemInfoType.Processes)); case SystemInfoType.Services: return(GetResponse(SystemInfoType.Services)); case SystemInfoType.Users: return(GetResponse(SystemInfoType.Users)); default: throw new NotImplementedException(); } }
private string GetSetObjectPropertyResponse(string address) { var queries = UrlUtilities.CrackUrl(address); PropertyCache cache; if (typeof(TObjectProperty) == typeof(ObjectProperty)) { cache = ObjectPropertyParser.GetPropertyInfoViaTypeLookup((Enum)(object)property); } else if (typeof(TObjectProperty) == typeof(ChannelProperty)) { cache = ObjectPropertyParser.GetPropertyInfoViaPropertyParameter <Channel>((Enum)(object)property); } else { throw new NotImplementedException($"Handler for object property type {nameof(TObjectProperty)} is not implemented"); } var queryName = ObjectPropertyParser.GetObjectPropertyNameViaCache((Enum)(object)property, cache); if (typeof(TObjectProperty) == typeof(ChannelProperty)) { queryName += "1"; //Channel ID used for tests } var val = queries[queryName]; Assert.IsTrue(val == expectedValue, $"The value of property '{property.ToString().ToLower()}' did not match the expected value. Expected '{expectedValue}', received: '{val}'"); return("OK"); }
internal static void ValidateAddSensorProgressResult(AddSensorProgress p, bool addFull) { if (p.TargetUrl.StartsWith("addsensorfailed")) { var parts = UrlUtilities.CrackUrl(p.TargetUrl); var message = parts["errormsg"]; var action = addFull ? "add sensor" : "resolve sensor targets"; if (message != null) { message = message.Trim('\r', '\n'); //todo: does this work in other languages? Not sure how to replicate it if (message.StartsWith("Incomplete connection settings")) { throw new PrtgRequestException("Failed to retrieve data from device; required credentials for sensor type may be missing. See PRTG UI for further details."); } throw new PrtgRequestException($"An exception occurred while trying to {action}: {message.EnsurePeriod()}"); } throw new PrtgRequestException($"An unspecified error occurred while trying to {action}. Specified sensor type may not be valid on this device, or sensor query target parameters may be incorrect. Check the Device 'Host' is still valid or try adding sensor with the PRTG UI."); } if (addFull && p.Percent == -1) { throw new PrtgRequestException($"PRTG was unable to complete the request. The server responded with the following error: '{p.Error.Replace("<br/><ul><li>", " ").Replace("</li></ul><br/>", " ")}'."); } }
public IWebResponse GetResponse(string address, string function) { var components = UrlUtilities.CrackUrl(address); requestNum++; return(GetResponse(address)); }
public static Content GetContent(string address) { var components = UrlUtilities.CrackUrl(address); Content content = components["content"].DescriptionToEnum <Content>(); return(content); }
public IWebResponse GetResponse(string address, string function) { var components = UrlUtilities.CrackUrl(address); Content content = components["content"].DescriptionToEnum <Content>(); requestNum++; return(GetResponse(address, content)); }
private IWebResponse GetTableResponse(ref string address, string function) { var components = UrlUtilities.CrackUrl(address); Content content = components["content"].DescriptionToEnum <Content>(); IncrementCount(content); return(base.GetResponse(ref address, function)); }
protected override IWebResponse GetResponse(ref string address, string function) { if (function == nameof(JsonFunction.GetStatus)) { return(new ServerStatusResponse(new ServerStatusItem())); } if (function == nameof(XmlFunction.TableData) || function == nameof(HtmlFunction.ChannelEdit)) { return(base.GetResponse(ref address, function)); } var queries = UrlUtilities.CrackUrl(address); queries.Remove("id"); queries.Remove("username"); queries.Remove("passhash"); if (property == ChannelProperty.LimitsEnabled) { if (Convert.ToBoolean(value)) { AssertCollectionLength(address, queries, 1); KeyExistsWithCorrectValue(queries, "limitmode", Convert.ToInt32(value)); } else { KeyExistsWithCorrectValue(queries, "limitmode", Convert.ToInt32(value)); KeyExistsWithCorrectValue(queries, "limitmaxerror", string.Empty); KeyExistsWithCorrectValue(queries, "limitmaxwarning", string.Empty); KeyExistsWithCorrectValue(queries, "limitminerror", string.Empty); KeyExistsWithCorrectValue(queries, "limitminwarning", string.Empty); KeyExistsWithCorrectValue(queries, "limiterrormsg", string.Empty); KeyExistsWithCorrectValue(queries, "limitwarningmsg", string.Empty); } } else if (property == ChannelProperty.UpperErrorLimit) { //If no value was specified, we didn't need to include a factor var limitMaxErrorCount = string.IsNullOrEmpty(queries["limitmaxerror_1"]) ? 2 : 3; AssertCollectionLength(address, queries, limitMaxErrorCount); KeyExistsWithCorrectValue(queries, "limitmode", "1"); KeyExistsWithCorrectValue(queries, "limitmaxerror", value); } else { throw new NotImplementedException($"Test code for property '{property}' is not implemented."); } return(new BasicResponse(string.Empty)); }
private string GetResponseText(ref string address, List <T> list) { var queries = UrlUtilities.CrackUrl(address); List <XElement> xmlList; var count = list.Count; if (queries["count"] != null && queries["count"] != "*") { var c = Convert.ToInt32(queries["count"]); var streaming = queries["start"] != null && Convert.ToInt32(queries["start"]) % 500 == 0 || IsStreaming(); var streamingLogs = queries["start"] != null && queries["content"] == "messages" && Convert.ToInt32(queries["start"]) % 500 == 1 || IsStreaming(); if ((c < list.Count && c > 0 || c == 0 || !streaming && !streamingLogs) && !(queries["content"] == "messages" && c == 1) || IsStreaming()) { count = c; var skip = 0; if (queries["start"] != null) { skip = Convert.ToInt32(queries["start"]); if (queries["content"] == "messages") { skip--; } } xmlList = list.Skip(skip).Take(count).Select(GetItem).ToList(); } else { xmlList = list.Select(GetItem).ToList(); } } else { xmlList = list.Select(GetItem).ToList(); } var xml = new XElement(rootName, new XAttribute("listend", 1), new XAttribute("totalcount", list.Count), new XElement("prtg-version", "1.2.3.4"), xmlList ); return(xml.ToString()); }
private string GetUrlInternal(string u, int i, Enum[] streamOrder) { var parts = UrlUtilities.CrackUrl(u); var keys = GetKeys(parts); var firstIndexCandidates = GetFirstIndexCandidates(keys, streamOrder); var firstIndex = firstIndexCandidates.Cast <int?>().FirstOrDefault(ix => ix > -1) ?? -1; var newKeys = keys.Select((k, ix) => SwapUrl(keys, firstIndex, parts, k, ix, streamOrder)).Where(p => p != null).ToList(); var joined = string.Join("&", newKeys); return($"https://prtg.example.com/api/table.xml?{joined}"); }
private int CalculateOffset() { if (address.Contains("filter_objid") && !address.Contains("filter_objid=@")) { var number = UrlUtilities.CrackUrl(address)["filter_objid"].Split(',').Select(v => Convert.ToInt32(v)).First(); if (number >= 1000 && number < 5000) { var offset = number % 1000; return(offset); } } return(0); }
private static Uri OrderUri(string str) { var sorted = new NameValueCollection(); var unsorted = UrlUtilities.CrackUrl(str); foreach (var key in unsorted.AllKeys.OrderBy(k => k)) { sorted.Add(key, unsorted[key]); } var builder = new UriBuilder(str); builder.Query = UrlUtilities.QueryCollectionToString(sorted); return(builder.Uri); }
internal static void ValidateHttpResponse(HttpResponseMessage responseMessage, PrtgResponse response) { if (responseMessage.StatusCode == HttpStatusCode.BadRequest) { var xDoc = XDocument.Load(response.ToXmlReader()); var errorMessage = xDoc.Descendants("error").First().Value; throw new PrtgRequestException($"PRTG was unable to complete the request. The server responded with the following error: {errorMessage.EnsurePeriod()}"); } else if (responseMessage.StatusCode == HttpStatusCode.Unauthorized) { throw new HttpRequestException("Could not authenticate to PRTG; the specified username and password were invalid."); } responseMessage.EnsureSuccessStatusCode(); if (responseMessage.RequestMessage?.RequestUri?.AbsolutePath == "/error.htm") { var errorUrl = responseMessage.RequestMessage.RequestUri.ToString() .Replace("&%2339;", "\""); //Strange text found when setting ChannelProperty.PercentMode in PRTG 18.4.47.1962 var queries = UrlUtilities.CrackUrl(errorUrl); var errorMsg = queries["errormsg"]; errorMsg = errorMsg.Replace("<br/><ul><li>", " ").Replace("</li></ul><br/>", " "); throw new PrtgRequestException($"PRTG was unable to complete the request. The server responded with the following error: {errorMsg.EnsurePeriod()}"); } if (response.Type == PrtgResponseType.String) { if (response.StringValue.StartsWith("<div class=\"errormsg\">")) //Example: GetProbeProperties specifying a content type of Probe instead of ProbeNode { var msgEnd = response.StringValue.IndexOf("</h3>"); var substr = response.StringValue.Substring(0, msgEnd); var substr1 = Regex.Replace(substr, "\\.</.+?><.+?>", ". "); var regex = new Regex("<.+?>"); var newStr = regex.Replace(substr1, ""); throw new PrtgRequestException($"PRTG was unable to complete the request. The server responded with the following error: {newStr.EnsurePeriod()}"); } } }
private IWebResponse GetTableResponse(string address) { var components = UrlUtilities.CrackUrl(address); Content content = components["content"].DescriptionToEnum <Content>(); switch (content) { case Content.Probes: return(GetProbeResponse()); case Content.Logs: return(GetMessageResponse()); default: throw new NotImplementedException($"Unknown content '{content}' requested from {nameof(RestartProbeResponse)}"); } }
private AssertFailedException GetDifference(string expected, string actual, AssertFailedException originalException) { var expectedParts = UrlUtilities.CrackUrl(expected); var actualParts = UrlUtilities.CrackUrl(actual); foreach (var part in actualParts.AllKeys) { var expectedVal = expectedParts[part]; var actualVal = actualParts[part]; if (expectedVal != actualVal) { Assert.Fail($"{part} was different. Expected: {expectedVal}. Actual: {actualVal}.{Environment.NewLine}{Environment.NewLine}{originalException.Message}"); } } return(originalException); }
protected override IWebResponse GetResponse(ref string address, string function) { if (function == nameof(JsonFunction.GetStatus)) { return(new ServerStatusResponse(new ServerStatusItem())); } var queries = UrlUtilities.CrackUrl(address); queries.Remove("id"); queries.Remove("username"); queries.Remove("passhash"); if (property == ChannelProperty.LimitsEnabled) { if (Convert.ToBoolean(value)) { AssertCollectionLength(address, queries, 1); KeyExistsWithCorrectValue(queries, "limitmode", Convert.ToInt32(value)); } else { KeyExistsWithCorrectValue(queries, "limitmode", Convert.ToInt32(value)); KeyExistsWithCorrectValue(queries, "limitmaxerror", string.Empty); KeyExistsWithCorrectValue(queries, "limitmaxwarning", string.Empty); KeyExistsWithCorrectValue(queries, "limitminerror", string.Empty); KeyExistsWithCorrectValue(queries, "limitminwarning", string.Empty); KeyExistsWithCorrectValue(queries, "limiterrormsg", string.Empty); KeyExistsWithCorrectValue(queries, "limitwarningmsg", string.Empty); } } else if (property == ChannelProperty.UpperErrorLimit) { AssertCollectionLength(address, queries, 2); KeyExistsWithCorrectValue(queries, "limitmode", "1"); KeyExistsWithCorrectValue(queries, "limitmaxerror", value); } else { throw new NotImplementedException($"Test code for property '{property}' is not implemented."); } return(new BasicResponse(string.Empty)); }
private string GetTableText(string address) { var components = UrlUtilities.CrackUrl(address); var content = MultiTypeResponse.GetContent(address); switch (content) { case Content.Triggers: if (xml.Length == 1) { xmlIndex = 0; } else { xmlIndex++; } Items = xml[xmlIndex].ToList(); return(base.GetResponseText(ref address)); case Content.Channels: return(new ChannelResponse(new[] { new ChannelItem() }).GetResponseText(ref address)); case Content.Objects: if (Convert.ToInt32(components["filter_objid"]) >= 4000) { return(new ObjectResponse(new SensorItem()).GetResponseText(ref address)); } return(new ObjectResponse(new DeviceItem()).GetResponseText(ref address)); case Content.Notifications: case Content.Schedules: return(new NotificationActionResponse(new NotificationActionItem("301"), new NotificationActionItem("302"), new NotificationActionItem("303")).GetResponseText(ref address)); default: throw new NotImplementedException($"Unknown content '{content}' requested from {nameof(NotificationTriggerResponse)}"); } }
internal static void ValidateSensorTargetProgressResult(SensorTargetProgress p) { if (p.TargetUrl.StartsWith("addsensorfailed")) { var parts = UrlUtilities.CrackUrl(p.TargetUrl); var message = parts["errormsg"]; if (message != null) { message = message.Trim('\r', '\n'); //todo: does this work in other languages? Not sure how to replicate it if (message.StartsWith("Incomplete connection settings")) { throw new PrtgRequestException("Failed to retrieve data from device; required credentials for sensor type may be missing. See PRTG UI for further details."); } throw new PrtgRequestException($"An exception occurred while trying to resolve sensor targets: {message}"); } throw new PrtgRequestException("An unspecified error occurred while trying to resolve sensor targets. Check the Device Host is still valid or try adding targets with the PRTG UI"); } }
private IWebResponse GetRawObjectProperty(string address) { var components = UrlUtilities.CrackUrl(address); if (components["subid"] != null) { return(GetRawSubObjectProperty(components)); } if (components["name"] == "name") { return(new RawPropertyResponse("testName")); } if (components["name"] == "active") { return(new RawPropertyResponse("1")); } if (components["name"] == "tags") { return(new RawPropertyResponse("tag1 tag2")); } if (components["name"] == "accessgroup") { return(new RawPropertyResponse("1")); } if (components["name"] == "intervalgroup") { return(new RawPropertyResponse(null)); } if (components["name"] == "dbauth") { return(new RawPropertyResponse("1")); } if (components["name"] == "comments") { return(new RawPropertyResponse("Do not turn off!")); } if (components["name"] == "banana") { return(new RawPropertyResponse("(Property not found)")); } if (components["name"] == "aggregationchannel") { return(new RawPropertyResponse("#1:Channel\nchannel(4001, 0)\n#2:Channel\nchannel(4002, 0)")); } if (components["name"] == "authorized") { var str = string.Empty; switch (components["id"]) { case "1": case "1001": //Not approved yet str = "0"; break; case "1002": //Already approved str = "1"; break; case "9001": //Not a probe (English) str = "(Property not found)"; break; default: str = "(Test)"; break; } return(new RawPropertyResponse(str)); } components.Remove("username"); components.Remove("passhash"); components.Remove("id"); throw new NotImplementedException($"Unknown raw object property '{components[0]}' passed to {GetType().Name}"); }
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)}"); } }
protected virtual IWebResponse GetResponse(ref string address, string function) { switch (function) { case nameof(XmlFunction.TableData): case nameof(XmlFunction.HistoricData): return(GetTableResponse(address, function, false)); case nameof(CommandFunction.Pause): case nameof(CommandFunction.PauseObjectFor): return(new BasicResponse("<a data-placement=\"bottom\" title=\"Resume\" href=\"#\" onclick=\"var self=this; _Prtg.objectTools.pauseObject.call(this,'1234',1);return false;\"><i class=\"icon-play icon-dark\"></i></a>")); case nameof(HtmlFunction.ChannelEdit): var components = UrlUtilities.CrackUrl(address); if (components["channel"] != "99") { return(new ChannelResponse(new ChannelItem())); } return(new BasicResponse(string.Empty)); case nameof(CommandFunction.DuplicateObject): address = "https://prtg.example.com/public/login.htm?loginurl=/object.htm?id=9999&errormsg="; return(new BasicResponse(string.Empty)); case nameof(HtmlFunction.EditSettings): return(new BasicResponse(string.Empty)); case nameof(JsonFunction.GetStatus): return(new ServerStatusResponse(new ServerStatusItem())); case nameof(JsonFunction.Triggers): return(new TriggerOverviewResponse()); case nameof(JsonFunction.SensorTypes): return(new SensorTypeResponse()); case nameof(HtmlFunction.ObjectData): return(GetObjectDataResponse(address)); case nameof(XmlFunction.GetObjectProperty): case nameof(XmlFunction.GetObjectStatus): return(GetRawObjectProperty(address)); case nameof(CommandFunction.AddSensor2): var sensorTypeStr = UrlUtilities.CrackUrl(address)["sensortype"]; try { var sensorTypeEnum = sensorTypeStr.XmlToEnum <SensorType>(); newSensorType = new StringEnum <SensorType>(sensorTypeEnum); } catch { newSensorType = new StringEnum <SensorType>(sensorTypeStr); } address = "http://prtg.example.com/controls/addsensor3.htm?id=9999&tmpid=2"; return(new BasicResponse(string.Empty)); case nameof(HtmlFunction.EditNotification): return(new NotificationActionResponse(new NotificationActionItem()) { HasSchedule = HasSchedule }); case nameof(JsonFunction.GetAddSensorProgress): var progress = hitCount[function] % 2 == 0 ? 100 : 50; return(new BasicResponse($"{{\"progress\":\"{progress}\",\"targeturl\":\" /addsensor4.htm?id=4251&tmpid=119\"}}")); case nameof(HtmlFunction.AddSensor4): return(GetSensorTargetResponse()); case nameof(XmlFunction.GetTreeNodeStats): return(new SensorTotalsResponse(new SensorTotalsItem())); case nameof(JsonFunction.GeoLocator): return(new GeoLocatorResponse()); case nameof(CommandFunction.AcknowledgeAlarm): case nameof(CommandFunction.AddSensor5): case nameof(CommandFunction.AddDevice2): case nameof(CommandFunction.AddGroup2): case nameof(CommandFunction.ClearCache): case nameof(CommandFunction.DeleteObject): case nameof(HtmlFunction.RemoveSubObject): case nameof(CommandFunction.DiscoverNow): case nameof(CommandFunction.LoadLookups): case nameof(CommandFunction.MoveObjectNow): case nameof(CommandFunction.ProbeState): case nameof(CommandFunction.RecalcCache): case nameof(CommandFunction.Rename): case nameof(CommandFunction.RestartServer): case nameof(CommandFunction.RestartProbes): case nameof(CommandFunction.ReloadFileLists): case nameof(CommandFunction.SaveNow): case nameof(CommandFunction.ScanNow): case nameof(CommandFunction.SetPosition): case nameof(CommandFunction.Simulate): case nameof(CommandFunction.SortSubObjects): case nameof(CommandFunction.SysInfoCheckNow): return(new BasicResponse(string.Empty)); default: throw GetUnknownFunctionException(function); } }
private IWebResponse GetTableResponse(ref string address, string function) { var components = UrlUtilities.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)}"); } }