ささみ学習帳 - sasami's study book

ささみ学習帳

Microsoft365 や Power Platform について学んだこと・アイデアのメモ

Microsoft365管理センターのサービス正常性を取得しSharePoint Listsに反映するPowerAutomateクラウドフロー💎

※2023/6/14更新:以下2点を修正しました。

  • 各種日時の項目を日本時間に変換
  • Listsへの更新処理を追加

 

 

このスクリプトで実現できること

Microsoft365管理センターのサービス正常性から指定条件でデータを取得しSharePoint Listsに反映する

 

準備するもの

PowerAutomate 有償ライセンス

PremiumコネクタのHTTPを使用しますのでPowerAutomate有償プランが必要になります。

※実運用には使用できませんが、PowerApps 開発者向けプランで無料で試してみることはできます。

 

SharePoint Listsを作成

取得した情報を保存するListsを作成しておきます。

種類 備考
タイトル 1行テキスト 問題id
title_EN 1行テキスト タイトル
title_JA 1行テキスト タイトルの日本語訳
startDateTime 日付と時刻 開始日時
endDateTime 日付と時刻 終了日時
isResolved はい/いいえ 解決済み?
lastModifiedDateTime 日付と時刻 最終更新日時
impactDescription 1行テキスト ユーザーへの影響
impactDescription_JA 1行テキスト ユーザーへの影響の日本語訳
classification 選択肢  
status 選択肢 状態
origin 1行テキスト 発行元
service 1行テキスト 影響を受けているサービス
feature 1行テキスト  
featureGroup 1行テキスト  
detailsSummary 複数行テキスト すべての更新
detailsSummary_JA 複数行テキスト すべての更新の日本語訳

 

AzureADにアプリ登録

※一部画像を使いまわしています。アプリ名が変なのは気にしないでください。

1.Microsoft Entra 管理センター にアクセス(管理者アカウントでサインイン)

https://entra.microsoft.com/#view/Microsoft_AAD_IAM/

2.Azure Active Directory→アプリケーション→アプリの登録→新規登録

3.アプリの新規登録画面

  • 名前
    • 適切な名前を設定
  • サポートされているアカウントの種類
  • リダイレクトURI
    • 省略

「登録」ボタンをクリックします

 

4.概要に表示される [アプリケーション (クライアント) ID] と [ディレクトリ (テナント) ID] の値をコピーしておきます

 

5.[API のアクセス許可] – [+アクセス許可の追加] をクリック

 

6.[Microsoft Graph] – [アプリケーションの許可] をクリック

 

7.[ServiceHealth.Read.All]  を選択して [アクセス許可の追加] をクリック

 

8.[<テナント名> に管理者の同意を与えます] をクリック

確認が表示されるので [はい] をクリック

 

10.概要に表示される [アプリケーション (クライアント) ID] と [ディレクトリ (テナント) ID] の値をコピーしておきます

 

11.証明書とシークレット→クライアントシークレット→新しいクライアントシークレット

 

12.説明を入力し有効期限を選択して「追加」

 

613値をコピーしておく(他の画面に遷移するとコピーできなくなるので忘れずに)

以上で準備は完了です。

 

フロー全体図

 

フロー解説

トリガー - 手動でフローをトリガーします

今回は検証目的で作成した為こちらのトリガーを使用しています。実際運用する場合はスケジュール実行になるかと思います。

 

変数を初期化する - messages

サービス正常性の問題の詳細部分はアレイで構成されているため、結合してまとめるための変数を初期化しています。

 

HTTP-issues

このフローの本体はここです。HTTPコネクタのHTTPアクションでサービス正常性の問題を一覧表示するGraph APIを実行しています。必要なアクセス許可(ServiceHealth.Read.All)の関係で、プレミアムコネクタのHTTPアクションが必要になっています。

GET https://graph.microsoft.com/v1.0/admin/serviceAnnouncement/issues

learn.microsoft.com

出力はこのようなjsonです。

