29 lines
1 KiB
C#
29 lines
1 KiB
C#
|
using System;
|
||
|
|
||
|
namespace Monithor.api.Alerting {
|
||
|
public static class General {
|
||
|
internal static string GetMessage(IMonitor mon, string displayName) {
|
||
|
return mon.Status switch {
|
||
|
MonitorStatus.Up => $"🟢 {displayName} is UP.\n" + $"Outage duration: {mon.ResolvedAt.Subtract(mon.StartedAt).ToStringCustom()}",
|
||
|
|
||
|
MonitorStatus.Recovering => $"🟡 {displayName} is recovering.",
|
||
|
MonitorStatus.Down => $"🔴 {displayName} is DOWN.\n" + $"Cause: {mon.LastValue}\n" + $"Outage started {mon.StartedAt:yyyy'-'MM'-'dd HH':'mm':'ss %K}",
|
||
|
MonitorStatus.Unknown => null,
|
||
|
MonitorStatus.Validating => null,
|
||
|
_ => null
|
||
|
};
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static class TimeSpanExtensions {
|
||
|
public static string ToStringCustom(this TimeSpan timeSpan) {
|
||
|
var retstr = $"{timeSpan.Seconds}s";
|
||
|
if (timeSpan.Minutes > 0)
|
||
|
retstr = $"{timeSpan.Minutes}m {retstr}";
|
||
|
if (Math.Floor(timeSpan.TotalHours) > 0)
|
||
|
retstr = $"{Math.Floor(timeSpan.TotalHours)}h {retstr}";
|
||
|
|
||
|
return retstr;
|
||
|
}
|
||
|
}
|
||
|
}
|