@@ -21,7 +21,7 @@ const deepEqual = require('deep-equal');
21
21
const m_alCollector = require ( '@alertlogic/al-collector-js' ) ;
22
22
const m_alAws = require ( './al_aws' ) ;
23
23
const m_healthChecks = require ( './health_checks' ) ;
24
- const m_stats = require ( './statistics ' ) ;
24
+ const m_alStatsTmpls = require ( './statistics_templates ' ) ;
25
25
26
26
var AIMS_DECRYPTED_CREDS = null ;
27
27
@@ -255,12 +255,12 @@ class AlAwsCollector {
255
255
//it is assumed that all functions here always return err != null
256
256
async . parallel ( [
257
257
function ( asyncCallback ) {
258
- m_healthChecks . getHealthStatus ( context , checks , function ( err , healthStatus ) {
258
+ collector . getHealthStatus ( context , checks , function ( err , healthStatus ) {
259
259
return asyncCallback ( null , healthStatus ) ;
260
260
} ) ;
261
261
} ,
262
262
function ( asyncCallback ) {
263
- m_stats . getStatistics ( context , statsFuns , function ( err , statistics ) {
263
+ collector . getStatistics ( context , statsFuns , function ( err , statistics ) {
264
264
return asyncCallback ( null , statistics ) ;
265
265
} ) ;
266
266
}
@@ -285,6 +285,58 @@ class AlAwsCollector {
285
285
} ) ;
286
286
}
287
287
288
+ getHealthStatus ( context , customChecks , callback ) {
289
+ const appliedHealthChecks = customChecks . map ( check => check . bind ( this ) ) ;
290
+ async . parallel ( [
291
+ function ( asyncCallback ) {
292
+ m_healthChecks . checkCloudFormationStatus ( process . env . stack_name , asyncCallback ) ;
293
+ }
294
+ ] . concat ( appliedHealthChecks ) ,
295
+ function ( errMsg ) {
296
+ var status = { } ;
297
+ if ( errMsg ) {
298
+ console . warn ( 'ALAWS00001 Health check failed with' , errMsg ) ;
299
+ status = {
300
+ status : errMsg . status ,
301
+ error_code : errMsg . code ,
302
+ details : [ errMsg . details ]
303
+ } ;
304
+ } else {
305
+ status = {
306
+ status : 'ok' ,
307
+ details : [ ]
308
+ } ;
309
+ }
310
+ return callback ( null , status ) ;
311
+ } ) ;
312
+ }
313
+
314
+ getStatistics ( context , statsFuns , callback ) {
315
+ const appliedStatsFuns = statsFuns . map ( fun => fun . bind ( this ) ) ;
316
+ var allFuns = [
317
+ function ( asyncCallback ) {
318
+ return m_alStatsTmpls . getLambdaMetrics (
319
+ context . functionName , 'Invocations' , asyncCallback
320
+ ) ;
321
+ } ,
322
+ function ( asyncCallback ) {
323
+ return m_alStatsTmpls . getLambdaMetrics (
324
+ context . functionName , 'Errors' , asyncCallback
325
+ ) ;
326
+ }
327
+ ] . concat ( appliedStatsFuns ) ;
328
+ async . parallel ( allFuns ,
329
+ function ( err , res ) {
330
+ if ( err ) {
331
+ return callback ( null , { statistics : [ ] } ) ;
332
+ } else {
333
+ return callback ( null , { statistics : res } ) ;
334
+ }
335
+ }
336
+ ) ;
337
+ }
338
+
339
+
288
340
deregister ( event , custom ) {
289
341
const context = this . _invokeContext ;
290
342
let regValues = Object . assign ( this . getProperties ( ) , custom ) ;
0 commit comments