mirror of
https://bitbucket.org/anguist/ntpa
synced 2026-09-30 14:01:13 +00:00
Simplified setup & improved error handling
This commit is contained in:
@@ -37,12 +37,14 @@ namespace Ntp.Analyzer.Config.Root
|
||||
"Host",
|
||||
"Name",
|
||||
"User",
|
||||
"Pass"
|
||||
"Pass",
|
||||
"Create"
|
||||
};
|
||||
private readonly string host;
|
||||
private readonly string name;
|
||||
private readonly string pass;
|
||||
private readonly string user;
|
||||
private readonly bool initialize;
|
||||
|
||||
private DatabaseConfiguration (
|
||||
string configName,
|
||||
@@ -50,7 +52,8 @@ namespace Ntp.Analyzer.Config.Root
|
||||
string host,
|
||||
string name,
|
||||
string user,
|
||||
string pass
|
||||
string pass,
|
||||
bool initialize
|
||||
)
|
||||
: base(configName, indentLevel)
|
||||
{
|
||||
@@ -58,6 +61,7 @@ namespace Ntp.Analyzer.Config.Root
|
||||
this.name = name;
|
||||
this.user = user;
|
||||
this.pass = pass;
|
||||
this.initialize = initialize;
|
||||
}
|
||||
|
||||
protected override IEnumerable<Object> Items {
|
||||
@@ -67,11 +71,24 @@ namespace Ntp.Analyzer.Config.Root
|
||||
host,
|
||||
name,
|
||||
user,
|
||||
pass
|
||||
pass,
|
||||
initialize
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public string Name {
|
||||
get {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Initialize {
|
||||
get {
|
||||
return initialize;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the database connection string.
|
||||
/// </summary>
|
||||
@@ -84,6 +101,18 @@ namespace Ntp.Analyzer.Config.Root
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the database initialization connection string.
|
||||
/// </summary>
|
||||
/// <value>The database initialization connection string.</value>
|
||||
public string InitializeConnectionString {
|
||||
get {
|
||||
return String.Format (
|
||||
"server={0};userid={1};password={2}",
|
||||
host, user, pass);
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString ()
|
||||
{
|
||||
return ConfigText (Params, Items);
|
||||
@@ -97,12 +126,13 @@ namespace Ntp.Analyzer.Config.Root
|
||||
Dictionary<String, String> options = GetOptions (Params, config);
|
||||
|
||||
return new DatabaseConfiguration (
|
||||
GetOptionConfigName (options, "Database", null, false, "Database"),
|
||||
GetOptionConfigName (options, Params [0], null, false, Params [0]),
|
||||
config.IndentLevel,
|
||||
GetOptionString (options, "Host", "Database", true),
|
||||
GetOptionString (options, "Name", "Database", true),
|
||||
GetOptionString (options, "User", "Database", true),
|
||||
GetOptionString (options, "Pass", "Database", true));
|
||||
GetOptionString (options, Params [1], Params [0], true),
|
||||
GetOptionString (options, Params [2], Params [0], true),
|
||||
GetOptionString (options, Params [3], Params [0], true),
|
||||
GetOptionString (options, Params [4], Params [0], true),
|
||||
GetOptionBoolean (options, Params [5], Params [0], false, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,12 +25,12 @@
|
||||
// THE SOFTWARE.
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Ntp.Config;
|
||||
using Ntp.Analyzer.Config.Graph;
|
||||
using Ntp.Analyzer.Config.Navigation;
|
||||
using Ntp.Analyzer.Config.Page;
|
||||
using Ntp.Analyzer.Config.Stats;
|
||||
using Ntp.Config;
|
||||
using Ntp.Analyzer.Config.Root;
|
||||
using Ntp.Analyzer.Config.Stats;
|
||||
|
||||
namespace Ntp.Analyzer.Config
|
||||
{
|
||||
@@ -41,6 +41,7 @@ namespace Ntp.Analyzer.Config
|
||||
int indentLevel,
|
||||
int hostId,
|
||||
string serverName,
|
||||
ServerType serverType,
|
||||
string configFile,
|
||||
string filePath,
|
||||
string webPath)
|
||||
@@ -48,6 +49,7 @@ namespace Ntp.Analyzer.Config
|
||||
{
|
||||
this.hostId = hostId;
|
||||
this.serverName = serverName;
|
||||
this.serverType = serverType;
|
||||
this.configFile = configFile;
|
||||
this.filePath = filePath;
|
||||
this.webPath = webPath;
|
||||
@@ -64,7 +66,8 @@ namespace Ntp.Analyzer.Config
|
||||
private static readonly String[] Params = new[] {
|
||||
Identifier,
|
||||
"HostID",
|
||||
"HostName",
|
||||
"HostAddress",
|
||||
"HostType",
|
||||
"ConfigFile",
|
||||
"FilePath",
|
||||
"WebPath",
|
||||
@@ -92,6 +95,7 @@ namespace Ntp.Analyzer.Config
|
||||
private readonly List<PeerPageConfiguration> peerPages;
|
||||
private readonly List<PeerSummeryPageConfiguration> peerSummeryPages;
|
||||
private readonly string serverName;
|
||||
private readonly ServerType serverType;
|
||||
private readonly string webPath;
|
||||
private AboutPageConfiguration aboutPage;
|
||||
private HostGraphPageConfiguration hostGraphPage;
|
||||
@@ -106,7 +110,11 @@ namespace Ntp.Analyzer.Config
|
||||
}
|
||||
|
||||
public string ServerName {
|
||||
get { return serverName; }
|
||||
get { return serverName != null ? serverName : HostId.ToString(); }
|
||||
}
|
||||
|
||||
public ServerType ServerType {
|
||||
get { return serverType; }
|
||||
}
|
||||
|
||||
public string ConfigFile {
|
||||
@@ -179,6 +187,7 @@ namespace Ntp.Analyzer.Config
|
||||
ConfigName,
|
||||
hostId,
|
||||
serverName,
|
||||
GetServerTypeString(serverType),
|
||||
configFile,
|
||||
filePath,
|
||||
webPath,
|
||||
@@ -199,6 +208,43 @@ namespace Ntp.Analyzer.Config
|
||||
}
|
||||
}
|
||||
|
||||
private string GetServerTypeString(ServerType type)
|
||||
{
|
||||
switch (type) {
|
||||
case ServerType.Ntpdc:
|
||||
return "ntpdc";
|
||||
case ServerType.Ntpq:
|
||||
return "ntpq";
|
||||
default:
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
private static ServerType GetServerTypeString(
|
||||
Dictionary<String, String> options,
|
||||
string type,
|
||||
string configPath)
|
||||
{
|
||||
if (!options.ContainsKey (type) || options [type].Trim () == String.Empty) {
|
||||
ConfigError (String.Format (
|
||||
"No value for setting {0} in section {1} was specified.",
|
||||
type, configPath));
|
||||
return ServerType.Unknown;
|
||||
}
|
||||
|
||||
switch (options [type].Trim ()) {
|
||||
case "ntpdc":
|
||||
return ServerType.Ntpdc;
|
||||
case "ntpq":
|
||||
return ServerType.Ntpq;
|
||||
default:
|
||||
ConfigError (String.Format (
|
||||
"Invalid value for setting {0} in section {1}. Specify either ntpq or ntpdc.",
|
||||
type, configPath));
|
||||
return ServerType.Unknown;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString ()
|
||||
{
|
||||
return ConfigText (Params, Items);
|
||||
@@ -212,42 +258,44 @@ namespace Ntp.Analyzer.Config
|
||||
GetOptionConfigName (options, Params [0], Params [0], true),
|
||||
configBlock.IndentLevel,
|
||||
GetOptionInteger (options, Params [1], Params [0], true),
|
||||
GetOptionString (options, Params [2], Params [0], true, "MISSING HOSTNAME"),
|
||||
GetOptionString (options, Params [3], Params [0], true, "MISSING NTP CONFIG"),
|
||||
GetOptionString (options, Params [4], Params [0], true, "MISSING FILE PATH"),
|
||||
GetOptionString (options, Params [5], Params [0], true, "MISSING WEB PATH"));
|
||||
GetOptionString (options, Params [2], Params [0], true),
|
||||
GetServerTypeString (options, Params [3], Params [0]),
|
||||
GetOptionString (options, Params [4], Params [0], false),
|
||||
GetOptionString (options, Params [5], Params [0], false),
|
||||
GetOptionString (options, Params [6], Params [0], false)
|
||||
);
|
||||
|
||||
// Set sub configuration blocks
|
||||
ConfigurationBlock block;
|
||||
|
||||
block = FindSingleBlock (Params [16], configBlock);
|
||||
block = FindSingleBlock (Params [17], configBlock);
|
||||
config.hostStats = block != null ? HostStatConfiguration.Create (config, bulk, block) : null;
|
||||
|
||||
block = FindSingleBlock (Params [17], configBlock);
|
||||
block = FindSingleBlock (Params [18], configBlock);
|
||||
config.hostIoStats = block != null ? HostIOStatConfiguration.Create (config, bulk, block) : null;
|
||||
|
||||
block = FindSingleBlock (Params [18], configBlock);
|
||||
block = FindSingleBlock (Params [19], configBlock);
|
||||
config.peerStats = block != null ? PeerStatConfiguration.Create (config, bulk, block) : null;
|
||||
|
||||
block = FindSingleBlock (Params [7], configBlock);
|
||||
block = FindSingleBlock (Params [8], configBlock);
|
||||
config.aboutPage = block != null ? AboutPageConfiguration.Create (config, block) : null;
|
||||
|
||||
ConfigurationBlock[] hostGraphBlock = FindBlocks (Params [9], configBlock);
|
||||
ConfigurationBlock[] hostGraphBlock = FindBlocks (Params [10], configBlock);
|
||||
foreach (ConfigurationBlock hostBlock in hostGraphBlock) {
|
||||
config.hostGraphs.Add (HostGraphConfiguration.Create (config, hostBlock));
|
||||
}
|
||||
|
||||
ConfigurationBlock[] trafficGraphBlocks = FindBlocks (Params [10], configBlock);
|
||||
ConfigurationBlock[] trafficGraphBlocks = FindBlocks (Params [11], configBlock);
|
||||
foreach (ConfigurationBlock trafficBlock in trafficGraphBlocks) {
|
||||
config.trafficGraphs.Add (TrafficGraphConfiguration.Create (config, trafficBlock));
|
||||
}
|
||||
|
||||
ConfigurationBlock[] peerGraphBlock = FindBlocks (Params [12], configBlock);
|
||||
ConfigurationBlock[] peerGraphBlock = FindBlocks (Params [13], configBlock);
|
||||
foreach (ConfigurationBlock peerBlock in peerGraphBlock) {
|
||||
config.peerGraphs.Add (PeerGraphConfiguration.Create (config, peerBlock));
|
||||
}
|
||||
|
||||
ConfigurationBlock[] peerBlocks = FindBlocks (Params [11], configBlock);
|
||||
ConfigurationBlock[] peerBlocks = FindBlocks (Params [12], configBlock);
|
||||
foreach (ConfigurationBlock peerBlock in peerBlocks) {
|
||||
config.peerPages.Add (PeerPageConfiguration.Create (
|
||||
config,
|
||||
@@ -255,7 +303,7 @@ namespace Ntp.Analyzer.Config
|
||||
config.peerGraphs));
|
||||
}
|
||||
|
||||
ConfigurationBlock[] peerSummeryBlocks = FindBlocks (Params [13], configBlock);
|
||||
ConfigurationBlock[] peerSummeryBlocks = FindBlocks (Params [14], configBlock);
|
||||
foreach (ConfigurationBlock peerSummeryBlock in peerSummeryBlocks) {
|
||||
config.peerSummeryPages.Add (PeerSummeryPageConfiguration.Create (
|
||||
config, peerSummeryBlock,
|
||||
@@ -267,7 +315,7 @@ namespace Ntp.Analyzer.Config
|
||||
graphs.AddRange (config.hostGraphs);
|
||||
graphs.AddRange (config.trafficGraphs);
|
||||
|
||||
ConfigurationBlock[] hostBlocks = FindBlocks (Params [8], configBlock);
|
||||
ConfigurationBlock[] hostBlocks = FindBlocks (Params [9], configBlock);
|
||||
foreach (ConfigurationBlock hostBlock in hostBlocks) {
|
||||
config.hostPages.Add (HostPageConfiguration.Create (
|
||||
config,
|
||||
@@ -277,14 +325,14 @@ namespace Ntp.Analyzer.Config
|
||||
config.peerSummeryPages));
|
||||
}
|
||||
|
||||
block = FindSingleBlock (Params [14], configBlock);
|
||||
block = FindSingleBlock (Params [15], configBlock);
|
||||
config.hostGraphPage =
|
||||
block != null ? HostGraphPageConfiguration.Create (
|
||||
config,
|
||||
block,
|
||||
config.hostPages) : null;
|
||||
|
||||
block = FindSingleBlock (Params [15], configBlock);
|
||||
block = FindSingleBlock (Params [16], configBlock);
|
||||
config.peerGraphPage =
|
||||
block != null ? PeerGraphPageConfiguration.Create (
|
||||
config,
|
||||
@@ -299,7 +347,7 @@ namespace Ntp.Analyzer.Config
|
||||
linkables.AddRange (config.peerPages);
|
||||
linkables.AddRange (config.peerSummeryPages);
|
||||
|
||||
block = FindSingleBlock (Params [6], configBlock);
|
||||
block = FindSingleBlock (Params [7], configBlock);
|
||||
config.menu = block != null ? MenuConfiguration.Create (block, linkables) : null;
|
||||
|
||||
return config;
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
using Ntp.Process;
|
||||
using Ntp.Analyzer.Config.Stats;
|
||||
|
||||
namespace Ntp.Analyzer.Config
|
||||
{
|
||||
@@ -54,6 +55,14 @@ namespace Ntp.Analyzer.Config
|
||||
get { return server.ServerName; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type of the server in the <see cref="Ntp.Analyzer.Config.ServerSubConfiguration" />.
|
||||
/// </summary>
|
||||
/// <value>The type of the server.</value>
|
||||
public ServerType ServerType {
|
||||
get { return server.ServerType; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the config file in the <see cref="Ntp.Analyzer.Config.ServerSubConfiguration" />.
|
||||
/// </summary>
|
||||
@@ -78,4 +87,4 @@ namespace Ntp.Analyzer.Config
|
||||
get { return server.WebPath; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
//
|
||||
// ServerType.cs
|
||||
//
|
||||
// Author:
|
||||
// Carsten Sonne Larsen <cs@innolan.dk>
|
||||
//
|
||||
// Copyright (c) 2016 Carsten Sonne Larsen
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
using System;
|
||||
|
||||
namespace Ntp.Analyzer.Config.Stats
|
||||
{
|
||||
public enum ServerType
|
||||
{
|
||||
/// <summary>
|
||||
/// The unknown type of server.
|
||||
/// </summary>
|
||||
Unknown,
|
||||
|
||||
/// <summary>
|
||||
/// The ntpdc type of server (old fashion).
|
||||
/// </summary>
|
||||
Ntpdc,
|
||||
|
||||
/// <summary>
|
||||
/// The ntpq type of server. All requests done using ntpq.
|
||||
/// </summary>
|
||||
Ntpq
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user