Skip to content

Commit

Permalink
Add agent status datatype into Ingestc. (#37)
Browse files Browse the repository at this point in the history
* Add agent status datatype into Ingestc.

* Separate out ingestc

* Code cleanup

* Remove aicspmsgs
  • Loading branch information
kkuzmin authored Mar 11, 2020
1 parent db1f490 commit 29f0ea9
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 84 deletions.
75 changes: 0 additions & 75 deletions al_servicec.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,80 +139,6 @@ class AlServiceC extends m_alUtil.RestServiceClient {
}


/**
* @class
* HTTPS client for Alert Logic Ingest service.
*
* @constructor
* @param {string} apiEndpoint - Alert Logic API hostname.
* @param {Object} aimsCreds - Alert Logic API credentials object, refer to AimsC.
* @param {string} [aimsCreds.access_key_id] - Alert Logic API access key id.
* @param {string} [aimsCreds.secret_key] - Alert Logic API secret key.
*
*/
class IngestC extends AlServiceC {
constructor(apiEndpoint, aimsCreds, functionType, retryOptions) {
super(apiEndpoint, 'ingest', 'v1', aimsCreds, retryOptions);
this._functionType = functionType ? functionType : 'lambda_function';
}

sendSecmsgs(data) {
let payload = {
json : false,
headers : {
'Content-Type': 'alertlogic.com/cwe-json',
'x-invoked-by' : this._functionType,
'Content-Encoding' : 'deflate',
'Content-Length' : Buffer.byteLength(data)
},
body : data
};
return this.post(`/data/secmsgs`, payload);
}

sendVpcFlow(data) {
let payload = {
json : false,
headers : {
'Content-Type': 'alertlogic.com/cwl-json',
'x-invoked-by' : this._functionType,
'Content-Encoding' : 'deflate',
'Content-Length' : Buffer.byteLength(data)
},
body : data
};
return this.post(`/data/vpcflow`, payload);
}

sendAicspmsgs(data) {
let payload = {
json : false,
headers : {
'Content-Type': 'alertlogic.com/lm3-protobuf',
'x-invoked-by' : this._functionType,
'Content-Encoding' : 'deflate',
'Content-Length' : Buffer.byteLength(data)
},
body : data
};
return this.post(`/data/logmsgs`, payload);
}

sendLogmsgs(data) {
let payload = {
json : false,
headers : {
'Content-Type': 'alertlogic.com/lm3-protobuf',
'x-invoked-by' : this._functionType,
'Content-Encoding' : 'deflate',
'Content-Length' : Buffer.byteLength(data)
},
body : data
};
return this.post(`/data/logmsgs`, payload);
}
}

/**
* @class
* HTTPS client for Alert Logic Endpoints service.
Expand All @@ -237,7 +163,6 @@ class EndpointsC extends AlServiceC {
module.exports = {
AlServiceC: AlServiceC,
AimsC: AimsC,
IngestC: IngestC,
EndpointsC: EndpointsC
};

2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
module.exports = {
AimsC : require('./al_servicec').AimsC,
AlServiceC : require('./al_servicec').AlServiceC,
IngestC : require('./al_servicec').IngestC,
IngestC : require('./ingestc').IngestC,
AzcollectC : require('./azcollectc').AzcollectC,
EndpointsC : require('./al_servicec').EndpointsC,
AlLog : require('./al_log'),
Expand Down
91 changes: 91 additions & 0 deletions ingestc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/* -----------------------------------------------------------------------------
* @copyright (C) 2020, Alert Logic, Inc
* @doc
*
* HTTP client for Ingest service.
*
* @end
* -----------------------------------------------------------------------------
*/
'use strict';

const AlServiceC = require('./al_servicec').AlServiceC;

/**
* @class
* HTTPS client for Alert Logic Ingest service.
*
* @constructor
* @param {string} apiEndpoint - Alert Logic API hostname.
* @param {Object} aimsCreds - Alert Logic API credentials object, refer to AimsC.
* @param {string} [aimsCreds.access_key_id] - Alert Logic API access key id.
* @param {string} [aimsCreds.secret_key] - Alert Logic API secret key.
*
*/
class IngestC extends AlServiceC {
constructor(apiEndpoint, aimsCreds, functionType, retryOptions) {
super(apiEndpoint, 'ingest', 'v1', aimsCreds, retryOptions);
this._functionType = functionType ? functionType : 'lambda_function';
}

sendSecmsgs(data) {
let payload = {
json : false,
headers : {
'Content-Type': 'alertlogic.com/cwe-json',
'x-invoked-by' : this._functionType,
'Content-Encoding' : 'deflate',
'Content-Length' : Buffer.byteLength(data)
},
body : data
};
return this.post(`/data/secmsgs`, payload);
}

sendVpcFlow(data) {
let payload = {
json : false,
headers : {
'Content-Type': 'alertlogic.com/cwl-json',
'x-invoked-by' : this._functionType,
'Content-Encoding' : 'deflate',
'Content-Length' : Buffer.byteLength(data)
},
body : data
};
return this.post(`/data/vpcflow`, payload);
}

sendLogmsgs(data) {
let payload = {
json : false,
headers : {
'Content-Type': 'alertlogic.com/lm3-protobuf',
'x-invoked-by' : this._functionType,
'Content-Encoding' : 'deflate',
'Content-Length' : Buffer.byteLength(data)
},
body : data
};
return this.post(`/data/logmsgs`, payload);
}

sendAgentstatus(data) {
let payload = {
json : false,
headers : {
'Content-Type': 'alertlogic.com/json',
'x-invoked-by' : this._functionType,
'Content-Encoding' : 'deflate',
'Content-Length' : Buffer.byteLength(data)
},
body : data
};
return this.post(`/data/agentstatus`, payload);
}
}

module.exports = {
IngestC: IngestC
};

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@alertlogic/al-collector-js",
"version": "1.4.3",
"version": "1.4.4",
"license": "MIT",
"description": "Alert Logic Collector Common Library",
"repository": {
Expand Down
14 changes: 7 additions & 7 deletions test/ingestc_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const fs = require('fs');
const assert = require('assert');
const sinon = require('sinon');
const AimsC = require('../al_servicec').AimsC;
const IngestC = require('../al_servicec').IngestC;
const IngestC = require('../ingestc').IngestC;
const m_alMock = require('./al_mock');
var m_servicec = require('../al_servicec');

Expand Down Expand Up @@ -65,7 +65,7 @@ describe('Unit Tests', function() {
ingest.sendVpcFlow('testing payload');
});

it('Verify aicspmsgs body', function(done) {
it('Verify logmsgs body', function(done) {
fakePost = sinon.stub(m_servicec.AlServiceC.prototype, 'post').callsFake(
function fakeFn(path, extraOptions) {
assert.equal(extraOptions.headers['Content-Type'], 'alertlogic.com/lm3-protobuf');
Expand All @@ -76,21 +76,21 @@ describe('Unit Tests', function() {

var aimsc = new AimsC(m_alMock.AL_API, m_alMock.AIMS_CREDS);
var ingest = new IngestC(m_alMock.INGEST_ENDPOINT, aimsc);
ingest.sendAicspmsgs('testing payload');
ingest.sendLogmsgs('testing payload');
});

it('Verify logmsgs body', function(done) {
it('Verify agentstatus body', function(done) {
fakePost = sinon.stub(m_servicec.AlServiceC.prototype, 'post').callsFake(
function fakeFn(path, extraOptions) {
assert.equal(extraOptions.headers['Content-Type'], 'alertlogic.com/lm3-protobuf');
assert.equal(path, '/data/logmsgs');
assert.equal(extraOptions.headers['Content-Type'], 'alertlogic.com/json');
assert.equal(path, '/data/agentstatus');

done();
});

var aimsc = new AimsC(m_alMock.AL_API, m_alMock.AIMS_CREDS);
var ingest = new IngestC(m_alMock.INGEST_ENDPOINT, aimsc);
ingest.sendLogmsgs('testing payload');
ingest.sendAgentstatus('testing payload');
});

});
Expand Down

0 comments on commit 29f0ea9

Please sign in to comment.