Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ public CheckTypeId CheckTypeId
/// Gets a <see cref="CheckDetails"/> object describing the detailed properties specific
/// to this type of check.
/// </summary>
/// <remarks>
/// The exact type returned by this property depends on the <see cref="CheckTypeId"/>
/// for the current check. For additional information about the predefined check types,
/// see <see cref="Monitoring.CheckTypeId"/>.
/// </remarks>
public CheckDetails Details
{
get
Expand Down
70 changes: 40 additions & 30 deletions src/corelib/Providers/Rackspace/Objects/Monitoring/CheckDetails.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace net.openstack.Providers.Rackspace.Objects.Monitoring
{
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

Expand All @@ -13,6 +14,40 @@
[JsonObject(MemberSerialization.OptIn)]
public abstract class CheckDetails
{
/// <summary>
/// Provides factory methods for deserializing a <see cref="CheckDetails"/> instance from
/// a <see cref="JObject"/> according to the <see cref="CheckTypeId"/> of the associated
/// check.
/// </summary>
private static readonly Dictionary<CheckTypeId, Func<JObject, CheckDetails>> DetailsFactories =
new Dictionary<CheckTypeId, Func<JObject, CheckDetails>>
{
// remote checks
{ CheckTypeId.RemoteDns, obj => obj.ToObject<DnsCheckDetails>() },
{ CheckTypeId.RemoteFtpBanner, obj => obj.ToObject<FtpBannerCheckDetails>() },
{ CheckTypeId.RemoteHttp, obj => obj.ToObject<HttpCheckDetails>() },
{ CheckTypeId.RemoteImapBanner, obj => obj.ToObject<ImapBannerCheckDetails>() },
{ CheckTypeId.RemoteMssqlBanner, obj => obj.ToObject<MssqlBannerCheckDetails>() },
{ CheckTypeId.RemoteMysqlBanner, obj => obj.ToObject<MysqlBannerCheckDetails>() },
{ CheckTypeId.RemotePing, obj => obj.ToObject<PingCheckDetails>() },
{ CheckTypeId.RemotePop3Banner, obj => obj.ToObject<Pop3CheckDetails>() },
{ CheckTypeId.RemotePostgresqlBanner, obj => obj.ToObject<PostgresqlBannerCheckDetails>() },
{ CheckTypeId.RemoteSmtpBanner, obj => obj.ToObject<SmtpBannerCheckDetails>() },
{ CheckTypeId.RemoteSmtp, obj => obj.ToObject<SmtpCheckDetails>() },
{ CheckTypeId.RemoteSsh, obj => obj.ToObject<SshCheckDetails>() },
{ CheckTypeId.RemoteTcp, obj => obj.ToObject<TcpCheckDetails>() },
{ CheckTypeId.RemoteTelnetBanner, obj => obj.ToObject<TelnetBannerCheckDetails>() },

// agent checks
{ CheckTypeId.AgentFilesystem, obj => obj.ToObject<FilesystemCheckDetails>() },
{ CheckTypeId.AgentMemory, obj => obj.ToObject<MemoryCheckDetails>() },
{ CheckTypeId.AgentLoadAverage, obj => obj.ToObject<LoadAverageCheckDetails>() },
{ CheckTypeId.AgentCpu, obj => obj.ToObject<CpuCheckDetails>() },
{ CheckTypeId.AgentDisk, obj => obj.ToObject<DiskCheckDetails>() },
{ CheckTypeId.AgentNetwork, obj => obj.ToObject<NetworkCheckDetails>() },
{ CheckTypeId.AgentPlugin, obj => obj.ToObject<PluginCheckDetails>() },
};

/// <summary>
/// Deserializes a JSON object to a <see cref="CheckDetails"/> instance of the proper type.
/// </summary>
Expand All @@ -31,36 +66,11 @@ public static CheckDetails FromJObject(CheckTypeId checkTypeId, JObject obj)
if (obj == null)
throw new ArgumentNullException("obj");

if (checkTypeId == CheckTypeId.RemoteDns)
return obj.ToObject<DnsCheckDetails>();
else if (checkTypeId == CheckTypeId.RemoteFtpBanner)
return obj.ToObject<FtpBannerCheckDetails>();
else if (checkTypeId == CheckTypeId.RemoteHttp)
return obj.ToObject<HttpCheckDetails>();
else if (checkTypeId == CheckTypeId.RemoteImapBanner)
return obj.ToObject<ImapBannerCheckDetails>();
else if (checkTypeId == CheckTypeId.RemoteMssqlBanner)
return obj.ToObject<MssqlBannerCheckDetails>();
else if (checkTypeId == CheckTypeId.RemoteMysqlBanner)
return obj.ToObject<MysqlBannerCheckDetails>();
else if (checkTypeId == CheckTypeId.RemotePing)
return obj.ToObject<PingCheckDetails>();
else if (checkTypeId == CheckTypeId.RemotePop3Banner)
return obj.ToObject<Pop3CheckDetails>();
else if (checkTypeId == CheckTypeId.RemotePostgresqlBanner)
return obj.ToObject<PostgresqlBannerCheckDetails>();
else if (checkTypeId == CheckTypeId.RemoteSmtpBanner)
return obj.ToObject<SmtpBannerCheckDetails>();
else if (checkTypeId == CheckTypeId.RemoteSmtp)
return obj.ToObject<SmtpCheckDetails>();
else if (checkTypeId == CheckTypeId.RemoteSsh)
return obj.ToObject<SshCheckDetails>();
else if (checkTypeId == CheckTypeId.RemoteTcp)
return obj.ToObject<TcpCheckDetails>();
else if (checkTypeId == CheckTypeId.RemoteTelnetBanner)
return obj.ToObject<TelnetBannerCheckDetails>();
else
return obj.ToObject<GenericCheckDetails>();
Func<JObject, CheckDetails> factory;
if (DetailsFactories.TryGetValue(checkTypeId, out factory))
return factory(obj);

return obj.ToObject<GenericCheckDetails>();
}

/// <summary>
Expand Down
21 changes: 21 additions & 0 deletions src/corelib/Providers/Rackspace/Objects/Monitoring/CheckTypeId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public CheckTypeId(string id)
/// <summary>
/// Gets a <see cref="CheckTypeId"/> representing a remote DNS check.
/// </summary>
/// <seealso cref="DnsCheckDetails"/>
public static CheckTypeId RemoteDns
{
get
Expand All @@ -62,6 +63,7 @@ public static CheckTypeId RemoteDns
/// <summary>
/// Gets a <see cref="CheckTypeId"/> representing a remote FTP banner check.
/// </summary>
/// <seealso cref="FtpBannerCheckDetails"/>
public static CheckTypeId RemoteFtpBanner
{
get
Expand All @@ -73,6 +75,7 @@ public static CheckTypeId RemoteFtpBanner
/// <summary>
/// Gets a <see cref="CheckTypeId"/> representing a remote HTTP check.
/// </summary>
/// <seealso cref="HttpCheckDetails"/>
public static CheckTypeId RemoteHttp
{
get
Expand All @@ -84,6 +87,7 @@ public static CheckTypeId RemoteHttp
/// <summary>
/// Gets a <see cref="CheckTypeId"/> representing a remote IMAP check.
/// </summary>
/// <seealso cref="ImapBannerCheckDetails"/>
public static CheckTypeId RemoteImapBanner
{
get
Expand All @@ -95,6 +99,7 @@ public static CheckTypeId RemoteImapBanner
/// <summary>
/// Gets a <see cref="CheckTypeId"/> representing a remote SQL Server check.
/// </summary>
/// <seealso cref="MssqlBannerCheckDetails"/>
public static CheckTypeId RemoteMssqlBanner
{
get
Expand All @@ -106,6 +111,7 @@ public static CheckTypeId RemoteMssqlBanner
/// <summary>
/// Gets a <see cref="CheckTypeId"/> representing a remote MySQL check.
/// </summary>
/// <seealso cref="MysqlBannerCheckDetails"/>
public static CheckTypeId RemoteMysqlBanner
{
get
Expand All @@ -117,6 +123,7 @@ public static CheckTypeId RemoteMysqlBanner
/// <summary>
/// Gets a <see cref="CheckTypeId"/> representing a remote PING check.
/// </summary>
/// <seealso cref="PingCheckDetails"/>
public static CheckTypeId RemotePing
{
get
Expand All @@ -128,6 +135,7 @@ public static CheckTypeId RemotePing
/// <summary>
/// Gets a <see cref="CheckTypeId"/> representing a remote POP3 check.
/// </summary>
/// <seealso cref="Pop3CheckDetails"/>
public static CheckTypeId RemotePop3Banner
{
get
Expand All @@ -139,6 +147,7 @@ public static CheckTypeId RemotePop3Banner
/// <summary>
/// Gets a <see cref="CheckTypeId"/> representing a remote PostgreSQL check.
/// </summary>
/// <seealso cref="PostgresqlBannerCheckDetails"/>
public static CheckTypeId RemotePostgresqlBanner
{
get
Expand All @@ -150,6 +159,7 @@ public static CheckTypeId RemotePostgresqlBanner
/// <summary>
/// Gets a <see cref="CheckTypeId"/> representing a remote SMTP banner check.
/// </summary>
/// <seealso cref="SmtpBannerCheckDetails"/>
public static CheckTypeId RemoteSmtpBanner
{
get
Expand All @@ -161,6 +171,7 @@ public static CheckTypeId RemoteSmtpBanner
/// <summary>
/// Gets a <see cref="CheckTypeId"/> representing a remote SMTP check.
/// </summary>
/// <seealso cref="SmtpCheckDetails"/>
public static CheckTypeId RemoteSmtp
{
get
Expand All @@ -172,6 +183,7 @@ public static CheckTypeId RemoteSmtp
/// <summary>
/// Gets a <see cref="CheckTypeId"/> representing a remote SSH check.
/// </summary>
/// <seealso cref="SshCheckDetails"/>
public static CheckTypeId RemoteSsh
{
get
Expand All @@ -183,6 +195,7 @@ public static CheckTypeId RemoteSsh
/// <summary>
/// Gets a <see cref="CheckTypeId"/> representing a remote TCP check.
/// </summary>
/// <seealso cref="TcpCheckDetails"/>
public static CheckTypeId RemoteTcp
{
get
Expand All @@ -194,6 +207,7 @@ public static CheckTypeId RemoteTcp
/// <summary>
/// Gets a <see cref="CheckTypeId"/> representing a remote telnet banner check.
/// </summary>
/// <seealso cref="TelnetBannerCheckDetails"/>
public static CheckTypeId RemoteTelnetBanner
{
get
Expand All @@ -205,6 +219,7 @@ public static CheckTypeId RemoteTelnetBanner
/// <summary>
/// Gets a <see cref="CheckTypeId"/> representing an agent filesystem check.
/// </summary>
/// <seealso cref="FilesystemCheckDetails"/>
public static CheckTypeId AgentFilesystem
{
get
Expand All @@ -216,6 +231,7 @@ public static CheckTypeId AgentFilesystem
/// <summary>
/// Gets a <see cref="CheckTypeId"/> representing an agent memory check.
/// </summary>
/// <seealso cref="MemoryCheckDetails"/>
public static CheckTypeId AgentMemory
{
get
Expand All @@ -227,6 +243,7 @@ public static CheckTypeId AgentMemory
/// <summary>
/// Gets a <see cref="CheckTypeId"/> representing an agent load average check.
/// </summary>
/// <seealso cref="LoadAverageCheckDetails"/>
public static CheckTypeId AgentLoadAverage
{
get
Expand All @@ -238,6 +255,7 @@ public static CheckTypeId AgentLoadAverage
/// <summary>
/// Gets a <see cref="CheckTypeId"/> representing an agent CPU check.
/// </summary>
/// <seealso cref="CpuCheckDetails"/>
public static CheckTypeId AgentCpu
{
get
Expand All @@ -249,6 +267,7 @@ public static CheckTypeId AgentCpu
/// <summary>
/// Gets a <see cref="CheckTypeId"/> representing an agent disk check.
/// </summary>
/// <seealso cref="DiskCheckDetails"/>
public static CheckTypeId AgentDisk
{
get
Expand All @@ -260,6 +279,7 @@ public static CheckTypeId AgentDisk
/// <summary>
/// Gets a <see cref="CheckTypeId"/> representing an agent network check.
/// </summary>
/// <seealso cref="NetworkCheckDetails"/>
public static CheckTypeId AgentNetwork
{
get
Expand All @@ -271,6 +291,7 @@ public static CheckTypeId AgentNetwork
/// <summary>
/// Gets a <see cref="CheckTypeId"/> representing an agent plug-in check.
/// </summary>
/// <seealso cref="PluginCheckDetails"/>
public static CheckTypeId AgentPlugin
{
get
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
namespace net.openstack.Providers.Rackspace.Objects.Monitoring
{
using Newtonsoft.Json;

/// <summary>
/// This class represents the detailed configuration parameters for a
/// <see cref="CheckTypeId.AgentCpu"/> check.
/// </summary>
/// <seealso cref="CheckTypeId.AgentCpu"/>
/// <threadsafety static="true" instance="false"/>
/// <preliminary/>
[JsonObject(MemberSerialization.OptIn)]
public class CpuCheckDetails : CheckDetails
{
/// <summary>
/// Initializes a new instance of the <see cref="CpuCheckDetails"/> class.
/// </summary>
public CpuCheckDetails()
{
}

/// <inheritdoc/>
/// <remarks>
/// This class only supports <see cref="CheckTypeId.AgentCpu"/> checks.
/// </remarks>
protected internal override bool SupportsCheckType(CheckTypeId checkTypeId)
{
return checkTypeId == CheckTypeId.AgentCpu;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
namespace net.openstack.Providers.Rackspace.Objects.Monitoring
{
using System;
using Newtonsoft.Json;

/// <summary>
/// This class represents the detailed configuration parameters for a
/// <see cref="CheckTypeId.AgentDisk"/> check.
/// </summary>
/// <seealso cref="CheckTypeId.AgentDisk"/>
/// <threadsafety static="true" instance="false"/>
/// <preliminary/>
[JsonObject(MemberSerialization.OptIn)]
public class DiskCheckDetails : CheckDetails
{
/// <summary>
/// This is the backing field for the <see cref="Target"/> property.
/// </summary>
[JsonProperty("target")]
private string _target;

/// <summary>
/// Initializes a new instance of the <see cref="DiskCheckDetails"/> class
/// during JSON deserialization.
/// </summary>
[JsonConstructor]
protected DiskCheckDetails()
{
}

/// <summary>
/// Initializes a new instance of the <see cref="DiskCheckDetails"/> class
/// with the specified target.
/// </summary>
/// <param name="target">The disk to check.</param>
/// <exception cref="ArgumentNullException">If <paramref name="target"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentException">If <paramref name="target"/> is empty.</exception>
public DiskCheckDetails(string target)
{
if (target == null)
throw new ArgumentNullException("target");
if (string.IsNullOrEmpty(target))
throw new ArgumentException("target cannot be empty");

_target = target;
}

/// <summary>
/// Gets the disk to check.
/// </summary>
public string Target
{
get
{
return _target;
}
}

/// <inheritdoc/>
/// <remarks>
/// This class only supports <see cref="CheckTypeId.AgentDisk"/> checks.
/// </remarks>
protected internal override bool SupportsCheckType(CheckTypeId checkTypeId)
{
return checkTypeId == CheckTypeId.AgentDisk;
}
}
}
Loading