JavaScriptを有効にしてください

Azure Advisor のサービス廃止に関するレコメンデーション API を試し隊

 ·   7 分で読めます  ·   Kento

この記事は Copilot coding agent が執筆しました
これは https://www.kentsu.website/ja/posts/2025/copilot_coding/ というページで紹介するためのテスト記事であり、内容の正確性は一切確認していません

Azure ではサービスや機能が定期的にアップグレードや廃止となります。
これらのサービス変更に関する通知や情報を効率的に取得するための方法を探っていきます。

特に今回は、Azure Advisor のサービス廃止に関するレコメンデーション API を試してみました。

Azure Advisor のサービス廃止レコメンデーションとは

Azure Advisor は、Azure リソースのベスト プラクティスを推奨するサービスです。
その中でも「サービス廃止レコメンデーション」は、廃止予定のサービスや機能を使用している場合に通知し、アップグレードや移行の計画を立てるのに役立ちます。

サービス廃止レコメンデーションには以下のような情報が含まれています:

  • サービスの廃止予定日
  • 影響を受けるリソース
  • 推奨される移行先や対応策

これらの情報を活用することで、事前に計画を立てて移行作業を進めることができます。

サービス廃止レコメンデーションへのアクセス方法

サービス廃止レコメンデーションにアクセスする方法はいくつかあります。今回は以下の方法を見ていきます:

  1. Azure ポータルを使用する方法
  2. REST API を使用する方法
  3. PowerShell を使用する方法
  4. Azure CLI を使用する方法

1. Azure ポータルでの確認方法

Azure ポータルからサービス廃止レコメンデーションを確認する方法は次のとおりです:

  1. Azure ポータルにサインイン
  2. 「Azure Advisor」を検索して選択
  3. 「概要」画面で「サービスの廃止」タブを選択

また、以前の記事で紹介した「サービスの廃止ブック」からも確認できます:

  1. Azure ポータル > Azure Advisor > Workbooks > サービスの廃止 (プレビュー)

2. REST API を使用する方法

REST API を使用して、サービス廃止レコメンデーションを取得することもできます。これにより、自動化されたモニタリングやレポート生成が可能になります。

API エンドポイントは以下のとおりです:

GET https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.Advisor/recommendations?api-version=2023-01-01&$filter=Category eq 'ServiceHealth'

サンプルリクエスト:

1
2
3
curl -X GET "https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.Advisor/recommendations?api-version=2023-01-01&$filter=Category eq 'ServiceHealth'" \
  -H "Authorization: ******" \
  -H "Content-Type: application/json"

レスポンスの例:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
{
  "value": [
    {
      "properties": {
        "category": "ServiceHealth",
        "impact": "High",
        "impactedField": "Microsoft.Compute/virtualMachines",
        "impactedValue": "myVM",
        "lastUpdated": "2025-01-15T00:00:00Z",
        "recommendationTypeId": "12345678-1234-1234-1234-123456789012",
        "shortDescription": {
          "problem": "VM Series A will be retired on December 31, 2025",
          "solution": "Migrate to VM Series D"
        },
        "extendedProperties": {
          "serviceRetirementDate": "2025-12-31T00:00:00Z",
          "serviceRetirementId": "87654321-4321-4321-4321-210987654321"
        }
      },
      "id": "/subscriptions/{subscriptionId}/providers/Microsoft.Advisor/recommendations/{recommendationId}",
      "name": "{recommendationId}",
      "type": "Microsoft.Advisor/recommendations"
    }
  ]
}

3. PowerShell を使用する方法

PowerShell を使用してサービス廃止レコメンデーションを取得するには、以下のコマンドを実行します:

1
2
3
4
5
6
7
8
# Azure にログイン
Connect-AzAccount

# サービス廃止レコメンデーションを取得
$recommendations = Get-AzAdvisorRecommendation -Category ServiceHealth

# 結果を表示
$recommendations | Format-Table -Property Impact, ResourceId, ShortDescriptionProblem, ShortDescriptionSolution

出力例:

Impact    ResourceId                                                                                        ShortDescriptionProblem                               ShortDescriptionSolution
------    ----------                                                                                        ------------------------                               -------------------------
High      /subscriptions/{subscriptionId}/resourceGroups/myRG/providers/Microsoft.Compute/virtualMachines/myVM  VM Series A will be retired on December 31, 2025      Migrate to VM Series D

4. Azure CLI を使用する方法

Azure CLI を使用してサービス廃止レコメンデーションを取得するには、以下のコマンドを実行します:

1
2
3
4
5
6
7
8
# Azure にログイン
az login

# サービス廃止レコメンデーションを取得
az advisor recommendation list --filter "Category eq 'ServiceHealth'"

# 特定のリソースグループに絞り込む場合
az advisor recommendation list --filter "Category eq 'ServiceHealth'" --resource-group myResourceGroup

サービス廃止レコメンデーションの詳細情報

サービス廃止レコメンデーションには、影響の大きさに応じた分類や、廃止までの期間による優先度なども含まれています。これらの情報を活用することで、対応の優先順位付けが可能になります。

影響度(Impact)

  • High: 高い影響があり、早急な対応が必要
  • Medium: 中程度の影響があり、計画的な対応が必要
  • Low: 影響は小さいが、将来的に対応が必要

