Skip to content

Commit

Permalink
Add severity member in IFTTT event api (#160)
Browse files Browse the repository at this point in the history
Fixes #51

Signed-off-by: Dave Thaler <[email protected]>
  • Loading branch information
dthaler authored Oct 15, 2024
1 parent 8ea3fcf commit b217ceb
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions OrcanodeMonitor/Models/OrcanodeEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ public OrcanodeEventIftttMeta(string id, DateTime timestamp)
/// </summary>
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; }
Expand All @@ -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
Expand Down Expand Up @@ -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()
{
Expand Down

0 comments on commit b217ceb

Please sign in to comment.