使用 Rest 从 LogAnalytics Workspace 获取日志数据 API
Get log data from LogAnalytics Workspace using Rest API
我正在尝试使用保存在工作区内的查询从 Azure Log Analytics 工作区获取日志数据。我已经开始开发 Web API 来获取查询结果,并且我将此 Web API 注册到我在 Visual Studio Enterprise Azure 订阅中创建的 Azure Active Directory。但是,当我尝试 'Request Permission' for LogAnalytics API 时,我无法从 Microsoft API 中找到 LogAnalytics API。我正在按照以下 link 中的说明进行操作:
https://dev.loganalytics.io/oms/documentation/1-Tutorials/1-Direct-API
有人可以告诉我如何从 LogAnalytics 工作区中获取日志数据吗?我查看了仅提供 API 但未说明如何获取令牌的 Microsoft 文档:
https://docs.microsoft.com/en-us/rest/api/loganalytics/savedsearches/get
But when I try to 'Request Permission' for LogAnalytics API, I am not able to find LogAnalytics API from Microsoft API.
您需要导航到 APIs my organization uses
,搜索 Log Analytics API
,添加 Application permission
,如下所示。
注:link you provided should be out of date, it uses the Delegated permission
, that is not correct, it must be Application permission
, because we will use the client credential flow获取token。
授予权限后,还要确保您的 AD 应用具有 RBAC 角色,例如Contributor
, Log Analytics Reader
在你的工作区 Access control (IAM)
中,如果没有,请按照此 doc 添加它。
然后使用客户端凭证流获取token,获取token后,用它来调用api.
POST /YOUR_AAD_TENANT/oauth2/token HTTP/1.1
Host: https://login.microsoftonline.com
Content-Type: application/x-www-form-urlencoded
grant_type=client_credentials
&client_id=YOUR_CLIENT_ID
&redirect_uri=YOUR_REDIRECT_URI
&resource=https://api.loganalytics.io
&client_secret=YOUR_CLIENT_SECRET
更多细节可以参考这个link,不要错过任何一步。
I have looked into Microsoft documentation which just gives the API but does not say how to get the token: https://docs.microsoft.com/en-us/rest/api/loganalytics/savedsearches/get
要获取此 REST API 的令牌,与 Log Analytics API
相同。要调用此API,无需为您的AD App 添加[=53=] 权限,它只需要RBAC 角色。区别在于您需要将请求正文中的 resource
更改为 https://management.azure.com
,如下所示。
POST /YOUR_AAD_TENANT/oauth2/token HTTP/1.1
Host: https://login.microsoftonline.com
Content-Type: application/x-www-form-urlencoded
grant_type=client_credentials
&client_id=YOUR_CLIENT_ID
&redirect_uri=YOUR_REDIRECT_URI
&resource=https://management.azure.com
&client_secret=YOUR_CLIENT_SECRET
有关详细信息,请参阅此 link。
我正在尝试使用保存在工作区内的查询从 Azure Log Analytics 工作区获取日志数据。我已经开始开发 Web API 来获取查询结果,并且我将此 Web API 注册到我在 Visual Studio Enterprise Azure 订阅中创建的 Azure Active Directory。但是,当我尝试 'Request Permission' for LogAnalytics API 时,我无法从 Microsoft API 中找到 LogAnalytics API。我正在按照以下 link 中的说明进行操作:
https://dev.loganalytics.io/oms/documentation/1-Tutorials/1-Direct-API
有人可以告诉我如何从 LogAnalytics 工作区中获取日志数据吗?我查看了仅提供 API 但未说明如何获取令牌的 Microsoft 文档: https://docs.microsoft.com/en-us/rest/api/loganalytics/savedsearches/get
But when I try to 'Request Permission' for LogAnalytics API, I am not able to find LogAnalytics API from Microsoft API.
您需要导航到 APIs my organization uses
,搜索 Log Analytics API
,添加 Application permission
,如下所示。
注:link you provided should be out of date, it uses the Delegated permission
, that is not correct, it must be Application permission
, because we will use the client credential flow获取token。
授予权限后,还要确保您的 AD 应用具有 RBAC 角色,例如Contributor
, Log Analytics Reader
在你的工作区 Access control (IAM)
中,如果没有,请按照此 doc 添加它。
然后使用客户端凭证流获取token,获取token后,用它来调用api.
POST /YOUR_AAD_TENANT/oauth2/token HTTP/1.1
Host: https://login.microsoftonline.com
Content-Type: application/x-www-form-urlencoded
grant_type=client_credentials
&client_id=YOUR_CLIENT_ID
&redirect_uri=YOUR_REDIRECT_URI
&resource=https://api.loganalytics.io
&client_secret=YOUR_CLIENT_SECRET
更多细节可以参考这个link,不要错过任何一步。
I have looked into Microsoft documentation which just gives the API but does not say how to get the token: https://docs.microsoft.com/en-us/rest/api/loganalytics/savedsearches/get
要获取此 REST API 的令牌,与 Log Analytics API
相同。要调用此API,无需为您的AD App 添加[=53=] 权限,它只需要RBAC 角色。区别在于您需要将请求正文中的 resource
更改为 https://management.azure.com
,如下所示。
POST /YOUR_AAD_TENANT/oauth2/token HTTP/1.1
Host: https://login.microsoftonline.com
Content-Type: application/x-www-form-urlencoded
grant_type=client_credentials
&client_id=YOUR_CLIENT_ID
&redirect_uri=YOUR_REDIRECT_URI
&resource=https://management.azure.com
&client_secret=YOUR_CLIENT_SECRET
有关详细信息,请参阅此 link。