Container for the parameters to the PutMetricAlarm operation.

Creates or updates an alarm and associates it with the specified Amazon CloudWatch metric. Optionally, this operation can associate one or more Amazon Simple Notification Service resources with the alarm.

When this operation creates an alarm, the alarm state is immediately set to INSUFFICIENT_DATA . The alarm is evaluated and its StateValue is set appropriately. Any actions associated with the StateValue is then executed.

NOTE: When updating an existing alarm, its StateValue is left unchanged.

Inheritance: Amazon.Runtime.AmazonWebServiceRequest
Beispiel #1
0
 private Amazon.CloudWatch.Model.PutMetricAlarmResponse CallAWSServiceOperation(IAmazonCloudWatch client, Amazon.CloudWatch.Model.PutMetricAlarmRequest request)
 {
     Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon CloudWatch", "PutMetricAlarm");
     try
     {
         #if DESKTOP
         return(client.PutMetricAlarm(request));
         #elif CORECLR
         return(client.PutMetricAlarmAsync(request).GetAwaiter().GetResult());
         #else
                 #error "Unknown build edition"
         #endif
     }
     catch (AmazonServiceException exc)
     {
         var webException = exc.InnerException as System.Net.WebException;
         if (webException != null)
         {
             throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException);
         }
         throw;
     }
 }
        /// <summary>
        /// Creates or updates an alarm and associates it with the specified Amazon CloudWatch
        /// metric. Optionally, this operation can associate one or more Amazon Simple Notification
        /// Service resources with the alarm. 
        /// 
        ///  
        /// <para>
        ///  When this operation creates an alarm, the alarm state is immediately set to <code>INSUFFICIENT_DATA</code>.
        /// The alarm is evaluated and its <code>StateValue</code> is set appropriately. Any actions
        /// associated with the <code>StateValue</code> is then executed. 
        /// </para>
        /// </summary>
        /// <param name="request">Container for the necessary parameters to execute the PutMetricAlarm service method.</param>
        /// 
        /// <returns>The response from the PutMetricAlarm service method, as returned by CloudWatch.</returns>
        /// <exception cref="Amazon.CloudWatch.Model.LimitExceededException">
        /// The quota for alarms for this customer has already been reached.
        /// </exception>
        public PutMetricAlarmResponse PutMetricAlarm(PutMetricAlarmRequest request)
        {
            var marshaller = new PutMetricAlarmRequestMarshaller();
            var unmarshaller = PutMetricAlarmResponseUnmarshaller.Instance;

            return Invoke<PutMetricAlarmRequest,PutMetricAlarmResponse>(request, marshaller, unmarshaller);
        }
        /// <summary>
        /// <para> Creates or updates an alarm and associates it with the specified Amazon CloudWatch metric. Optionally, this operation can associate
        /// one or more Amazon Simple Notification Service resources with the alarm. </para> <para> When this operation creates an alarm, the alarm
        /// state is immediately set to <c>INSUFFICIENT_DATA</c> . The alarm is evaluated and its <c>StateValue</c> is set appropriately. Any actions
        /// associated with the <c>StateValue</c> is then executed. </para> <para><b>NOTE:</b> When updating an existing alarm, its StateValue is left
        /// unchanged. </para>
        /// </summary>
        /// 
        /// <param name="putMetricAlarmRequest">Container for the necessary parameters to execute the PutMetricAlarm service method on
        /// AmazonCloudWatch.</param>
        /// 
        /// <exception cref="T:Amazon.CloudWatch.Model.LimitExceededException" />
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
		public Task<PutMetricAlarmResponse> PutMetricAlarmAsync(PutMetricAlarmRequest putMetricAlarmRequest, CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new PutMetricAlarmRequestMarshaller();
            var unmarshaller = PutMetricAlarmResponseUnmarshaller.GetInstance();
            return Invoke<IRequest, PutMetricAlarmRequest, PutMetricAlarmResponse>(putMetricAlarmRequest, marshaller, unmarshaller, signer, cancellationToken);
        }
