Skip to content

Commit 87f7986

Browse files
committed
Merge pull request #309 from sharwell/check-details
Check details
2 parents 3948382 + 352e9e2 commit 87f7986

12 files changed

Lines changed: 502 additions & 30 deletions

src/corelib/Providers/Rackspace/Objects/Monitoring/CheckConfiguration.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@ public CheckTypeId CheckTypeId
191191
/// Gets a <see cref="CheckDetails"/> object describing the detailed properties specific
192192
/// to this type of check.
193193
/// </summary>
194+
/// <remarks>
195+
/// The exact type returned by this property depends on the <see cref="CheckTypeId"/>
196+
/// for the current check. For additional information about the predefined check types,
197+
/// see <see cref="Monitoring.CheckTypeId"/>.
198+
/// </remarks>
194199
public CheckDetails Details
195200
{
196201
get

src/corelib/Providers/Rackspace/Objects/Monitoring/CheckDetails.cs

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace net.openstack.Providers.Rackspace.Objects.Monitoring
22
{
33
using System;
4+
using System.Collections.Generic;
45
using Newtonsoft.Json;
56
using Newtonsoft.Json.Linq;
67

@@ -13,6 +14,40 @@
1314
[JsonObject(MemberSerialization.OptIn)]
1415
public abstract class CheckDetails
1516
{
17+
/// <summary>
18+
/// Provides factory methods for deserializing a <see cref="CheckDetails"/> instance from
19+
/// a <see cref="JObject"/> according to the <see cref="CheckTypeId"/> of the associated
20+
/// check.
21+
/// </summary>
22+
private static readonly Dictionary<CheckTypeId, Func<JObject, CheckDetails>> DetailsFactories =
23+
new Dictionary<CheckTypeId, Func<JObject, CheckDetails>>
24+
{
25+
// remote checks
26+
{ CheckTypeId.RemoteDns, obj => obj.ToObject<DnsCheckDetails>() },
27+
{ CheckTypeId.RemoteFtpBanner, obj => obj.ToObject<FtpBannerCheckDetails>() },
28+
{ CheckTypeId.RemoteHttp, obj => obj.ToObject<HttpCheckDetails>() },
29+
{ CheckTypeId.RemoteImapBanner, obj => obj.ToObject<ImapBannerCheckDetails>() },
30+
{ CheckTypeId.RemoteMssqlBanner, obj => obj.ToObject<MssqlBannerCheckDetails>() },
31+
{ CheckTypeId.RemoteMysqlBanner, obj => obj.ToObject<MysqlBannerCheckDetails>() },
32+
{ CheckTypeId.RemotePing, obj => obj.ToObject<PingCheckDetails>() },
33+
{ CheckTypeId.RemotePop3Banner, obj => obj.ToObject<Pop3CheckDetails>() },
34+
{ CheckTypeId.RemotePostgresqlBanner, obj => obj.ToObject<PostgresqlBannerCheckDetails>() },
35+
{ CheckTypeId.RemoteSmtpBanner, obj => obj.ToObject<SmtpBannerCheckDetails>() },
36+
{ CheckTypeId.RemoteSmtp, obj => obj.ToObject<SmtpCheckDetails>() },
37+
{ CheckTypeId.RemoteSsh, obj => obj.ToObject<SshCheckDetails>() },
38+
{ CheckTypeId.RemoteTcp, obj => obj.ToObject<TcpCheckDetails>() },
39+
{ CheckTypeId.RemoteTelnetBanner, obj => obj.ToObject<TelnetBannerCheckDetails>() },
40+
41+
// agent checks
42+
{ CheckTypeId.AgentFilesystem, obj => obj.ToObject<FilesystemCheckDetails>() },
43+
{ CheckTypeId.AgentMemory, obj => obj.ToObject<MemoryCheckDetails>() },
44+
{ CheckTypeId.AgentLoadAverage, obj => obj.ToObject<LoadAverageCheckDetails>() },
45+
{ CheckTypeId.AgentCpu, obj => obj.ToObject<CpuCheckDetails>() },
46+
{ CheckTypeId.AgentDisk, obj => obj.ToObject<DiskCheckDetails>() },
47+
{ CheckTypeId.AgentNetwork, obj => obj.ToObject<NetworkCheckDetails>() },
48+
{ CheckTypeId.AgentPlugin, obj => obj.ToObject<PluginCheckDetails>() },
49+
};
50+
1651
/// <summary>
1752
/// Deserializes a JSON object to a <see cref="CheckDetails"/> instance of the proper type.
1853
/// </summary>
@@ -31,36 +66,11 @@ public static CheckDetails FromJObject(CheckTypeId checkTypeId, JObject obj)
3166
if (obj == null)
3267
throw new ArgumentNullException("obj");
3368

34-
if (checkTypeId == CheckTypeId.RemoteDns)
35-
return obj.ToObject<DnsCheckDetails>();
36-
else if (checkTypeId == CheckTypeId.RemoteFtpBanner)
37-
return obj.ToObject<FtpBannerCheckDetails>();
38-
else if (checkTypeId == CheckTypeId.RemoteHttp)
39-
return obj.ToObject<HttpCheckDetails>();
40-
else if (checkTypeId == CheckTypeId.RemoteImapBanner)
41-
return obj.ToObject<ImapBannerCheckDetails>();
42-
else if (checkTypeId == CheckTypeId.RemoteMssqlBanner)
43-
return obj.ToObject<MssqlBannerCheckDetails>();
44-
else if (checkTypeId == CheckTypeId.RemoteMysqlBanner)
45-
return obj.ToObject<MysqlBannerCheckDetails>();
46-
else if (checkTypeId == CheckTypeId.RemotePing)
47-
return obj.ToObject<PingCheckDetails>();
48-
else if (checkTypeId == CheckTypeId.RemotePop3Banner)
49-
return obj.ToObject<Pop3CheckDetails>();
50-
else if (checkTypeId == CheckTypeId.RemotePostgresqlBanner)
51-
return obj.ToObject<PostgresqlBannerCheckDetails>();
52-
else if (checkTypeId == CheckTypeId.RemoteSmtpBanner)
53-
return obj.ToObject<SmtpBannerCheckDetails>();
54-
else if (checkTypeId == CheckTypeId.RemoteSmtp)
55-
return obj.ToObject<SmtpCheckDetails>();
56-
else if (checkTypeId == CheckTypeId.RemoteSsh)
57-
return obj.ToObject<SshCheckDetails>();
58-
else if (checkTypeId == CheckTypeId.RemoteTcp)
59-
return obj.ToObject<TcpCheckDetails>();
60-
else if (checkTypeId == CheckTypeId.RemoteTelnetBanner)
61-
return obj.ToObject<TelnetBannerCheckDetails>();
62-
else
63-
return obj.ToObject<GenericCheckDetails>();
69+
Func<JObject, CheckDetails> factory;
70+
if (DetailsFactories.TryGetValue(checkTypeId, out factory))
71+
return factory(obj);
72+
73+
return obj.ToObject<GenericCheckDetails>();
6474
}
6575

6676
/// <summary>

src/corelib/Providers/Rackspace/Objects/Monitoring/CheckTypeId.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public CheckTypeId(string id)
5151
/// <summary>
5252
/// Gets a <see cref="CheckTypeId"/> representing a remote DNS check.
5353
/// </summary>
54+
/// <seealso cref="DnsCheckDetails"/>
5455
public static CheckTypeId RemoteDns
5556
{
5657
get
@@ -62,6 +63,7 @@ public static CheckTypeId RemoteDns
6263
/// <summary>
6364
/// Gets a <see cref="CheckTypeId"/> representing a remote FTP banner check.
6465
/// </summary>
66+
/// <seealso cref="FtpBannerCheckDetails"/>
6567
public static CheckTypeId RemoteFtpBanner
6668
{
6769
get
@@ -73,6 +75,7 @@ public static CheckTypeId RemoteFtpBanner
7375
/// <summary>
7476
/// Gets a <see cref="CheckTypeId"/> representing a remote HTTP check.
7577
/// </summary>
78+
/// <seealso cref="HttpCheckDetails"/>
7679
public static CheckTypeId RemoteHttp
7780
{
7881
get
@@ -84,6 +87,7 @@ public static CheckTypeId RemoteHttp
8487
/// <summary>
8588
/// Gets a <see cref="CheckTypeId"/> representing a remote IMAP check.
8689
/// </summary>
90+
/// <seealso cref="ImapBannerCheckDetails"/>
8791
public static CheckTypeId RemoteImapBanner
8892
{
8993
get
@@ -95,6 +99,7 @@ public static CheckTypeId RemoteImapBanner
9599
/// <summary>
96100
/// Gets a <see cref="CheckTypeId"/> representing a remote SQL Server check.
97101
/// </summary>
102+
/// <seealso cref="MssqlBannerCheckDetails"/>
98103
public static CheckTypeId RemoteMssqlBanner
99104
{
100105
get
@@ -106,6 +111,7 @@ public static CheckTypeId RemoteMssqlBanner
106111
/// <summary>
107112
/// Gets a <see cref="CheckTypeId"/> representing a remote MySQL check.
108113
/// </summary>
114+
/// <seealso cref="MysqlBannerCheckDetails"/>
109115
public static CheckTypeId RemoteMysqlBanner
110116
{
111117
get
@@ -117,6 +123,7 @@ public static CheckTypeId RemoteMysqlBanner
117123
/// <summary>
118124
/// Gets a <see cref="CheckTypeId"/> representing a remote PING check.
119125
/// </summary>
126+
/// <seealso cref="PingCheckDetails"/>
120127
public static CheckTypeId RemotePing
121128
{
122129
get
@@ -128,6 +135,7 @@ public static CheckTypeId RemotePing
128135
/// <summary>
129136
/// Gets a <see cref="CheckTypeId"/> representing a remote POP3 check.
130137
/// </summary>
138+
/// <seealso cref="Pop3CheckDetails"/>
131139
public static CheckTypeId RemotePop3Banner
132140
{
133141
get
@@ -139,6 +147,7 @@ public static CheckTypeId RemotePop3Banner
139147
/// <summary>
140148
/// Gets a <see cref="CheckTypeId"/> representing a remote PostgreSQL check.
141149
/// </summary>
150+
/// <seealso cref="PostgresqlBannerCheckDetails"/>
142151
public static CheckTypeId RemotePostgresqlBanner
143152
{
144153
get
@@ -150,6 +159,7 @@ public static CheckTypeId RemotePostgresqlBanner
150159
/// <summary>
151160
/// Gets a <see cref="CheckTypeId"/> representing a remote SMTP banner check.
152161
/// </summary>
162+
/// <seealso cref="SmtpBannerCheckDetails"/>
153163
public static CheckTypeId RemoteSmtpBanner
154164
{
155165
get
@@ -161,6 +171,7 @@ public static CheckTypeId RemoteSmtpBanner
161171
/// <summary>
162172
/// Gets a <see cref="CheckTypeId"/> representing a remote SMTP check.
163173
/// </summary>
174+
/// <seealso cref="SmtpCheckDetails"/>
164175
public static CheckTypeId RemoteSmtp
165176
{
166177
get
@@ -172,6 +183,7 @@ public static CheckTypeId RemoteSmtp
172183
/// <summary>
173184
/// Gets a <see cref="CheckTypeId"/> representing a remote SSH check.
174185
/// </summary>
186+
/// <seealso cref="SshCheckDetails"/>
175187
public static CheckTypeId RemoteSsh
176188
{
177189
get
@@ -183,6 +195,7 @@ public static CheckTypeId RemoteSsh
183195
/// <summary>
184196
/// Gets a <see cref="CheckTypeId"/> representing a remote TCP check.
185197
/// </summary>
198+
/// <seealso cref="TcpCheckDetails"/>
186199
public static CheckTypeId RemoteTcp
187200
{
188201
get
@@ -194,6 +207,7 @@ public static CheckTypeId RemoteTcp
194207
/// <summary>
195208
/// Gets a <see cref="CheckTypeId"/> representing a remote telnet banner check.
196209
/// </summary>
210+
/// <seealso cref="TelnetBannerCheckDetails"/>
197211
public static CheckTypeId RemoteTelnetBanner
198212
{
199213
get
@@ -205,6 +219,7 @@ public static CheckTypeId RemoteTelnetBanner
205219
/// <summary>
206220
/// Gets a <see cref="CheckTypeId"/> representing an agent filesystem check.
207221
/// </summary>
222+
/// <seealso cref="FilesystemCheckDetails"/>
208223
public static CheckTypeId AgentFilesystem
209224
{
210225
get
@@ -216,6 +231,7 @@ public static CheckTypeId AgentFilesystem
216231
/// <summary>
217232
/// Gets a <see cref="CheckTypeId"/> representing an agent memory check.
218233
/// </summary>
234+
/// <seealso cref="MemoryCheckDetails"/>
219235
public static CheckTypeId AgentMemory
220236
{
221237
get
@@ -227,6 +243,7 @@ public static CheckTypeId AgentMemory
227243
/// <summary>
228244
/// Gets a <see cref="CheckTypeId"/> representing an agent load average check.
229245
/// </summary>
246+
/// <seealso cref="LoadAverageCheckDetails"/>
230247
public static CheckTypeId AgentLoadAverage
231248
{
232249
get
@@ -238,6 +255,7 @@ public static CheckTypeId AgentLoadAverage
238255
/// <summary>
239256
/// Gets a <see cref="CheckTypeId"/> representing an agent CPU check.
240257
/// </summary>
258+
/// <seealso cref="CpuCheckDetails"/>
241259
public static CheckTypeId AgentCpu
242260
{
243261
get
@@ -249,6 +267,7 @@ public static CheckTypeId AgentCpu
249267
/// <summary>
250268
/// Gets a <see cref="CheckTypeId"/> representing an agent disk check.
251269
/// </summary>
270+
/// <seealso cref="DiskCheckDetails"/>
252271
public static CheckTypeId AgentDisk
253272
{
254273
get
@@ -260,6 +279,7 @@ public static CheckTypeId AgentDisk
260279
/// <summary>
261280
/// Gets a <see cref="CheckTypeId"/> representing an agent network check.
262281
/// </summary>
282+
/// <seealso cref="NetworkCheckDetails"/>
263283
public static CheckTypeId AgentNetwork
264284
{
265285
get
@@ -271,6 +291,7 @@ public static CheckTypeId AgentNetwork
271291
/// <summary>
272292
/// Gets a <see cref="CheckTypeId"/> representing an agent plug-in check.
273293
/// </summary>
294+
/// <seealso cref="PluginCheckDetails"/>
274295
public static CheckTypeId AgentPlugin
275296
{
276297
get
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
namespace net.openstack.Providers.Rackspace.Objects.Monitoring
2+
{
3+
using Newtonsoft.Json;
4+
5+
/// <summary>
6+
/// This class represents the detailed configuration parameters for a
7+
/// <see cref="CheckTypeId.AgentCpu"/> check.
8+
/// </summary>
9+
/// <seealso cref="CheckTypeId.AgentCpu"/>
10+
/// <threadsafety static="true" instance="false"/>
11+
/// <preliminary/>
12+
[JsonObject(MemberSerialization.OptIn)]
13+
public class CpuCheckDetails : CheckDetails
14+
{
15+
/// <summary>
16+
/// Initializes a new instance of the <see cref="CpuCheckDetails"/> class.
17+
/// </summary>
18+
public CpuCheckDetails()
19+
{
20+
}
21+
22+
/// <inheritdoc/>
23+
/// <remarks>
24+
/// This class only supports <see cref="CheckTypeId.AgentCpu"/> checks.
25+
/// </remarks>
26+
protected internal override bool SupportsCheckType(CheckTypeId checkTypeId)
27+
{
28+
return checkTypeId == CheckTypeId.AgentCpu;
29+
}
30+
}
31+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
namespace net.openstack.Providers.Rackspace.Objects.Monitoring
2+
{
3+
using System;
4+
using Newtonsoft.Json;
5+
6+
/// <summary>
7+
/// This class represents the detailed configuration parameters for a
8+
/// <see cref="CheckTypeId.AgentDisk"/> check.
9+
/// </summary>
10+
/// <seealso cref="CheckTypeId.AgentDisk"/>
11+
/// <threadsafety static="true" instance="false"/>
12+
/// <preliminary/>
13+
[JsonObject(MemberSerialization.OptIn)]
14+
public class DiskCheckDetails : CheckDetails
15+
{
16+
/// <summary>
17+
/// This is the backing field for the <see cref="Target"/> property.
18+
/// </summary>
19+
[JsonProperty("target")]
20+
private string _target;
21+
22+
/// <summary>
23+
/// Initializes a new instance of the <see cref="DiskCheckDetails"/> class
24+
/// during JSON deserialization.
25+
/// </summary>
26+
[JsonConstructor]
27+
protected DiskCheckDetails()
28+
{
29+
}
30+
31+
/// <summary>
32+
/// Initializes a new instance of the <see cref="DiskCheckDetails"/> class
33+
/// with the specified target.
34+
/// </summary>
35+
/// <param name="target">The disk to check.</param>
36+
/// <exception cref="ArgumentNullException">If <paramref name="target"/> is <see langword="null"/>.</exception>
37+
/// <exception cref="ArgumentException">If <paramref name="target"/> is empty.</exception>
38+
public DiskCheckDetails(string target)
39+
{
40+
if (target == null)
41+
throw new ArgumentNullException("target");
42+
if (string.IsNullOrEmpty(target))
43+
throw new ArgumentException("target cannot be empty");
44+
45+
_target = target;
46+
}
47+
48+
/// <summary>
49+
/// Gets the disk to check.
50+
/// </summary>
51+
public string Target
52+
{
53+
get
54+
{
55+
return _target;
56+
}
57+
}
58+
59+
/// <inheritdoc/>
60+
/// <remarks>
61+
/// This class only supports <see cref="CheckTypeId.AgentDisk"/> checks.
62+
/// </remarks>
63+
protected internal override bool SupportsCheckType(CheckTypeId checkTypeId)
64+
{
65+
return checkTypeId == CheckTypeId.AgentDisk;
66+
}
67+
}
68+
}

0 commit comments

Comments
 (0)