File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -10,6 +10,10 @@ it as a volume into your container, this script will also look to see if there
1010is a stream that it can recreate from it. If it can, it will delete that existing
1111stream from primary and recreate it.
1212
13+ Screammachine can also alert by checking the streamdash api URL and finding
14+ the listeners count. If the listeners count fall below a certain threshold,
15+ it will alert (see optional env variables below).
16+
1317## requirements
1418
1519* slack webhook url (https://api.slack.com/incoming-webhooks )
@@ -28,6 +32,12 @@ before you want this script to alert. (Example: 30)
2832* ` PREPEND_MESSAGE ` what you'd like to prepend to the slack message. For example, if you want to ` @channel ` here or add
2933some emoji's like ` :hear_no_evil: :radio: `
3034
35+ ** optional**
36+
37+ * ` LOW_LISTENERS_THRESHOLD `
38+ * ` STREAMDASH_HOURS_URL ` the URL that your streamdash's hours api URL is at. Example: http://streamdash.com/api/hour
39+
40+
3141This can be set up to run as a regular cronjob on a machine (` node index.js ` ),
3242or set up as a container running as a kubernetes cronjob.
3343
Original file line number Diff line number Diff line change @@ -5,6 +5,8 @@ const SOURCE_URL = process.env.SOURCE_URL;
55const SECONDS_OFFSET = process . env . SECONDS_OFFSET ;
66const WEBHOOK_URL = process . env . WEBHOOK_URL ;
77const PREPEND_MESSAGE = process . env . PREPEND_MESSAGE || ':cry:' ;
8+ const LOW_LISTENERS_THRESHOLD = process . env . LOW_LISTENERS_THRESHOLD ;
9+ const STREAMDASH_HOURS_URL = process . env . STREAMDASH_HOURS_URL ;
810
911// JSON file that contains the body to POST to streammachine when creating streams.
1012const streamsJson = require ( './streams.json' ) ;
@@ -139,3 +141,26 @@ http.get(SOURCE_URL, (resp) => {
139141 notify ( err . message ) ;
140142} ) ;
141143
144+ if ( LOW_LISTENERS_THRESHOLD && STREAMDASH_HOURS_URL ) {
145+ http . get ( STREAMDASH_HOURS_URL , ( resp ) => {
146+ let data = '' ;
147+
148+ resp . on ( 'data' , ( chunk ) => {
149+ data += chunk ;
150+ } ) ;
151+
152+ resp . on ( 'end' , ( ) => {
153+ let notify_body = [ ] ;
154+ const body = JSON . parse ( data ) ;
155+ if ( body === undefined ) {
156+ return ;
157+ }
158+ console . log ( `listeners count was ${ body . listens . listeners } ` ) ;
159+ if ( body . listens . listeners < LOW_LISTENERS_THRESHOLD ) {
160+ notify ( `Listeners count (${ body . listens . listeners } ) fell below threshold (${ LOW_LISTENERS_THRESHOLD } ).` +
161+ `Something may be wrong with the stream. Check out Streamdash: ${ STREAMDASH_HOURS_URL } ` ) ;
162+ }
163+ } ) ;
164+ } ) ;
165+ }
166+
You can’t perform that action at this time.
0 commit comments