Merge pull request #14 from mindcollapse/scan-time

Duration of scan
This commit is contained in:
Volodymyr Smirnov 2020-10-27 21:42:10 +02:00 committed by GitHub
commit 3a57427135
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 40 additions and 4 deletions

View File

@ -1,9 +1,12 @@
using System;
namespace MalwareMultiScan.Api.Data.Models namespace MalwareMultiScan.Api.Data.Models
{ {
public class ScanResultEntry public class ScanResultEntry
{ {
public bool Completed { get; set; } public bool Completed { get; set; }
public bool? Succeeded { get; set; } public bool? Succeeded { get; set; }
public long Duration { get; set; }
public string[] Threats { get; set; } public string[] Threats { get; set; }
} }
} }

View File

@ -46,7 +46,7 @@ namespace MalwareMultiScan.Api.Services
$"with threats {string.Join(",", message.Threats)}"); $"with threats {string.Join(",", message.Threats)}");
await _scanResultService.UpdateScanResultForBackend( await _scanResultService.UpdateScanResultForBackend(
message.Id, message.Backend, true, message.Id, message.Backend, message.Duration, true,
message.Succeeded, message.Threats); message.Succeeded, message.Threats);
}); });

View File

@ -68,10 +68,11 @@ namespace MalwareMultiScan.Api.Services
/// </summary> /// </summary>
/// <param name="resultId">Result id.</param> /// <param name="resultId">Result id.</param>
/// <param name="backendId">Backend id.</param> /// <param name="backendId">Backend id.</param>
/// <param name="duration">Duration of scan.</param>
/// <param name="completed">If the scan has been completed.</param> /// <param name="completed">If the scan has been completed.</param>
/// <param name="succeeded">If the scan has been succeeded.</param> /// <param name="succeeded">If the scan has been succeeded.</param>
/// <param name="threats">List of found threats.</param> /// <param name="threats">List of found threats.</param>
public async Task UpdateScanResultForBackend(string resultId, string backendId, public async Task UpdateScanResultForBackend(string resultId, string backendId, long duration,
bool completed = false, bool succeeded = false, string[] threats = null) bool completed = false, bool succeeded = false, string[] threats = null)
{ {
await _collection.UpdateOneAsync( await _collection.UpdateOneAsync(
@ -80,6 +81,7 @@ namespace MalwareMultiScan.Api.Services
{ {
Completed = completed, Completed = completed,
Succeeded = succeeded, Succeeded = succeeded,
Duration = duration,
Threats = threats ?? new string[] { } Threats = threats ?? new string[] { }
})); }));
} }

View File

@ -1,3 +1,5 @@
using System;
namespace MalwareMultiScan.Backends.Messages namespace MalwareMultiScan.Backends.Messages
{ {
public class ScanResultMessage public class ScanResultMessage
@ -7,5 +9,7 @@ namespace MalwareMultiScan.Backends.Messages
public bool Succeeded { get; set; } public bool Succeeded { get; set; }
public string[] Threats { get; set; } public string[] Threats { get; set; }
public long Duration { get; set; }
} }
} }

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Diagnostics;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using EasyNetQ; using EasyNetQ;
@ -62,6 +63,10 @@ namespace MalwareMultiScan.Scanner.Services
Backend = _backend.Id Backend = _backend.Id
}; };
var stopwatch = new Stopwatch();
stopwatch.Start();
try try
{ {
result.Threats = await _backend.ScanAsync( result.Threats = await _backend.ScanAsync(
@ -80,6 +85,12 @@ namespace MalwareMultiScan.Scanner.Services
_logger.LogError( _logger.LogError(
exception, "Scanning failed with exception"); exception, "Scanning failed with exception");
} }
finally
{
stopwatch.Stop();
}
result.Duration = stopwatch.ElapsedMilliseconds / 1000;
_logger.LogInformation( _logger.LogInformation(
$"Sending scan results with status {result.Succeeded}"); $"Sending scan results with status {result.Succeeded}");

View File

@ -1,3 +1,7 @@
.git
*.Dockerfile
Dockerfile
# Created by .ignore support plugin (hsz.mobi) # Created by .ignore support plugin (hsz.mobi)
### Node template ### Node template
# Logs # Logs

View File

@ -4,12 +4,16 @@ export default class ScanResultEntryFlattened implements ScanResultEntry {
readonly id: string; readonly id: string;
readonly completed: boolean; readonly completed: boolean;
readonly succeeded: boolean | null; readonly succeeded: boolean | null;
readonly duration: number;
readonly threats: string[]; readonly threats: string[];
constructor(id: string, completed: boolean, succeeded: boolean | null, threats: string[]) { constructor(id: string, completed: boolean, succeeded: boolean | null, duration: number, threats: string[]) {
this.id = id; this.id = id;
this.completed = completed; this.completed = completed;
this.succeeded = succeeded; this.succeeded = succeeded;
this.duration = duration;
this.threats = threats; this.threats = threats;
} }
} }

View File

@ -1,5 +1,6 @@
export default interface ScanResultEntry { export default interface ScanResultEntry {
readonly completed: boolean, readonly completed: boolean,
readonly succeeded: boolean | null, readonly succeeded: boolean | null,
readonly duration: number,
readonly threats: string[] readonly threats: string[]
} }

View File

@ -10,6 +10,11 @@
</div> </div>
</template> </template>
<template #cell(duration)="data">
<b-badge v-if="data.item.completed" variant="primary">{{ data.value }} seconds</b-badge>
<b-badge v-if="!data.item.completed" variant="secondary">pending</b-badge>
</template>
<template #cell(threats)="data"> <template #cell(threats)="data">
<div class="text-success" v-if="data.item.succeeded && !data.item.threats.length">No threats have been detected</div> <div class="text-success" v-if="data.item.succeeded && !data.item.threats.length">No threats have been detected</div>
<div class="text-danger" v-if="data.item.succeeded === false">Scan failed to complete due to the error or timeout</div> <div class="text-danger" v-if="data.item.succeeded === false">Scan failed to complete due to the error or timeout</div>
@ -52,7 +57,8 @@ export default Vue.extend({
flattenedData(): ScanResultEntryFlattened[] { flattenedData(): ScanResultEntryFlattened[] {
return Object return Object
.entries((this.data as ScanResult).results) .entries((this.data as ScanResult).results)
.map(([k, v]) => new ScanResultEntryFlattened(k, v.completed, v.succeeded, v.threats)) .map(([k, v]) => new ScanResultEntryFlattened(
k, v.completed, v.succeeded, v.duration, v.threats))
} }
}, },
@ -63,6 +69,7 @@ export default Vue.extend({
fields: [ fields: [
{key: 'id', label: 'Backend'}, {key: 'id', label: 'Backend'},
{key: 'completed', label: 'Completed'}, {key: 'completed', label: 'Completed'},
{key: 'duration', label: 'Duration'},
{key: 'threats', label: 'Threats'}, {key: 'threats', label: 'Threats'},
], ],