PKUI}.#datacollectorapi/version.pyVERSION = "0.1.2" PKFIS{LXXdatacollectorapi/__init__.pyversion = '0.1.0' #from handlersocket.client import Client, TransportError, RemoteError PKFI{ { datacollectorapi/client.py# -*- coding: utf-8 -*- import requests import datetime import hashlib import hmac import base64 import simplejson as json """ This is Azure Log Analytics Data Collector API Client libraries Data Collector API can be refered in the following document: https://docs.microsoft.com/en-us/azure/log-analytics/log-analytics-data-collector-api """ __author__ = 'Yoichi Kawasaki' ### Global Defines _LOG_ANALYTICS_DATA_COLLECTOR_API_VERSION = '2016-04-01' class DataCollectorAPIClient: """ Azure Log Analytics Data Collector API Client Class """ def __init__(self, customer_id, shared_key): self.customer_id = customer_id self.shared_key = shared_key # Build the API signature def __signature(self, date, content_length): sigs= "POST\n{}\napplication/json\nx-ms-date:{}\n/api/logs".format( str(content_length),date) utf8_sigs = bytes(sigs).encode('utf-8') decoded_shared_key = base64.b64decode(self.shared_key) hmac_sha256_sigs = hmac.new( decoded_shared_key, utf8_sigs,digestmod=hashlib.sha256).digest() encoded_hash = base64.b64encode(hmac_sha256_sigs) authorization = "SharedKey {}:{}".format(self.customer_id,encoded_hash) return authorization def __rfc1123date(self): return datetime.datetime.utcnow().strftime('%a, %d %b %Y %H:%M:%S GMT') # Build and send a request to the POST API def post_data(self, log_type, json_records, record_timestamp=''): # Check if string contains other than alpha characters if not log_type.isalpha(): raise Exception( "ERROR: log_type supports only alpha characters: {}".format(log_type)) body = json.dumps(json_records) rfc1123date = self.__rfc1123date() content_length = len(body) signature = self.__signature(rfc1123date, content_length) uri = "https://{}.ods.opinsights.azure.com/api/logs?api-version={}".format( self.customer_id, _LOG_ANALYTICS_DATA_COLLECTOR_API_VERSION) """ time-generated-field The name of a field in the data that contains the timestamp of the data item. If this isn’t specified, the default is the time that the message is ingested. The field format is ISO 8601 format YYYY-MM-DDThh:mm:ssZ """ headers = { 'content-type': 'application/json', 'Authorization': signature, 'Log-Type': log_type, 'x-ms-date': rfc1123date, 'time-generated-field': record_timestamp } return requests.post(uri,data=body, headers=headers) PKIUPPdatacollectorapi/helper.pydef is_success(status_code): return True if (status_code == 200) else False PKj I^- Fazure_log_analytics_data_collector_api-0.1.2.dist-info/DESCRIPTION.rstUNKNOWN PKj IDazure_log_analytics_data_collector_api-0.1.2.dist-info/metadata.json{"classifiers": ["Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 2.7", "Topic :: Utilities"], "extensions": {"python.details": {"contacts": [{"email": "yoichi.kawasaki@outlook.com", "name": "Yoichi Kawasaki", "role": "author"}], "document_names": {"description": "DESCRIPTION.rst"}, "project_urls": {"Home": "https://github.com/yokawasa/azure-log-analytics-data-collector"}}}, "extras": [], "generator": "bdist_wheel (0.26.0)", "keywords": ["azure", "loganalysis", "datacollctorapi", "logs"], "license": "MIT", "metadata_version": "2.0", "name": "azure-log-analytics-data-collector-api", "platform": "any", "run_requires": [{"requires": ["simplejson"]}], "summary": "Azure Log Analytics Data Collector API Client", "version": "0.1.2"}PKj I8@І88Dazure_log_analytics_data_collector_api-0.1.2.dist-info/top_level.txtazure-log-analytics-data-collector-api datacollectorapi PKj I''\\<azure_log_analytics_data_collector_api-0.1.2.dist-info/WHEELWheel-Version: 1.0 Generator: bdist_wheel (0.26.0) Root-Is-Purelib: true Tag: py2-none-any PKj Iȑp66?azure_log_analytics_data_collector_api-0.1.2.dist-info/METADATAMetadata-Version: 2.0 Name: azure-log-analytics-data-collector-api Version: 0.1.2 Summary: Azure Log Analytics Data Collector API Client Home-page: https://github.com/yokawasa/azure-log-analytics-data-collector Author: Yoichi Kawasaki Author-email: yoichi.kawasaki@outlook.com License: MIT Keywords: azure loganalysis datacollctorapi logs Platform: any Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: MIT License Classifier: Programming Language :: Python :: 2.7 Classifier: Topic :: Utilities Requires-Dist: simplejson UNKNOWN PKj Ik =azure_log_analytics_data_collector_api-0.1.2.dist-info/RECORDazure_log_analytics_data_collector_api-0.1.2.dist-info/DESCRIPTION.rst,sha256=OCTuuN6LcWulhHS3d5rfjdsQtW22n7HENFRh6jC6ego,10 azure_log_analytics_data_collector_api-0.1.2.dist-info/METADATA,sha256=s4QVR-5r9ofL5oR651IT4t7UMW0Cc7As0VLLp5COBJ0,566 azure_log_analytics_data_collector_api-0.1.2.dist-info/RECORD,, azure_log_analytics_data_collector_api-0.1.2.dist-info/WHEEL,sha256=JTb7YztR8fkPg6aSjc571Q4eiVHCwmUDlX8PhuuqIIE,92 azure_log_analytics_data_collector_api-0.1.2.dist-info/metadata.json,sha256=Uoi38LYgnNN_l6Gr2aDoZw-BUDzuWEFScPX15t6eKMY,798 azure_log_analytics_data_collector_api-0.1.2.dist-info/top_level.txt,sha256=WY6wnzY1G3RWMD8uJ81XH7uPAVQ8r_u3UrXO4iDfN1g,56 datacollectorapi/__init__.py,sha256=oMVVq2ER0k9uzIXhQ8DoUHXl0FN-WnHFvE59Oim6llE,88 datacollectorapi/client.py,sha256=0POqcGzA6WS2yuOEpYiOxLaVhn22U74C9j2JckdH7a0,2683 datacollectorapi/helper.py,sha256=Z0-H1NLT8r06mtgGTnIRsewszwVi1PLGUyjEuPHdvBg,80 datacollectorapi/version.py,sha256=3ITyQfKn-h4AMdaHk5rHJaliZbCnbLZ7O3QQnAJH8yI,18 PKUI}.#datacollectorapi/version.pyPKFIS{LXXKdatacollectorapi/__init__.pyPKFI{ { datacollectorapi/client.pyPKIUPP datacollectorapi/helper.pyPKj I^- F azure_log_analytics_data_collector_api-0.1.2.dist-info/DESCRIPTION.rstPKj ID azure_log_analytics_data_collector_api-0.1.2.dist-info/metadata.jsonPKj I8@І88Dazure_log_analytics_data_collector_api-0.1.2.dist-info/top_level.txtPKj I''\\<azure_log_analytics_data_collector_api-0.1.2.dist-info/WHEELPKj Iȑp66?Vazure_log_analytics_data_collector_api-0.1.2.dist-info/METADATAPKj Ik =azure_log_analytics_data_collector_api-0.1.2.dist-info/RECORDPK 5