Compare commits
23 Commits
Author | SHA1 | Date | |
---|---|---|---|
484e5d51cc | |||
a8bac181a4 | |||
76d3926ba4 | |||
0310c03ecb | |||
9e8efc7dea | |||
00e1b8d862 | |||
c5cedb027d | |||
f075f7f23a | |||
809df76043 | |||
d1dde293f6 | |||
b7ee6bb9a6 | |||
15cfa8fe88 | |||
1e222c7ad8 | |||
91a1571635 | |||
2e39906fd2 | |||
7950cb1649 | |||
b085dc32db | |||
e44aeccdb6 | |||
6c471f3722 | |||
99bfc485cf | |||
a55311c0fd | |||
7a45f829fc | |||
d95d2705b0 |
4
.snyk
Normal file
4
.snyk
Normal file
@ -0,0 +1,4 @@
|
||||
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
|
||||
version: v1.12.0
|
||||
ignore: {}
|
||||
patch: {}
|
17
package-lock.json
generated
17
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@mojoio/logdna",
|
||||
"version": "1.0.4",
|
||||
"version": "1.0.16",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
@ -127,12 +127,19 @@
|
||||
"integrity": "sha512-HbH2b6ybd1cD8VTlx5kEt4N/Vgh9TQTHKlUV4kAORFIOTJOQD5WbCMIVWo+VqYHvYQtokoYFCjM1gctp4M1aWw==",
|
||||
"requires": {
|
||||
"@pushrocks/smartlog-interfaces": "^1.0.9"
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"@pushrocks/smartlog-interfaces": {
|
||||
"version": "1.0.15",
|
||||
"resolved": "https://registry.npmjs.org/@pushrocks/smartlog-interfaces/-/smartlog-interfaces-1.0.15.tgz",
|
||||
"integrity": "sha512-dn9a+IhneukhtVGQG031oodOITmmQ5s5hcMThd+cMUQL3XYTbLPnZVuJfTDeWCT0iqLqrBD/qp2d1RRc3W/qIQ=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"@pushrocks/smartlog-interfaces": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/@pushrocks/smartlog-interfaces/-/smartlog-interfaces-2.0.2.tgz",
|
||||
"integrity": "sha512-kJNQ/6kfljgtwebhoiD8WtRWfdVhOoE1nr8FoUJLlOjLphU8SPa42Hg6/yPkSTaGxWwDhk6PkMJl64O7HNjRUQ=="
|
||||
},
|
||||
"@pushrocks/smartpath": {
|
||||
"version": "4.0.1",
|
||||
@ -268,9 +275,9 @@
|
||||
"integrity": "sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA=="
|
||||
},
|
||||
"@types/node": {
|
||||
"version": "10.12.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.12.1.tgz",
|
||||
"integrity": "sha512-i1sl+WCX2OCHeUi9oi7PiCNUtYFrpWhpcx878vpeq/tlZTKzcFdHePlyFHVbWqeuKN0SRPl/9ZFDSTsfv9h7VQ=="
|
||||
"version": "10.12.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.12.2.tgz",
|
||||
"integrity": "sha512-53ElVDSnZeFUUFIYzI8WLQ25IhWzb6vbddNp8UHlXQyU0ET2RhV5zg0NfubzU7iNMh5bBXb0htCzfvrSVNgzaQ=="
|
||||
},
|
||||
"@types/vinyl": {
|
||||
"version": "2.0.2",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@mojoio/logdna",
|
||||
"version": "1.0.4",
|
||||
"version": "1.0.16",
|
||||
"private": false,
|
||||
"description": "anunoffical package for the logdna api",
|
||||
"main": "dist/index.js",
|
||||
@ -17,12 +17,12 @@
|
||||
"@gitzone/tstest": "^1.0.15",
|
||||
"@pushrocks/qenv": "^2.0.2",
|
||||
"@pushrocks/tapbundle": "^3.0.7",
|
||||
"@types/node": "^10.11.7",
|
||||
"@types/node": "^10.12.2",
|
||||
"tslint": "^5.11.0",
|
||||
"tslint-config-prettier": "^1.15.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@pushrocks/smartlog-interfaces": "^1.0.15",
|
||||
"@pushrocks/smartlog-interfaces": "^2.0.2",
|
||||
"@pushrocks/smartrequest": "^1.1.14",
|
||||
"@pushrocks/smartstring": "^3.0.4",
|
||||
"@pushrocks/taskbuffer": "^2.0.5"
|
||||
|
12
test/test.ts
12
test/test.ts
@ -14,21 +14,23 @@ tap.test('should create a valid logDna account', async () => {
|
||||
|
||||
tap.test('should create a standard log message', async () => {
|
||||
testLogMessage = logdna.LogdnaMessage.fromSmartLogPackage({
|
||||
logContext: {
|
||||
timestamp: Date.now(),
|
||||
type: 'log',
|
||||
level: 'info',
|
||||
context: {
|
||||
company: 'Lossless GmbH',
|
||||
companyunit: 'lossless.cloud',
|
||||
containerName: 'ci-mojoio-logdna',
|
||||
environment: 'test',
|
||||
runtime: 'node',
|
||||
zone: 'ship.zone'
|
||||
zone: 'shipzone'
|
||||
},
|
||||
logLevel: 'info',
|
||||
message: 'this is a awesome log message :)'
|
||||
message: 'this is an awesome log message sent by the tapbundle test'
|
||||
});
|
||||
});
|
||||
|
||||
tap.test('should send the message', async () => {
|
||||
await testLogDnaAccount.sendLogDnaMessage(testLogMessage);
|
||||
})
|
||||
});
|
||||
|
||||
tap.start();
|
||||
|
@ -6,6 +6,11 @@ import { TLogLevel, TEnvironment, ILogPackage } from '@pushrocks/smartlog-interf
|
||||
* the constructor options for LogdnaMessage
|
||||
*/
|
||||
export interface ILogdnaMessageContructorOptions {
|
||||
/**
|
||||
* a timestamp for then the log message was created
|
||||
*/
|
||||
timestamp: number;
|
||||
|
||||
/**
|
||||
* the hostname where the log message was created
|
||||
*/
|
||||
@ -62,22 +67,26 @@ export class LogdnaMessage {
|
||||
*/
|
||||
static fromSmartLogPackage(smartlogPackageArg: ILogPackage): LogdnaMessage {
|
||||
return new LogdnaMessage({
|
||||
timestamp: smartlogPackageArg.timestamp,
|
||||
line: smartlogPackageArg.message,
|
||||
meta: smartlogPackageArg.logContext,
|
||||
env: smartlogPackageArg.logContext.environment,
|
||||
hostname: smartlogPackageArg.logContext.zone,
|
||||
level: smartlogPackageArg.logLevel,
|
||||
app: smartlogPackageArg.logContext.zone,
|
||||
meta: {
|
||||
...smartlogPackageArg.context,
|
||||
logType: smartlogPackageArg.type
|
||||
},
|
||||
env: smartlogPackageArg.context.environment,
|
||||
hostname: smartlogPackageArg.context.zone,
|
||||
level: smartlogPackageArg.level,
|
||||
app: smartlogPackageArg.context.containerName,
|
||||
tags: (() => {
|
||||
const tagArray: string[] = [];
|
||||
tagArray.push(smartlogPackageArg.logContext.company);
|
||||
tagArray.push(smartlogPackageArg.logContext.companyunit);
|
||||
tagArray.push(smartlogPackageArg.context.company);
|
||||
tagArray.push(smartlogPackageArg.context.companyunit);
|
||||
return tagArray;
|
||||
})(),
|
||||
ip: '0.0.0.0',
|
||||
mac: 'aa:aa:aa:aa:aa:aa'
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* the options of this log message
|
||||
@ -85,5 +94,5 @@ export class LogdnaMessage {
|
||||
public options: ILogdnaMessageContructorOptions;
|
||||
constructor(optionsArg: ILogdnaMessageContructorOptions) {
|
||||
this.options = optionsArg;
|
||||
};
|
||||
}
|
||||
}
|
@ -1,18 +1,19 @@
|
||||
import * as plugins from './logdna.plugins';
|
||||
|
||||
import { LogdnaMessage } from './logdna.classes.logmessage';
|
||||
import { ILogPackage, ILogDestination } from '@pushrocks/smartlog-interfaces';
|
||||
|
||||
/**
|
||||
* the main logdna account
|
||||
*/
|
||||
export class LogdnaAccount {
|
||||
apiKey: string;
|
||||
baseUrl = 'https://logs.logdna.com/logs/ingest';
|
||||
private apiKey: string;
|
||||
private baseUrl = 'https://logs.logdna.com/logs/ingest';
|
||||
|
||||
/**
|
||||
* Create basic authentication
|
||||
*/
|
||||
createBasicAuth() {
|
||||
private createBasicAuth() {
|
||||
const userNamePasswordString = `${this.apiKey}:`;
|
||||
return `Basic ${plugins.smartstring.base64.encode(userNamePasswordString)}`;
|
||||
}
|
||||
@ -36,26 +37,28 @@ export class LogdnaAccount {
|
||||
// let construct the request uri
|
||||
const requestUrlWithParams = `${this.baseUrl}?hostname=${euc(lm.options.hostname)}&mac=${euc(
|
||||
lm.options.mac
|
||||
)}&ip=1${euc(lm.options.ip)}&now=${Date.now()}`;
|
||||
|
||||
const requestBodyObject = {
|
||||
lines: [
|
||||
{
|
||||
line: lm.options.line,
|
||||
app: lm.options.app,
|
||||
level: lm.options.level,
|
||||
env: lm.options.env,
|
||||
meta: lm.options.meta,
|
||||
tags: (() => {
|
||||
)}&ip=1${euc(lm.options.ip)}&now=${Date.now()}&tags=${euc(
|
||||
(() => {
|
||||
return lm.options.tags.reduce((reduced, newItem) => {
|
||||
return `${reduced},${newItem}`;
|
||||
});
|
||||
})()
|
||||
)}`;
|
||||
|
||||
const requestBodyObject = {
|
||||
lines: [
|
||||
{
|
||||
timestamp: lm.options.timestamp,
|
||||
line: lm.options.line,
|
||||
app: lm.options.app,
|
||||
level: lm.options.level,
|
||||
env: lm.options.env,
|
||||
meta: lm.options.meta
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
console.log(requestBodyObject);
|
||||
// console.log(requestBodyObject);
|
||||
|
||||
// lets post the message to logdna
|
||||
await plugins.smartrequest.postJson(requestUrlWithParams, {
|
||||
@ -66,4 +69,22 @@ export class LogdnaAccount {
|
||||
requestBody: requestBodyObject
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* convenience function for smartlog
|
||||
*/
|
||||
public async sendSmartlogPackage(smartlogPackageArg: ILogPackage) {
|
||||
this.sendLogDnaMessage(LogdnaMessage.fromSmartLogPackage(smartlogPackageArg));
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a smartlog compatible log destination
|
||||
*/
|
||||
public get smartlogDestination(): ILogDestination {
|
||||
return {
|
||||
handleLog: logPackageArg => {
|
||||
this.sendSmartlogPackage(logPackageArg);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,4 @@ import * as smartrequest from '@pushrocks/smartrequest';
|
||||
import * as smartstring from '@pushrocks/smartstring';
|
||||
import * as smartlogInterfaces from '@pushrocks/smartlog-interfaces';
|
||||
|
||||
export {
|
||||
smartrequest,
|
||||
smartstring,
|
||||
smartlogInterfaces
|
||||
};
|
||||
export { smartrequest, smartstring, smartlogInterfaces };
|
||||
|
@ -1,19 +0,0 @@
|
||||
curl "https://logs.logdna.com/logs/ingest?hostname=EXAMPLE_HOST&mac=C0:FF:EE:C0:FF:EE&ip=10.0.1.101&now=$(date +%s)" \
|
||||
-u INSERT_INGESTION_KEY: \
|
||||
-H "Content-Type: application/json; charset=UTF-8" \
|
||||
-d \
|
||||
'{
|
||||
"lines": [
|
||||
{
|
||||
"line":"This is an awesome log statement",
|
||||
"app":"myapp",
|
||||
"level": "INFO",
|
||||
"env": "production",
|
||||
"meta": {
|
||||
"customfield": {
|
||||
"nestedfield": "nestedvalue"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}'
|
Reference in New Issue
Block a user