SDKAWS を使用してSDKCloudWatch を使用してアラームアクションを無効化する - AWSSDK コードサンプル

AWSDocAWS SDKGitHub サンプルリポジトリには、さらに多くの SDK サンプルがあります

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

SDKAWS を使用してSDKCloudWatch を使用してアラームアクションを無効化する

次のコード例は、AmazonCloudWatch アラームアクションを無効化する方法を示しています。

.NET
AWS SDK for .NET
注記

他にもありますGitHub。用例一覧を検索し、AWS コード例リポジトリでの設定と実行の方法を確認してください。

/// <summary> /// Disable the actions for a list of alarms from CloudWatch. /// </summary> /// <param name="alarmNames">A list of names of alarms.</param> /// <returns>True if successful.</returns> public async Task<bool> DisableAlarmActions(List<string> alarmNames) { var disableAlarmActionsResult = await _amazonCloudWatch.DisableAlarmActionsAsync( new DisableAlarmActionsRequest() { AlarmNames = alarmNames }); return disableAlarmActionsResult.HttpStatusCode == HttpStatusCode.OK; }
  • API の詳細については、AWS SDK for .NETAPI DisableAlarmActionsリファレンスのを参照してください

C++
SDK for C++
注記

他にもありますGitHub。完全な例を見つけて、AWS コード例リポジトリでの設定と実行の方法を確認してください。

必要なファイルを含めます。

#include <aws/core/Aws.h> #include <aws/monitoring/CloudWatchClient.h> #include <aws/monitoring/model/DisableAlarmActionsRequest.h> #include <iostream>

アラームアクションを無効化します。

Aws::CloudWatch::CloudWatchClient cw; Aws::CloudWatch::Model::DisableAlarmActionsRequest disableAlarmActionsRequest; disableAlarmActionsRequest.AddAlarmNames(alarm_name); auto disableAlarmActionsOutcome = cw.DisableAlarmActions(disableAlarmActionsRequest); if (!disableAlarmActionsOutcome.IsSuccess()) { std::cout << "Failed to disable actions for alarm " << alarm_name << ": " << disableAlarmActionsOutcome.GetError().GetMessage() << std::endl; } else { std::cout << "Successfully disabled actions for alarm " << alarm_name << std::endl; }
  • API の詳細については、AWS SDK for C++API DisableAlarmActionsリファレンスのを参照してください

Java
SDK for Java 2.x
注記

他にもありますGitHub。用例一覧を検索し、AWS コード例リポジトリでの設定と実行の方法を確認してください。

public static void disableActions(CloudWatchClient cw, String alarmName) { try { DisableAlarmActionsRequest request = DisableAlarmActionsRequest.builder() .alarmNames(alarmName) .build(); cw.disableAlarmActions(request); System.out.printf("Successfully disabled actions on alarm %s", alarmName); } catch (CloudWatchException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } }
  • API の詳細については、AWS SDK for Java 2.xAPI DisableAlarmActionsリファレンスのを参照してください

JavaScript
SDK forJavaScript (3)
注記

他にもありますGitHub。用例一覧を検索し、AWS コード例リポジトリでの設定と実行の方法を確認してください。

別のモジュールでクライアントを作成し、エクスポートします。

import { CloudWatchClient } from "@aws-sdk/client-cloudwatch"; import { DEFAULT_REGION } from "libs/utils/util-aws-sdk.js"; export const client = new CloudWatchClient({ region: DEFAULT_REGION });

SDK モジュールとクライアントモジュールをインポートし、API を呼び出します。

