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.
38 lines
825 B
38 lines
825 B
![]()
6 years ago
|
import { findById } from '../models/analytic_unit';
|
||
|
|
||
![]()
6 years ago
|
import axios from 'axios';
|
||
![]()
6 years ago
|
|
||
![]()
6 years ago
|
|
||
6 years ago
|
export async function sendNotification(predictorId, active) {
|
||
![]()
6 years ago
|
let anomalyName = findById(predictorId).name;
|
||
![]()
6 years ago
|
console.log('Notification ' + anomalyName);
|
||
|
|
||
![]()
6 years ago
|
let notification = {
|
||
|
anomaly: anomalyName,
|
||
|
status: ''
|
||
|
};
|
||
|
if(active) {
|
||
|
notification.status = 'alert';
|
||
![]()
6 years ago
|
} else {
|
||
![]()
6 years ago
|
notification.status = 'OK';
|
||
![]()
6 years ago
|
}
|
||
|
|
||
![]()
6 years ago
|
let endpoint = process.env.HASTIC_ALERT_ENDPOINT;
|
||
![]()
6 years ago
|
if(endpoint === undefined) {
|
||
|
console.error(`Can't send alert, env HASTIC_ALERT_ENDPOINT is undefined`);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
try {
|
||
|
var data = await axios.post(endpoint, {
|
||
![]()
6 years ago
|
method: 'POST',
|
||
|
body: JSON.stringify(notification)
|
||
|
})
|
||
![]()
6 years ago
|
console.log(data);
|
||
|
} catch(err) {
|
||
|
console.error(`Can't send alert to ${endpoint}. Error: ${err}`)
|
||
![]()
6 years ago
|
}
|
||
![]()
6 years ago
|
|
||
![]()
6 years ago
|
}
|
||
|
|