簡體   English   中英

如何配置 Google Workspace 提醒中心以向 PubSub 主題發布提醒?

[英]How to configure Google Workspace Alert Center to publish alerts to a PubSub topic?

我正在構建一個通知系統,該系統會在員工采取觸發 DLP 規則的操作時通知他們。

我想要達到的理想流程是:

員工采取行動 > 規則觸發 > 警報發布到 PubSub 主題 > 觸發器雲 function 呈現松弛消息並將其發送給用戶。

我卡住的地方是讓 API 警報中心將警報發布到 PubSub 主題。 我過去用 Gmail API 做過類似的事情,當特定帳戶收到 email 時發布到主題。並且有一個觀察請求來配置帳戶以發布到主題。

我查看了警報中心 API 文檔,但沒有找到監視請求或執行類似操作的任何內容。

有沒有辦法做到這一點? 或者這是不可能的?

我在 Google 警報中心API 參考資料和警報中心控制台中搜索了任何用於配置發布到 pubsub 主題或 webhook 的選項。

經過幾個小時的反復試驗,我找到了解決方案。

我們必須通過 making 和updateSetting更新設置,並在正文中發送設置object。

這是一些 python 代碼,使用具有域范圍委托的服務帳戶來執行此操作:

from google.oauth2 import service_account
from googleapiclient.discovery import build
import json

def main():

    # Authenticate the service account
    scopes = ['https://www.googleapis.com/auth/apps.alerts']
    admin_to_impersonate = '******'
    credentials = service_account.Credentials.from_service_account_file(
        'client_secrets.json', scopes=scopes, subject=admin_to_impersonate
        )
    
    # Build the service
    service = build('alertcenter', 'v1beta1', credentials=credentials)

    settings = {
        'notifications': [
            {
                'cloudPubsubTopic': {
                    'topicName': '<YOUR TOPIC NAME>',
                    'payloadFormat': 'JSON'
                }
            }
        ]
    }

    # Execute a updateSetting request
    response = service.v1beta1().updateSettings(body=settings).execute()
    print(response)

if __name__ == '__main__':
    main()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM