diff --git a/server/AyaNova/Controllers/EventLogController.cs b/server/AyaNova/Controllers/EventLogController.cs index 66fc5568..85ef1e0e 100644 --- a/server/AyaNova/Controllers/EventLogController.cs +++ b/server/AyaNova/Controllers/EventLogController.cs @@ -1,3 +1,4 @@ +using System; using System.IO; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; @@ -5,6 +6,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Routing; using Microsoft.AspNetCore.Authorization; using Microsoft.Extensions.Logging; +using System.ComponentModel.DataAnnotations; using Newtonsoft.Json.Linq; using AyaNova.Models; using AyaNova.Api.ControllerHelpers; @@ -25,7 +27,7 @@ namespace AyaNova.Api.Controllers private readonly AyContext ct; private readonly ILogger log; private readonly ApiServerState serverState; - + /// /// ctor @@ -41,15 +43,21 @@ namespace AyaNova.Api.Controllers } +//TODO: flesh out these routes, just text only for now +//Need to set roles properly +// User should be able to get own user log, but not someone else's without elevated rights, this is a bizadmin type thing, ops maybe shouldn't be able to see it? Or should? not sure +//Owner or with rights to type should be able to get object log +//Actual log processor and constructor should be in EventLogProcessor + /// /// Get events as text document for object specified /// /// Required roles: /// OpsAdminFull | OpsAdminLimited /// - /// Snapshot of metrics - [HttpGet("TextSnapShot")] - public async Task GetObjectLog() + /// Event log for object + [HttpGet("ObjectLog")] + public async Task GetObjectLog([FromQuery] EventLogOptions opt) { //Open or opsOnly and user is opsadminfull or opsadminlimited if (!serverState.IsOpenOrOpsOnly || (serverState.IsOpsOnly && !Authorized.HasAnyRole(HttpContext.Items, AuthorizationRoles.OpsAdminFull | AuthorizationRoles.OpsAdminLimited))) @@ -71,15 +79,16 @@ namespace AyaNova.Api.Controllers } - /// - /// Get metrics as json object + + /// + /// Get events for a user as text document for object specified /// /// Required roles: /// OpsAdminFull | OpsAdminLimited /// - /// Snapshot of metrics - [HttpGet("JsonSnapShot")] - public async Task GetJsonMetrics() + /// Event log for user + [HttpGet("UserLog")] + public async Task GetUserLog([FromQuery] EventLogOptions opt) { //Open or opsOnly and user is opsadminfull or opsadminlimited if (!serverState.IsOpenOrOpsOnly || (serverState.IsOpsOnly && !Authorized.HasAnyRole(HttpContext.Items, AuthorizationRoles.OpsAdminFull | AuthorizationRoles.OpsAdminLimited))) @@ -92,45 +101,31 @@ namespace AyaNova.Api.Controllers return StatusCode(401, new ApiNotAuthorizedResponse()); } - string sResult = await GetTheMetrics("json"); - JObject json = JObject.Parse(sResult); + string sResult = await GetTheMetrics("plain"); - //Log + //Log EventLogProcessor.AddEntry(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.Metrics, AyaEvent.Retrieved), ct); - - return Ok(new ApiOkResponse(json)); + + return Content(sResult); } - /// - /// Get the metrics snapshot - /// - /// Either "json" for json format or "plain" for plaintext format - /// - private async Task GetTheMetrics(string format) - { - var snapshot = metrics.Snapshot.Get(); - - var formatters = ((IMetricsRoot)metrics).OutputMetricsFormatters; - string sResult = $"ERROR GETTING METRICS IN {format} FORMAT"; - - foreach (var formatter in formatters) - { - if (formatter.MediaType.Format == format) - { - using (var stream = new MemoryStream()) - { - await formatter.WriteAsync(stream, snapshot); - sResult = System.Text.Encoding.UTF8.GetString(stream.ToArray()); - } - } - } - - return sResult; - } + //------------ - } -} \ No newline at end of file + public sealed class EventLogOptions + { + [FromQuery] + public AyaType AyType { get; set; } + [FromQuery] + public long AyId { get; set; } + [FromQuery] + public DateTime StartDate { get; set; } + [FromQuery] + public DateTime EndDate { get; set; } + } + + }//eoc +}//eons \ No newline at end of file diff --git a/server/AyaNova/biz/EventLogProcessor.cs b/server/AyaNova/biz/EventLogProcessor.cs index c175e939..2f91b49f 100644 --- a/server/AyaNova/biz/EventLogProcessor.cs +++ b/server/AyaNova/biz/EventLogProcessor.cs @@ -46,6 +46,9 @@ namespace AyaNova.Biz ///////////////////////////////////////////////////////////////////// + + + }//eoc }//eons