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?

LogicAppsからRunbook(Hybrid Runbook Worker)に入力パラメータを渡す方法

Last updated at Posted at 2024-07-19

はじめに

LogicAppsにはMicrosoft Defender for EndpointやAzure Monitorのアラートをトリガーとして利用ができます。一方で、Hybrid Runbook WorkerはPowershellを任意の仮想マシンのローカルで起動できるなど、LogicAppsには無い便利な要素があります。
そこで、今回はLogicAppsからRunbookを呼び出して起動するときに、LogicAppsで定義した変数値をRunbookへ渡す方法について検証しましたので、その結果をこちらにまとめます。

やりたいこと

今回検証していくアプリの処理フローはこんな感じです
image.png
注意:スケジュールの設定をしておりますが、今回の検証では手動でトリガーを起動しています。

前提条件

以下、今回の検証の条件です。

■ Azureの構成
Logic Apps:Standard構成(ここは従量課金でも問題ないと思われます)
Automation:Hybrid Runbook Workerを使用

■ Runbookを起動した仮想マシン
OS:Redhat 8系
PowerShell:7.2

LogicApps側の設定

Logic AppsにマネージドIDをオンにして、以下権限を割り振っておきます。

  • Automation ジョブオペレーター
  • Automation Runbookオペレーター

「Automation Runbookオペレーター」はジョブの起動では必要ないですが、設定する際に必要です。設定後に外しても問題ありません。

LogicApps側はこんな感じで設定
image.png

Automationへの連携コネクタはCreate Job Response(参考のDocs)を使用します。

Parameters内には以下のように記載しています。

{"name": "John Doe", "age": 30}

Runbook側の設定

以下内容でRunbookを記載していきます。

Param
(
  [Parameter (Mandatory= $true)]
  [String] $name,
  
  [Parameter (Mandatory= $true)]
  [Int32] $age
)

Write-Output "My name is $name."
Write-Output "I started a businness at $age."

Runbookの入力パラメータという機能を使うことで、引き渡したパラメータの使用が可能です。詳しくはDocsを確認してください。

結果

LogicAppsの実行履歴を確認します。以下の通りSucceededになっていますね。
image.png

Automation Account>Runbook>ジョブ>入力タブで、Runbook側のログの確認ができます。入力タブで入力値がしっかりと引き渡せているか確認できます。見た感じ、大丈夫そうですね。
image.png

そして・・・出力結果はこんな感じで、うまく出力できています。
image.png

念のため、エラータブでエラーが発生していないことを確認します。
image.png

以下、現状確認できている制約です。もしかしたら解決方法あるかもですが、現在確認中です。知ってる方いたら教えて下さい。

  • Strings型は間にスペースあると、Runbook側でエラーになります
  • Script内のPRAMで定義していない値を渡すと、Runbook側でエラーになります
  • PythonとPowershellでPARAMの記載方法が若干異なるようです。
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?