|
|
@ -39,6 +39,8 @@ namespace Cachet_Monitor |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Log.Configure(Configuration); |
|
|
|
|
|
|
|
|
|
|
|
Cachet = new CachetClient(Configuration.ApiBase.OriginalString, Configuration.ApiKey); |
|
|
|
Cachet = new CachetClient(Configuration.ApiBase.OriginalString, Configuration.ApiKey); |
|
|
|
|
|
|
|
|
|
|
|
MainAsync().GetAwaiter().GetResult(); |
|
|
|
MainAsync().GetAwaiter().GetResult(); |
|
|
@ -52,8 +54,15 @@ namespace Cachet_Monitor |
|
|
|
{ |
|
|
|
{ |
|
|
|
Thread.CurrentThread.IsBackground = true; |
|
|
|
Thread.CurrentThread.IsBackground = true; |
|
|
|
while (true) |
|
|
|
while (true) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
await DoMonitorCheck(Cachet, monitor).ConfigureAwait(false); |
|
|
|
await DoMonitorCheck(Cachet, monitor).ConfigureAwait(false); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch (Exception ex) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
File.WriteAllText(Path.Combine(Environment.CurrentDirectory, "lastexception.txt"), ex.ToString()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
await Task.Delay(monitor.Interval * 1000); |
|
|
|
await Task.Delay(monitor.Interval * 1000); |
|
|
|
} |
|
|
|
} |
|
|
@ -70,22 +79,38 @@ namespace Cachet_Monitor |
|
|
|
{ |
|
|
|
{ |
|
|
|
case MonitorType.PORT: |
|
|
|
case MonitorType.PORT: |
|
|
|
{ |
|
|
|
{ |
|
|
|
using (TcpClient tcpClient = new TcpClient()) |
|
|
|
using TcpClient tcpClient = new TcpClient(); |
|
|
|
{ |
|
|
|
|
|
|
|
try |
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
tcpClient.Connect(monitor.Target, monitor.Settings.Port); |
|
|
|
tcpClient.Connect(monitor.Target, monitor.Settings.Port); |
|
|
|
|
|
|
|
try |
|
|
|
|
|
|
|
{ |
|
|
|
await Cachet.UpdateComponentAsync(monitor.ComponentId, new PutComponent |
|
|
|
await Cachet.UpdateComponentAsync(monitor.ComponentId, new PutComponent |
|
|
|
{ |
|
|
|
{ |
|
|
|
Status = ComponentStatus.Operational, |
|
|
|
Status = ComponentStatus.Operational, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
Log.Verbose("PortMonitorCheck", "Sent to Cachet successfully"); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception) |
|
|
|
catch (Exception ex) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Log.Error("PortMonitorCheck", ex.Message, ex); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch (Exception ex) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Log.Error("PortMonitorCheck", ex.Message, ex); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
await Cachet.UpdateComponentAsync(monitor.ComponentId, new PutComponent |
|
|
|
await Cachet.UpdateComponentAsync(monitor.ComponentId, new PutComponent |
|
|
|
{ |
|
|
|
{ |
|
|
|
Status = ComponentStatus.MajorOutage, |
|
|
|
Status = ComponentStatus.MajorOutage, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
Log.Verbose("PortMonitorCheck", "Sent to Cachet successfully"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch(Exception ex2) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Log.Error("PortMonitorCheck", ex2.Message, ex2); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -102,42 +127,82 @@ namespace Cachet_Monitor |
|
|
|
|
|
|
|
|
|
|
|
PingReply reply = ping.Send(monitor.Target, monitor.Timeout, null, options); |
|
|
|
PingReply reply = ping.Send(monitor.Target, monitor.Timeout, null, options); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try |
|
|
|
|
|
|
|
{ |
|
|
|
await Cachet.AddMetricPointAsync(monitor.MetricId, new PostMetricPoint |
|
|
|
await Cachet.AddMetricPointAsync(monitor.MetricId, new PostMetricPoint |
|
|
|
{ |
|
|
|
{ |
|
|
|
Value = (int)reply.RoundtripTime |
|
|
|
Value = (int)reply.RoundtripTime |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
Log.Verbose("IPMonitorCheck", "Sent to Cachet successfully"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch (Exception ex) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Log.Error("IPMonitorCheck", ex.Message, ex); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (reply.Status == IPStatus.Success) |
|
|
|
if (reply.Status == IPStatus.Success) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
await Cachet.UpdateComponentAsync(monitor.ComponentId, new PutComponent |
|
|
|
await Cachet.UpdateComponentAsync(monitor.ComponentId, new PutComponent |
|
|
|
{ |
|
|
|
{ |
|
|
|
Status = ComponentStatus.Operational, |
|
|
|
Status = ComponentStatus.Operational, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
Log.Verbose("IPMonitorCheck", "Sent to Cachet successfully"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch (Exception ex) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Log.Error("IPMonitorCheck", ex.Message, ex); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (reply.RoundtripTime >= monitor.Timeout) |
|
|
|
if (reply.RoundtripTime >= monitor.Timeout) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
await Cachet.UpdateComponentAsync(monitor.ComponentId, new PutComponent |
|
|
|
await Cachet.UpdateComponentAsync(monitor.ComponentId, new PutComponent |
|
|
|
{ |
|
|
|
{ |
|
|
|
Status = ComponentStatus.PerformanceIssues, |
|
|
|
Status = ComponentStatus.PerformanceIssues, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
Log.Verbose("IPMonitorCheck", "Sent to Cachet successfully"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch (Exception ex) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Log.Error("IPMonitorCheck", ex.Message, ex); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (reply.Status != IPStatus.Success) |
|
|
|
if (reply.Status != IPStatus.Success) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (reply.Status == IPStatus.TimedOut) |
|
|
|
if (reply.Status == IPStatus.TimedOut) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
await Cachet.UpdateComponentAsync(monitor.ComponentId, new PutComponent |
|
|
|
await Cachet.UpdateComponentAsync(monitor.ComponentId, new PutComponent |
|
|
|
{ |
|
|
|
{ |
|
|
|
Status = ComponentStatus.PartialOutage, |
|
|
|
Status = ComponentStatus.PartialOutage, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
Log.Verbose("IPMonitorCheck", "Sent to Cachet successfully"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch (Exception ex) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Log.Error("IPMonitorCheck", ex.Message, ex); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
await Cachet.UpdateComponentAsync(monitor.ComponentId, new PutComponent |
|
|
|
await Cachet.UpdateComponentAsync(monitor.ComponentId, new PutComponent |
|
|
|
{ |
|
|
|
{ |
|
|
|
Status = ComponentStatus.MajorOutage, |
|
|
|
Status = ComponentStatus.MajorOutage, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
Log.Verbose("IPMonitorCheck", "Sent to Cachet successfully"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch (Exception ex) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Log.Error("IPMonitorCheck", ex.Message, ex); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -158,17 +223,34 @@ namespace Cachet_Monitor |
|
|
|
|
|
|
|
|
|
|
|
if (response.StatusCode == (HttpStatusCode)monitor.Settings.ExpectedStatusCode) |
|
|
|
if (response.StatusCode == (HttpStatusCode)monitor.Settings.ExpectedStatusCode) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var x = await Cachet.UpdateComponentAsync(monitor.ComponentId, new PutComponent |
|
|
|
try |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
await Cachet.UpdateComponentAsync(monitor.ComponentId, new PutComponent |
|
|
|
{ |
|
|
|
{ |
|
|
|
Status = ComponentStatus.Operational, |
|
|
|
Status = ComponentStatus.Operational, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
Log.Verbose("WebMonitorCheck", "Sent to Cachet successfully"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch (Exception ex) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Log.Error("WebMonitorCheck", ex.Message, ex); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
await Cachet.UpdateComponentAsync(monitor.ComponentId, new PutComponent |
|
|
|
await Cachet.UpdateComponentAsync(monitor.ComponentId, new PutComponent |
|
|
|
{ |
|
|
|
{ |
|
|
|
Status = ComponentStatus.PartialOutage, |
|
|
|
Status = ComponentStatus.PartialOutage, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
Log.Verbose("WebMonitorCheck", "Sent to Cachet successfully"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch (Exception ex) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Log.Error("WebMonitorCheck", ex.Message, ex); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
response.Close(); |
|
|
|
response.Close(); |
|
|
@ -176,35 +258,60 @@ namespace Cachet_Monitor |
|
|
|
catch (WebException ex) |
|
|
|
catch (WebException ex) |
|
|
|
{ |
|
|
|
{ |
|
|
|
timer.Stop(); |
|
|
|
timer.Stop(); |
|
|
|
|
|
|
|
Log.Warning("WebMonitorChcek", ex.Message, ex); |
|
|
|
|
|
|
|
|
|
|
|
if (ex.Status == WebExceptionStatus.ProtocolError) |
|
|
|
if (ex.Status == WebExceptionStatus.ProtocolError) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (ex.Response is HttpWebResponse response) |
|
|
|
if (ex.Response is HttpWebResponse response) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (response.StatusCode == (HttpStatusCode)monitor.Settings.ExpectedStatusCode) |
|
|
|
if (response.StatusCode == (HttpStatusCode)monitor.Settings.ExpectedStatusCode) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
await Cachet.UpdateComponentAsync(monitor.ComponentId, new PutComponent |
|
|
|
await Cachet.UpdateComponentAsync(monitor.ComponentId, new PutComponent |
|
|
|
{ |
|
|
|
{ |
|
|
|
Status = ComponentStatus.Operational, |
|
|
|
Status = ComponentStatus.Operational, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
Log.Verbose("WebMonitorCheck", "Sent to Cachet successfully"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch (Exception ex2) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Log.Error("WebMonitorCheck", ex2.Message, ex2); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (ex.Status == WebExceptionStatus.Timeout) |
|
|
|
if (ex.Status == WebExceptionStatus.Timeout) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
await Cachet.UpdateComponentAsync(monitor.ComponentId, new PutComponent |
|
|
|
await Cachet.UpdateComponentAsync(monitor.ComponentId, new PutComponent |
|
|
|
{ |
|
|
|
{ |
|
|
|
Status = ComponentStatus.PerformanceIssues, |
|
|
|
Status = ComponentStatus.PerformanceIssues, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
Log.Verbose("WebMonitorCheck", "Sent to Cachet successfully"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch (Exception ex2) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Log.Error("WebMonitorCheck", ex2.Message, ex2); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
await Cachet.UpdateComponentAsync(monitor.ComponentId, new PutComponent |
|
|
|
await Cachet.UpdateComponentAsync(monitor.ComponentId, new PutComponent |
|
|
|
{ |
|
|
|
{ |
|
|
|
Status = ComponentStatus.MajorOutage, |
|
|
|
Status = ComponentStatus.MajorOutage, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
Log.Verbose("WebMonitorCheck", "Sent to Cachet successfully"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch (Exception ex2) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Log.Error("WebMonitorCheck", ex2.Message, ex2); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -217,7 +324,7 @@ namespace Cachet_Monitor |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Console.WriteLine($"Ran check on \"{monitor.Target}\" Status: {componentStatus}"); |
|
|
|
Log.Verbose("DoMonitorCheck", $"Ran check on \"{monitor.Name}\" Status: {componentStatus}"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |