/// <summary> /// Deserializes a JSON object to a <see cref="CheckDetails"/> instance of the proper type. /// </summary> /// <param name="checkTypeId">The check type ID.</param> /// <param name="obj">The JSON object representing the check details.</param> /// <returns>A <see cref="CheckDetails"/> object corresponding to the JSON object.</returns> /// <exception cref="ArgumentNullException"> /// If <paramref name="checkTypeId"/> is <see langword="null"/>. /// <para>-or-</para> /// <para>If <paramref name="obj"/> is <see langword="null"/>.</para> /// </exception> public static CheckDetails FromJObject(CheckTypeId checkTypeId, JObject obj) { if (checkTypeId == null) throw new ArgumentNullException("checkTypeId"); if (obj == null) throw new ArgumentNullException("obj"); Func<JObject, CheckDetails> factory; if (DetailsFactories.TryGetValue(checkTypeId, out factory)) return factory(obj); return obj.ToObject<GenericCheckDetails>(); }
/// <summary> /// Initializes a new instance of the <see cref="NewCheckConfiguration"/> class /// with the specified properties. /// </summary> /// <param name="label">The friendly name of the check. If this is <see langword="null"/>, the label assigned to the new check is unspecified.</param> /// <param name="checkTypeId">The check type ID. This is obtained from <see cref="CheckType.Id">CheckType.Id</see>, or from the predefined values in <see cref="CheckTypeId"/>.</param> /// <param name="details">A <see cref="CheckDetails"/> object containing detailed configuration information for the specific check type.</param> /// <param name="monitoringZonesPoll">A collection of <see cref="MonitoringZoneId"/> objects identifying the monitoring zones to poll from.</param> /// <param name="timeout">The timeout of a check operation. If this value is <see langword="null"/>, a provider-specific default value is used.</param> /// <param name="period">The period between check operations. If this value is <see langword="null"/>, a provider-specific default value is used.</param> /// <param name="targetAlias">The alias of the target for this check in the associated entity's <see cref="EntityConfiguration.IPAddresses"/> map.</param> /// <param name="targetHostname">The hostname this check should target.</param> /// <param name="resolverType">The type of resolver to use for converting <paramref name="targetHostname"/> to an IP address.</param> /// <param name="metadata">A collection of metadata to associate with the check. If this parameter is <see langword="null"/>, the check is created without any custom metadata.</param> /// <exception cref="ArgumentNullException"> /// If <paramref name="checkTypeId"/> is <see langword="null"/>. /// <para>-or-</para> /// <para>If <paramref name="details"/> is <see langword="null"/>.</para> /// </exception> /// <exception cref="ArgumentException"> /// If <paramref name="label"/> is non-<see langword="null"/> but empty. /// <para>-or-</para> /// <para>If the specified <paramref name="details"/> object does support checks of type <paramref name="checkTypeId"/>.</para> /// <para>-or-</para> /// <para>If <paramref name="checkTypeId"/> is a remote check (i.e. the <see cref="Monitoring.CheckTypeId.IsRemote"/> property is <see langword="true"/>) and <paramref name="monitoringZonesPoll"/> is <see langword="null"/> or empty.</para> /// <para>-or-</para> /// <para>If <paramref name="checkTypeId"/> is a remote check (i.e. the <see cref="Monitoring.CheckTypeId.IsRemote"/> property is <see langword="true"/>) and both <paramref name="targetAlias"/> and <paramref name="targetHostname"/> are <see langword="null"/>.</para> /// <para>-or-</para> /// <para>If <paramref name="monitoringZonesPoll"/> contains any <see langword="null"/> values.</para> /// <para>-or-</para> /// <para>If <paramref name="period"/> is less than or equal to <paramref name="timeout"/>.</para> /// <para>-or-</para> /// <para>If <paramref name="targetAlias"/> is non-<see langword="null"/> but empty.</para> /// <para>-or-</para> /// <para>If <paramref name="targetHostname"/> is non-<see langword="null"/> but empty.</para> /// <para>-or-</para> /// <para>If <paramref name="metadata"/> contains any empty keys, or any <see langword="null"/> values.</para> /// </exception> /// <exception cref="ArgumentOutOfRangeException"> /// If <paramref name="timeout"/> is less than or equal to <see cref="TimeSpan.Zero"/>. /// <para>-or-</para> /// <para>If <paramref name="period"/> is less than or equal to <see cref="TimeSpan.Zero"/>.</para> /// </exception> /// <exception cref="InvalidOperationException"> /// If <paramref name="targetAlias"/> and <paramref name="targetHostname"/> are both non-<see langword="null"/>. /// </exception> public NewCheckConfiguration(string label, CheckTypeId checkTypeId, CheckDetails details, IEnumerable<MonitoringZoneId> monitoringZonesPoll, TimeSpan? timeout, TimeSpan? period, string targetAlias, string targetHostname, TargetResolverType resolverType, IDictionary<string, string> metadata) : base(label, checkTypeId, details, monitoringZonesPoll, timeout, period, targetAlias, targetHostname, resolverType, metadata) { if (checkTypeId == null) throw new ArgumentNullException("checkTypeId"); if (details == null) throw new ArgumentNullException("details"); if (checkTypeId.IsRemote && monitoringZonesPoll == null) throw new ArgumentException("monitoringZonesPoll cannot be null or empty for remote checks", "monitoringZonesPoll"); if (checkTypeId.IsRemote && targetAlias == null && targetHostname == null) throw new ArgumentException("targetAlias and targetHostname cannot both be null for remote checks"); if (checkTypeId.IsRemote && MonitoringZonesPoll.Count == 0) throw new ArgumentException("monitoringZonesPoll cannot be null or empty for remote checks", "monitoringZonesPoll"); }
/// <inheritdoc/> /// <remarks> /// This class only supports <see cref="CheckTypeId.RemotePostgresqlBanner"/> checks. /// </remarks> protected internal override bool SupportsCheckType(CheckTypeId checkTypeId) { return checkTypeId == CheckTypeId.RemotePostgresqlBanner; }
/// <inheritdoc/> /// <remarks> /// This class can be used for any check type. Clients using this class are responsible /// for adding the necessary properties for their specific check type. /// </remarks> protected internal override bool SupportsCheckType(CheckTypeId checkTypeId) { return true; }
/// <summary> /// Gets a monitoring check type by ID. /// </summary> /// <param name="service">The monitoring service instance.</param> /// <param name="checkTypeId">The check type ID. This is obtained from <see cref="CheckType.Id">CheckType.Id</see>, or from the predefined values in <see cref="CheckTypeId"/>.</param> /// <returns>A <see cref="CheckType"/> object describing the check type.</returns> /// <exception cref="ArgumentNullException">If <paramref name="service"/> is <see langword="null"/>.</exception> /// <exception cref="ArgumentNullException">If <paramref name="checkTypeId"/> is <see langword="null"/>.</exception> /// <exception cref="WebException">If the REST request does not return successfully.</exception> /// <seealso href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/service-check-types.html#service-check-types-get">Get Check Type (Rackspace Cloud Monitoring Developer Guide - API v1.0)</seealso> public static CheckType GetCheckType(this IMonitoringService service, CheckTypeId checkTypeId) { if (service == null) throw new ArgumentNullException("service"); try { return service.GetCheckTypeAsync(checkTypeId, CancellationToken.None).Result; } catch (AggregateException ex) { ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions; if (innerExceptions.Count == 1) throw innerExceptions[0]; throw; } }
/// <summary> /// Gets a collection of monitoring check types. /// </summary> /// <param name="service">The monitoring service instance.</param> /// <param name="marker">A marker identifying the next page of results. This parameter is used for <see href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/api-paginated-collections.html">pagination</see>, and is obtained from <see cref="ReadOnlyCollectionPage{T, TMarker}.NextMarker"/>. If the value is <see langword="null"/>, the list starts at the beginning.</param> /// <param name="limit">The maximum number of items to include in a single page of results. This parameter is used for <see href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/api-paginated-collections.html">pagination</see>. If the value is <see langword="null"/>, a provider-specific default value is used.</param> /// <returns> /// A <see cref="ReadOnlyCollectionPage{T, TMarker}"/> object containing the page /// of results and its associated pagination metadata. /// </returns> /// <exception cref="ArgumentNullException">If <paramref name="service"/> is <see langword="null"/>.</exception> /// <exception cref="ArgumentOutOfRangeException">If <paramref name="limit"/> is less than or equal to 0.</exception> /// <exception cref="WebException">If the REST request does not return successfully.</exception> /// <seealso href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/service-check-types.html#service-check-types-list">List Check Types (Rackspace Cloud Monitoring Developer Guide - API v1.0)</seealso> /// <seealso href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/api-paginated-collections.html">Paginated Collections (Rackspace Cloud Monitoring Developer Guide - API v1.0)</seealso> public static ReadOnlyCollectionPage<CheckType, CheckTypeId> ListCheckTypes(this IMonitoringService service, CheckTypeId marker, int? limit) { if (service == null) throw new ArgumentNullException("service"); try { return service.ListCheckTypesAsync(marker, limit, CancellationToken.None).Result; } catch (AggregateException ex) { ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions; if (innerExceptions.Count == 1) throw innerExceptions[0]; throw; } }
/// <inheritdoc/> /// <remarks> /// This class only supports <see cref="CheckTypeId.RemoteSsh"/> checks. /// </remarks> protected internal override bool SupportsCheckType(CheckTypeId checkTypeId) { return checkTypeId == CheckTypeId.RemoteSsh; }
/// <summary> /// Determines whether the current <see cref="CheckDetails"/> object is compatible /// with checks of a particular type. /// </summary> /// <param name="checkTypeId">The check type ID.</param> /// <returns><see langword="true"/> if the current <see cref="CheckDetails"/> object is compatible with <paramref name="checkTypeId"/>; otherwise, <see langword="false"/>.</returns> /// <exception cref="ArgumentNullException">If <paramref name="checkTypeId"/> is <see langword="null"/>.</exception> protected internal abstract bool SupportsCheckType(CheckTypeId checkTypeId);
/// <inheritdoc/> /// <remarks> /// This class only supports <see cref="CheckTypeId.AgentLoadAverage"/> checks. /// </remarks> protected internal override bool SupportsCheckType(CheckTypeId checkTypeId) { return checkTypeId == CheckTypeId.AgentLoadAverage; }
/// <inheritdoc/> /// <remarks> /// This class only supports <see cref="CheckTypeId.AgentMemory"/> checks. /// </remarks> protected internal override bool SupportsCheckType(CheckTypeId checkTypeId) { return checkTypeId == CheckTypeId.AgentMemory; }
/// <summary> /// Initializes a new instance of the <see cref="CheckConfiguration"/> class /// with the specified properties. /// </summary> /// <param name="label">The friendly name of the check. If this value is <see langword="null"/>, the underlying property will be omitted from the JSON representation of the object.</param> /// <param name="checkTypeId">The check type ID. This is obtained from <see cref="CheckType.Id">CheckType.Id</see>, or from the predefined values in <see cref="CheckTypeId"/>. If this value is <see langword="null"/>, the underlying property will be omitted from the JSON representation of the object.</param> /// <param name="details">A <see cref="CheckDetails"/> object containing detailed configuration information for the specific check type. If this value is <see langword="null"/>, the underlying property will be omitted from the JSON representation of the object.</param> /// <param name="monitoringZonesPoll">A collection of <see cref="MonitoringZoneId"/> objects identifying the monitoring zones to poll from. If this value is <see langword="null"/>, the underlying property will be omitted from the JSON representation of the object.</param> /// <param name="timeout">The timeout of a check operation. If this value is <see langword="null"/>, the underlying property will be omitted from the JSON representation of the object.</param> /// <param name="period">The period between check operations. If this value is <see langword="null"/>, the underlying property will be omitted from the JSON representation of the object.</param> /// <param name="targetAlias">The alias of the target for this check in the associated entity's <see cref="EntityConfiguration.IPAddresses"/> map. If this value is <see langword="null"/>, the underlying property will be omitted from the JSON representation of the object.</param> /// <param name="targetHostname">The hostname this check should target. If this value is <see langword="null"/>, the underlying property will be omitted from the JSON representation of the object.</param> /// <param name="resolverType">The type of resolver to use for converting <paramref name="targetHostname"/> to an IP address. If this value is <see langword="null"/>, the underlying property will be omitted from the JSON representation of the object.</param> /// <param name="metadata">A collection of metadata to associate with the check. If this value is <see langword="null"/>, the underlying property will be omitted from the JSON representation of the object.</param> /// <exception cref="ArgumentException"> /// If <paramref name="label"/> is non-<see langword="null"/> but empty. /// <para>-or-</para> /// <para>If the specified <paramref name="details"/> object does support checks of type <paramref name="checkTypeId"/>.</para> /// <para>-or-</para> /// <para>If <paramref name="monitoringZonesPoll"/> contains any <see langword="null"/> values.</para> /// <para>-or-</para> /// <para>If <paramref name="period"/> is less than or equal to <paramref name="timeout"/>.</para> /// <para>-or-</para> /// <para>If <paramref name="targetAlias"/> is non-<see langword="null"/> but empty.</para> /// <para>-or-</para> /// <para>If <paramref name="targetHostname"/> is non-<see langword="null"/> but empty.</para> /// <para>-or-</para> /// <para>If <paramref name="metadata"/> contains any empty keys.</para> /// </exception> /// <exception cref="ArgumentOutOfRangeException"> /// If <paramref name="timeout"/> is less than or equal to <see cref="TimeSpan.Zero"/>. /// <para>-or-</para> /// <para>If <paramref name="period"/> is less than or equal to <see cref="TimeSpan.Zero"/>.</para> /// </exception> /// <exception cref="InvalidOperationException"> /// If <paramref name="targetAlias"/> and <paramref name="targetHostname"/> are both non-<see langword="null"/>. /// </exception> protected CheckConfiguration(string label, CheckTypeId checkTypeId, CheckDetails details, IEnumerable<MonitoringZoneId> monitoringZonesPoll, TimeSpan? timeout, TimeSpan? period, string targetAlias, string targetHostname, TargetResolverType resolverType, IDictionary<string, string> metadata) { if (label == string.Empty) throw new ArgumentException("label cannot be empty"); if (targetAlias == string.Empty) throw new ArgumentException("targetAlias cannot be empty"); if (targetHostname == string.Empty) throw new ArgumentException("targetHostname cannot be empty"); if (details != null && !details.SupportsCheckType(checkTypeId)) throw new ArgumentException(string.Format("The check details object does not support '{0}' checks.", checkTypeId), "details"); if (timeout <= TimeSpan.Zero) throw new ArgumentOutOfRangeException("timeout"); if (period <= TimeSpan.Zero) throw new ArgumentOutOfRangeException("period"); if (period <= timeout) throw new ArgumentException("period cannot be less than or equal to timeout", "period"); if (targetAlias != null && targetHostname != null) throw new InvalidOperationException("targetAlias and targetHostname cannot both be specified"); if (metadata != null && metadata.ContainsKey(string.Empty)) throw new ArgumentException("metadata cannot contain any empty keys", "metadata"); _label = label; _type = checkTypeId; _details = details != null ? JObject.FromObject(details) : null; _monitoringZonesPoll = monitoringZonesPoll != null ? monitoringZonesPoll.ToArray() : null; _timeout = timeout.HasValue ? (int?)timeout.Value.TotalSeconds : null; _period = period.HasValue ? (int?)period.Value.TotalSeconds : null; _targetAlias = targetAlias; _targetHostname = targetHostname; _resolverType = resolverType; _metadata = metadata; // this check is at the end of the constructor so monitoringZonesPoll is only enumerated once if (_monitoringZonesPoll != null && _monitoringZonesPoll.Contains(null)) throw new ArgumentException("monitoringZonesPoll cannot contain any null values", "monitoringZonesPoll"); }
/// <inheritdoc/> /// <remarks> /// This class only supports <see cref="CheckTypeId.RemoteTelnetBanner"/> checks. /// </remarks> protected internal override bool SupportsCheckType(CheckTypeId checkTypeId) { return checkTypeId == CheckTypeId.RemoteTelnetBanner; }
/// <summary> /// Initializes a new instance of the <see cref="UpdateCheckConfiguration"/> class /// with the specified properties. /// </summary> /// <param name="label">The friendly name of the check. If this value is <see langword="null"/>, the existing value for the check is not changed.</param> /// <param name="checkTypeId">The check type ID. This is obtained from <see cref="CheckType.Id">CheckType.Id</see>, or from the predefined values in <see cref="CheckTypeId"/>. If this value is <see langword="null"/>, the existing value for the check is not changed.</param> /// <param name="details">A <see cref="CheckDetails"/> object containing detailed configuration information for the specific check type. If this value is <see langword="null"/>, the existing value for the check is not changed.</param> /// <param name="monitoringZonesPoll">A collection of <see cref="MonitoringZoneId"/> objects identifying the monitoring zones to poll from. If this value is <see langword="null"/>, the existing value for the check is not changed.</param> /// <param name="timeout">The timeout of a check operation. If this value is <see langword="null"/>, the existing value for the check is not changed.</param> /// <param name="period">The period between check operations. If this value is <see langword="null"/>, the existing value for the check is not changed.</param> /// <param name="targetAlias">The alias of the target for this check in the associated entity's <see cref="EntityConfiguration.IPAddresses"/> map. If this value is <see langword="null"/>, the existing value for the check is not changed.</param> /// <param name="targetHostname">The hostname this check should target. If this value is <see langword="null"/>, the existing value for the check is not changed.</param> /// <param name="resolverType">The type of resolver to use for converting <paramref name="targetHostname"/> to an IP address. If this value is <see langword="null"/>, the existing value for the check is not changed.</param> /// <param name="metadata">A collection of metadata to associate with the check. If this value is <see langword="null"/>, the existing value for the check is not changed.</param> /// <exception cref="ArgumentException"> /// If <paramref name="label"/> is non-<see langword="null"/> but empty. /// <para>-or-</para> /// <para>If the specified <paramref name="details"/> object does support checks of type <paramref name="checkTypeId"/>.</para> /// <para>-or-</para> /// <para>If <paramref name="monitoringZonesPoll"/> contains any <see langword="null"/> values.</para> /// <para>-or-</para> /// <para>If <paramref name="period"/> is less than or equal to <paramref name="timeout"/>.</para> /// <para>-or-</para> /// <para>If <paramref name="targetAlias"/> is non-<see langword="null"/> but empty.</para> /// <para>-or-</para> /// <para>If <paramref name="targetHostname"/> is non-<see langword="null"/> but empty.</para> /// <para>-or-</para> /// <para>If <paramref name="metadata"/> contains any empty keys.</para> /// </exception> /// <exception cref="ArgumentOutOfRangeException"> /// If <paramref name="timeout"/> is less than or equal to <see cref="TimeSpan.Zero"/>. /// <para>-or-</para> /// <para>If <paramref name="period"/> is less than or equal to <see cref="TimeSpan.Zero"/>.</para> /// </exception> /// <exception cref="InvalidOperationException"> /// If <paramref name="targetAlias"/> and <paramref name="targetHostname"/> are both non-<see langword="null"/>. /// </exception> public UpdateCheckConfiguration(string label = null, CheckTypeId checkTypeId = null, CheckDetails details = null, IEnumerable<MonitoringZoneId> monitoringZonesPoll = null, TimeSpan? timeout = null, TimeSpan? period = null, string targetAlias = null, string targetHostname = null, TargetResolverType resolverType = null, IDictionary<string, string> metadata = null) : base(label, checkTypeId, details, monitoringZonesPoll, timeout, period, targetAlias, targetHostname, resolverType, metadata) { }
/// <inheritdoc/> /// <remarks> /// This class only supports <see cref="CheckTypeId.AgentFilesystem"/> checks. /// </remarks> protected internal override bool SupportsCheckType(CheckTypeId checkTypeId) { return checkTypeId == CheckTypeId.AgentFilesystem; }