예제 #1
0
        /// <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");
            }
        }
예제 #2
0
        /// <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>());
        }
예제 #3
0
 /// <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.RemoteMysqlBanner"/> checks.
 /// </remarks>
 protected internal override bool SupportsCheckType(CheckTypeId checkTypeId)
 {
     return(checkTypeId == CheckTypeId.RemoteMysqlBanner);
 }
예제 #5
0
 /// <inheritdoc/>
 /// <remarks>
 /// This class only supports <see cref="CheckTypeId.AgentLoadAverage"/> checks.
 /// </remarks>
 protected internal override bool SupportsCheckType(CheckTypeId checkTypeId)
 {
     return(checkTypeId == CheckTypeId.AgentLoadAverage);
 }
 /// <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 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)
 {
 }
예제 #7
0
 /// <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);
 }
예제 #8
0
 /// <inheritdoc/>
 /// <remarks>
 /// This class only supports <see cref="CheckTypeId.AgentMemory"/> checks.
 /// </remarks>
 protected internal override bool SupportsCheckType(CheckTypeId checkTypeId)
 {
     return(checkTypeId == CheckTypeId.AgentMemory);
 }
예제 #9
0
 /// <inheritdoc/>
 /// <remarks>
 /// This class only supports <see cref="CheckTypeId.RemoteHttp"/> checks.
 /// </remarks>
 protected internal override bool SupportsCheckType(CheckTypeId checkTypeId)
 {
     return(checkTypeId == CheckTypeId.RemoteHttp);
 }
예제 #10
0
 /// <inheritdoc/>
 /// <remarks>
 /// This class only supports <see cref="CheckTypeId.AgentFilesystem"/> checks.
 /// </remarks>
 protected internal override bool SupportsCheckType(CheckTypeId checkTypeId)
 {
     return(checkTypeId == CheckTypeId.AgentFilesystem);
 }
예제 #11
0
 /// <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);