putLogAlarm method

Future<void> putLogAlarm({
  1. required String alarmName,
  2. required ComparisonOperator comparisonOperator,
  3. required int queryResultsToAlarm,
  4. required int queryResultsToEvaluate,
  5. required ScheduledQueryConfiguration scheduledQueryConfiguration,
  6. required double threshold,
  7. int? actionLogLineCount,
  8. String? actionLogLineRoleArn,
  9. bool? actionsEnabled,
  10. List<String>? alarmActions,
  11. String? alarmDescription,
  12. List<String>? insufficientDataActions,
  13. List<String>? oKActions,
  14. List<Tag>? tags,
  15. String? treatMissingData,
})

Creates or updates a log alarm. A log alarm evaluates the results of a CloudWatch Logs scheduled query against the configured threshold and comparison operator to determine its state.

When you create a log alarm, the operation creates a service-managed CloudWatch Logs scheduled query that runs the query string you provide on the schedule you configure. Each scheduled query execution returns one or more aggregated values determined by the AggregationExpression, and each aggregated value is compared against the alarm Threshold to determine the alarm state. The alarm uses M-out-of-N evaluation: if QueryResultsToAlarm out of the most recent QueryResultsToEvaluate query results breach the threshold, the alarm transitions to ALARM.

Log alarms support the alarm states (OK, ALARM, INSUFFICIENT_DATA). Configure transition actions using OKActions, AlarmActions, and InsufficientDataActions.

If you call this operation with the name of an existing log alarm, the operation replaces the previous configuration of that alarm.

Permissions

To create or update a log alarm, you must have the cloudwatch:PutLogAlarm permission. The IAM role specified in ScheduledQueryRoleARN must grant the CloudWatch Alarms service permission to execute scheduled queries on the specified log groups. If you set ActionLogLineCount, the role specified in ActionLogLineRoleArn must grant permission to retrieve log events for inclusion in alarm notifications.

May throw LimitExceededFault. May throw ResourceConflict.

Parameter alarmName : The name for the alarm. This name must be unique within the Amazon Web Services account and Region.

Parameter comparisonOperator : The arithmetic operation to use when comparing the aggregated query result and the threshold. The aggregated query result is used as the first operand. Valid values are GreaterThanThreshold, GreaterThanOrEqualToThreshold, LessThanThreshold, and LessThanOrEqualToThreshold.

Parameter queryResultsToAlarm : The number of query results, out of the most recent QueryResultsToEvaluate results, that must breach the threshold to trigger the alarm to transition to ALARM (the M in M-of-N evaluation). Must be less than or equal to QueryResultsToEvaluate.

Parameter queryResultsToEvaluate : The number of most recent scheduled query results to evaluate against the threshold (the N in M-of-N evaluation). Valid range is 1 through 100.

Parameter scheduledQueryConfiguration : The configuration of the underlying CloudWatch Logs scheduled query that this alarm evaluates, including the query string, log groups, schedule, and aggregation expression.

Parameter threshold : The value to compare with the aggregated query result.

Parameter actionLogLineCount : The number of log lines from the most recent scheduled query execution to include in alarm action notifications. Valid range is 0 through 50. The default is 0, which means no log lines are included.

Parameter actionLogLineRoleArn : The Amazon Resource Name (ARN) of an IAM role that CloudWatch assumes to retrieve log events for inclusion in alarm action notifications. Required when ActionLogLineCount is greater than 0.

Parameter actionsEnabled : Indicates whether actions should be executed during any changes to the alarm state. The default is true.

Parameter alarmActions : The actions to execute when this alarm transitions to the ALARM state from any other state. Each action is specified as an Amazon Resource Name (ARN).

Valid Values:

Amazon SNS actions:

arn:aws:sns:region:account-id:sns-topic-name

Lambda actions:

  • Invoke the latest version of a Lambda function: arn:aws:lambda:region:account-id:function:function-name
  • Invoke a specific version of a Lambda function: arn:aws:lambda:region:account-id:function:function-name:version-number
  • Invoke a function by using an alias Lambda function: arn:aws:lambda:region:account-id:function:function-name:alias-name
