11var https = require ( 'https' )
2+ , AWS = require ( 'aws-sdk' )
23 , utils = require ( './utils' ) ;
34
5+ var sns = new AWS . SNS ( ) ;
6+
7+ var INGEST_TOPIC = process . env . INGEST_TOPIC ;
8+
9+ if ( ! INGEST_TOPIC ) {
10+ throw new Error ( "INGEST_TOPIC not defined" ) ;
11+ }
12+
413var webCheckTimeoutMs = 8000 ;
514
615var webChecks = [ ] ;
@@ -89,29 +98,11 @@ function checkWebProperty(checkDefinition, failOrSucceed) {
8998
9099// alert = { subject: ..., details: ... }
91100function postAlert ( alert , next ) {
92- var alertJsonBody = JSON . stringify ( alert ) ;
93-
94- var request = https . request ( {
95- hostname : 'b4eac0iqek.execute-api.us-east-1.amazonaws.com' ,
96- method : 'POST' ,
97- path : '/prod/ingest' ,
98- headers : {
99- 'Content-Type' : 'application/json' ,
100- 'Content-Length' : Buffer . byteLength ( alertJsonBody )
101- } ,
102- } , function ( response ) {
103- response . on ( 'error' , next ) ;
104- response . on ( 'data' , function ( chunk ) {
105- console . log ( 'Alert ingestor response: ' + chunk . toString ( ) ) ;
106- } ) ;
107-
108- response . on ( 'end' , function ( ) {
109- next ( null ) ;
110- } ) ;
111- } ) ;
112-
113- request . on ( 'error' , next ) ;
114- request . end ( alertJsonBody ) ;
101+ sns . publish ( {
102+ Message : alert . details ,
103+ Subject : alert . subject ,
104+ TopicArn : INGEST_TOPIC
105+ } , next ) ;
115106}
116107
117108function checkOne ( checkDefinition , next ) {
@@ -135,6 +126,7 @@ function checkOne(checkDefinition, next) {
135126 if ( err ) {
136127 postAlert ( { subject : checkDefinition . url , details : err . message } , function ( alertPostErr ) {
137128 if ( alertPostErr ) { // alert posting failed - not much we can do :(
129+ console . log ( 'ALERT POSTING ERROR' , alertPostErr ) ;
138130 next ( alertPostErr ) ; // TODO: wrap error with text that makes super clear what happened
139131 return ;
140132 }
@@ -144,7 +136,7 @@ function checkOne(checkDefinition, next) {
144136 } ) ;
145137 }
146138 else {
147- next ( err ) ;
139+ next ( null ) ;
148140 }
149141 }
150142
@@ -154,7 +146,7 @@ function checkOne(checkDefinition, next) {
154146 checkWebProperty ( checkDefinition , failOrSucceed ) ;
155147 }
156148 else {
157- failOrSucceed ( err , duration ) ;
149+ failOrSucceed ( null , duration ) ;
158150 }
159151 } ) ;
160152}
0 commit comments