|
|
|
|
@ -1,4 +1,5 @@
@@ -1,4 +1,5 @@
|
|
|
|
|
using System; |
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
using System.Linq; |
|
|
|
|
using System.Threading.Tasks; |
|
|
|
|
using Bit.Admin.Models; |
|
|
|
|
@ -6,8 +7,8 @@ using Bit.Core.Settings;
@@ -6,8 +7,8 @@ using Bit.Core.Settings;
|
|
|
|
|
using Bit.Core.Utilities; |
|
|
|
|
using Microsoft.AspNetCore.Authorization; |
|
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
|
using Microsoft.Azure.Documents.Client; |
|
|
|
|
using Microsoft.Azure.Documents.Linq; |
|
|
|
|
using Microsoft.Azure.Cosmos; |
|
|
|
|
using Microsoft.Azure.Cosmos.Linq; |
|
|
|
|
using Serilog.Events; |
|
|
|
|
|
|
|
|
|
namespace Bit.Admin.Controllers |
|
|
|
|
@ -17,7 +18,7 @@ namespace Bit.Admin.Controllers
@@ -17,7 +18,7 @@ namespace Bit.Admin.Controllers
|
|
|
|
|
public class LogsController : Controller |
|
|
|
|
{ |
|
|
|
|
private const string Database = "Diagnostics"; |
|
|
|
|
private const string Collection = "Logs"; |
|
|
|
|
private const string Container = "Logs"; |
|
|
|
|
|
|
|
|
|
private readonly GlobalSettings _globalSettings; |
|
|
|
|
|
|
|
|
|
@ -29,17 +30,18 @@ namespace Bit.Admin.Controllers
@@ -29,17 +30,18 @@ namespace Bit.Admin.Controllers
|
|
|
|
|
public async Task<IActionResult> Index(string cursor = null, int count = 50, |
|
|
|
|
LogEventLevel? level = null, string project = null, DateTime? start = null, DateTime? end = null) |
|
|
|
|
{ |
|
|
|
|
var collectionLink = UriFactory.CreateDocumentCollectionUri(Database, Collection); |
|
|
|
|
using (var client = new DocumentClient(new Uri(_globalSettings.DocumentDb.Uri), |
|
|
|
|
using (var client = new CosmosClient(_globalSettings.DocumentDb.Uri, |
|
|
|
|
_globalSettings.DocumentDb.Key)) |
|
|
|
|
{ |
|
|
|
|
var options = new FeedOptions |
|
|
|
|
{ |
|
|
|
|
MaxItemCount = count, |
|
|
|
|
RequestContinuation = cursor |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
var query = client.CreateDocumentQuery<LogModel>(collectionLink, options).AsQueryable(); |
|
|
|
|
var cosmosContainer = client.GetContainer(Database, Container); |
|
|
|
|
var query = cosmosContainer.GetItemLinqQueryable<LogModel>( |
|
|
|
|
requestOptions: new QueryRequestOptions() |
|
|
|
|
{ |
|
|
|
|
MaxItemCount = count |
|
|
|
|
}, |
|
|
|
|
continuationToken: cursor |
|
|
|
|
).AsQueryable(); |
|
|
|
|
|
|
|
|
|
if (level.HasValue) |
|
|
|
|
{ |
|
|
|
|
query = query.Where(l => l.Level == level.Value.ToString()); |
|
|
|
|
@ -56,9 +58,8 @@ namespace Bit.Admin.Controllers
@@ -56,9 +58,8 @@ namespace Bit.Admin.Controllers
|
|
|
|
|
{ |
|
|
|
|
query = query.Where(l => l.Timestamp <= end.Value); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var docQuery = query.OrderByDescending(l => l.Timestamp).AsDocumentQuery(); |
|
|
|
|
var response = await docQuery.ExecuteNextAsync<LogModel>(); |
|
|
|
|
var feedIterator = query.OrderByDescending(l => l.Timestamp).ToFeedIterator(); |
|
|
|
|
var response = await feedIterator.ReadNextAsync(); |
|
|
|
|
|
|
|
|
|
return View(new LogsModel |
|
|
|
|
{ |
|
|
|
|
@ -69,24 +70,27 @@ namespace Bit.Admin.Controllers
@@ -69,24 +70,27 @@ namespace Bit.Admin.Controllers
|
|
|
|
|
Items = response.ToList(), |
|
|
|
|
Count = count, |
|
|
|
|
Cursor = cursor, |
|
|
|
|
NextCursor = response.ResponseContinuation |
|
|
|
|
NextCursor = response.ContinuationToken |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public async Task<IActionResult> View(Guid id) |
|
|
|
|
{ |
|
|
|
|
using (var client = new DocumentClient(new Uri(_globalSettings.DocumentDb.Uri), |
|
|
|
|
using (var client = new CosmosClient(_globalSettings.DocumentDb.Uri, |
|
|
|
|
_globalSettings.DocumentDb.Key)) |
|
|
|
|
{ |
|
|
|
|
var uri = UriFactory.CreateDocumentUri(Database, Collection, id.ToString()); |
|
|
|
|
var response = await client.ReadDocumentAsync<LogDetailsModel>(uri); |
|
|
|
|
if (response?.Document == null) |
|
|
|
|
var cosmosContainer = client.GetContainer(Database, Container); |
|
|
|
|
var query = cosmosContainer.GetItemLinqQueryable<LogDetailsModel>() |
|
|
|
|
.AsQueryable() |
|
|
|
|
.Where(l => l.Id == id.ToString()); |
|
|
|
|
|
|
|
|
|
var response = await query.ToFeedIterator().ReadNextAsync(); |
|
|
|
|
if (response == null || response.Count == 0) |
|
|
|
|
{ |
|
|
|
|
return RedirectToAction("Index"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return View(response.Document); |
|
|
|
|
return View(response.First()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|