Beispiel #4
0
        public object Execute(ExecutorContext context)
        {
            var cmdletContext = context as CmdletContext;
            // create request
            var request = new Amazon.CloudWatch.Model.PutMetricAlarmRequest();

            if (cmdletContext.ActionsEnabled != null)
            {
                request.ActionsEnabled = cmdletContext.ActionsEnabled.Value;
            }
            if (cmdletContext.AlarmAction != null)
            {
                request.AlarmActions = cmdletContext.AlarmAction;
            }
            if (cmdletContext.AlarmDescription != null)
            {
                request.AlarmDescription = cmdletContext.AlarmDescription;
            }
            if (cmdletContext.AlarmName != null)
            {
                request.AlarmName = cmdletContext.AlarmName;
            }
            if (cmdletContext.ComparisonOperator != null)
            {
                request.ComparisonOperator = cmdletContext.ComparisonOperator;
            }
            if (cmdletContext.DatapointsToAlarm != null)
            {
                request.DatapointsToAlarm = cmdletContext.DatapointsToAlarm.Value;
            }
            if (cmdletContext.Dimension != null)
            {
                request.Dimensions = cmdletContext.Dimension;
            }
            if (cmdletContext.EvaluateLowSampleCountPercentile != null)
            {
                request.EvaluateLowSampleCountPercentile = cmdletContext.EvaluateLowSampleCountPercentile;
            }
            if (cmdletContext.EvaluationPeriod != null)
            {
                request.EvaluationPeriods = cmdletContext.EvaluationPeriod.Value;
            }
            if (cmdletContext.ExtendedStatistic != null)
            {
                request.ExtendedStatistic = cmdletContext.ExtendedStatistic;
            }
            if (cmdletContext.InsufficientDataAction != null)
            {
                request.InsufficientDataActions = cmdletContext.InsufficientDataAction;
            }
            if (cmdletContext.MetricName != null)
            {
                request.MetricName = cmdletContext.MetricName;
            }
            if (cmdletContext.Metric != null)
            {
                request.Metrics = cmdletContext.Metric;
            }
            if (cmdletContext.Namespace != null)
            {
                request.Namespace = cmdletContext.Namespace;
            }
            if (cmdletContext.OKAction != null)
            {
                request.OKActions = cmdletContext.OKAction;
            }
            if (cmdletContext.Period != null)
            {
                request.Period = cmdletContext.Period.Value;
            }
            if (cmdletContext.Statistic != null)
            {
                request.Statistic = cmdletContext.Statistic;
            }
            if (cmdletContext.Tag != null)
            {
                request.Tags = cmdletContext.Tag;
            }
            if (cmdletContext.Threshold != null)
            {
                request.Threshold = cmdletContext.Threshold.Value;
            }
            if (cmdletContext.ThresholdMetricId != null)
            {
                request.ThresholdMetricId = cmdletContext.ThresholdMetricId;
            }
            if (cmdletContext.TreatMissingData != null)
            {
                request.TreatMissingData = cmdletContext.TreatMissingData;
            }
            if (cmdletContext.Unit != null)
            {
                request.Unit = cmdletContext.Unit;
            }

            CmdletOutput output;

            // issue call
            var client = Client ?? CreateClient(_CurrentCredentials, _RegionEndpoint);

            try
            {
                var    response       = CallAWSServiceOperation(client, request);
                object pipelineOutput = null;
                pipelineOutput = cmdletContext.Select(response, this);
                output         = new CmdletOutput
                {
                    PipelineOutput  = pipelineOutput,
                    ServiceResponse = response
                };
            }
            catch (Exception e)
            {
                output = new CmdletOutput {
                    ErrorResponse = e
                };
            }

            return(output);
        }
        /// <summary>
        /// <para> Creates or updates an alarm and associates it with the specified Amazon CloudWatch metric. Optionally, this operation can associate
        /// one or more Amazon Simple Notification Service resources with the alarm. </para> <para> When this operation creates an alarm, the alarm
        /// state is immediately set to <c>INSUFFICIENT_DATA</c> . The alarm is evaluated and its <c>StateValue</c> is set appropriately. Any actions
        /// associated with the <c>StateValue</c> is then executed. </para> <para><b>NOTE:</b> When updating an existing alarm, its StateValue is left
        /// unchanged. </para>
        /// </summary>
        /// 
        /// <param name="putMetricAlarmRequest">Container for the necessary parameters to execute the PutMetricAlarm service method on
        /// AmazonCloudWatch.</param>
        /// 
        /// <exception cref="T:Amazon.CloudWatch.Model.LimitExceededException" />
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
		public async Task<PutMetricAlarmResponse> PutMetricAlarmAsync(PutMetricAlarmRequest putMetricAlarmRequest, CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new PutMetricAlarmRequestMarshaller();
            var unmarshaller = PutMetricAlarmResponseUnmarshaller.GetInstance();
            var response = await Invoke<IRequest, PutMetricAlarmRequest, PutMetricAlarmResponse>(putMetricAlarmRequest, marshaller, unmarshaller, signer, cancellationToken)
                .ConfigureAwait(continueOnCapturedContext: false);
            return response;
        }
		internal PutMetricAlarmResponse PutMetricAlarm(PutMetricAlarmRequest request)
        {
            var task = PutMetricAlarmAsync(request);
            try
            {
                return task.Result;
            }
            catch(AggregateException e)
            {
                throw e.InnerException;
            }
        }
        /// two weeks, whether or not you delete the alarm. </para>
        /// </summary>
        /// 
        /// <param name="describeAlarmHistoryRequest">Container for the necessary parameters to execute the DescribeAlarmHistory service method on
        ///          AmazonCloudWatch.</param>
        /// 
        /// <returns>The response from the DescribeAlarmHistory service method, as returned by AmazonCloudWatch.</returns>
        /// 
        /// <exception cref="InvalidNextTokenException"/>
        public DescribeAlarmHistoryResponse DescribeAlarmHistory(DescribeAlarmHistoryRequest describeAlarmHistoryRequest)
        {
            IAsyncResult asyncResult = invokeDescribeAlarmHistory(describeAlarmHistoryRequest, null, null, true);
            return EndDescribeAlarmHistory(asyncResult);
        }

        
        private void CreatePhysicalMemoryUtlizationAlarm()
        {
            var dimensions = new List<Dimension>
            {
                new Dimension()
                    .WithName("InstanceId")
                    .WithValue(_instanceId)
            };

            var putMetricAlarmReq = new PutMetricAlarmRequest
            {
                ActionsEnabled = true,
                AlarmActions = _amazonSnsTopics,
                AlarmDescription = "Physical memory utilization alarm",
                AlarmName = _instanceName + "-physical-memory",
                ComparisonOperator = "GreaterThanOrEqualToThreshold",
                Dimensions = dimensions,
                EvaluationPeriods = 1,
                MetricName = "PhysicalMemoryUtilization",
                Namespace = "System/Windows",
                Period = 60*5,
                Statistic = "Average",
                Threshold = 85,
                Unit = "Percent"
            };

            RegionEndpoint regionEndpoint = RegionEndpoint.GetBySystemName(_region);
            AmazonCloudWatch cloudwatchClient = AWSClientFactory.CreateAmazonCloudWatchClient(regionEndpoint);

            cloudwatchClient.PutMetricAlarm(putMetricAlarmReq);
        }
		internal PutMetricAlarmResponse PutMetricAlarm(PutMetricAlarmRequest request)
        {
            var task = PutMetricAlarmAsync(request);
            try
            {
                return task.Result;
            }
            catch(AggregateException e)
            {
                ExceptionDispatchInfo.Capture(e.InnerException).Throw();
                return null;
            }
        }
        /// <exception cref="InvalidParameterValueException"/>
        public ListMetricsResponse ListMetrics(ListMetricsRequest listMetricsRequest)
        {
            IAsyncResult asyncResult = invokeListMetrics(listMetricsRequest, null, null, true);
            return EndListMetrics(asyncResult);
        }

        

        /// <summary>
        /// Initiates the asynchronous execution of the ListMetrics operation.
        /// <seealso cref="Amazon.CloudWatch.AmazonCloudWatch.ListMetrics"/>
        /// </summary>
        /// 
        /// <summary>
        /// Initiates the asynchronous execution of the PutMetricAlarm operation.
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the PutMetricAlarm operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        public Task<PutMetricAlarmResponse> PutMetricAlarmAsync(PutMetricAlarmRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new PutMetricAlarmRequestMarshaller();
            var unmarshaller = PutMetricAlarmResponseUnmarshaller.Instance;

            return InvokeAsync<PutMetricAlarmRequest,PutMetricAlarmResponse>(request, marshaller, 
                unmarshaller, cancellationToken);
        }
