forked from rockem/create-opsgenie-alert-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
30 lines (24 loc) · 879 Bytes
/
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
const core = require('@actions/core');
const opsgenie = require('opsgenie-sdk');
const {connectionOptions} = require("./src/connection");
const {createAlertRequestFrom} = require("./src/alert");
opsgenie.configure(
connectionOptions(core.getInput('api_key'), core.getInput('using_eu_url')))
const allInputs = () => {
const inputs = {}
for (let [k,v] of Object.entries(process.env)) {
if (k.startsWith('INPUT_')) {
inputs[k.toLowerCase().substring(6)] = v;
}
}
return inputs;
}
const alertRequest = createAlertRequestFrom(allInputs());
console.log(`Creating alert with: ${JSON.stringify(alertRequest)}`)
opsgenie.alertV2.create(alertRequest, function (error, _) {
if (error) {
core.setFailed(error.message);
} else {
console.log(`Request sent for creating new alert: ${alertRequest.message}`);
}
});