@@ -21,7 +21,7 @@ const deepEqual = require('deep-equal');
2121const m_alCollector = require ( '@alertlogic/al-collector-js' ) ;
2222const m_alAws = require ( './al_aws' ) ;
2323const m_healthChecks = require ( './health_checks' ) ;
24- const m_stats = require ( './statistics ' ) ;
24+ const m_alStatsTmpls = require ( './statistics_templates ' ) ;
2525
2626var AIMS_DECRYPTED_CREDS = null ;
2727
@@ -255,12 +255,12 @@ class AlAwsCollector {
255255 //it is assumed that all functions here always return err != null
256256 async . parallel ( [
257257 function ( asyncCallback ) {
258- m_healthChecks . getHealthStatus ( context , checks , function ( err , healthStatus ) {
258+ collector . getHealthStatus ( context , checks , function ( err , healthStatus ) {
259259 return asyncCallback ( null , healthStatus ) ;
260260 } ) ;
261261 } ,
262262 function ( asyncCallback ) {
263- m_stats . getStatistics ( context , statsFuns , function ( err , statistics ) {
263+ collector . getStatistics ( context , statsFuns , function ( err , statistics ) {
264264 return asyncCallback ( null , statistics ) ;
265265 } ) ;
266266 }
@@ -285,6 +285,58 @@ class AlAwsCollector {
285285 } ) ;
286286 }
287287
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+
288340 deregister ( event , custom ) {
289341 const context = this . _invokeContext ;
290342 let regValues = Object . assign ( this . getProperties ( ) , custom ) ;
0 commit comments