From b217ceb35b02db279cd77f969560e185ef60b304 Mon Sep 17 00:00:00 2001 From: Dave Thaler Date: Tue, 15 Oct 2024 14:31:27 -0700 Subject: [PATCH] Add severity member in IFTTT event api (#160) Fixes #51 Signed-off-by: Dave Thaler --- OrcanodeMonitor/Models/OrcanodeEvent.cs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/OrcanodeMonitor/Models/OrcanodeEvent.cs b/OrcanodeMonitor/Models/OrcanodeEvent.cs index 61d39f9..d01a298 100644 --- a/OrcanodeMonitor/Models/OrcanodeEvent.cs +++ b/OrcanodeMonitor/Models/OrcanodeEvent.cs @@ -26,13 +26,14 @@ public OrcanodeEventIftttMeta(string id, DateTime timestamp) /// public class OrcanodeIftttEventDTO { - public OrcanodeIftttEventDTO(string id, string nodeName, string slug, string type, string value, DateTime timestamp) + public OrcanodeIftttEventDTO(string id, string nodeName, string slug, string type, string value, DateTime timestamp, int severity) { Slug = slug; Type = type; Value = value; Meta = new OrcanodeEventIftttMeta(id, timestamp); Description = string.Format("{0} {1} was detected as {2}", nodeName, type, value); + Severity = severity; } [JsonPropertyName("slug")] public string Slug { get; private set; } @@ -50,6 +51,8 @@ public override string ToString() public DateTime? CreatedAt => Fetcher.UnixTimeStampToDateTimeUtc(Meta.UnixTimestamp); [JsonPropertyName("description")] public string Description { get; private set; } + [JsonPropertyName("severity")] + public int Severity { get; private set; } } // Instances of this class are persisted in a SQL database. If any changes @@ -124,10 +127,25 @@ public string Description } } + public int DerivedSeverity + { + get + { + // Changing to offline or unintelligible is considered critical. + if (Value == "OFFLINE" || Value == "UNINTELLIGIBLE") + { + return 2; + } + + // Other values are informational. + return 0; + } + } + #endregion derived #region methods - public OrcanodeIftttEventDTO ToIftttEventDTO() => new OrcanodeIftttEventDTO(ID, NodeName, Slug, Type, Value, DateTimeUtc); + public OrcanodeIftttEventDTO ToIftttEventDTO() => new OrcanodeIftttEventDTO(ID, NodeName, Slug, Type, Value, DateTimeUtc, DerivedSeverity); public override string ToString() {