This repository has been archived by the owner on Oct 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
51 lines (46 loc) · 1.55 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const core = require("@actions/core");
const proc = require("child_process");
function getHealthCheckStatus(applicationURL) {
let retryConfig = `--retry 3 --retry-delay 5 --retry-connrefused --max-time 180`;
let healthCheckRequest = `curl --fail ${applicationURL} ${retryConfig}`;
let response = proc.execSync(healthCheckRequest).toString();
core.info(response);
return JSON.parse(response)
}
function sendNotificationToTeams(teamsWebHookURL, applicationURL) {
const data = JSON.stringify({
"@type": "MessageCard",
"themeColor": "0076D7",
"text": "Health check failed",
"sections": [
{
"facts": [
{
"name": "Application:",
"value": applicationURL
}
]
}
]
})
let params = `--header \"Content-Type: application/json\" --request POST`
let teamsRequest = `curl ${params} --data '${data}' ${teamsWebHookURL}`;
let response = proc.execSync(teamsRequest).toString();
core.info(response);
}
let teamsWebHookURL = core.getInput("teamsWebHookURL", {required: true});
let applicationURL = core.getInput("url", {required: true});
try {
core.info(`Health check of ${applicationURL}`);
let healthCheckStatus = getHealthCheckStatus(applicationURL);
if (healthCheckStatus.status === 'UP') {
core.info("Success");
} else {
sendNotificationToTeams(teamsWebHookURL, applicationURL);
core.setFailed(e.message);
}
} catch (e) {
console.error("Action failed with error", e);
sendNotificationToTeams(teamsWebHookURL, applicationURL);
core.setFailed(e.message);
}