1
0
mirror of https://bitbucket.org/anguist/ntpa synced 2025-10-05 18:41:13 +00:00

Improved error handling

This commit is contained in:
2016-03-25 00:39:15 +01:00
parent 86cf01ad8c
commit fd76147eed
8 changed files with 60 additions and 27 deletions

View File

@ -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;
}

View File

@ -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)
{

View File

@ -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])
{

View File

@ -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)
{

View File

@ -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])
{

View File

@ -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);
}
}
}
}