@alertlogic/al-collector-js 3.0.4 → 3.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/al_util.js +3 -0
- package/collector_statusc.js +40 -0
- package/index.js +2 -1
- package/package.json +15 -15
- package/test/al_mock.js +18 -0
- package/test/collector_statusc_test.js +146 -0
package/al_util.js
CHANGED
|
@@ -124,6 +124,9 @@ class RestServiceClient {
|
|
|
124
124
|
deleteRequest(path, extraOptions) {
|
|
125
125
|
return this.request('DELETE', path, extraOptions);
|
|
126
126
|
}
|
|
127
|
+
put(path, extraOptions) {
|
|
128
|
+
return this.request('PUT', path, extraOptions);
|
|
129
|
+
}
|
|
127
130
|
get host() {
|
|
128
131
|
return this._host;
|
|
129
132
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/* -----------------------------------------------------------------------------
|
|
2
|
+
* @copyright (C) 2023, Alert Logic, Inc
|
|
3
|
+
* @doc
|
|
4
|
+
*
|
|
5
|
+
* HTTP client for Collector status service.
|
|
6
|
+
*
|
|
7
|
+
* @end
|
|
8
|
+
* -----------------------------------------------------------------------------
|
|
9
|
+
*/
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
const AlServiceC = require('./al_servicec').AlServiceC;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @class
|
|
16
|
+
* HTTPS client for Alert Logic Collector_status service.
|
|
17
|
+
*
|
|
18
|
+
* @constructor
|
|
19
|
+
* @param {string} apiEndpoint - Alert Logic API hostname.
|
|
20
|
+
* @param {Object} aimsCreds - Alert Logic API credentials object, refer to AimsC.
|
|
21
|
+
* @param {*} retryOptions
|
|
22
|
+
*/
|
|
23
|
+
class CollectorStatusC extends AlServiceC {
|
|
24
|
+
constructor(apiEndpoint, aimsCreds, retryOptions) {
|
|
25
|
+
super(apiEndpoint, 'collectors_status', 'v1', aimsCreds, retryOptions);
|
|
26
|
+
}
|
|
27
|
+
sendStatus(statusId, stream, data) {
|
|
28
|
+
let payload = {
|
|
29
|
+
headers: {
|
|
30
|
+
'Content-Type': 'application/json'
|
|
31
|
+
},
|
|
32
|
+
body: data
|
|
33
|
+
};
|
|
34
|
+
return this.put(`/statuses/${statusId}/streams/${stream}`, payload);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
module.exports = {
|
|
39
|
+
CollectorStatusC: CollectorStatusC
|
|
40
|
+
};
|
package/index.js
CHANGED
|
@@ -16,6 +16,7 @@ module.exports = {
|
|
|
16
16
|
EndpointsC : require('./al_servicec').EndpointsC,
|
|
17
17
|
AlLog : require('./al_log'),
|
|
18
18
|
Parse: require('./parse'),
|
|
19
|
-
RestServiceClient: require('./al_util').RestServiceClient
|
|
19
|
+
RestServiceClient: require('./al_util').RestServiceClient,
|
|
20
|
+
CollectorStatusC: require('./collector_statusc').CollectorStatusC
|
|
20
21
|
};
|
|
21
22
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alertlogic/al-collector-js",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.6",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Alert Logic Collector Common Library",
|
|
6
6
|
"repository": {
|
|
@@ -21,25 +21,25 @@
|
|
|
21
21
|
],
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"jshint": "^2.9.5",
|
|
24
|
-
"mocha": "^
|
|
24
|
+
"mocha": "^10.2.0",
|
|
25
25
|
"mocha-jenkins-reporter": "^0.4.2",
|
|
26
|
-
"nock": "^
|
|
27
|
-
"nyc": "^
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
26
|
+
"nock": "^13.2.9",
|
|
27
|
+
"nyc": "^15.1.0",
|
|
28
|
+
"rewire": "^5.0.0",
|
|
29
|
+
"sinon": "^15.0.1",
|
|
30
|
+
"timekeeper": "^2.2.0"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"async": "3.
|
|
34
|
-
"debug": "4.
|
|
33
|
+
"async": "^3.2.4",
|
|
34
|
+
"debug": "^4.3.4",
|
|
35
|
+
"lodash.clonedeep": "^4.5.0",
|
|
35
36
|
"lodash.filter": "^4.6.0",
|
|
36
37
|
"lodash.remove": "^4.7.0",
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"request": "
|
|
41
|
-
"
|
|
42
|
-
"retry": "0.12.0"
|
|
38
|
+
"moment": "^2.29.4",
|
|
39
|
+
"protobufjs": "^7.1.2",
|
|
40
|
+
"request": "^2.88.2",
|
|
41
|
+
"request-promise-native": "^1.0.9",
|
|
42
|
+
"retry": "^0.13.1"
|
|
43
43
|
},
|
|
44
44
|
"author": "Alert Logic Inc."
|
|
45
45
|
}
|
package/test/al_mock.js
CHANGED
|
@@ -28,6 +28,7 @@ const CID = '12345678';
|
|
|
28
28
|
|
|
29
29
|
const AL_API = 'al-api-endpoint.alertlogic.com';
|
|
30
30
|
const INGEST_API = 'ingest-api-endpoint.alertlogic.com';
|
|
31
|
+
const COLLECTOR_STATUS_API = 'collector-status-api-endpoint.alertlogic.com';
|
|
31
32
|
|
|
32
33
|
const AWS_CHECKIN_URL = '/aws/cwe/checkin/1234567890/us-east-1/test-function';
|
|
33
34
|
|
|
@@ -94,6 +95,21 @@ const AZCOLLECT_CHECKIN_QUERY_COMPRESSED = {
|
|
|
94
95
|
body : COMPRESSED_CHECKIN_BODY
|
|
95
96
|
};
|
|
96
97
|
|
|
98
|
+
const SEND_COLLECTOR_STATUS_BODY_DATA = {
|
|
99
|
+
status: "error",
|
|
100
|
+
inst_type: "collector",
|
|
101
|
+
stream: "Audit.Exchange",
|
|
102
|
+
status_id: "FC561097-E51D-4CB6-AB86-2A90CFFE60C7",
|
|
103
|
+
timestamp: 1685377308,
|
|
104
|
+
reported_by: "paws",
|
|
105
|
+
collection_type: "o365",
|
|
106
|
+
errorinfo: {
|
|
107
|
+
code: "500",
|
|
108
|
+
description: "server error",
|
|
109
|
+
details: "failed to send logmsgs"
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
|
|
97
113
|
const AIMS_RESPONSE_200 = {
|
|
98
114
|
'authentication': {
|
|
99
115
|
'user': {
|
|
@@ -170,6 +186,8 @@ module.exports = {
|
|
|
170
186
|
AIMS_RESPONSE_200: AIMS_RESPONSE_200,
|
|
171
187
|
AZURE_REGISTER_VALUES: AZURE_REGISTER_VALUES,
|
|
172
188
|
AZURE_CHECKIN_VALUES: AZURE_CHECKIN_VALUES,
|
|
189
|
+
SEND_COLLECTOR_STATUS_BODY_DATA: SEND_COLLECTOR_STATUS_BODY_DATA,
|
|
190
|
+
COLLECTOR_STATUS_API: COLLECTOR_STATUS_API,
|
|
173
191
|
|
|
174
192
|
gen_auth_response : gen_auth_response
|
|
175
193
|
};
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/* -----------------------------------------------------------------------------
|
|
2
|
+
* @copyright (C) 2023, Alert Logic, Inc
|
|
3
|
+
* @doc
|
|
4
|
+
*
|
|
5
|
+
* Tests for base Alert Logic Collectors Status client
|
|
6
|
+
*
|
|
7
|
+
* @end
|
|
8
|
+
* -----------------------------------------------------------------------------
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const fs = require('fs');
|
|
12
|
+
const sinon = require('sinon');
|
|
13
|
+
const assert = require('assert');
|
|
14
|
+
const AimsC = require('../al_servicec').AimsC;
|
|
15
|
+
const AlServiceC = require('../al_servicec').AlServiceC;
|
|
16
|
+
const m_alMock = require('./al_mock');
|
|
17
|
+
const CollectorStatusC = require('../collector_statusc').CollectorStatusC;
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
describe('Unit Tests', function () {
|
|
21
|
+
|
|
22
|
+
describe('Collector_statusc', function () {
|
|
23
|
+
var fakeAuth;
|
|
24
|
+
let fakePut;
|
|
25
|
+
beforeEach(function () {
|
|
26
|
+
fakeAuth = sinon.stub(AimsC.prototype, 'authenticate').callsFake(
|
|
27
|
+
function fakeFn() {
|
|
28
|
+
return new Promise(function (resolve, reject) {
|
|
29
|
+
resolve(m_alMock.gen_auth_response());
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
afterEach(function (done) {
|
|
34
|
+
fakeAuth.restore();
|
|
35
|
+
fakePut.restore();
|
|
36
|
+
fs.unlink(m_alMock.CACHE_FILENAME, function (err) {
|
|
37
|
+
done();
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('Verify send Status called with correct parameter', function (done) {
|
|
42
|
+
|
|
43
|
+
fakePut = sinon.stub(AlServiceC.prototype, 'put').callsFake(
|
|
44
|
+
function fakeFn(path, extraOptions) {
|
|
45
|
+
assert.equal(extraOptions.body, m_alMock.SEND_COLLECTOR_STATUS_BODY_DATA);
|
|
46
|
+
assert.equal(path, `/statuses/${m_alMock.SEND_COLLECTOR_STATUS_BODY_DATA.status_id}/streams/${m_alMock.SEND_COLLECTOR_STATUS_BODY_DATA.stream}`);
|
|
47
|
+
done();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
var aimsc = new AimsC(m_alMock.AL_API, m_alMock.AIMS_CREDS);
|
|
51
|
+
var collectorStatus = new CollectorStatusC(m_alMock.COLLECTOR_STATUS_API, aimsc);
|
|
52
|
+
collectorStatus.sendStatus(m_alMock.SEND_COLLECTOR_STATUS_BODY_DATA.status_id, m_alMock.SEND_COLLECTOR_STATUS_BODY_DATA.stream, m_alMock.SEND_COLLECTOR_STATUS_BODY_DATA).then(res => {
|
|
53
|
+
fakePut.restore();
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('If sequence of parameter is not correct then api throw the error', function (done) {
|
|
58
|
+
const error = {
|
|
59
|
+
"errorinfo": {
|
|
60
|
+
"error_id": "246A66D0-2910-46E1-9C1F-24359B6714A0",
|
|
61
|
+
"description": "Stream does not match payload",
|
|
62
|
+
"code": "stream_mismatch"
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
fakePut = sinon.stub(AlServiceC.prototype, 'put').callsFake(
|
|
66
|
+
function fakeFn(path, extraOptions) {
|
|
67
|
+
return new Promise(function (resolve, reject) {
|
|
68
|
+
reject(error);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
var aimsc = new AimsC(m_alMock.AL_API, m_alMock.AIMS_CREDS);
|
|
73
|
+
var collectorStatus = new CollectorStatusC(m_alMock.COLLECTOR_STATUS_API, aimsc);
|
|
74
|
+
collectorStatus.sendStatus(m_alMock.SEND_COLLECTOR_STATUS_BODY_DATA.stream, m_alMock.SEND_COLLECTOR_STATUS_BODY_DATA.status_id, m_alMock.SEND_COLLECTOR_STATUS_BODY_DATA).then(res => {
|
|
75
|
+
}).catch(err => {
|
|
76
|
+
assert.deepEqual(err, error);
|
|
77
|
+
done();
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('collection_type and inst_type value should be within the defined enum else throw error', function (done) {
|
|
82
|
+
const error = {
|
|
83
|
+
"errorinfo": {
|
|
84
|
+
"error_id": "5BC87CAB-8CC7-4B36-9B09-3E26B3088F77",
|
|
85
|
+
"details": {
|
|
86
|
+
"schema_validation_error": [
|
|
87
|
+
{
|
|
88
|
+
"invalid": "data",
|
|
89
|
+
"schema": {
|
|
90
|
+
"type": "string",
|
|
91
|
+
"enum": [
|
|
92
|
+
"o365",
|
|
93
|
+
"auth0",
|
|
94
|
+
"Carbonblack",
|
|
95
|
+
"Ciscoamp",
|
|
96
|
+
"Ciscoduo",
|
|
97
|
+
"crowdstrike",
|
|
98
|
+
"googlestackdriver",
|
|
99
|
+
"gsuite",
|
|
100
|
+
"Mimecast",
|
|
101
|
+
"salesforce",
|
|
102
|
+
"aws_elb_classic",
|
|
103
|
+
"s3_audit_logs",
|
|
104
|
+
"redshift_connection_logs",
|
|
105
|
+
"redshift_user_activity_logs",
|
|
106
|
+
"redshift_user_logs",
|
|
107
|
+
"vpc_flow_logs_v2",
|
|
108
|
+
"aws_elb_application",
|
|
109
|
+
"aws_elb_network",
|
|
110
|
+
"aws_network_firewall",
|
|
111
|
+
"carbon_black_edr",
|
|
112
|
+
"aws_eks_log_cwl_export",
|
|
113
|
+
"crowdstrike_fdr",
|
|
114
|
+
"aws_waf"
|
|
115
|
+
]
|
|
116
|
+
},
|
|
117
|
+
"error": "not_in_enum",
|
|
118
|
+
"data": "CiscoMeraki",
|
|
119
|
+
"path": [
|
|
120
|
+
"collection_type"
|
|
121
|
+
]
|
|
122
|
+
}
|
|
123
|
+
]
|
|
124
|
+
},
|
|
125
|
+
"description": "JSON Schema Validation error",
|
|
126
|
+
"code": "schema_validation_error"
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
fakePut = sinon.stub(AlServiceC.prototype, 'put').callsFake(
|
|
130
|
+
function fakeFn(path, extraOptions) {
|
|
131
|
+
return new Promise(function (resolve, reject) {
|
|
132
|
+
reject(error);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
var aimsc = new AimsC(m_alMock.AL_API, m_alMock.AIMS_CREDS);
|
|
137
|
+
var collectorStatus = new CollectorStatusC(m_alMock.COLLECTOR_STATUS_API, aimsc);
|
|
138
|
+
m_alMock.SEND_COLLECTOR_STATUS_BODY_DATA.collection_type = 'CiscoMeraki';
|
|
139
|
+
collectorStatus.sendStatus(m_alMock.SEND_COLLECTOR_STATUS_BODY_DATA.stream, m_alMock.SEND_COLLECTOR_STATUS_BODY_DATA.status_id, m_alMock.SEND_COLLECTOR_STATUS_BODY_DATA).then(res => {
|
|
140
|
+
}).catch(err => {
|
|
141
|
+
assert.deepEqual(err.code, error.code);
|
|
142
|
+
done();
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
});
|