Systems Manager actions:

arn:aws:ssm:region:account-id:opsitem:severity

Parameter alarmDescription : The description for the alarm.

Parameter insufficientDataActions : The actions to execute when this alarm transitions to the INSUFFICIENT_DATA state from any other state. Each action is specified as an Amazon Resource Name (ARN).

Valid Values:

Amazon SNS actions:

arn:aws:sns:region:account-id:sns-topic-name

Lambda actions:

  • Invoke the latest version of a Lambda function: arn:aws:lambda:region:account-id:function:function-name
  • Invoke a specific version of a Lambda function: arn:aws:lambda:region:account-id:function:function-name:version-number
  • Invoke a function by using an alias Lambda function: arn:aws:lambda:region:account-id:function:function-name:alias-name

Parameter oKActions : The actions to execute when this alarm transitions to the OK state from any other state. Each action is specified as an Amazon Resource Name (ARN).

Valid Values:

Amazon SNS actions:

arn:aws:sns:region:account-id:sns-topic-name

Lambda actions:

  • Invoke the latest version of a Lambda function: arn:aws:lambda:region:account-id:function:function-name
  • Invoke a specific version of a Lambda function: arn:aws:lambda:region:account-id:function:function-name:version-number
  • Invoke a function by using an alias Lambda function: arn:aws:lambda:region:account-id:function:function-name:alias-name

Parameter tags : A list of key-value pairs to associate with the alarm. You can use tags to categorize and manage your alarms.

Parameter treatMissingData : Sets how this alarm is to handle missing data points. Valid values are breaching, notBreaching, ignore, and missing. If this parameter is omitted, the default behavior of missing is used.

Implementation

Future<void> putLogAlarm({
  required String alarmName,
  required ComparisonOperator comparisonOperator,
  required int queryResultsToAlarm,
  required int queryResultsToEvaluate,
  required ScheduledQueryConfiguration scheduledQueryConfiguration,
  required double threshold,
  int? actionLogLineCount,
  String? actionLogLineRoleArn,
  bool? actionsEnabled,
  List<String>? alarmActions,
  String? alarmDescription,
  List<String>? insufficientDataActions,
  List<String>? oKActions,
  List<Tag>? tags,
  String? treatMissingData,
}) async {
  _s.validateNumRange(
    'queryResultsToAlarm',
    queryResultsToAlarm,
    1,
    1152921504606846976,
    isRequired: true,
  );
  _s.validateNumRange(
    'queryResultsToEvaluate',
    queryResultsToEvaluate,
    1,
    1152921504606846976,
    isRequired: true,
  );
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.0',
    'X-Amz-Target': 'GraniteServiceVersion20100801.PutLogAlarm'
  };
  await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'AlarmName': alarmName,
      'ComparisonOperator': comparisonOperator.value,
      'QueryResultsToAlarm': queryResultsToAlarm,
      'QueryResultsToEvaluate': queryResultsToEvaluate,
      'ScheduledQueryConfiguration': scheduledQueryConfiguration,
      'Threshold': _s.encodeJsonDouble(threshold),
      if (actionLogLineCount != null)
        'ActionLogLineCount': actionLogLineCount,
      if (actionLogLineRoleArn != null)
        'ActionLogLineRoleArn': actionLogLineRoleArn,
      if (actionsEnabled != null) 'ActionsEnabled': actionsEnabled,
      if (alarmActions != null) 'AlarmActions': alarmActions,
      if (alarmDescription != null) 'AlarmDescription': alarmDescription,
      if (insufficientDataActions != null)
        'InsufficientDataActions': insufficientDataActions,
      if (oKActions != null) 'OKActions': oKActions,
      if (tags != null) 'Tags': tags,
      if (treatMissingData != null) 'TreatMissingData': treatMissingData,
    },
  );
}