diff --git a/cellar-azure-backups/MonitoringDeadHTTPTrigger/function.json b/cellar-azure-backups/MonitoringDeadHTTPTrigger/function.json index 7eb1f8f..98acb63 100644 --- a/cellar-azure-backups/MonitoringDeadHTTPTrigger/function.json +++ b/cellar-azure-backups/MonitoringDeadHTTPTrigger/function.json @@ -11,9 +11,9 @@ ] }, { - "type": "http", - "direction": "out", - "name": "res" - } + "name": "$return", + "type": "sendGrid", + "direction": "out" + } ] } diff --git a/cellar-azure-backups/MonitoringDeadHTTPTrigger/index.js b/cellar-azure-backups/MonitoringDeadHTTPTrigger/index.js index ff0f3ed..e8442f3 100644 --- a/cellar-azure-backups/MonitoringDeadHTTPTrigger/index.js +++ b/cellar-azure-backups/MonitoringDeadHTTPTrigger/index.js @@ -1,11 +1,19 @@ module.exports = async function (context, req) { context.log('JavaScript HTTP trigger function processed a request.'); - - const name = (req.query.name || (req.body && req.body.name)); - const responseMessage = req; - context.res = { - // status: 200, /* Defaults to 200 */ - body: responseMessage - }; + const lastTimestamp = (req.body || {})._start; + const humidity = (req.body || {}).humidity; + const reading = (req.body || {}).reading; + + var message = { + "personalizations": [ { "to": [ { "email": "jlengrand@gmail.com" } ] } ], + from: { email: "jlengrand@gmail.com" }, + subject: `Cellar Monitoring is down! Last ${reading} value read ${humidity} at ${lastTimestamp}`, + content: [{ + type: 'text/plain', + value: JSON.stringify(req.body) + }] + }; + + context.done(null, message); } \ No newline at end of file diff --git a/cellar-azure-backups/MonitoringDeadHTTPTrigger/sample.dat b/cellar-azure-backups/MonitoringDeadHTTPTrigger/sample.dat index 2e60943..f87d3ba 100644 --- a/cellar-azure-backups/MonitoringDeadHTTPTrigger/sample.dat +++ b/cellar-azure-backups/MonitoringDeadHTTPTrigger/sample.dat @@ -1,3 +1,33 @@ { - "name": "Azure" + "method": "POST", + "x-forwarded-proto": "https", + "x-appservice-proto": "https", + "x-forwarded-tlsversion": "1.2", + "disguised-host": "cellar-backup-node.azurewebsites.net" +}, +"query": {}, +"params": {}, +"body": { + "_check_id": "06a6a0d27569d000", + "_check_name": "No more data", + "_level": "crit", + "_measurement": "notifications", + "_message": "Check: No more data is: crit", + "_notification_endpoint_id": "06a7d934f3051000", + "_notification_endpoint_name": "AzureEmailTrigger", + "_notification_rule_id": "06a9c236da126000", + "_notification_rule_name": "CheckDataComingIn", + "_source_measurement": "cellar-point", + "_source_timestamp": 1606311643000000000, + "_start": "2020-11-25T13:44:00Z", + "_status_timestamp": 1606311960000000000, + "_stop": "2020-11-25T14:00:00Z", + "_time": "2020-11-25T14:00:00Z", + "_type": "deadman", + "_version": 1, + "dead": true, + "humidity": 58, + "reading": "OK" +}, +"rawBody": "{\"_check_id\":\"06a6a0d27569d000\",\"_check_name\":\"No more data\",\"_level\":\"crit\",\"_measurement\":\"notifications\",\"_message\":\"Check: No more data is: crit\",\"_notification_endpoint_id\":\"06a7d934f3051000\",\"_notification_endpoint_name\":\"AzureEmailTrigger\",\"_notification_rule_id\":\"06a9c236da126000\",\"_notification_rule_name\":\"CheckDataComingIn\",\"_source_measurement\":\"cellar-point\",\"_source_timestamp\":1606311643000000000,\"_start\":\"2020-11-25T13:44:00Z\",\"_status_timestamp\":1606311960000000000,\"_stop\":\"2020-11-25T14:00:00Z\",\"_time\":\"2020-11-25T14:00:00Z\",\"_type\":\"deadman\",\"_version\":1,\"dead\":true,\"humidity\":58,\"reading\":\"OK\"}" } \ No newline at end of file diff --git a/cellar-azure-backups/host.json b/cellar-azure-backups/host.json index 6ab6643..8889531 100644 --- a/cellar-azure-backups/host.json +++ b/cellar-azure-backups/host.json @@ -1,11 +1,19 @@ { "version": "2.0", + "extensions": { + "sendGrid": { + "from": "jlengrand@gmail.com" + } + }, "logging": { "applicationInsights": { "samplingSettings": { "isEnabled": true, "excludedTypes": "Request" } + }, + "logLevel": { + "default": "Debug" } }, "extensionBundle": { diff --git a/cellar-azure-backups/package.json b/cellar-azure-backups/package.json index 88b0877..978daaf 100644 --- a/cellar-azure-backups/package.json +++ b/cellar-azure-backups/package.json @@ -7,5 +7,8 @@ "test": "echo \"No tests yet...\"" }, "dependencies": {}, - "devDependencies": {} + "devDependencies": {}, + "engines": { + "node": "12.18.3" + } }