testAlarm method

Future<TestAlarmResult> testAlarm({
  1. required String alarmName,
  2. required AlarmState state,
})

Tests an alarm by displaying a banner on the Amazon Lightsail console. If a notification trigger is configured for the specified alarm, the test also sends a notification to the notification protocol (Email and/or SMS) configured for the alarm.

An alarm is used to monitor a single metric for one of your resources. When a metric condition is met, the alarm can notify you by email, SMS text message, and a banner displayed on the Amazon Lightsail console. For more information, see Alarms in Amazon Lightsail.

May throw ServiceException. May throw InvalidInputException. May throw OperationFailureException. May throw UnauthenticatedException. May throw AccessDeniedException. May throw NotFoundException.

Parameter alarmName : The name of the alarm to test.

Parameter state : The alarm state to test.

An alarm has the following possible states that can be tested:

  • ALARM - The metric is outside of the defined threshold.
  • INSUFFICIENT_DATA - The alarm has just started, the metric is not available, or not enough data is available for the metric to determine the alarm state.
  • OK - The metric is within the defined threshold.

Implementation

Future<TestAlarmResult> testAlarm({
  required String alarmName,
  required AlarmState state,
}) async {
  ArgumentError.checkNotNull(alarmName, 'alarmName');
  ArgumentError.checkNotNull(state, 'state');
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'Lightsail_20161128.TestAlarm'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'alarmName': alarmName,
      'state': state.toValue(),
    },
  );

  return TestAlarmResult.fromJson(jsonResponse.body);
}