public ApiModule(IMetricService metricService, IAnnotationRegistry annotationRegistry, IMetricRegistry metricRegistry, IMetricAggregator metricAggregator, ExpressionCompiler expressionCompiler) : base("/api/v1") { JsonSettings.MaxJsonLength = int.MaxValue; Get["find/{query}"] = x => { string query = x.query; var metrics = metricService.Find(query); return(Response.AsJson(metrics)); }; Get["annotations"] = x => { var model = new AnnotationsQueryModel(); this.BindTo(model, new BindingConfig { BodyOnly = false }); var now = DateTime.UtcNow; var from = DateTimeParser.ParseDateTime(model.From, now, now.AddHours(-1)); var until = DateTimeParser.ParseDateTime(model.Until, now, now); var annotations = annotationRegistry. ReadAnnotations(from, until). Where(a => model.Tag == null || model.Tag.Length == 0 || a.Tags.Intersect(model.Tag).Any()). Select(a => new { Timestamp = a.Timestamp.ToUnixTimestamp(), a.Title, a.Message });; return(Response.AsJson(annotations)); }; Post["annotations"] = x => { string title = Request.Form.title; string message = Request.Form.message; annotationRegistry.WriteAnnotation(new Annotation(DateTime.UtcNow, title, message)); return(Response.AsJson(new { Success = true })); }; Get["series"] = x => GetSeries(metricRegistry, metricAggregator, expressionCompiler); Post["purge"] = x => { var model = new PurgeModel(); this.BindTo(model, new BindingConfig { BodyOnly = false }); var now = DateTime.UtcNow; var from = DateTimeParser.ParseDateTime(model.From, now, now.AddYears(-1)); metricRegistry.PurgeMetrics(from); return(204); }; Post["metrics"] = x => PostMetrics(metricAggregator); }
public static bool GetAccessTokenAndMakePurgeCall(PurgeModel purge) { var uri = @"https://management.azure.com/subscriptions/" + purge.Subscriptions + @"/resourcegroups/" + purge.ResourceGroup + @"/providers/Microsoft.Cdn/profiles/" + purge.CdnProfile + @"/endpoints/" + purge.CdnEndpoint + @"/purge?api-version=2018-04-02"; var authenticationContext = new AuthenticationContext(@"https://login.microsoftonline.com/" + purge.ActiveDirectory + @".onmicrosoft.com"); var clientCredential = new ClientCredential(purge.ClientId, purge.ClientSecret); var resultstr = authenticationContext.AcquireTokenAsync(@"https://management.core.windows.net/", clientCredential); var token = resultstr.Result.AccessToken; dynamic content = new { ContentPaths = purge.PurgeList }; //For purge all (*.*) bodyText = "{\”ContentPaths\”:[\”/*\”]}”; var responeCode = GetPurgeHttpStatusCode(uri, token, content); return(responeCode == HttpStatusCode.Accepted); }