import { DisableAlarmActionsCommand } from "@aws-sdk/client-cloudwatch"; import { client } from "../libs/client.js"; const run = async () => { const command = new DisableAlarmActionsCommand({ AlarmNames: process.env.CLOUDWATCH_ALARM_NAME, // Set the value of CLOUDWATCH_ALARM_NAME to the name of an existing alarm. }); try { return await client.send(command); } catch (err) { console.error(err); } }; export default run();
  • 詳細については、AWS SDK for JavaScript デベロッパーガイドを参照してください。

  • API の詳細については、AWS SDK for JavaScriptAPI DisableAlarmActionsリファレンスのを参照してください

SDK forJavaScript (2)
注記

他にもありますGitHub。完全な例を見つけて、AWS コード例リポジトリでの設定と実行の方法を確認してください。

SDK モジュールとクライアントモジュールをインポートし、API を呼び出します。

// Load the AWS SDK for Node.js var AWS = require('aws-sdk'); // Set the region AWS.config.update({region: 'REGION'}); // Create CloudWatch service object var cw = new AWS.CloudWatch({apiVersion: '2010-08-01'}); cw.disableAlarmActions({AlarmNames: ['Web_Server_CPU_Utilization']}, function(err, data) { if (err) { console.log("Error", err); } else { console.log("Success", data); } });
  • 詳細については、AWS SDK for JavaScript デベロッパーガイドを参照してください。

  • API の詳細については、AWS SDK for JavaScriptAPI DisableAlarmActionsリファレンスのを参照してください

Kotlin
SDK for Kotlin
注記

これはプレビューリリースの機能に関するプレリリースドキュメントです。このドキュメントは変更される可能性があります。

注記

他にもありますGitHub。用例一覧を検索し、AWS コード例リポジトリでの設定と実行の方法を確認してください。

suspend fun disableActions(alarmName: String) { val request = DisableAlarmActionsRequest { alarmNames = listOf(alarmName) } CloudWatchClient { region = "us-east-1" }.use { cwClient -> cwClient.disableAlarmActions(request) println("Successfully disabled actions on alarm $alarmName") } }
  • API の詳細については、「AWSSDK for Kotlin API リファレンス」を参照してくださいDisableAlarmActions

Python
SDK for Python (Boto3)
注記

他にもありますGitHub。用例一覧を検索し、AWS コード例リポジトリでの設定と実行の方法を確認してください。

class CloudWatchWrapper: """Encapsulates Amazon CloudWatch functions.""" def __init__(self, cloudwatch_resource): """ :param cloudwatch_resource: A Boto3 CloudWatch resource. """ self.cloudwatch_resource = cloudwatch_resource def enable_alarm_actions(self, alarm_name, enable): """ Enables or disables actions on the specified alarm. Alarm actions can be used to send notifications or automate responses when an alarm enters a particular state. :param alarm_name: The name of the alarm. :param enable: When True, actions are enabled for the alarm. Otherwise, they disabled. """ try: alarm = self.cloudwatch_resource.Alarm(alarm_name) if enable: alarm.enable_actions() else: alarm.disable_actions() logger.info( "%s actions for alarm %s.", "Enabled" if enable else "Disabled", alarm_name) except ClientError: logger.exception( "Couldn't %s actions alarm %s.", "enable" if enable else "disable", alarm_name) raise
  • API の詳細については、「AWSSDK for Python (Boto3) API リファレンス」のを参照してくださいDisableAlarmActions

SAP ABAP
SDK for SAP ABAP
注記

これはデベロッパープレビューリリースの SDK に関するドキュメントです。SDK は変更される場合があるため、本稼働環境での使用はお勧めできません。

注記

他にもありますGitHub。用例一覧を検索し、AWS コード例リポジトリでの設定と実行の方法を確認してください。

"Disables actions on the specified alarm. " TRY. lo_cwt->disablealarmactions( it_alarmnames = it_alarm_names ). MESSAGE 'Alarm actions disabled.' TYPE 'I'. CATCH /aws1/cx_rt_service_generic INTO DATA(lo_exception). DATA(lv_error) = |"{ lo_exception->av_err_code }" - { lo_exception->av_err_msg }|. MESSAGE lv_error TYPE 'E'. ENDTRY.
  • API の詳細については、「DisableAlarmActionsAWSSDK for SAP ABAP API リファレンス」の「API リファレンス」の「API リファレンス」の「S