0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

#AzureAutomation のログを #AzureMonitor(Log Analytics)と統合する際に発生したエラー(microsoft.insights 未登録)を解消する

Last updated at Posted at 2020-01-13

初めに

Azure Automation を利用して運用作業の自動化を検討していたが、自動実行された PowerShell が正常終了したかどうかの判断がつかなかったため、Log Analytics を利用した検知機能を設定しました。
設定の際に、「Set-AzDiagnosticSetting」というコマンドで Azure Automation のログを Azure Monitor と統合する設定を行うわけですが、microsoft.insights が登録されていないというエラーが発生しました。microsoft.insights を登録することでエラーは解消したため、その手順をまとめたいと思います。

Azure Automation のエラーをLog Analyticsで検知する手順については以下記事を参考にしてください。

参考にした記事・サイト

Azure AutomationのエラーをLog Analyticsで検知する(Qiita)
[Automation から Azure Monitor ログにジョブの状態とジョブ ストリームを転送する(MSドキュメント)]
(https://docs.microsoft.com/ja-jp/azure/automation/automation-manage-send-joblogs-log-analytics)
[Configuring Network Security Group Flow logs with PowerShell]
(https://docs.microsoft.com/bs-latn-ba/Azure/network-watcher/network-watcher-nsg-flow-logging-powershell)

環境

  • Azure Automation
  • Azure Monitor (Log Analytics)
  • Office 365 開発者プログラム → 今回の手順には直接関係ありません
  • Microsoft.Online.SharePoint.PowerShell 16.0.19515.12000 → 今回の手順には直接関係ありません
  • SharePointPnPPowerShellOnline 3.16.1912.0 → 今回の手順には直接関係ありませ

発生したエラー

 Set-AzDiagnosticSetting : Exception type: ErrorResponseException, Message: The subscription '<サブスクリプションID>' is not registered to use microsoft.insights., Code:
  SubscriptionNotRegistered, Status code:BadRequest, Reason phrase: Bad Request
 発生場所 行:1 文字:1
 + Set-AzDiagnosticSetting -ResourceId $automationAccountId -WorkspaceId ...
 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     + CategoryInfo          : CloseError: (:) [Set-AzDiagnosticSetting]、PSInvalidOperationException
     + FullyQualifiedErrorId : Microsoft.Azure.Commands.Insights.Diagnostics.SetAzureRmDiagnosticSettingCommand

メッセージにある通り、microsoft.insights が登録されていないのが理由なのですが、通常、microsoft.insightsって最初から登録されてるものじゃないんですかね?
ネットで調べながら、microsoft.insights を登録する以下の手順を実施しました。

登録されているプロバイダ一覧を取得する

Get-AzResourceProvider -ListAvailable | Select-Object ProviderNamespace, RegistrationState

未登録の場合、以下が表示される

microsoft.insights                     NotRegistered

microsoft.insights をプロバイダとして登録する → 正常に登録完了

Register-AzResourceProvider -ProviderNamespace microsoft.insights

再度、登録されているプロバイダ一覧を取得する

Get-AzResourceProvider -ListAvailable | Select-Object ProviderNamespace, RegistrationState

登録が完了すると Registerd となる
登録済み
microsoft.insights                     Registered

以下は登録中の状態。しばらくたってから再度確認する
microsoft.insights                     Registereding

エラーとなったコマンドを再度発行する

Set-AzDiagnosticSetting -ResourceId $automationAccountId -WorkspaceId $workspaceId -Enabled 1
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?