public static PrtgResponse BuildPrtgResponseObject(HealthReport report)
        {
            var response = new PrtgResponse();

            response.Error = report.Status == HealthStatus.Unhealthy ? 1 : 0;

            var errors = report.Entries
                         .Where(e => !string.IsNullOrWhiteSpace(e.Value.Description) || e.Value.Exception != null || e.Value.Status == HealthStatus.Unhealthy)
                         .Select(BuildErrorText)
                         .ToList();

            if (errors.Any())
            {
                response.Text = string.Join("\n", errors);
            }

            response.Result.Add(new PrtgResponseChannelValueTimeSpan {
                Channel = "TotalDuration", Value = report.TotalDuration.TotalMilliseconds
            });

            foreach (var entry in report.Entries)
            {
                response.Result.Add(new PrtgResponseChannelValueTimeSpan {
                    Channel = $"{entry.Key}.Duration", Value = entry.Value.Duration.TotalMilliseconds
                });
            }

            return(response);
        }
Esempio n. 2
0
        internal static Dictionary <string, string> GetDictionary(PrtgResponse response)
        {
            var xml = GetXml(response);

            var dictionary = xml.Descendants().ToDictionary(x => x.Name.ToString().Substring(prefix.Length), e => e.Value);

            return(dictionary);
        }
Esempio n. 3
0
        internal static XElement GetXml(PrtgResponse response)
        {
            var str = response.StringValue;

            var inputXml      = GetInputXml(str);
            var ddlXml        = GetDropDownListXml(str);
            var textXml       = GetTextAreaXml(str);
            var dependencyXml = GetDependency(str); //if the dependency xml is null does that cause an issue for the xelement we create below?

            var elm = new XElement("properties", inputXml, ddlXml, textXml, dependencyXml);

            return(elm);
        }
Esempio n. 4
0
        internal static T DeserializeType(PrtgResponse response)
        {
            switch (response.Type)
            {
            case PrtgResponseType.Stream:
                return(DeserializeType(response.GetStreamUnsafe()));

            case PrtgResponseType.String:
                return(DeserializeType(response.StringValue));

            default:
                throw new NotImplementedException($"Don't know how to deserialize JSON from response of type {response.Type}");
            }
        }
        internal static XElement GetChannelXml(PrtgResponse response, int channelId)
        {
            var str = response.StringValue;

            var basicMatchRegex = "<input.+?name=\".*?_.+?\".+?value=\".*?\".*?>";
            var nameRegex       = "(.+?name=\")(.+?)(\".+)";

            Func <string, string> nameTransformer = n => n.Replace($"_{channelId}", "");

            var inputXml = HtmlParser.Default.GetInputXml(str, basicMatchRegex, nameRegex, nameTransformer);
            var ddlXml   = HtmlParser.Default.GetDropDownListXml(str, nameRegex, nameTransformer);
            var elm      = new XElement("properties", inputXml, ddlXml);

            return(elm);
        }