Exemplo n.º 1
0
        /// <summary>
        /// Deletes the enrichment rule.
        /// </summary>
        /// <param name="rule">Rule to be deleted.</param>
        /// <returns>A task the caller can wait on.</returns>
        public async Task DeleteAsync(MetricEnrichmentRule rule)
        {
            if (rule == null)
            {
                throw new ArgumentNullException(nameof(rule));
            }

            var validationFailureMessage = rule.Validate();

            if (!string.IsNullOrEmpty(validationFailureMessage))
            {
                throw new ArgumentException(validationFailureMessage);
            }

            var path = $"{this.configurationUrlPrefix}";

            var uriBuilder = new UriBuilder(this.connectionInfo.GetEndpoint(string.Empty))
            {
                Path = path
            };

            var serializedMetric = JsonConvert.SerializeObject(rule, Formatting.Indented, this.serializerSettings);
            await HttpClientHelper.GetResponseAsStringAsync(
                uriBuilder.Uri,
                HttpMethod.Delete,
                this.httpClient,
                string.Empty,
                this.configurationUrlPrefix,
                serializedContent : serializedMetric).ConfigureAwait(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Save the metric configuration provided.
        /// </summary>
        /// <param name="rule">Rule to save.</param>
        /// <returns>A task the caller can wait on.</returns>
        public async Task SaveAsync(MetricEnrichmentRule rule)
        {
            if (rule == null)
            {
                throw new ArgumentNullException(nameof(rule));
            }

            var validationFailureMessage = rule.Validate();

            if (!string.IsNullOrEmpty(validationFailureMessage))
            {
                throw new ArgumentException(validationFailureMessage);
            }

            if (!rule.MonitoringAccountFilter.Equals("*"))
            {
                throw new ArgumentException("Monitoring account needs to be * as this is stamp level rule.");
            }

            var path = $"{this.configurationUrlPrefix}";

            var uriBuilder = new UriBuilder(this.connectionInfo.GetEndpoint(string.Empty))
            {
                Path  = path,
                Query = "apiVersion=1"
            };

            var serializedMetric = JsonConvert.SerializeObject(rule, Formatting.Indented, this.serializerSettings);

            await HttpClientHelper.GetResponseAsStringAsync(
                uriBuilder.Uri,
                HttpMethod.Post,
                this.httpClient,
                string.Empty,
                this.configurationUrlPrefix,
                serializedContent : serializedMetric).ConfigureAwait(false);
        }
        /// <summary>
        /// Save the metric configuration provided.
        /// </summary>
        /// <param name="monitoringAccount">The monitoring account configuration.</param>
        /// <param name="rule">Rule to save.</param>
        /// <returns>A task the caller can wait on.</returns>
        public async Task SaveAsync(string monitoringAccount, MetricEnrichmentRule rule)
        {
            if (string.IsNullOrEmpty(monitoringAccount))
            {
                throw new ArgumentNullException(nameof(monitoringAccount));
            }

            if (rule == null)
            {
                throw new ArgumentNullException(nameof(rule));
            }

            var validationFailureMessage = rule.Validate();

            if (!string.IsNullOrEmpty(validationFailureMessage))
            {
                throw new ArgumentException(validationFailureMessage);
            }

            var path = $"{this.configurationUrlPrefix}monitoringAccount/{monitoringAccount}";

            var uriBuilder = new UriBuilder(this.connectionInfo.GetEndpoint(monitoringAccount))
            {
                Path  = path,
                Query = "apiVersion=1"
            };

            var serializedMetric = JsonConvert.SerializeObject(rule);

            await HttpClientHelper.GetResponseAsStringAsync(
                uriBuilder.Uri,
                HttpMethod.Post,
                this.httpClient,
                monitoringAccount,
                this.configurationUrlPrefix,
                serializedContent : serializedMetric).ConfigureAwait(false);
        }