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