correct conversion of MonitorParameters
This commit is contained in:
@@ -11,19 +11,15 @@ namespace UptimeSharp.Tests
|
||||
public MonitorsTest() : base() { }
|
||||
|
||||
|
||||
public async Task Dispose()
|
||||
{
|
||||
List<Monitor> monitors = await client.GetMonitors();
|
||||
monitors.ForEach(item => monitorsToDelete.Add(item.ID));
|
||||
}
|
||||
public async Task Dispose() { }
|
||||
|
||||
|
||||
[Fact]
|
||||
public async Task AddHTTPMonitor()
|
||||
public async void AddHTTPMonitor()
|
||||
{
|
||||
Assert.True(await client.AddMonitor(
|
||||
name: "test_1",
|
||||
uri: "http://test1.com"
|
||||
target: "http://test1.com"
|
||||
));
|
||||
}
|
||||
|
||||
@@ -33,7 +29,7 @@ namespace UptimeSharp.Tests
|
||||
{
|
||||
Assert.True(await client.AddMonitor(
|
||||
name: "test_2",
|
||||
uri: "http://test2.com",
|
||||
target: "http://test2.com",
|
||||
type: Models.Type.Keyword,
|
||||
keywordType: KeywordType.Exists,
|
||||
keywordValue: "test"
|
||||
@@ -46,7 +42,7 @@ namespace UptimeSharp.Tests
|
||||
{
|
||||
Assert.True(await client.AddMonitor(
|
||||
name: "test_3",
|
||||
uri: "http://test3.com",
|
||||
target: "http://test3.com",
|
||||
type: Models.Type.Ping
|
||||
));
|
||||
}
|
||||
@@ -57,7 +53,7 @@ namespace UptimeSharp.Tests
|
||||
{
|
||||
Assert.True(await client.AddMonitor(
|
||||
name: "test_4",
|
||||
uri: "127.0.0.1",
|
||||
target: "127.0.0.1",
|
||||
type: Models.Type.Port,
|
||||
subtype: Subtype.Custom,
|
||||
port: 50004
|
||||
@@ -70,7 +66,7 @@ namespace UptimeSharp.Tests
|
||||
{
|
||||
//Assert.True(await client.AddMonitor(
|
||||
// name: "test_5",
|
||||
// uri: "255.0.0.1",
|
||||
// target: "255.0.0.1",
|
||||
// type: Models.Type.Port,
|
||||
// subtype: Subtype.HTTP
|
||||
//));
|
||||
@@ -91,7 +87,7 @@ namespace UptimeSharp.Tests
|
||||
{
|
||||
Assert.True(await client.AddMonitor(
|
||||
name: "test_6",
|
||||
uri: "http://test6.com"
|
||||
target: "http://test6.com"
|
||||
));
|
||||
|
||||
List<Monitor> items = await client.GetMonitors();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using UptimeSharp.Models;
|
||||
using Xunit;
|
||||
|
||||
namespace UptimeSharp.Tests
|
||||
@@ -25,13 +26,14 @@ namespace UptimeSharp.Tests
|
||||
|
||||
|
||||
// teardown
|
||||
public void Dispose()
|
||||
public async void Dispose()
|
||||
{
|
||||
List<Monitor> monitors = await client.GetMonitors();
|
||||
alertsToDelete.ForEach(async id =>
|
||||
{
|
||||
await client.DeleteAlert(id.ToString());
|
||||
});
|
||||
monitorsToDelete.ForEach(async id =>
|
||||
monitors.ForEach(async id =>
|
||||
{
|
||||
await client.DeleteMonitor(id);
|
||||
});
|
||||
@@ -42,7 +44,7 @@ namespace UptimeSharp.Tests
|
||||
public static async Task ThrowsAsync<TException>(Func<Task> func)
|
||||
{
|
||||
var expected = typeof(TException);
|
||||
Type actual = null;
|
||||
System.Type actual = null;
|
||||
try
|
||||
{
|
||||
await func();
|
||||
|
||||
@@ -107,7 +107,7 @@ namespace UptimeSharp
|
||||
/// Creates a monitor.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the new monitor.</param>
|
||||
/// <param name="uri">The URI or IP to watch.</param>
|
||||
/// <param name="target">The URI or IP to watch.</param>
|
||||
/// <param name="type">The type of the monitor.</param>
|
||||
/// <param name="subtype">The subtype of the monitor (if port).</param>
|
||||
/// <param name="port">The port (only for Subtype.Custom).</param>
|
||||
@@ -123,7 +123,7 @@ namespace UptimeSharp
|
||||
/// <exception cref="UptimeSharpException"></exception>
|
||||
public async Task<bool> AddMonitor(
|
||||
string name,
|
||||
string uri,
|
||||
string target,
|
||||
Type type = Type.HTTP,
|
||||
Subtype subtype = Subtype.Unknown,
|
||||
int? port = null, string keywordValue = null,
|
||||
@@ -137,7 +137,7 @@ namespace UptimeSharp
|
||||
MonitorParameters parameters = new MonitorParameters()
|
||||
{
|
||||
Name = name,
|
||||
Uri = uri,
|
||||
Target = target,
|
||||
Type = type,
|
||||
Subtype = subtype,
|
||||
Port = port,
|
||||
@@ -174,7 +174,7 @@ namespace UptimeSharp
|
||||
MonitorParameters parameters = new MonitorParameters()
|
||||
{
|
||||
Name = monitor.Name,
|
||||
Uri = monitor.Target != null ? monitor.Target : null,
|
||||
Target = monitor.Target != null ? monitor.Target : null,
|
||||
Port = monitor.Port,
|
||||
HTTPPassword = monitor.HTTPPassword,
|
||||
HTTPUsername = monitor.HTTPUsername,
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using System.Runtime.Serialization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace UptimeSharp.Models
|
||||
{
|
||||
@@ -24,7 +26,7 @@ namespace UptimeSharp.Models
|
||||
/// The URI.
|
||||
/// </value>
|
||||
[DataMember(Name = "monitorURL")]
|
||||
public string Uri { get; set; }
|
||||
public string Target { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the port.
|
||||
@@ -98,5 +100,55 @@ namespace UptimeSharp.Models
|
||||
/// </value>
|
||||
[DataMember(Name = "monitorAlertContacts")]
|
||||
public string[] Alerts { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Converts an object to a list of HTTP Get parameters.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Dictionary<string, string> Convert()
|
||||
{
|
||||
Dictionary<string, string> parameters = new Dictionary<string, string>();
|
||||
|
||||
parameters.Add("monitorFriendlyName", Name);
|
||||
parameters.Add("monitorURL", Target);
|
||||
|
||||
if ((int)Type != 0)
|
||||
{
|
||||
parameters.Add("monitorType", Type.ToString());
|
||||
}
|
||||
|
||||
// special params for port listener
|
||||
if (Type == Type.Port && Subtype != Subtype.Unknown)
|
||||
{
|
||||
parameters.Add("monitorSubType", Subtype.ToString());
|
||||
|
||||
if (Subtype == Subtype.Custom && Port.HasValue)
|
||||
{
|
||||
parameters.Add("monitorPort", Port.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
// keyword listener
|
||||
if (Type == Type.Keyword && !String.IsNullOrEmpty(KeywordValue))
|
||||
{
|
||||
parameters.Add("monitorKeywordType", KeywordType.ToString());
|
||||
parameters.Add("monitorKeywordValue", KeywordValue);
|
||||
}
|
||||
|
||||
// HTTP basic auth credentials
|
||||
if (!String.IsNullOrEmpty(HTTPUsername))
|
||||
{
|
||||
parameters.Add("monitorHTTPUsername", HTTPUsername);
|
||||
parameters.Add("monitorHTTPPassword", HTTPPassword);
|
||||
}
|
||||
|
||||
// alert notifications
|
||||
if (Alerts != null && Alerts.Length > 0)
|
||||
{
|
||||
parameters.Add("monitorAlertContacts", String.Join("-", Alerts));
|
||||
}
|
||||
|
||||
return parameters;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ namespace UptimeSharp
|
||||
_restClient.Timeout = TimeSpan.FromSeconds(timeout.Value);
|
||||
}
|
||||
|
||||
// set base uri
|
||||
// set base target
|
||||
_restClient.BaseAddress = baseUri;
|
||||
|
||||
// defines the response format
|
||||
|
||||
Reference in New Issue
Block a user