问题描述
我正在将Stackdriver Error Logging REST API与Apps脚本一起使用。
文档位于:
https://cloud.google.com/error-reporting/reference/rest/v1beta1/projects.events/list
查询参数字符串中必须有组ID。 我需要组ID,但我不知道从何处获取组名称或组ID。我查看了IAM设置:
https://console.cloud.google.com/iam-admin/settings?authuser=0
IAM设置有一个组部分,但是我没有任何组。 我不知道从哪里获取组ID。 在哪里可以找到组ID?
我得到的错误是:
{
"error": {
"code": 400,"message": "Missing group_id.","status": "INVALID_ARGUMENT"
}
}
我正在使用的代码是:
function getStackdriverLogs(){
var entries,groupId,httpResponse,logs,options,param,projectId,url;
/*
Get StackDriver Logs -
*/
/*
The Stackdriver Error Reporting API (Error Reporting API) must be enabled -
https://cloud.google.com/error-reporting/reference/rest/v1beta1/projects.events/list
*/
groupId = "Put group ID here";
projectId = "Put the Cloud Project ID here";
param = 'projects/' + projectId;
url = "https://clouderrorreporting.googleapis.com/v1beta1/" + param + "/events";
url = url + "?groupId=" + groupId;
options = {};
options.muteHttpExceptions = true;
options.headers = {Authorization: 'Bearer ' + ScriptApp.getoAuthToken()};
options.contentType = "application/json";
options.method = 'get';
httpResponse = UrlFetchApp.fetch(url,options);
Logger.log('httpResponse.getResponseCode(): ' + httpResponse.getResponseCode());
if (httpResponse.getResponseCode() !== 200) {
return httpResponse.getContentText();
}
logs = httpResponse.getContentText();
Logger.log('logs: ' + logs)
logs = JSON.parse(logs);
entries = logs.entries;
Logger.log('pgTkn',pgTkn)
}
解决方法
错误消息根据set of criteria分组。每个组都可以在Stack driver error reporting中看到。如果在信息中心中单击一个组,则会打开该组错误消息,并且网址如下:
https://console.cloud.google.com/errors/[GROUP_ID]?project=[PROJECT_ID]&time=[TIME_DATA]
可以从URL推断出组ID。或者(最好是),使用projects.groupStats.list端点获取给定项目中的所有组ID。
相关:Stackdriver Logging API returns response code 200,but response is empty