You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
920 B
39 lines
920 B
import { findById } from '../models/analytic_unit'; |
|
|
|
import axios from 'axios'; |
|
|
|
|
|
// TODO: send notification with payload without dep to AnalyticUnit |
|
export async function sendNotification(predictorId, active) { |
|
let anomalyName = findById(predictorId).name; |
|
console.log('Notification ' + anomalyName); |
|
|
|
let notification = { |
|
anomaly: anomalyName, |
|
status: '' |
|
}; |
|
if(active) { |
|
notification.status = 'alert'; |
|
} else { |
|
notification.status = 'OK'; |
|
} |
|
|
|
// TODO: more to config |
|
let endpoint = process.env.HASTIC_ALERT_ENDPOINT; |
|
if(endpoint === undefined) { |
|
console.error(`Can't send alert, env HASTIC_ALERT_ENDPOINT is undefined`); |
|
return; |
|
} |
|
|
|
try { |
|
var data = await axios.post(endpoint, { |
|
method: 'POST', |
|
body: JSON.stringify(notification) |
|
}) |
|
console.log(data); |
|
} catch(err) { |
|
console.error(`Can't send alert to ${endpoint}. Error: ${err}`); |
|
} |
|
|
|
} |
|
|
|
|