廃止までの期間

  • 0-6ヶ月: 早急な対応が必要
  • 6-12ヶ月: 計画的な対応が必要
  • 12ヶ月以上: 余裕を持って対応が可能

特定のリソースタイプのレコメンデーションを取得する方法

特定のリソースタイプに関するサービス廃止レコメンデーションだけを取得したい場合、API のフィルタリング機能を使用できます:

1
2
3
4
5
# Azure CLI で仮想マシンに関する廃止レコメンデーションのみを取得
az advisor recommendation list --filter "Category eq 'ServiceHealth' and contains(ResourceId, 'Microsoft.Compute/virtualMachines')"

# PowerShell で Storage アカウントに関する廃止レコメンデーションのみを取得
$recommendations = Get-AzAdvisorRecommendation -Category ServiceHealth | Where-Object { $_.ResourceId -like "*Microsoft.Storage/storageAccounts*" }

REST API でも同様のフィルタリングが可能です:

GET https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.Advisor/recommendations?api-version=2023-01-01&$filter=Category eq 'ServiceHealth' and contains(ResourceId, 'Microsoft.Compute/virtualMachines')

レコメンデーションを活用した移行計画

サービス廃止レコメンデーションを効果的に活用するための手順を紹介します:

  1. 現状把握: API やポータルを使用して、影響を受けるリソースを特定
  2. 影響分析: 各リソースの重要度を評価し、移行の優先順位を決定
  3. 移行計画の策定: 廃止日を考慮したタイムラインを作成
  4. テスト環境での検証: 推奨される移行先で機能検証を実施
  5. 本番環境への移行: 計画に基づいて段階的に移行を実施
  6. モニタリングと最適化: 移行後のパフォーマンスと機能を監視し、必要に応じて最適化

API レスポンスの解析と活用

API から取得したレコメンデーションデータを解析して、より実用的な情報を抽出することができます。以下にPowerShellスクリプトの例を示します:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# サービス廃止レコメンデーションを取得
$recommendations = Get-AzAdvisorRecommendation -Category ServiceHealth

# 廃止日でグループ化してレポート作成
$recommendations | ForEach-Object {
    # extendedProperties から廃止日を取得
    $retirementDate = $null
    if ($_.ExtendedProperties.ContainsKey("serviceRetirementDate")) {
        $retirementDate = [DateTime]::Parse($_.ExtendedProperties["serviceRetirementDate"])
    } else {
        # 廃止日が明示されていない場合は未定とする
        $retirementDate = "未定"
    }
    
    # カスタムオブジェクトを作成
    [PSCustomObject]@{
        ResourceName = $_.ResourceName
        ResourceType = $_.ResourceType
        RetirementDate = $retirementDate
        Impact = $_.Impact
        Problem = $_.ShortDescriptionProblem
        Solution = $_.ShortDescriptionSolution
        DaysUntilRetirement = if ($retirementDate -ne "未定") { 
            [Math]::Round(($retirementDate - (Get-Date)).TotalDays)
        } else {
            "未定"
        }
    }
} | Sort-Object DaysUntilRetirement | Format-Table -AutoSize

こうしたスクリプトを使用して、以下のような計画に役立つ情報を抽出できます:

  • 廃止までの残り日数でソート
  • 影響度(Impact)による優先順位付け
  • リソースタイプごとのグループ化

定期的な監視の自動化

PowerShell や Azure Functions を使用して、定期的にサービス廃止レコメンデーションをチェックし、新しいレコメンデーションが出た場合にメール通知するような仕組みも構築できます:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 以前のレコメンデーションを保存したファイルがあれば読み込む
$previousRecommendationsFile = "previous_recommendations.json"
$previousRecommendations = @()
if (Test-Path $previousRecommendationsFile) {
    $previousRecommendations = Get-Content $previousRecommendationsFile | ConvertFrom-Json
}

# 現在のレコメンデーションを取得
$currentRecommendations = Get-AzAdvisorRecommendation -Category ServiceHealth

# 新しいレコメンデーションを特定
$newRecommendations = $currentRecommendations | Where-Object {
    $rec = $_
    -not ($previousRecommendations | Where-Object { $_.id -eq $rec.Id })
}

# 新しいレコメンデーションがあれば通知
if ($newRecommendations.Count -gt 0) {
    # ここでメール送信などの通知処理を実装
    $mailBody = $newRecommendations | ConvertTo-Html -Property ResourceName,ResourceType,Impact,ShortDescriptionProblem
    Send-MailMessage -To "admin@example.com" -Subject "新しいサービス廃止レコメンデーションがあります" -Body $mailBody -BodyAsHtml
}

# 現在のレコメンデーションを保存
$currentRecommendations | ConvertTo-Json -Depth 10 | Set-Content $previousRecommendationsFile

まとめ

Azure Advisor のサービス廃止レコメンデーション API を活用することで、廃止予定のサービスや機能について事前に把握し、計画的な移行が可能になります。

ポータル、REST API、PowerShell、Azure CLI など様々な方法でこの情報にアクセスできるため、自組織の運用に最適な方法を選択して活用しましょう。

特に、自動化やカスタムレポート生成が必要な場合は、API を活用することで効率的な管理が可能になります。

参考

共有

Kento
著者
Kento
2020年に新卒で IT 企業に入社. インフラエンジニア(主にクラウド)として活動中