Skip to content
This repository has been archived by the owner on May 5, 2023. It is now read-only.

Commit

Permalink
Adding Log Analytics query capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeldeib committed Jun 14, 2018
1 parent 0687a1a commit 8ec9de7
Show file tree
Hide file tree
Showing 20 changed files with 1,803 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/azure.js
Original file line number Diff line number Diff line change
Expand Up @@ -2919,6 +2919,21 @@ exports.createCosmosDBManagementClient = function (credentials, subscriptionId,
return new CosmosDBManagementClient(credentials, subscriptionId, null, options);
};

/**
* Creates a new LogAnalyticsClient for data plane access.
* @param {credentials} credentials - Subscription credentials which uniquely identify client subscription.
* @param {string} [baseUri] - The base URI of the service.
* @param {object} [options] - The parameter options
* @param {Array} [options.filters] - Filters to be added to the request pipeline
* @param {object} [options.requestOptions] - Options for the underlying request object
* {@link https://github.com/request/request#requestoptions-callback Options doc}
* @param {boolean} [options.noRetryPolicy] - If set to true, turn off default retry policy
*/
exports.createLogAnalyticsClient = function (credentials, baseUri, options) {
const LogAnalyticsClient = require('azure-loganalytics');
return new LogAnalyticsClient(credentials, baseUri, options);
};

//runtime
var msRestAzure = require('ms-rest-azure');

Expand Down
21 changes: 21 additions & 0 deletions lib/services/loganalytics/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2018 Microsoft

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
76 changes: 76 additions & 0 deletions lib/services/loganalytics/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
uid: azure-loganalytics
summary: *content

---
# Microsoft Azure SDK for Node.js - LogAnalyticsClient
This project provides a Node.js package for accessing Azure Log Analytics query services.
- **Node.js version 6.x.x or higher**

## How to Install

```bash
npm install azure-loganalytics
```

## How to use

### Authentication, client creation and query execution example.

```javascript
const msrestazure = require('ms-rest-azure');
const LogAnalyticsClient = require('azure-loganalytics');

var options = {
tokenAudience: 'https://api.loganalytics.io'
}

msrestazure.loginWithServicePrincipalSecret(
'clientId or appId',
'secret or password',
'AAD domain or tenantId',
options,
(err, credentials) => {
if (err) throw err
// ..use the client instance to access service resources.
const client = new LogAnalyticsClient(creds);

const workspaceId = 'ed6078ff-9048-4dd7-9b21-fc39e3fc7249';
var body = {
query: 'Heartbeat | getschema',
timespan: 'P2D'
};

client.query(workspaceId, body).then((result) => {
console.log('The result is:');
console.log('Columns:')
console.table(result.tables[0].columns)
console.log('Rows:')
console.table(result.tables[0].rows);
}).catch((err) => {
console.log('An error occurred:');
console.dir(err, {depth: null, colors: true});
});

// Join additional workspaces in the body
body = {
query: 'AzureActivity | getschema',
workspaces: ['f30c1f56-e33c-418e-b515-9212fa3b7904']
};

client.query(workspaceId, body).then((result) => {
console.log('The result is:');
console.log('Columns:')
console.table(result.tables[0].columns)
console.log('Rows:')
console.table(result.tables[0].rows);
}).catch((err) => {
console.log('An error occurred:');
console.dir(err, {depth: null, colors: true});
});
}
);
```
## Related projects

