public object Get() { string hrtUuid = Context.Request.Query[Defines.IDENTIFIER]; if (string.IsNullOrEmpty(hrtUuid)) { return(new StatusCodeResult((int)HttpStatusCode.NotFound)); } HttpRequestTracingId hrtId = new HttpRequestTracingId(hrtUuid); Site site = hrtId.SiteId == null ? null : SiteHelper.GetSite(hrtId.SiteId.Value); var providers = ProvidersHelper.GetProviders(site, hrtId.Path); this.Context.Response.SetItemsCount(providers.Count()); Fields fields = Context.Request.GetFields(); return(new { providers = providers.Select(p => ProvidersHelper.ToJsonModelRef(p, site, hrtId.Path, fields)) }); }
internal static object ToJsonModel(TraceRule rule, Site site, string path, Fields fields = null, bool full = true) { if (rule == null) { return(null); } RuleId ruleId = new RuleId(site?.Id, path, rule.Path); if (fields == null) { fields = Fields.All; } dynamic obj = new ExpandoObject(); // // path if (fields.Exists("path")) { obj.path = rule.Path; } // // id obj.id = new RuleId(site?.Id, path, rule.Path).Uuid; // // status_codes if (fields.Exists("status_codes")) { var statusCodes = rule.FailureDefinition.StatusCodes.Split(',') .Select(statusCode => statusCode.Trim()) .Where(statusCode => !string.IsNullOrEmpty(statusCode)); obj.status_codes = statusCodes; } // // min_request_execution_time if (fields.Exists("min_request_execution_time")) { // 0 turns off the time taken trigger, display this value as int max var totalSeconds = rule.FailureDefinition.TimeTaken.TotalSeconds; obj.min_request_execution_time = totalSeconds == 0 ? int.MaxValue : totalSeconds; } // // event_severity if (fields.Exists("event_severity")) { obj.event_severity = Enum.GetName(rule.FailureDefinition.Verbosity.GetType(), rule.FailureDefinition.Verbosity).ToLower(); } // // custom_action if (fields.Exists("custom_action")) { obj.custom_action = new { executable = rule.CustomActionExe, @params = rule.CustomActionParams, trigger_limit = rule.CustomActionTriggerLimit }; } // // traces if (fields.Exists("traces")) { // It is possible that a trace rule was created and the provider that was providing the areas was removed // We do not want to error out in this case, instead display a null provider obj.traces = rule.TraceAreas.Select(ta => { var areas = ta.Areas.Split(',') .Select(area => area.Trim()) .Where(area => !string.IsNullOrEmpty(area)); var provider = ProvidersHelper.GetProviders(site, path).Where(p => p.Name.Equals(ta.Provider, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); Dictionary <string, bool> allowedAreas = new Dictionary <string, bool>(); if (provider != null) { foreach (var area in provider.Areas) { allowedAreas.Add(area.Name, false); } foreach (var area in areas) { allowedAreas[area] = true; } } return(new { allowed_areas = allowedAreas, provider = ProvidersHelper.ToJsonModelRef(provider, site, path), verbosity = Enum.GetName(ta.Verbosity.GetType(), ta.Verbosity).ToLower() }); }); } // // request_tracing if (fields.Exists("request_tracing")) { obj.request_tracing = Helper.ToJsonModelRef(site, path); } return(Core.Environment.Hal.Apply(Defines.RulesResource.Guid, obj, full)); }