forked from alertlogic/paws-collector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaws_health_checks.js
40 lines (36 loc) · 1.3 KB
/
paws_health_checks.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/** -----------------------------------------------------------------------------
* @copyright (C) 2021, Alert Logic, Inc
* @doc
*
* Health checks functions for PAWS collector
*
* @end
* -----------------------------------------------------------------------------
*/
'use strict';
const AlAwsStatsTmpls = require('@alertlogic/al-aws-collector-js').Stats;
const al_health = require('@alertlogic/al-aws-collector-js').Health
/**
* To fetch the custom metrics data and return the error if PawsClientError metrics show errors.
* @param {*} asyncCallback
* @returns
*/
function customHealthCheck(asyncCallback) {
const customDimentions =
{
Name: 'CollectorType',
Value: process.env.paws_type_name
}
AlAwsStatsTmpls.getCustomMetrics(
process.env.AWS_LAMBDA_FUNCTION_NAME, 'PawsClientError', 'PawsCollectors', customDimentions, (err, res) => {
const datapointSum = res && res.Datapoints.length > 0 && res.Datapoints[0].Sum ? res.Datapoints[0].Sum : 0;
if (datapointSum > 0) {
return asyncCallback(al_health.errorMsg('PAWS000403','Please check stream status errors and collector configuration'));
}
return asyncCallback(null);
}
);
}
module.exports = {
customHealthCheck: customHealthCheck
}