diff --git a/al_servicec.js b/al_servicec.js index 61a3101..b2713fa 100644 --- a/al_servicec.js +++ b/al_servicec.js @@ -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. @@ -237,7 +163,6 @@ class EndpointsC extends AlServiceC { module.exports = { AlServiceC: AlServiceC, AimsC: AimsC, - IngestC: IngestC, EndpointsC: EndpointsC }; diff --git a/index.js b/index.js index f368172..a935eca 100644 --- a/index.js +++ b/index.js @@ -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'), diff --git a/ingestc.js b/ingestc.js new file mode 100644 index 0000000..e1a433c --- /dev/null +++ b/ingestc.js @@ -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 +}; + diff --git a/package.json b/package.json index 5cff809..2217975 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/test/ingestc_test.js b/test/ingestc_test.js index 486b160..a170a6f 100644 --- a/test/ingestc_test.js +++ b/test/ingestc_test.js @@ -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'); @@ -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'); @@ -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'); }); });