[
    {
      "startDateTime": "2023-04-18T17:41:33Z",
      "endDateTime": null,
      "lastModifiedDateTime": "2023-06-07T20:47:53.77Z",
      "title": "Some users may see some meetings scheduled in Mexico time zones are displaying with the incorrect time",
      "id": "EX543234",
      "impactDescription": "Users may see some meetings scheduled in Mexico time zones are displaying with the incorrect time.",
      "classification": "advisory",
      "origin": "microsoft",
      "status": "extendedRecovery",
      "service": "Exchange Online",
      "feature": "Reports of an Incident",
      "featureGroup": "E-Mail and calendar access",
      "isResolved": false,
      "details": [],
      "posts": [
        {
          "createdDateTime": "2023-04-18T17:43:19.53Z",
          "postType": "regular",
          "description": {
            "contentType": "html",
            "content": "Title: Users’ meetings viewed within Outlook on the web and mobile clients show the incorrect time\n\nUser impact: Users’ meetings viewed within Outlook on the web and mobile clients show the incorrect time.\n\nCurrent status: We're investigating a potential issue and checking for impact to your organization. We'll provide an update within 30 minutes."
          }
        },
        {
          "createdDateTime": "2023-04-18T18:04:32.517Z",
          "postType": "regular",
          "description": {
            "contentType": "html",
            "content": "Title: Users’ meetings viewed within Outlook on the web and mobile clients show the incorrect time\n\nUser impact: Users’ meetings viewed within Outlook on the web and mobile clients show the incorrect time.\n\nCurrent status: We're working with your representatives to gather browser captures of the issue in progress to assist in our investigation and determine our next actions.\n\nScope of impact: This issue may affect any user with meetings scheduled by users in the Mexico region.\n\nNext update by: Tuesday, April 18, 2023, at 7:30 PM UTC"
          }
        },
(以降省略)

 

JSONの解析

HTTPアクションの出力を解析しています。

スキーマはこちら

{
    "type": "object",
    "properties": {
        "statusCode": {
            "type": "integer"
        },
        "headers": {
            "type": "object",
            "properties": {
                "Transfer-Encoding": {
                    "type": "string"
                },
                "Vary": {
                    "type": "string"
                },
                "Strict-Transport-Security": {
                    "type": "string"
                },
                "request-id": {
                    "type": "string"
                },
                "client-request-id": {
                    "type": "string"
                },
                "x-ms-ags-diagnostic": {
                    "type": "string"
                },
                "X-Instance": {
                    "type": "string"
                },
                "X-TimeTaken": {
                    "type": "string"
                },
                "OData-Version": {
                    "type": "string"
                },
                "Date": {
                    "type": "string"
                },
                "Content-Type": {
                    "type": "string"
                },
                "Content-Length": {
                    "type": "string"
                }
            }
        },
        "body": {
            "type": "object",
            "properties": {
                "@@odata.context": {
                    "type": "string"
                },
                "@@odata.nextLink": {
                    "type": "string"
                },
                "value": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "properties": {
                            "startDateTime": {
                                "type": "string"
                            },
                            "endDateTime": {
                                "type": "string"
                            },
                            "lastModifiedDateTime": {
                                "type": "string"
                            },
                            "title": {
                                "type": "string"
                            },
                            "id": {
                                "type": "string"
                            },
                            "impactDescription": {
                                "type": "string"
                            },
                            "classification": {
                                "type": "string"
                            },
                            "origin": {
                                "type": "string"
                            },
                            "status": {
                                "type": "string"
                            },
                            "service": {
                                "type": "string"
                            },
                            "feature": {
                                "type": "string"
                            },
                            "featureGroup": {
                                "type": "string"
                            },
                            "isResolved": {
                                "type": "boolean"
                            },
                            "details": {
                                "type": "array"
                            },
                            "posts": {
                                "type": "array",
                                "items": {
                                    "type": "object",
                                    "properties": {
                                        "createdDateTime": {
                                            "type": "string"
                                        },
                                        "postType": {
                                            "type": "string"
                                        },
                                        "description": {
                                            "type": "object",
                                            "properties": {
                                                "contentType": {
                                                    "type": "string"
                                                },
                                                "content": {
                                                    "type": "string"
                                                }
                                            }
                                        }
                                    },
                                    "required": [
                                        "createdDateTime",
                                        "postType",
                                        "description"
                                    ]
                                }
                            }
                        },
                        "required": [
                            "startDateTime",
                            "endDateTime",
                            "lastModifiedDateTime",
                            "title",
                            "id",
                            "impactDescription",
                            "classification",
                            "origin",
                            "status",
                            "service",
                            "feature",
                            "featureGroup",
                            "isResolved",
                            "details",
                            "posts"
                        ]
                    }
                }
            }
        }
    }
}

アレイのフィルター処理-x日以内に更新アクション

HTTPアクションの出力から、1日以内に更新された問題のみを抽出しています。
(毎日取得して差分更新する想定)

HTTPアクションの出力にある lastModifiedDateTime が最終更新日時ですので、式で1日前の日時を指定してフィルター処理します。

adddays(utcNow(), -1)

 

Apply to each

問題を1つ1つ処理する為に、Apply to Eachアクションを使用します。


更新情報の組み立て

問題の更新部分は更新日時ごとにアレイとして格納されています。

このままでは扱いづらい為すべて結合して文字列変数に格納しています。




テキストの翻訳

HTTPアクションの出力は英文で出力されます。英語苦手なので、Microsoft Translator V2コネクタを使って日本語に翻訳します。

Microsoft Translator V2コネクタは無料利用では1日の変換数に上限がありますので上限を超えないようにご注意ください。

 

Listに作成 or 更新

取得できた情報をSharePoint Listsに登録します。

「複数の項目を取得」アクションを使いID(EX571516のような問題番号)を条件でリストの既存アイテムを検索しています。

既存アイテムが存在した場合は項目の更新アクション、存在しない場合は項目の作成アクションでListsに登録します。




※lastModifiedDateTimeの式: 日本時間に変換しています。

convertFromUtc(
    items('Apply_to_each')?['lastModifiedDateTime'],
    'Tokyo Standard Time',
    'yyyy/MM/dd HH:mm:ss'
)

※StartDateTimeの式: 日本時間に変換しています。

convertFromUtc(
    items('Apply_to_each')?['startDateTime'],
    'Tokyo Standard Time',
    'yyyy/MM/dd HH:mm:ss'
)

※EndDateTimeの式: 日本時間に変換しています。EndDateはnullの場合を考慮

if(equals(items('Apply_to_each')?['endDateTime'],null),
    null,
    convertFromUtc(
        items('Apply_to_each')?['endDateTime'],
        'Tokyo Standard Time',
        'yyyy/MM/dd HH:mm:ss'
    )
)

 

 

実行イメージ

Sharepoint Lists上にサービス正常性が反映されます。

 

さいごに

取得したリストをTeams チャネルに表示したり、SharePointポータルサイトに掲載したり、いろいろ使い道はありそうです。

しかし、私はワンオペ管理者なので共有する相手がいませんので、検証のみで実際に運用はしていません。いつの日か…情報共有できる管理者2号・3号…ができた時の為に手順を残しておきます。

 

参考にしたページ

jpdynamicscrm.github.io

 

learn.microsoft.com