mirror of
https://bitbucket.org/anguist/ntpa
synced 2025-10-06 02:51:23 +00:00
Improved error handling
This commit is contained in:
@ -72,6 +72,7 @@ namespace Ntp.Analyzer.Log
|
||||
if (severity < treshold)
|
||||
return;
|
||||
|
||||
string pad = String.Empty;
|
||||
string severityText;
|
||||
|
||||
switch (severity) {
|
||||
@ -80,12 +81,14 @@ namespace Ntp.Analyzer.Log
|
||||
break;
|
||||
case Severity.Warn:
|
||||
severityText = "WARN";
|
||||
pad = " ";
|
||||
break;
|
||||
case Severity.Notice:
|
||||
severityText = "NOTICE";
|
||||
break;
|
||||
case Severity.Info:
|
||||
severityText = "INFO";
|
||||
pad = " ";
|
||||
break;
|
||||
case Severity.Debug:
|
||||
severityText = "DEBUG";
|
||||
@ -102,7 +105,7 @@ namespace Ntp.Analyzer.Log
|
||||
string entry = String.Concat(
|
||||
now.ToString(timeFormat),
|
||||
" [", severityText, "] ",
|
||||
text);
|
||||
pad, text);
|
||||
|
||||
lock (locker)
|
||||
{
|
||||
|
@ -60,17 +60,12 @@ namespace Ntp.Analyzer.Process.Description
|
||||
|
||||
protected override void InternalExecute()
|
||||
{
|
||||
// Find host in database.
|
||||
Host host;
|
||||
Host host = DataFace.Instance.Hosts.SingleOrDefault (h => h.Id == config.HostId);
|
||||
|
||||
try
|
||||
{
|
||||
host = DataFace.Instance.Hosts.Single(h => h.Name == config.ServerName);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.WriteLine("Hostname not found in database: " + config.ServerName, Severity.Warn);
|
||||
Log.WriteLine (e, Severity.Trace);
|
||||
if (host == null) {
|
||||
Log.WriteLine (String.Format (
|
||||
"Host with ID {0} was not found in database. ", config.HostId),
|
||||
Severity.Warn);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Ntp.Analyzer.Config.Destination;
|
||||
using Ntp.Analyzer.Config.Graph;
|
||||
@ -61,7 +62,14 @@ namespace Ntp.Analyzer.Process.Description
|
||||
|
||||
protected override void InternalExecute()
|
||||
{
|
||||
Host host = DataFace.Instance.Hosts.Single(h => h.Id == config.HostId);
|
||||
Host host = DataFace.Instance.Hosts.SingleOrDefault (h => h.Id == config.HostId);
|
||||
|
||||
if (host == null) {
|
||||
Log.WriteLine (String.Format (
|
||||
"Host with ID {0} was not found in database. ", config.HostId),
|
||||
Severity.Warn);
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (GraphSetConfiguration graphSet in config.GraphSets)
|
||||
{
|
||||
|
@ -24,6 +24,7 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Ntp.Analyzer.Config.Graph;
|
||||
@ -60,7 +61,14 @@ namespace Ntp.Analyzer.Process.Description
|
||||
|
||||
protected override void InternalExecute()
|
||||
{
|
||||
Host host = DataFace.Instance.Hosts.Single(h => h.Id == config.HostId);
|
||||
Host host = DataFace.Instance.Hosts.SingleOrDefault (h => h.Id == config.HostId);
|
||||
|
||||
if (host == null) {
|
||||
Log.WriteLine (String.Format (
|
||||
"Host with ID {0} was not found in database. ", config.HostId),
|
||||
Severity.Warn);
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (NtpConfEntry entry in DataFace.Instance.NtpConfigCache[config.ConfigFile])
|
||||
{
|
||||
|
@ -24,6 +24,7 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Ntp.Analyzer.Config.Destination;
|
||||
@ -62,7 +63,14 @@ namespace Ntp.Analyzer.Process.Description
|
||||
|
||||
protected override void InternalExecute()
|
||||
{
|
||||
Host host = DataFace.Instance.Hosts.Single(h => h.Id == config.HostId);
|
||||
Host host = DataFace.Instance.Hosts.SingleOrDefault (h => h.Id == config.HostId);
|
||||
|
||||
if (host == null) {
|
||||
Log.WriteLine (String.Format (
|
||||
"Host with ID {0} was not found in database. ", config.HostId),
|
||||
Severity.Warn);
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (GraphSetConfiguration graphSet in config.GraphSets)
|
||||
{
|
||||
|
@ -24,6 +24,7 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
@ -67,7 +68,14 @@ namespace Ntp.Analyzer.Process.Description
|
||||
|
||||
protected override void InternalExecute()
|
||||
{
|
||||
Host host = DataFace.Instance.Hosts.Single(h => h.Id == page.HostId);
|
||||
Host host = DataFace.Instance.Hosts.SingleOrDefault (h => h.Id == page.HostId);
|
||||
|
||||
if (host == null) {
|
||||
Log.WriteLine (String.Format (
|
||||
"Host with ID {0} was not found in database. ", page.HostId),
|
||||
Severity.Warn);
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (NtpConfEntry entry in DataFace.Instance.NtpConfigCache[page.ConfigFile])
|
||||
{
|
||||
|
@ -60,16 +60,12 @@ namespace Ntp.Analyzer.Process.Description
|
||||
|
||||
protected override void InternalExecute()
|
||||
{
|
||||
Host host;
|
||||
Host host = DataFace.Instance.Hosts.SingleOrDefault (h => h.Id == config.HostId);
|
||||
|
||||
try
|
||||
{
|
||||
host = DataFace.Instance.Hosts.Single(h => h.Name == config.ServerName);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.WriteLine("Hostname not found in database: " + config.ServerName, Severity.Warn);
|
||||
Log.WriteLine (e, Severity.Trace);
|
||||
if (host == null) {
|
||||
Log.WriteLine (String.Format (
|
||||
"Host with ID {0} was not found in database. ", config.HostId),
|
||||
Severity.Warn);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -77,4 +73,4 @@ namespace Ntp.Analyzer.Process.Description
|
||||
SaveStream(graph);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -162,19 +162,26 @@ namespace Ntp.Process
|
||||
Running = true;
|
||||
runCount++;
|
||||
|
||||
bool error = false;
|
||||
log.WriteLine (String.Format ("{0} -> Executing", this), Severity.Debug);
|
||||
|
||||
try {
|
||||
description.Execute ();
|
||||
} catch (Exception ex) {
|
||||
error = true;
|
||||
log.WriteLine ("Error while executing " + ToString (), Severity.Error);
|
||||
log.WriteLine (ex.Message, Severity.Debug);
|
||||
log.WriteLine (String.Format ("Error in {0} -> {1}", this, ex.Message), Severity.Debug);
|
||||
log.WriteLine (ex, Severity.Trace);
|
||||
} finally {
|
||||
Running = false;
|
||||
}
|
||||
|
||||
time += DateTime.Now.Subtract (started);
|
||||
log.WriteLine (String.Format ("{0} -> Done", this), Severity.Debug);
|
||||
if (error) {
|
||||
log.WriteLine (String.Format ("{0} -> Failed", this), Severity.Debug);
|
||||
} else {
|
||||
log.WriteLine (String.Format ("{0} -> Done", this), Severity.Debug);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
Reference in New Issue
Block a user