本文档讨论了如何设置权限和启用访问权限,以便您能够:
- 使用 Service Health 信息中心查看服务健康状况事件。
- 使用 Service Health API 拉取服务健康状况信息。
- 配置与您的项目相关的提醒。
准备工作
Verify that billing is enabled for your Google Cloud project.
访问服务运行状况 API 和信息中心
Personalized Service Health 提供了一个预定义的 servicehealth.viewer 角色,您可以使用该角色为项目成员授予访问权限。使用此角色可访问 Service Health API 和信息中心。
| 角色名称 | 说明 | 个性化服务健康权限 |
roles/servicehealth.viewer Personalized Service Health 查看器
|
拥有对服务健康状况事件的只读权限。 | servicehealth.location.list
|
您可以通过 gcloud CLI 直接使用角色和权限来设置适当的访问控制。例如,您可以使用以下命令直接授予角色:
gcloud projects add-iam-policy-binding PROJECT_ID \
--member {USER|GROUP|SERVICE_ACCOUNT} \
--role roles/servicehealth.viewer
您可以使用以下命令查看指定项目的 Identity and Access Management (IAM) 政策:
gcloud projects get-iam-policy PROJECT_ID
或者,您也可以直接向现有角色添加权限:
gcloud iam roles update ROLE_ID --project=PROJECT_ID \
--add-permissions=servicehealth.events.list
gcloud iam roles update ROLE_ID --project=PROJECT_ID \
--add-permissions=servicehealth.events.get
gcloud iam roles update ROLE_ID --project=PROJECT_ID \
--add-permissions=servicehealth.locations.list
gcloud iam roles update ROLE_ID --project=PROJECT_ID \
--add-permissions=servicehealth.locations.get
在项目中使用 API 和服务
- 为项目启用 Service Health API。
- 授予 Service Usage Consumer 角色 (
roles/serviceusage.serviceUsageConsumer)。
访问日志和配置日志提醒
执行以下操作:
- 为项目启用 Service Health API。
- 获取基于日志的提醒的权限。
如果您不想授予 Monitoring NotificationChannel Editor 角色 (roles/monitoring.notificationChannelEditor),则可以改为授予 Monitoring NotificationChannel Viewer 角色 (roles/monitoring.notificationChannelViewer),以便您将通知渠道与提醒政策相关联。
如需详细了解如何授予角色,请参阅管理访问权限。
为单个项目启用 Service Health API
设置提醒和提取服务健康状况信息需要启用 Service Health API。您可以通过Google Cloud 控制台或 Google Cloud CLI 启用该 API。
控制台
在“API 和服务”库中,前往 Service Health API。
或者,您也可以前往 API 库,然后搜索“Service Health API”。
选择项目。
选择启用按钮。
gcloud
-
In the Google Cloud console, activate Cloud Shell.
确保已安装最新版本的 Google Cloud CLI。在 Cloud Shell 中运行以下命令:
gcloud components update
创建或选择一个新项目,
PROJECT_ID。创建 Google Cloud 项目:
gcloud projects create PROJECT_ID
选择您创建的 Google Cloud 项目:
gcloud projects config set project PROJECT_ID
在您刚刚创建的项目中启用 Service Health API。
gcloud services enable servicehealth.googleapis.com \ --project PROJECT_ID
脚本
您可以使用脚本为组织或文件夹中的项目启用 Service Health API。
如需了解背景信息,请参阅在 Google Cloud 项目中启用 API。
启用 API 后,Service Health API 和提醒会在几个小时后识别新事件。