次の方法で共有


JavaScript 用 Azure Automanage クライアント ライブラリ - バージョン 1.0.2

このパッケージには、Azure Automanage クライアント用の同型 SDK (Node.js とブラウザーの両方で実行) が含まれています。

Automanage クライアント

ソースコード | パッケージ (NPM) | API リファレンス ドキュメント | サンプル

はじめに

現在サポートされている環境

詳細については、Microsoft のサポート ポリシーを参照してください。

前提条件

@azure/arm-automanage パッケージのインストール

を使用して、JavaScript 用の Azure Automanage クライアント ライブラリを npmインストールします。

npm install @azure/arm-automanage

AutomanageClient を作成して認証する

Azure Automanage API にアクセスするためのクライアント オブジェクトを作成するには、Azure Automanage リソースの と credentialが必要endpointです。 Azure Automanage クライアントは、Azure Active Directory 資格情報を使用して認証できます。 Azure Automanage リソースのエンドポイントは 、Azure Portal で確認できます。

@azure/ID ライブラリまたは既存の AAD トークンからの資格情報を使用して、Azure Active Directory で認証できます。

次に示す DefaultAzureCredential プロバイダー、または Azure SDK で提供されている他の資格情報プロバイダーを使用するには、パッケージを @azure/identity インストールしてください。

npm install @azure/identity

また、 新しい AAD アプリケーションを登録し、適切なロールをサービス プリンシパルに割り当てることで Azure Automanage へのアクセス 権を付与する必要があります (注: などの "Owner" ロールでは、必要なアクセス許可は付与されません)。 AAD アプリケーションのクライアント ID、テナント ID、およびクライアント シークレットの値を、環境変数 AZURE_CLIENT_IDAZURE_TENANT_ID、、AZURE_CLIENT_SECRET、 として設定します。

Azure AD アプリケーションを作成する方法の詳細については、 こちらのガイドを参照してください。

const { AutomanageClient } = require("@azure/arm-automanage");
const { DefaultAzureCredential } = require("@azure/identity");
// For client-side applications running in the browser, use InteractiveBrowserCredential instead of DefaultAzureCredential. See https://aka.ms/azsdk/js/identity/examples for more details.

const subscriptionId = "00000000-0000-0000-0000-000000000000";
const client = new AutomanageClient(new DefaultAzureCredential(), subscriptionId);

// For client-side applications running in the browser, use this code instead:
// const credential = new InteractiveBrowserCredential({
//   tenantId: "<YOUR_TENANT_ID>",
//   clientId: "<YOUR_CLIENT_ID>"
// });
// const client = new AutomanageClient(credential, subscriptionId);

構成プロファイルの作成または更新

ファイルを更新するには、 プロパティ 内の値のいずれかを置き換えて、 createOrUpdate() 関数をもう一度実行します。

const newProfile = {
    "location": "eastus",
    "tags": {
        "environment": "prod"
    },
    "properties": {
        "configuration": {
            "Antimalware/Enable": true,
            "Antimalware/EnableRealTimeProtection": true,
            "Antimalware/RunScheduledScan": true,
            "Antimalware/ScanType": "Quick",
            "Antimalware/ScanDay": 7,
            "Antimalware/ScanTimeInMinutes": 120,
            "Backup/Enable": true,
            "Backup/PolicyName": "dailyBackupPolicy",
            "Backup/TimeZone": "UTC",
            "Backup/InstantRpRetentionRangeInDays": 2,
            "Backup/SchedulePolicy/ScheduleRunFrequency": "Daily",
            "Backup/SchedulePolicy/SchedulePolicyType": "SimpleSchedulePolicy",
            "Backup/RetentionPolicy/RetentionPolicyType": "LongTermRetentionPolicy",
            "Backup/RetentionPolicy/DailySchedule/RetentionDuration/Count": 180,
            "Backup/RetentionPolicy/DailySchedule/RetentionDuration/DurationType": "Days",
            "WindowsAdminCenter/Enable": false,
            "VMInsights/Enable": true,
            "AzureSecurityCenter/Enable": true,
            "UpdateManagement/Enable": true,
            "ChangeTrackingAndInventory/Enable": true,
            "GuestConfiguration/Enable": true,
            "AutomationAccount/Enable": true,
            "LogAnalytics/Enable": true,
            "BootDiagnostics/Enable": true
        }
    }
}

await client.configurationProfiles.createOrUpdate("configurationProfileName", "resourceGroupName", newProfile);

構成プロファイルの削除

await client.configurationProfiles.delete("resourceGroupName", "configurationProfileName");

ベスト プラクティスの作成 運用プロファイルの割り当て

let assignment = {
    "properties": {
        "configurationProfile": "/providers/Microsoft.Automanage/bestPractices/AzureBestPracticesProduction"
    }
}

await client.configurationProfileAssignments.createOrUpdate("default", "resourceGroupName", "vmName", assignment);

カスタム プロファイル割り当ての作成

let assignment = {
    "properties": {
        "configurationProfile": "/subscriptions/<subscription ID>/resourceGroups/resourceGroupName/providers/Microsoft.Automanage/configurationProfiles/configurationProfileName"
    }
}

await client.configurationProfileAssignments.createOrUpdate("default", "resourceGroupName", "vmName", assignment);

JavaScript バンドル

ブラウザーでこのクライアント ライブラリを使用するには、まず bundler を使用する必要があります。 これを行う方法の詳細については、 バンドルに関するドキュメントを参照してください。

主要な概念

AutomanageClient

AutomanageClient は、Azure Automanage クライアント ライブラリを使用する開発者向けの主要なインターフェイスです。 このクライアント オブジェクトのメソッドを調べて、アクセスできる Azure Automanage サービスのさまざまな機能を理解します。

トラブルシューティング

ログ記録

ログの記録を有効にすると、エラーに関する有用な情報を明らかにするのに役立つ場合があります。 HTTP 要求と応答のログを表示するには、環境変数 AZURE_LOG_LEVELinfo に設定します。 または、@azure/loggersetLogLevel を呼び出して、実行時にログ記録を有効にすることもできます。

const { setLogLevel } = require("@azure/logger");
setLogLevel("info");

ログを有効にする方法の詳細については、@azure/logger パッケージに関するドキュメントを参照してください。

次の手順

このライブラリの使用方法の詳細な例については、 samples ディレクトリを参照してください。

共同作成

このライブラリに投稿する場合、コードをビルドしてテストする方法の詳細については、投稿ガイドを参照してください。

インプレッション数