- [Microsoft Azure SDK for Node.js](https://github.com/Azure/azure-sdk-for-node)
130 changes: 130 additions & 0 deletions lib/services/loganalytics/lib/logAnalyticsClient.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/*
* 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.
*/

import { ServiceClient, ServiceClientOptions, ServiceCallback, HttpOperationResponse, ServiceClientCredentials } from 'ms-rest';
import * as models from "./models";

export default class LogAnalyticsClient extends ServiceClient {
/**
* @class
* Initializes a new instance of the LogAnalyticsClient class.
* @constructor
*
* @param {credentials} credentials - Subscription credentials which uniquely identify client subscription.
*
* @param {string} [baseUri] - The base URI of the service.
*
* @param {object} [options] - The parameter options
*
* @param {Array} [options.filters] - Filters to be added to the request pipeline
*
* @param {object} [options.requestOptions] - Options for the underlying request object
* {@link https://github.com/request/request#requestoptions-callback Options doc}
*
* @param {boolean} [options.noRetryPolicy] - If set to true, turn off default retry policy
*
*/
constructor(credentials: ServiceClientCredentials, baseUri?: string, options?: ServiceClientOptions);

credentials: ServiceClientCredentials;


/**
* @summary 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 {string} workspaceId ID of the workspace. This is Workspace ID from
* the Properties blade in the Azure portal.
*
* @param {object} body The Analytics query. Learn more about the [Analytics
* query
* syntax](https://azure.microsoft.com/documentation/articles/app-insights-analytics-reference/)
*
* @param {string} body.query The query to execute.
*
* @param {string} [body.timespan] Optional. The timespan over which to query
* data. This is an ISO8601 time period value. This timespan is applied in
* addition to any that are specified in the query expression.
*
* @param {array} [body.workspaces] A list of workspaces that are included in
* the query.
*
* @param {object} [options] Optional Parameters.
*
* @param {object} [options.customHeaders] Headers that will be added to the
* request
*
* @returns {Promise} A promise is returned
*
* @resolve {HttpOperationResponse<QueryResults>} - The deserialized result object.
*
* @reject {Error|ServiceError} - The error object.
*/
queryWithHttpOperationResponse(workspaceId: string, body: models.QueryBody, options?: { customHeaders? : { [headerName: string]: string; } }): Promise<HttpOperationResponse<models.QueryResults>>;

/**
* @summary 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 {string} workspaceId ID of the workspace. This is Workspace ID from
* the Properties blade in the Azure portal.
*
* @param {object} body The Analytics query. Learn more about the [Analytics
* query
* syntax](https://azure.microsoft.com/documentation/articles/app-insights-analytics-reference/)
*
* @param {string} body.query The query to execute.
*
* @param {string} [body.timespan] Optional. The timespan over which to query
* data. This is an ISO8601 time period value. This timespan is applied in
* addition to any that are specified in the query expression.
*
* @param {array} [body.workspaces] A list of workspaces that are included in
* the query.
*
* @param {object} [options] Optional Parameters.
*
* @param {object} [options.customHeaders] Headers that will be added to the
* request
*
* @param {ServiceCallback} [optionalCallback] - The optional callback.
*
* @returns {ServiceCallback|Promise} If a callback was passed as the last
* parameter then it returns the callback else returns a Promise.
*
* {Promise} A promise is returned.
*
* @resolve {QueryResults} - The deserialized result object.
*
* @reject {Error|ServiceError} - The error object.
*
* {ServiceCallback} optionalCallback(err, result, request, response)
*
* {Error|ServiceError} err - The Error object if an error occurred, null otherwise.
*
* {QueryResults} [result] - The deserialized result object if an error did not occur.
* See {@link QueryResults} for more information.
*
* {WebResource} [request] - The HTTP Request object if an error did not occur.
*
* {http.IncomingMessage} [response] - The HTTP Response stream if an error did not occur.
*/
query(workspaceId: string, body: models.QueryBody, options?: { customHeaders? : { [headerName: string]: string; } }): Promise<models.QueryResults>;
query(workspaceId: string, body: models.QueryBody, callback: ServiceCallback<models.QueryResults>): void;
query(workspaceId: string, body: models.QueryBody, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback<models.QueryResults>): void;
}

export { LogAnalyticsClient, models as LogAnalyticsModels };
Loading

0 comments on commit 8ec9de7

Please sign in to comment.