Modify a monitor
This commit is contained in:
@@ -95,7 +95,7 @@ namespace UptimeSharp
|
||||
/// <summary>
|
||||
/// Creates a monitor.
|
||||
/// </summary>
|
||||
/// <param name="monitor">The monitor.</param>
|
||||
/// <param name="parameters">The monitor parameters.</param>
|
||||
/// <returns>
|
||||
/// success state
|
||||
/// </returns>
|
||||
@@ -174,5 +174,65 @@ namespace UptimeSharp
|
||||
Alerts = alerts
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/// <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(Utilities.CreateParam("monitorID", monitorID));
|
||||
|
||||
return Get<DefaultResponse>("editorMonitor", paramList).Status;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Edits a monitor.
|
||||
/// </summary>
|
||||
/// <param name="monitor">The monitor.</param>
|
||||
/// <returns>
|
||||
/// success state
|
||||
/// </returns>
|
||||
public bool Modify(Monitor monitor)
|
||||
{
|
||||
List<int> alerts = null;
|
||||
|
||||
if (monitor.Alerts != null)
|
||||
{
|
||||
monitor.Alerts.ForEach(item => alerts.Add((int)item.ID));
|
||||
}
|
||||
|
||||
MonitorParameters parameters = new MonitorParameters()
|
||||
{
|
||||
Name = monitor.Name,
|
||||
Uri = monitor.UriString != null ? monitor.UriString : null,
|
||||
Port = monitor.Port,
|
||||
HTTPPassword = monitor.HTTPPassword,
|
||||
HTTPUsername = monitor.HTTPUsername,
|
||||
KeywordType = monitor.KeywordType,
|
||||
KeywordValue = monitor.KeywordValue,
|
||||
Subtype = monitor.Subtype,
|
||||
Alerts = alerts != null ? alerts.ToArray() : null
|
||||
};
|
||||
|
||||
List<Parameter> paramList = parameters.Convert();
|
||||
|
||||
// fix bad behaviour in API if no subtype is submitted
|
||||
if(parameters.Subtype == Subtype.Unknown)
|
||||
{
|
||||
paramList.Add(Utilities.CreateParam("monitorSubType", 0));
|
||||
}
|
||||
|
||||
paramList.Add(Utilities.CreateParam("monitorID", monitor.ID));
|
||||
|
||||
return Get<DefaultResponse>("editMonitor", paramList).Status;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -97,12 +97,22 @@ namespace UptimeSharp.Models
|
||||
/// <returns>Parameter list</returns>
|
||||
public List<Parameter> Convert()
|
||||
{
|
||||
List<Parameter> parameters = new List<Parameter>()
|
||||
List<Parameter> parameters = new List<Parameter>();
|
||||
|
||||
if(!string.IsNullOrEmpty(Name))
|
||||
{
|
||||
Utilities.CreateParam("monitorFriendlyName", Name),
|
||||
Utilities.CreateParam("monitorURL", Uri),
|
||||
Utilities.CreateParam("monitorType", (int)Type)
|
||||
};
|
||||
parameters.Add(Utilities.CreateParam("monitorFriendlyName", Name));
|
||||
}
|
||||
|
||||
if(!string.IsNullOrEmpty(Uri))
|
||||
{
|
||||
parameters.Add(Utilities.CreateParam("monitorURL", Uri));
|
||||
}
|
||||
|
||||
if(Type != null && (int)Type != 0)
|
||||
{
|
||||
parameters.Add(Utilities.CreateParam("monitorType", (int)Type));
|
||||
}
|
||||
|
||||
// special params for port listener
|
||||
if (Type == Type.Port && Subtype != Subtype.Unknown && Port.HasValue)
|
||||
|
||||
Reference in New Issue
Block a user