Beispiel #12
0
    public static void CWPutMetricAlarm()
    {
      #region CWPutMetricAlarm
      var client = new AmazonCloudWatchClient();

      var dimension = new Dimension
      {
        Name = "Desktop Machine Metrics",
        Value = "Virtual Desktop Machine Usage"
      };

      var request = new PutMetricAlarmRequest
      {
        ActionsEnabled = true,
        AlarmActions = new List<string>() 
          { "arn:aws:sns:us-east-1:80398EXAMPLE:CodingTestResults" },
        AlarmDescription = "Too many instances offline",
        AlarmName = "Offline Instances",
        ComparisonOperator = ComparisonOperator.GreaterThanOrEqualToThreshold,
        Dimensions = new List<Dimension>() { dimension },
        EvaluationPeriods = 1,
        MetricName = "Desktop Machines Offline",
        Namespace = "Example.com Custom Metrics",
        Period = (int)TimeSpan.FromMinutes(5).TotalSeconds,
        Statistic = new Statistic("Maximum"),
        Threshold = 5,
        Unit = StandardUnit.Count
      };

      client.PutMetricAlarm(request);
      #endregion
    }
        private void CreateStatusCheckAlarm()
        {
            var dimensions = new List<Dimension>
            {
                new Dimension()
                    .WithName("InstanceId")
                    .WithValue(_instanceId)
            };

            var putMetricAlarmReq = new PutMetricAlarmRequest
            {
                ActionsEnabled = true,
                AlarmActions = _amazonSnsTopics,
                AlarmDescription = "Status check alarm",
                AlarmName = _instanceName + "-status-check",
                ComparisonOperator = "GreaterThanOrEqualToThreshold",
                Dimensions = dimensions,
                EvaluationPeriods = 1,
                MetricName = "StatusCheckFailed",
                Namespace = "AWS/EC2",
                Period = 60*5,
                Statistic = "Average",
                Threshold = 1,
                Unit = "Count"
            };

            RegionEndpoint regionEndpoint = RegionEndpoint.GetBySystemName(_region);
            AmazonCloudWatch cloudwatchClient = AWSClientFactory.CreateAmazonCloudWatchClient(regionEndpoint);

            cloudwatchClient.PutMetricAlarm(putMetricAlarmReq);
        }
        /// <summary>
        /// Initiates the asynchronous execution of the PutMetricAlarm operation.
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the PutMetricAlarm operation on AmazonCloudWatchClient.</param>
        /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param>
        /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
        ///          procedure using the AsyncState property.</param>
        /// 
        /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndPutMetricAlarm
        ///         operation.</returns>
        public IAsyncResult BeginPutMetricAlarm(PutMetricAlarmRequest request, AsyncCallback callback, object state)
        {
            var marshaller = new PutMetricAlarmRequestMarshaller();
            var unmarshaller = PutMetricAlarmResponseUnmarshaller.Instance;

            return BeginInvoke<PutMetricAlarmRequest>(request, marshaller, unmarshaller,
                callback, state);
        }
        }
        
        

        #endregion
    
        #region DeleteAlarms
 /// <summary>
 /// <para> Creates or updates an alarm and associates it with the
 /// specified Amazon CloudWatch metric. Optionally, this operation can
 /// associate one or more Amazon Simple Notification Service resources
 /// with the alarm. </para> <para> When this operation creates an alarm,
 /// the alarm state is immediately set to <c>INSUFFICIENT_DATA</c> . The
 /// alarm is evaluated and its <c>StateValue</c> is set appropriately.
 /// Any actions associated with the <c>StateValue</c> is then executed.
 /// </para> <para><b>NOTE:</b> When updating an existing alarm, its
 /// StateValue is left unchanged. </para>
 /// </summary>
 /// 
 /// <param name="putMetricAlarmRequest">Container for the necessary
 ///           parameters to execute the PutMetricAlarm service method on
 ///           AmazonCloudWatch.</param>
 /// 
 /// <exception cref="LimitExceededException"/>
 public PutMetricAlarmResponse PutMetricAlarm(PutMetricAlarmRequest putMetricAlarmRequest)
 {
     IRequest<PutMetricAlarmRequest> request = new PutMetricAlarmRequestMarshaller().Marshall(putMetricAlarmRequest);
     PutMetricAlarmResponse response = Invoke<PutMetricAlarmRequest, PutMetricAlarmResponse> (request, this.signer, PutMetricAlarmResponseUnmarshaller.GetInstance());
     return response;
 }
        private void CreateDriveUtilizationAlarm(string driveName)
        {
            var dimensions = new List<Dimension>
            {
                new Dimension
                {
                    Name = "InstanceId",
                    Value = _instanceId
                },
                new Dimension
                {
                    Name = "Drive",
                    Value = driveName
                }
            };

            var putMetricAlarmReq = new PutMetricAlarmRequest
            {
                ActionsEnabled = true,
                AlarmActions = _amazonSnsTopics,
                AlarmDescription = "Disk space utilization alarm",
                AlarmName = _instanceName + "-disk-space-" + driveName,
                ComparisonOperator = "GreaterThanOrEqualToThreshold",
                Dimensions = dimensions,
                EvaluationPeriods = 1,
                MetricName = "DiskSpaceUtilization",
                Namespace = "System/Windows",
                Period = 60*5,
                Statistic = "Average",
                Threshold = 85,
                Unit = "Percent"
            };

            RegionEndpoint regionEndpoint = RegionEndpoint.GetBySystemName(_region);
            AmazonCloudWatch cloudwatchClient = AWSClientFactory.CreateAmazonCloudWatchClient(regionEndpoint);

            cloudwatchClient.PutMetricAlarm(putMetricAlarmReq);
        }