simplify Monitor API
This commit is contained in:
@@ -9,27 +9,23 @@ namespace UptimeSharp
|
||||
/// </summary>
|
||||
public partial class UptimeClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Retrieves all monitors from UptimeRobot
|
||||
/// </summary>
|
||||
/// <param name="parameters">parameters, which are mapped to the officials from http://www.uptimerobot.com/api.asp#methods </param>
|
||||
/// <returns></returns>
|
||||
public List<Monitor> Retrieve(RetrieveParameters parameters)
|
||||
{
|
||||
return Get<RetrieveResponse>("getMonitors", parameters.Convert()).Items;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all monitors from UptimeRobot
|
||||
/// Retrieves specified monitors from UptimeRobot
|
||||
/// </summary>
|
||||
/// <param name="monitors">monitor list</param>
|
||||
/// <returns></returns>
|
||||
public List<Monitor> Retrieve()
|
||||
public List<Monitor> Retrieve(int[] monitors = null, float[] customUptimeRatio = null, bool showLog = false, bool showAlerts = true)
|
||||
{
|
||||
return Retrieve(new RetrieveParameters()
|
||||
RetrieveParameters parameters = new RetrieveParameters()
|
||||
{
|
||||
ShowAlerts = true
|
||||
});
|
||||
Monitors = monitors,
|
||||
CustomUptimeRatio = customUptimeRatio,
|
||||
ShowAlerts = showAlerts,
|
||||
ShowLog = showLog
|
||||
};
|
||||
|
||||
return Get<RetrieveResponse>("getMonitors", parameters.Convert()).Items;
|
||||
}
|
||||
|
||||
|
||||
@@ -40,43 +36,18 @@ namespace UptimeSharp
|
||||
/// <returns></returns>
|
||||
public Monitor Retrieve(int monitorId)
|
||||
{
|
||||
return Retrieve(new RetrieveParameters()
|
||||
{
|
||||
Monitors = new int[] { monitorId },
|
||||
ShowAlerts = true
|
||||
})[0];
|
||||
return Retrieve(new int[] { monitorId })[0];
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves specified monitors from UptimeRobot
|
||||
/// </summary>
|
||||
/// <param name="monitors">monitor list</param>
|
||||
/// <returns></returns>
|
||||
public List<Monitor> Retrieve(int[] monitors)
|
||||
{
|
||||
return Retrieve(new RetrieveParameters()
|
||||
{
|
||||
Monitors = monitors,
|
||||
ShowAlerts = true
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a monitor
|
||||
/// </summary>
|
||||
/// <param name="ID">The unique identifier for the monitor.</param>
|
||||
/// <param name="monitorId">The unique identifier for the monitor.</param>
|
||||
/// <returns>success state</returns>
|
||||
public bool Delete(int ID)
|
||||
public bool Delete(int monitorId)
|
||||
{
|
||||
List<Parameter> parameters = new List<Parameter>()
|
||||
{
|
||||
new Parameter() { Name = "monitorID", Value = ID, Type = ParameterType.GetOrPost }
|
||||
};
|
||||
|
||||
return Get<DefaultResponse>("deleteMonitor", parameters).Status;
|
||||
return Get<DefaultResponse>("deleteMonitor", Parameter("monitorID", monitorId)).Status;
|
||||
}
|
||||
|
||||
|
||||
@@ -91,105 +62,40 @@ namespace UptimeSharp
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Creates a monitor.
|
||||
/// </summary>
|
||||
/// <param name="parameters">The monitor parameters.</param>
|
||||
/// <returns>
|
||||
/// success state
|
||||
/// </returns>
|
||||
public bool Add(MonitorParameters parameters)
|
||||
{
|
||||
return Get<DefaultResponse>("newMonitor", parameters.Convert()).Status;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Creates a HTTP/IP monitor.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the new monitor.</param>
|
||||
/// <param name="uri">The URI or IP to watch.</param>
|
||||
/// <param name="alerts">A ID list of existing alerts to notify.</param>
|
||||
/// <returns>
|
||||
/// success state
|
||||
/// </returns>
|
||||
public bool Add(string name, string uri, int[] alerts = null)
|
||||
{
|
||||
return Add(new MonitorParameters()
|
||||
{
|
||||
Name = name,
|
||||
Uri = uri,
|
||||
Type = Type.HTTP,
|
||||
Alerts = alerts
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Creates a Port monitor.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the new monitor.</param>
|
||||
/// <param name="uri">The URI or IP to watch.</param>
|
||||
/// <param name="type">The type of the monitor.</param>
|
||||
/// <param name="subtype">The subtype of the port.</param>
|
||||
/// <param name="port">The port (only for Subtype.Custom).</param>
|
||||
/// <param name="keywordValue">The keyword value.</param>
|
||||
/// <param name="keywordType">Type of the keyword.</param>
|
||||
/// <param name="alerts">A ID list of existing alerts to notify.</param>
|
||||
/// <returns>
|
||||
/// success state
|
||||
/// </returns>
|
||||
public bool Add(string name, string uri, Subtype subtype, int? port = null, int[] alerts = null)
|
||||
public bool Add(string name, string uri, Type type = Type.HTTP, Subtype subtype = Subtype.Unknown,
|
||||
int? port = null, string keywordValue = null, KeywordType keywordType = KeywordType.Unknown,
|
||||
int[] alerts = null, string HTTPPassword = null, string HTTPUsername = null)
|
||||
{
|
||||
return Add(new MonitorParameters()
|
||||
|
||||
MonitorParameters parameters = new MonitorParameters()
|
||||
{
|
||||
Name = name,
|
||||
Uri = uri,
|
||||
Type = Type.Port,
|
||||
Type = type,
|
||||
Subtype = subtype,
|
||||
Port = port,
|
||||
Alerts = alerts
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Creates a Keyword monitor.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the new monitor.</param>
|
||||
/// <param name="uri">The URI or IP to watch.</param>
|
||||
/// <param name="keywordType">Type of the keyword.</param>
|
||||
/// <param name="keywordValue">The keyword value.</param>
|
||||
/// <param name="alerts">A ID list of existing alerts to notify.</param>
|
||||
/// <returns>
|
||||
/// success state
|
||||
/// </returns>
|
||||
public bool Add(string name, string uri, string keyword, KeywordType keywordType = KeywordType.Exists, int[] alerts = null)
|
||||
{
|
||||
return Add(new MonitorParameters()
|
||||
{
|
||||
Name = name,
|
||||
Uri = uri,
|
||||
Type = Type.Keyword,
|
||||
KeywordValue = keyword,
|
||||
KeywordType = keywordType,
|
||||
Alerts = alerts
|
||||
});
|
||||
}
|
||||
KeywordValue = keywordValue,
|
||||
Alerts = alerts,
|
||||
HTTPPassword = HTTPPassword,
|
||||
HTTPUsername = HTTPUsername
|
||||
};
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Edits a monitor.
|
||||
/// </summary>
|
||||
/// <param name="monitorID">The monitor unique identifier.</param>
|
||||
/// <param name="parameters">The monitor parameters.</param>
|
||||
/// <returns>
|
||||
/// success state
|
||||
/// </returns>
|
||||
public bool Modify(int monitorID, MonitorParameters parameters)
|
||||
{
|
||||
List<Parameter> paramList = parameters.Convert();
|
||||
paramList.Add(Parameter("monitorID", monitorID));
|
||||
|
||||
return Get<DefaultResponse>("editorMonitor", paramList).Status;
|
||||
return Get<DefaultResponse>("newMonitor", parameters.Convert()).Status;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace UptimeSharp.Models
|
||||
/// <summary>
|
||||
/// All parameters which can be passed for monitor modifications
|
||||
/// </summary>
|
||||
public class MonitorParameters
|
||||
internal class MonitorParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the name.
|
||||
@@ -102,7 +102,7 @@ namespace UptimeSharp.Models
|
||||
parameters.Add(UptimeClient.Parameter("monitorFriendlyName", Name));
|
||||
parameters.Add(UptimeClient.Parameter("monitorURL", Uri));
|
||||
|
||||
if(Type != null && (int)Type != 0)
|
||||
if ((int)Type != 0)
|
||||
{
|
||||
parameters.Add(UptimeClient.Parameter("monitorType", (int)Type));
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace UptimeSharp.Models
|
||||
/// <summary>
|
||||
/// All parameters which can be passed for monitor retrieval
|
||||
/// </summary>
|
||||
public class RetrieveParameters
|
||||
internal class RetrieveParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// List of monitor ids
|
||||
@@ -50,8 +50,15 @@ namespace UptimeSharp.Models
|
||||
{
|
||||
List<Parameter> parameters = new List<Parameter>();
|
||||
|
||||
parameters.Add(UptimeClient.Parameter("monitors", String.Join("-", Monitors)));
|
||||
parameters.Add(UptimeClient.Parameter("customUptimeRatio", String.Join("-", CustomUptimeRatio)));
|
||||
if (Monitors != null && Monitors.Length > 0)
|
||||
{
|
||||
parameters.Add(UptimeClient.Parameter("monitors", String.Join("-", Monitors)));
|
||||
}
|
||||
if (CustomUptimeRatio != null && CustomUptimeRatio.Length > 0)
|
||||
{
|
||||
parameters.Add(UptimeClient.Parameter("customUptimeRatio", String.Join("-", CustomUptimeRatio)));
|
||||
}
|
||||
|
||||
parameters.Add(UptimeClient.Parameter("showMonitorAlertContacts", (bool)ShowAlerts ? "1" : "0"));
|
||||
|
||||
if (ShowLog.HasValue)
|
||||
|
||||
Reference in New Issue
Block a user