Created
December 28, 2018 05:20
-
-
Save Band-Aid/e74a9e30fcada3e40afb922ac50d19ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// required node.js libraries | |
const request = require('request'); | |
const crypto = require('crypto'); | |
// Azure Log Analysis credentials | |
const workspaceId = 'xxxxx'; | |
const sharedKey = 'xxxx'; | |
// Specify the name of the record type that you'll be creating | |
const LogType = "BoxReports" | |
let apiVersion = '2016-04-01'; | |
let processingDate = new Date().toUTCString(); | |
let body = JSON.stringify([ | |
{ | |
//some json data | |
} | |
] | |
); | |
console.log('Body is ' + body); | |
var contentLength = Buffer.byteLength(body, 'utf8'); | |
var stringToSign = 'POST\n' + contentLength + '\napplication/json\nx-ms-date:' + processingDate + '\n/api/logs'; | |
var signature = crypto.createHmac('sha256', new Buffer(sharedKey, 'base64')).update(stringToSign, 'utf-8').digest('base64'); | |
var authorization = 'SharedKey ' + workspaceId + ':' + signature; | |
var headers = { | |
"content-type": "application/json", | |
"Authorization": authorization, | |
"Log-Type": LogType, | |
"x-ms-date": processingDate | |
}; | |
console.log( 'Request Headers: ' + JSON.stringify(headers) ); | |
var url = 'https://' + workspaceId + '.ods.opinsights.azure.com/api/logs?api-version=' + apiVersion; | |
request.post({url: url, headers: headers, body: body}, function (error, response, body) { | |
console.log('error:', error); | |
console.log('statusCode:', response && response.statusCode); | |
console.log('body:', body); | |
console.res = { 'status': response.statusCode, 'body': body } | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment