Skip to content

Commit

Permalink
Merge pull request #312 from cmu-sei/v8
Browse files Browse the repository at this point in the history
continued debugging and improvements in logging, etc.
  • Loading branch information
sei-dupdyke authored Apr 4, 2024
2 parents 0d14fa9 + a96dead commit f60b9b3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,14 @@ public async Task<string> GenerateTweet(NpcRecord agent)
}
else if (_configuration.Source.ToLower() == "ollama")
{
tweetText = await this._ollamaFormatterService.GenerateTweet(agent);
var tries = 0;
while (string.IsNullOrEmpty(tweetText))
{
tweetText = await this._ollamaFormatterService.GenerateTweet(agent);
tries++;
if (tries > 5)
return null;
}

var regArray = new [] {"\"activities\": \\[\"([^\"]+)\"", "\"activity\": \"([^\"]+)\"", "'activities': \\['([^\\']+)'\\]", "\"activities\": \\[\"([^\\']+)'\\]"} ;

Expand Down
27 changes: 8 additions & 19 deletions src/Ghosts.Api/Infrastructure/Services/QueueSyncService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ private async Task ProcessMachine(IServiceScope scope, ApplicationDbContext cont
case "WEBHOOKCREATE":
try
{
_log.Info("processing webhookcreate...");
var hook = JsonConvert.DeserializeObject<WebhookViewModel>(data.ToString());
var h = new Webhook(hook);
webhooks.Add(h);
Expand All @@ -306,9 +305,7 @@ private async Task ProcessMachine(IServiceScope scope, ApplicationDbContext cont
context.Machines.UpdateRange(machines);
try
{
var i = await context.SaveChangesAsync();
if (i > 0)
_log.Trace($"Queue: {i} (machines: {machines.Count}");
await context.SaveChangesAsync();
}
catch (Exception e)
{
Expand All @@ -321,9 +318,7 @@ private async Task ProcessMachine(IServiceScope scope, ApplicationDbContext cont
await context.HistoryTrackables.AddRangeAsync(trackables);
try
{
var i = await context.SaveChangesAsync();
if (i > 0)
_log.Trace($"Queue: {i} (Trackables: {trackables.Count})");
await context.SaveChangesAsync();
}
catch (Exception e)
{
Expand All @@ -336,9 +331,7 @@ private async Task ProcessMachine(IServiceScope scope, ApplicationDbContext cont
await context.HistoryHealth.AddRangeAsync(health);
try
{
var i = await context.SaveChangesAsync();
if (i > 0)
_log.Trace($"Queue: {i} (Health: {health.Count})");
await context.SaveChangesAsync();
}
catch (Exception e)
{
Expand All @@ -351,9 +344,7 @@ private async Task ProcessMachine(IServiceScope scope, ApplicationDbContext cont
await context.HistoryTimeline.AddRangeAsync(timelines);
try
{
var i = await context.SaveChangesAsync();
if (i > 0)
_log.Trace($"Queue: {i} (Timeline: {timelines.Count})");
await context.SaveChangesAsync();
}
catch (Exception e)
{
Expand All @@ -366,9 +357,7 @@ private async Task ProcessMachine(IServiceScope scope, ApplicationDbContext cont
await context.HistoryMachine.AddRangeAsync(histories);
try
{
var i = await context.SaveChangesAsync();
if (i > 0)
_log.Trace($"Queue: {i} (History: {histories.Count}");
await context.SaveChangesAsync();
}
catch (Exception e)
{
Expand All @@ -381,15 +370,15 @@ private async Task ProcessMachine(IServiceScope scope, ApplicationDbContext cont
await context.Webhooks.AddRangeAsync(webhooks);
try
{
var i = await context.SaveChangesAsync();
if (i > 0)
_log.Trace($"Queue: {i} (Webhooks: {webhooks.Count}");
await context.SaveChangesAsync();
}
catch (Exception e)
{
_log.Error(e);
}
}

_log.Trace($"Queue Processed — Machines: {machines.Count}, Histories: {histories.Count}, Timeline: {timelines.Count}, Health: {health.Count}, Trackables: {trackables.Count}, Webhooks: {webhooks.Count}");
}

internal static async void HandleWebhook(Webhook webhook, NotificationQueueEntry payload)
Expand Down
2 changes: 1 addition & 1 deletion src/Ghosts.Api/ghosts.api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<AssemblyName>ghosts.api</AssemblyName>

<AssemblyVersion>8.0.0.0</AssemblyVersion>
<FileVersion>8.0.8.100</FileVersion>
<FileVersion>8.0.8.202</FileVersion>

<Authors>GHOSTS Development Squad for CERT > Software Engineering Institute > Carnegie Mellon University</Authors>
<Company>Carnegie Mellon University</Company>
Expand Down

0 comments on commit f60b9b3

Please sign in to comment.