First working endpoint with influx

This commit is contained in:
Julien Lengrand-Lambert
2020-11-25 15:46:49 +01:00
parent 7bd74df930
commit 5310c65683
5 changed files with 62 additions and 13 deletions

View File

@@ -11,9 +11,9 @@
]
},
{
"type": "http",
"direction": "out",
"name": "res"
"name": "$return",
"type": "sendGrid",
"direction": "out"
}
]
}

View File

@@ -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;
const lastTimestamp = (req.body || {})._start;
const humidity = (req.body || {}).humidity;
const reading = (req.body || {}).reading;
context.res = {
// status: 200, /* Defaults to 200 */
body: responseMessage
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);
}

View File

@@ -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\"}"
}

View File

@@ -1,11 +1,19 @@
{
"version": "2.0",
"extensions": {
"sendGrid": {
"from": "jlengrand@gmail.com"
}
},
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
},
"logLevel": {
"default": "Debug"
}
},
"extensionBundle": {

View File

@@ -7,5 +7,8 @@
"test": "echo \"No tests yet...\""
},
"dependencies": {},
"devDependencies": {}
"devDependencies": {},
"engines": {
"node": "12.18.3"
}
}