1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
from msrest.service_client import SDKClient
from msrest import Configuration, Serializer, Deserializer
from .version import VERSION
from msrest.pipeline import ClientRawResponse
from . import models
class LogAnalyticsDataClientConfiguration(Configuration):
"""Configuration for LogAnalyticsDataClient
Note that all parameters used to create this instance are saved as instance
attributes.
:param credentials: Subscription credentials which uniquely identify
client subscription.
:type credentials: None
:param str base_url: Service URL
"""
def __init__(
self, credentials, base_url=None):
if credentials is None:
raise ValueError("Parameter 'credentials' must not be None.")
if not base_url:
base_url = 'https://api.loganalytics.io/v1'
super(LogAnalyticsDataClientConfiguration, self).__init__(base_url)
self.add_user_agent('azure-loganalytics/{}'.format(VERSION))
self.credentials = credentials
class LogAnalyticsDataClient(SDKClient):
"""Log Analytics Data Plane Client
:ivar config: Configuration for client.
:vartype config: LogAnalyticsDataClientConfiguration
:param credentials: Subscription credentials which uniquely identify
client subscription.
:type credentials: None
:param str base_url: Service URL
"""
def __init__(
self, credentials, base_url=None):
self.config = LogAnalyticsDataClientConfiguration(credentials, base_url)
super(LogAnalyticsDataClient, self).__init__(self.config.credentials, self.config)
client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)}
self.api_version = 'v1'
self._serialize = Serializer(client_models)
self._deserialize = Deserializer(client_models)
def query(
self, workspace_id, body, custom_headers=None, raw=False, **operation_config):
"""Execute an Analytics query.
Executes an Analytics query for data.
[Here](https://dev.loganalytics.io/documentation/Using-the-API) is an
example for using POST with an Analytics query.
:param workspace_id: ID of the workspace. This is Workspace ID from
the Properties blade in the Azure portal.
:type workspace_id: str
:param body: The Analytics query. Learn more about the [Analytics
query
syntax](https://azure.microsoft.com/documentation/articles/app-insights-analytics-reference/)
:type body: ~azure.loganalytics.models.QueryBody
:param dict custom_headers: headers that will be added to the request
:param bool raw: returns the direct response alongside the
deserialized response
:param operation_config: :ref:`Operation configuration
overrides<msrest:optionsforoperations>`.
:return: QueryResults or ClientRawResponse if raw=true
:rtype: ~azure.loganalytics.models.QueryResults or
~msrest.pipeline.ClientRawResponse
:raises:
:class:`ErrorResponseException<azure.loganalytics.models.ErrorResponseException>`
"""
# Construct URL
url = self.query.metadata['url']
path_format_arguments = {
'workspaceId': self._serialize.url("workspace_id", workspace_id, 'str')
}
url = self._client.format_url(url, **path_format_arguments)
# Construct parameters
query_parameters = {}
# Construct headers
header_parameters = {}
header_parameters['Content-Type'] = 'application/json; charset=utf-8'
if custom_headers:
header_parameters.update(custom_headers)
# Construct body
body_content = self._serialize.body(body, 'QueryBody')
# Construct and send request
request = self._client.post(url, query_parameters)
response = self._client.send(
request, header_parameters, body_content, stream=False, **operation_config)
if response.status_code not in [200]:
raise models.ErrorResponseException(self._deserialize, response)
deserialized = None
if response.status_code == 200:
deserialized = self._deserialize('QueryResults', response)
if raw:
client_raw_response = ClientRawResponse(deserialized, response)
return client_raw_response
return deserialized
query.metadata = {'url': '/workspaces/{workspaceId}/query'}
|