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.

1615 lines
115 KiB

6 years ago
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
6 years ago
/******/ return __webpack_require__(__webpack_require__.s = 14);
6 years ago
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports) {
6 years ago
module.exports = require('babel-runtime/regenerator');
6 years ago
/***/ }),
/* 1 */
/***/ (function(module, exports) {
6 years ago
module.exports = require('babel-runtime/core-js/promise');
6 years ago
/***/ }),
6 years ago
/* 2 */
6 years ago
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
6 years ago
var path = __webpack_require__(4);
var json_1 = __webpack_require__(6);
var config_1 = __webpack_require__(3);
var fs = __webpack_require__(8);
var crypto = __webpack_require__(12);
6 years ago
var anomaliesNameToIdMap = {};
function loadAnomaliesMap() {
var filename = path.join(config_1.ANOMALIES_PATH, "all_anomalies.json");
if (!fs.existsSync(filename)) {
saveAnomaliesMap();
}
anomaliesNameToIdMap = json_1.getJsonDataSync(filename);
}
function saveAnomaliesMap() {
var filename = path.join(config_1.ANOMALIES_PATH, "all_anomalies.json");
json_1.writeJsonDataSync(filename, anomaliesNameToIdMap);
}
function getAnomalyIdByName(anomalyName) {
loadAnomaliesMap();
anomalyName = anomalyName.toLowerCase();
if (anomalyName in anomaliesNameToIdMap) {
return anomaliesNameToIdMap[anomalyName];
}
return anomalyName;
}
exports.getAnomalyIdByName = getAnomalyIdByName;
function insertAnomaly(anomaly) {
var hashString = anomaly.name + new Date().toString();
var anomalyId = crypto.createHash('md5').update(hashString).digest('hex');
anomaliesNameToIdMap[anomaly.name] = anomalyId;
saveAnomaliesMap();
// return anomalyId
// const anomalyId:AnomalyId = anomaly.name;
var filename = path.join(config_1.ANOMALIES_PATH, anomalyId + ".json");
if (fs.existsSync(filename)) {
return null;
}
saveAnomaly(anomalyId, anomaly);
return anomalyId;
}
exports.insertAnomaly = insertAnomaly;
function removeAnomaly(anomalyId) {
var filename = path.join(config_1.ANOMALIES_PATH, anomalyId + ".json");
fs.unlinkSync(filename);
}
exports.removeAnomaly = removeAnomaly;
function saveAnomaly(anomalyId, anomaly) {
var filename = path.join(config_1.ANOMALIES_PATH, anomalyId + ".json");
return json_1.writeJsonDataSync(filename, anomaly);
}
exports.saveAnomaly = saveAnomaly;
function loadAnomalyById(anomalyId) {
var filename = path.join(config_1.ANOMALIES_PATH, anomalyId + ".json");
if (!fs.existsSync(filename)) {
return null;
}
return json_1.getJsonDataSync(filename);
}
exports.loadAnomalyById = loadAnomalyById;
function loadAnomalyByName(anomalyName) {
var anomalyId = getAnomalyIdByName(anomalyName);
return loadAnomalyById(anomalyId);
}
exports.loadAnomalyByName = loadAnomalyByName;
function saveAnomalyTypeInfo(info) {
console.log('Saving');
var filename = path.join(config_1.ANOMALIES_PATH, info.name + ".json");
if (info.next_id === undefined) {
info.next_id = 0;
}
if (info.last_prediction_time === undefined) {
info.last_prediction_time = 0;
}
return json_1.writeJsonDataSync(filename, info);
}
exports.saveAnomalyTypeInfo = saveAnomalyTypeInfo;
function getAnomalyTypeInfo(name) {
return json_1.getJsonDataSync(path.join(config_1.ANOMALIES_PATH, name + ".json"));
}
exports.getAnomalyTypeInfo = getAnomalyTypeInfo;
function setAnomalyStatus(anomalyId, status, error) {
var info = loadAnomalyById(anomalyId);
info.status = status;
if (error !== undefined) {
info.error = error;
} else {
info.error = '';
}
saveAnomaly(anomalyId, info);
}
exports.setAnomalyStatus = setAnomalyStatus;
function setAnomalyPredictionTime(anomalyId, lastPredictionTime) {
var info = loadAnomalyById(anomalyId);
info.last_prediction_time = lastPredictionTime;
saveAnomaly(anomalyId, info);
}
exports.setAnomalyPredictionTime = setAnomalyPredictionTime;
/***/ }),
6 years ago
/* 3 */
6 years ago
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
6 years ago
var path = __webpack_require__(4);
6 years ago
exports.ANALYTICS_PATH = path.join(__dirname, '../../analytics');
exports.DATA_PATH = path.join(__dirname, '../../data');
exports.DATASETS_PATH = path.join(exports.DATA_PATH, 'datasets');
exports.ANOMALIES_PATH = path.join(exports.DATA_PATH, 'anomalies');
exports.MODELS_PATH = path.join(exports.DATA_PATH, 'models');
exports.METRICS_PATH = path.join(exports.DATA_PATH, 'metrics');
exports.SEGMENTS_PATH = path.join(exports.DATA_PATH, 'segments');
/***/ }),
6 years ago
/* 4 */
6 years ago
/***/ (function(module, exports) {
6 years ago
module.exports = require('path');
6 years ago
/***/ }),
6 years ago
/* 5 */
6 years ago
/***/ (function(module, exports) {
6 years ago
module.exports = require('koa-router');
6 years ago
/***/ }),
6 years ago
/* 6 */
6 years ago
/***/ (function(module, exports, __webpack_require__) {
6 years ago
"use strict";
6 years ago
6 years ago
var _stringify = __webpack_require__(7);
6 years ago
6 years ago
var _stringify2 = _interopRequireDefault(_stringify);
6 years ago
6 years ago
var _regenerator = __webpack_require__(0);
6 years ago
6 years ago
var _regenerator2 = _interopRequireDefault(_regenerator);
6 years ago
6 years ago
var _promise = __webpack_require__(1);
6 years ago
6 years ago
var _promise2 = _interopRequireDefault(_promise);
6 years ago
6 years ago
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
6 years ago
6 years ago
var __awaiter = undefined && undefined.__awaiter || function (thisArg, _arguments, P, generator) {
return new (P || (P = _promise2.default))(function (resolve, reject) {
function fulfilled(value) {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
}
function rejected(value) {
try {
step(generator["throw"](value));
} catch (e) {
reject(e);
}
}
function step(result) {
result.done ? resolve(result.value) : new P(function (resolve) {
resolve(result.value);
}).then(fulfilled, rejected);
}
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
6 years ago
};
6 years ago
Object.defineProperty(exports, "__esModule", { value: true });
var fs = __webpack_require__(8);
function getJsonData(filename) {
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator2.default.mark(function _callee() {
var data;
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return new _promise2.default(function (resolve, reject) {
fs.readFile(filename, 'utf8', function (err, data) {
if (err) {
console.error(err);
reject('Can`t read file');
} else {
resolve(data);
}
});
});
6 years ago
6 years ago
case 2:
data = _context.sent;
_context.prev = 3;
return _context.abrupt("return", JSON.parse(data));
6 years ago
6 years ago
case 7:
_context.prev = 7;
_context.t0 = _context["catch"](3);
6 years ago
6 years ago
console.error(_context.t0);
throw new Error('Wrong file format');
6 years ago
6 years ago
case 11:
case "end":
return _context.stop();
}
}
}, _callee, this, [[3, 7]]);
}));
6 years ago
}
6 years ago
exports.getJsonData = getJsonData;
function writeJsonData(filename, data) {
return new _promise2.default(function (resolve, reject) {
fs.writeFile(filename, (0, _stringify2.default)(data), 'utf8', function (err) {
if (err) {
console.error(err);
reject('Cat`t write file');
} else {
resolve();
}
});
});
6 years ago
}
6 years ago
exports.writeJsonData = writeJsonData;
function getJsonDataSync(filename) {
var data = fs.readFileSync(filename, 'utf8');
try {
return JSON.parse(data);
} catch (e) {
console.error(e);
throw new Error('Wrong file format');
}
6 years ago
}
6 years ago
exports.getJsonDataSync = getJsonDataSync;
function writeJsonDataSync(filename, data) {
fs.writeFileSync(filename, (0, _stringify2.default)(data));
6 years ago
}
6 years ago
exports.writeJsonDataSync = writeJsonDataSync;
6 years ago
6 years ago
/***/ }),
/* 7 */
/***/ (function(module, exports) {
6 years ago
6 years ago
module.exports = require('babel-runtime/core-js/json/stringify');
6 years ago
6 years ago
/***/ }),
/* 8 */
/***/ (function(module, exports) {
6 years ago
6 years ago
module.exports = require('fs');
6 years ago
/***/ }),
6 years ago
/* 9 */
6 years ago
/***/ (function(module, exports, __webpack_require__) {
"use strict";
6 years ago
var _regenerator = __webpack_require__(0);
6 years ago
6 years ago
var _regenerator2 = _interopRequireDefault(_regenerator);
6 years ago
6 years ago
var _stringify = __webpack_require__(7);
6 years ago
6 years ago
var _stringify2 = _interopRequireDefault(_stringify);
6 years ago
6 years ago
var _promise = __webpack_require__(1);
6 years ago
6 years ago
var _promise2 = _interopRequireDefault(_promise);
6 years ago
6 years ago
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
6 years ago
6 years ago
var __awaiter = undefined && undefined.__awaiter || function (thisArg, _arguments, P, generator) {
return new (P || (P = _promise2.default))(function (resolve, reject) {
function fulfilled(value) {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
}
function rejected(value) {
try {
step(generator["throw"](value));
} catch (e) {
reject(e);
}
}
function step(result) {
result.done ? resolve(result.value) : new P(function (resolve) {
resolve(result.value);
}).then(fulfilled, rejected);
}
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
var child_process_1 = __webpack_require__(18);
var config_1 = __webpack_require__(3);
var anomalyType_1 = __webpack_require__(2);
var metrics_1 = __webpack_require__(13);
var segments_1 = __webpack_require__(11);
var event_stream_1 = __webpack_require__(20);
var learnWorker = child_process_1.spawn('python3', ['worker.py'], { cwd: config_1.ANALYTICS_PATH });
learnWorker.stdout.pipe(event_stream_1.split()).pipe(event_stream_1.mapSync(onMessage));
learnWorker.stderr.on('data', function (data) {
return console.error("worker stderr: " + data);
});
var taskMap = {};
var nextTaskId = 0;
function onMessage(data) {
console.log("worker stdout: " + data);
var response = JSON.parse(data);
var taskId = response.__task_id;
// let anomalyName = response.anomaly_name;
// let task = response.task;
var status = response.status;
if (status === 'success' || status === 'failed') {
if (taskId in taskMap) {
var resolver = taskMap[taskId];
resolver(response);
delete taskMap[taskId];
6 years ago
}
}
6 years ago
}
function runTask(task) {
var anomaly = anomalyType_1.loadAnomalyById(task.anomaly_id);
task.metric = {
datasource: anomaly.metric.datasource,
targets: anomaly.metric.targets.map(function (t) {
return metrics_1.getTarget(t);
})
};
task.__task_id = nextTaskId++;
var command = (0, _stringify2.default)(task);
learnWorker.stdin.write(command + "\n");
return new _promise2.default(function (resolve, reject) {
taskMap[task.__task_id] = resolve;
});
}
function runLearning(anomalyId) {
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator2.default.mark(function _callee() {
var segments, anomaly, pattern, task, result;
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
segments = segments_1.getLabeledSegments(anomalyId);
6 years ago
6 years ago
anomalyType_1.setAnomalyStatus(anomalyId, 'learning');
anomaly = anomalyType_1.loadAnomalyById(anomalyId);
pattern = anomaly.pattern;
task = {
type: 'learn',
anomaly_id: anomalyId,
pattern: pattern,
segments: segments
};
_context.next = 7;
return runTask(task);
6 years ago
6 years ago
case 7:
result = _context.sent;
6 years ago
6 years ago
if (result.status === 'success') {
anomalyType_1.setAnomalyStatus(anomalyId, 'ready');
segments_1.insertSegments(anomalyId, result.segments, false);
anomalyType_1.setAnomalyPredictionTime(anomalyId, result.last_prediction_time);
} else {
anomalyType_1.setAnomalyStatus(anomalyId, 'failed', result.error);
}
6 years ago
6 years ago
case 9:
case "end":
return _context.stop();
}
}
}, _callee, this);
}));
}
exports.runLearning = runLearning;
function runPredict(anomalyId) {
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator2.default.mark(function _callee2() {
var anomaly, pattern, task, result, segments, lastOldSegment, firstNewSegment;
return _regenerator2.default.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
anomaly = anomalyType_1.loadAnomalyById(anomalyId);
pattern = anomaly.pattern;
task = {
type: 'predict',
anomaly_id: anomalyId,
pattern: pattern,
last_prediction_time: anomaly.last_prediction_time
};
_context2.next = 5;
return runTask(task);
6 years ago
6 years ago
case 5:
result = _context2.sent;
6 years ago
6 years ago
if (!(result.status === 'failed')) {
_context2.next = 8;
break;
}
6 years ago
6 years ago
return _context2.abrupt("return", []);
6 years ago
6 years ago
case 8:
// Merging segments
segments = segments_1.getLabeledSegments(anomalyId);
6 years ago
6 years ago
if (segments.length > 0 && result.segments.length > 0) {
lastOldSegment = segments[segments.length - 1];
firstNewSegment = result.segments[0];
6 years ago
6 years ago
if (firstNewSegment.start <= lastOldSegment.finish) {
result.segments[0].start = lastOldSegment.start;
segments_1.removeSegments(anomalyId, [lastOldSegment.id]);
}
}
segments_1.insertSegments(anomalyId, result.segments, false);
anomalyType_1.setAnomalyPredictionTime(anomalyId, result.last_prediction_time);
return _context2.abrupt("return", result.segments);
6 years ago
6 years ago
case 13:
case "end":
return _context2.stop();
}
}
}, _callee2, this);
}));
6 years ago
}
6 years ago
exports.runPredict = runPredict;
6 years ago
6 years ago
/***/ }),
/* 10 */
/***/ (function(module, exports) {
6 years ago
6 years ago
module.exports = require('babel-runtime/core-js/get-iterator');
6 years ago
6 years ago
/***/ }),
/* 11 */
/***/ (function(module, exports, __webpack_require__) {
6 years ago
6 years ago
"use strict";
6 years ago
6 years ago
var _getIterator2 = __webpack_require__(10);
6 years ago
6 years ago
var _getIterator3 = _interopRequireDefault(_getIterator2);
6 years ago
6 years ago
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
6 years ago
6 years ago
Object.defineProperty(exports, "__esModule", { value: true });
var path = __webpack_require__(4);
var json_1 = __webpack_require__(6);
var config_1 = __webpack_require__(3);
var anomalyType_1 = __webpack_require__(2);
var _ = __webpack_require__(19);
function getLabeledSegments(anomalyId) {
var filename = path.join(config_1.SEGMENTS_PATH, anomalyId + "_labeled.json");
var segments = [];
try {
segments = json_1.getJsonDataSync(filename);
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
6 years ago
6 years ago
try {
for (var _iterator = (0, _getIterator3.default)(segments), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var segment = _step.value;
6 years ago
6 years ago
if (segment.labeled === undefined) {
segment.labeled = false;
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
} catch (e) {
console.error(e.message);
6 years ago
}
6 years ago
return segments;
}
exports.getLabeledSegments = getLabeledSegments;
function getPredictedSegments(anomalyId) {
var filename = path.join(config_1.SEGMENTS_PATH, anomalyId + "_segments.json");
var jsonData = void 0;
try {
jsonData = json_1.getJsonDataSync(filename);
} catch (e) {
console.error(e.message);
jsonData = [];
6 years ago
}
6 years ago
return jsonData;
6 years ago
}
6 years ago
exports.getPredictedSegments = getPredictedSegments;
function saveSegments(anomalyId, segments) {
var filename = path.join(config_1.SEGMENTS_PATH, anomalyId + "_labeled.json");
try {
return json_1.writeJsonDataSync(filename, _.uniqBy(segments, 'start'));
} catch (e) {
console.error(e.message);
throw new Error('Can`t write to db');
}
6 years ago
}
6 years ago
exports.saveSegments = saveSegments;
function insertSegments(anomalyId, addedSegments, labeled) {
// Set status
var info = anomalyType_1.loadAnomalyById(anomalyId);
var segments = getLabeledSegments(anomalyId);
var nextId = info.next_id;
var addedIds = [];
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
6 years ago
6 years ago
try {
for (var _iterator2 = (0, _getIterator3.default)(addedSegments), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var segment = _step2.value;
6 years ago
6 years ago
segment.id = nextId;
segment.labeled = labeled;
addedIds.push(nextId);
nextId++;
segments.push(segment);
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
6 years ago
}
6 years ago
info.next_id = nextId;
saveSegments(anomalyId, segments);
anomalyType_1.saveAnomaly(anomalyId, info);
return addedIds;
}
exports.insertSegments = insertSegments;
function removeSegments(anomalyId, removedSegments) {
var segments = getLabeledSegments(anomalyId);
var _iteratorNormalCompletion3 = true;
var _didIteratorError3 = false;
var _iteratorError3 = undefined;
6 years ago
6 years ago
try {
var _loop = function _loop() {
var segmentId = _step3.value;
6 years ago
6 years ago
segments = segments.filter(function (el) {
return el.id !== segmentId;
});
};
6 years ago
6 years ago
for (var _iterator3 = (0, _getIterator3.default)(removedSegments), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
_loop();
}
} catch (err) {
_didIteratorError3 = true;
_iteratorError3 = err;
} finally {
try {
if (!_iteratorNormalCompletion3 && _iterator3.return) {
_iterator3.return();
}
} finally {
if (_didIteratorError3) {
throw _iteratorError3;
}
}
6 years ago
}
6 years ago
saveSegments(anomalyId, segments);
}
exports.removeSegments = removeSegments;
6 years ago
6 years ago
/***/ }),
/* 12 */
/***/ (function(module, exports) {
6 years ago
6 years ago
module.exports = require('crypto');
6 years ago
6 years ago
/***/ }),
/* 13 */
/***/ (function(module, exports, __webpack_require__) {
6 years ago
6 years ago
"use strict";
6 years ago
6 years ago
var _stringify = __webpack_require__(7);
6 years ago
6 years ago
var _stringify2 = _interopRequireDefault(_stringify);
6 years ago
6 years ago
var _getIterator2 = __webpack_require__(10);
6 years ago
6 years ago
var _getIterator3 = _interopRequireDefault(_getIterator2);
6 years ago
6 years ago
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
6 years ago
6 years ago
Object.defineProperty(exports, "__esModule", { value: true });
var path = __webpack_require__(4);
var json_1 = __webpack_require__(6);
var config_1 = __webpack_require__(3);
var crypto = __webpack_require__(12);
function saveTargets(targets) {
var metrics = [];
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
6 years ago
6 years ago
try {
for (var _iterator = (0, _getIterator3.default)(targets), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var target = _step.value;
6 years ago
6 years ago
metrics.push(saveTarget(target));
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
6 years ago
}
6 years ago
return metrics;
}
exports.saveTargets = saveTargets;
function saveTarget(target) {
//const md5 = crypto.createHash('md5')
var targetId = crypto.createHash('md5').update((0, _stringify2.default)(target)).digest('hex');
var filename = path.join(config_1.METRICS_PATH, targetId + ".json");
json_1.writeJsonDataSync(filename, target);
return targetId;
}
function getTarget(targetId) {
var filename = path.join(config_1.METRICS_PATH, targetId + ".json");
return json_1.getJsonDataSync(filename);
}
exports.getTarget = getTarget;
6 years ago
6 years ago
/***/ }),
/* 14 */
/***/ (function(module, exports, __webpack_require__) {
6 years ago
6 years ago
"use strict";
6 years ago
6 years ago
var _regenerator = __webpack_require__(0);
6 years ago
6 years ago
var _regenerator2 = _interopRequireDefault(_regenerator);
6 years ago
6 years ago
var _promise = __webpack_require__(1);
6 years ago
6 years ago
var _promise2 = _interopRequireDefault(_promise);
6 years ago
6 years ago
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
6 years ago
6 years ago
var __awaiter = undefined && undefined.__awaiter || function (thisArg, _arguments, P, generator) {
return new (P || (P = _promise2.default))(function (resolve, reject) {
function fulfilled(value) {
try {
step(generator.next(value));
} catch (e) {
reject(e);
6 years ago
}
6 years ago
}
function rejected(value) {
try {
step(generator["throw"](value));
} catch (e) {
reject(e);
6 years ago
}
}
6 years ago
function step(result) {
result.done ? resolve(result.value) : new P(function (resolve) {
resolve(result.value);
}).then(fulfilled, rejected);
}
step((generator = generator.apply(thisArg, _arguments || [])).next());
6 years ago
});
};
6 years ago
Object.defineProperty(exports, "__esModule", { value: true });
var Koa = __webpack_require__(15);
var Router = __webpack_require__(5);
var bodyParser = __webpack_require__(16);
var anomalies_1 = __webpack_require__(17);
var segments_1 = __webpack_require__(21);
var alerts_1 = __webpack_require__(22);
var data_1 = __webpack_require__(27);
data_1.checkDataFolders();
var app = new Koa();
var PORT = process.env.HASTIC_PORT || 8000;
app.use(bodyParser());
app.use(function (ctx, next) {
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator2.default.mark(function _callee() {
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
ctx.set('Access-Control-Allow-Origin', '*');
ctx.set('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS');
ctx.set('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
next();
6 years ago
6 years ago
case 4:
case "end":
return _context.stop();
}
}
}, _callee, this);
}));
});
var rootRouter = new Router();
rootRouter.use('/anomalies', anomalies_1.router.routes(), anomalies_1.router.allowedMethods());
rootRouter.use('/segments', segments_1.router.routes(), segments_1.router.allowedMethods());
rootRouter.use('/alerts', alerts_1.router.routes(), alerts_1.router.allowedMethods());
rootRouter.get('/', function (ctx) {
return __awaiter(undefined, void 0, void 0, /*#__PURE__*/_regenerator2.default.mark(function _callee2() {
return _regenerator2.default.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
ctx.response.body = { status: 'OK' };
6 years ago
6 years ago
case 1:
case "end":
return _context2.stop();
}
}
}, _callee2, this);
}));
});
app.use(rootRouter.routes()).use(rootRouter.allowedMethods());
app.listen(PORT, function () {
console.log("Server is running on :" + PORT);
});
6 years ago
6 years ago
/***/ }),
/* 15 */
/***/ (function(module, exports) {
6 years ago
6 years ago
module.exports = require('koa');
6 years ago
6 years ago
/***/ }),
/* 16 */
/***/ (function(module, exports) {
6 years ago
6 years ago
module.exports = require('koa-bodyparser');
6 years ago
/***/ }),
6 years ago
/* 17 */
6 years ago
/***/ (function(module, exports, __webpack_require__) {
"use strict";
6 years ago
var _regenerator = __webpack_require__(0);
6 years ago
var _regenerator2 = _interopRequireDefault(_regenerator);
6 years ago
var _promise = __webpack_require__(1);
6 years ago
var _promise2 = _interopRequireDefault(_promise);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var __awaiter = undefined && undefined.__awaiter || function (thisArg, _arguments, P, generator) {
return new (P || (P = _promise2.default))(function (resolve, reject) {
function fulfilled(value) {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
}
function rejected(value) {
try {
step(generator["throw"](value));
} catch (e) {
reject(e);
}
}
function step(result) {
result.done ? resolve(result.value) : new P(function (resolve) {
resolve(result.value);
}).then(fulfilled, rejected);
}
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
6 years ago
var Router = __webpack_require__(5);
var anomalyType_1 = __webpack_require__(2);
var analytics_1 = __webpack_require__(9);
var metrics_1 = __webpack_require__(13);
function sendAnomalyTypeStatus(ctx) {
6 years ago
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator2.default.mark(function _callee() {
6 years ago
var id, name, anomaly;
6 years ago
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
6 years ago
id = ctx.request.query.id;
name = ctx.request.query.name;
_context.prev = 2;
anomaly = void 0;
6 years ago
6 years ago
if (id !== undefined) {
anomaly = anomalyType_1.loadAnomalyById(id);
} else {
anomaly = anomalyType_1.loadAnomalyByName(name);
}
6 years ago
6 years ago
if (!(anomaly === null)) {
_context.next = 8;
break;
}
ctx.response.status = 404;
return _context.abrupt("return");
case 8:
if (!(anomaly.status === undefined)) {
_context.next = 10;
break;
}
throw new Error('No status for ' + name);
case 10:
ctx.response.body = { status: anomaly.status, errorMessage: anomaly.error };
_context.next = 18;
break;
case 13:
_context.prev = 13;
_context.t0 = _context["catch"](2);
6 years ago
console.error(_context.t0);
6 years ago
// TODO: better send 404 when we know than isn`t found
ctx.response.status = 500;
ctx.response.body = { error: 'Can`t return anything' };
6 years ago
6 years ago
case 18:
6 years ago
case "end":
return _context.stop();
}
}
6 years ago
}, _callee, this, [[2, 13]]);
6 years ago
}));
}
6 years ago
function getAnomaly(ctx) {
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator2.default.mark(function _callee2() {
var id, name, anomaly;
return _regenerator2.default.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_context2.prev = 0;
id = ctx.request.query.id;
name = ctx.request.query.name;
anomaly = void 0;
6 years ago
6 years ago
if (id !== undefined) {
anomaly = anomalyType_1.loadAnomalyById(id);
} else {
anomaly = anomalyType_1.loadAnomalyByName(name.toLowerCase());
}
6 years ago
6 years ago
if (!(anomaly === null)) {
_context2.next = 8;
break;
}
6 years ago
6 years ago
ctx.response.status = 404;
return _context2.abrupt("return");
6 years ago
6 years ago
case 8:
ctx.response.body = {
name: anomaly.name,
metric: anomaly.metric,
status: anomaly.status
};
_context2.next = 16;
break;
6 years ago
6 years ago
case 11:
_context2.prev = 11;
_context2.t0 = _context2["catch"](0);
6 years ago
6 years ago
console.error(_context2.t0);
// TODO: better send 404 when we know than isn`t found
ctx.response.status = 500;
ctx.response.body = 'Can`t get anything';
6 years ago
6 years ago
case 16:
case "end":
return _context2.stop();
}
}
}, _callee2, this, [[0, 11]]);
}));
}
function createAnomaly(ctx) {
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator2.default.mark(function _callee3() {
var body, metric, anomaly, anomalyId;
return _regenerator2.default.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
try {
body = ctx.request.body;
metric = {
datasource: body.metric.datasource,
targets: metrics_1.saveTargets(body.metric.targets)
};
anomaly = {
name: body.name,
panelUrl: body.panelUrl,
pattern: body.pattern.toLowerCase(),
metric: metric,
datasource: body.datasource,
status: 'learning',
last_prediction_time: 0,
next_id: 0
};
anomalyId = anomalyType_1.insertAnomaly(anomaly);
6 years ago
6 years ago
if (anomalyId === null) {
ctx.response.status = 403;
ctx.response.body = {
code: 403,
message: 'Already exists'
};
}
ctx.response.body = { anomaly_id: anomalyId };
analytics_1.runLearning(anomalyId);
} catch (e) {
ctx.response.status = 500;
ctx.response.body = {
code: 500,
message: 'Internal error'
};
}
6 years ago
6 years ago
case 1:
case "end":
return _context3.stop();
}
}
}, _callee3, this);
}));
}
function deleteAnomaly(ctx) {
try {
var id = ctx.request.query.id;
var name = ctx.request.query.name;
if (id !== undefined) {
anomalyType_1.removeAnomaly(id);
} else {
anomalyType_1.removeAnomaly(name.toLowerCase());
}
ctx.response.body = {
code: 200,
message: 'Success'
};
} catch (e) {
ctx.response.status = 500;
ctx.response.body = {
code: 500,
message: 'Internal error'
};
6 years ago
}
6 years ago
}
exports.router = new Router();
exports.router.get('/status', sendAnomalyTypeStatus);
exports.router.get('/', getAnomaly);
exports.router.post('/', createAnomaly);
exports.router.delete('/', deleteAnomaly);
6 years ago
/***/ }),
6 years ago
/* 18 */
6 years ago
/***/ (function(module, exports) {
6 years ago
module.exports = require('child_process');
6 years ago
/***/ }),
6 years ago
/* 19 */
/***/ (function(module, exports) {
6 years ago
6 years ago
module.exports = require('lodash');
6 years ago
/***/ }),
6 years ago
/* 20 */
6 years ago
/***/ (function(module, exports) {
6 years ago
module.exports = require('event-stream');
6 years ago
/***/ }),
6 years ago
/* 21 */
6 years ago
/***/ (function(module, exports, __webpack_require__) {
6 years ago
"use strict";
6 years ago
6 years ago
var _regenerator = __webpack_require__(0);
6 years ago
6 years ago
var _regenerator2 = _interopRequireDefault(_regenerator);
6 years ago
6 years ago
var _promise = __webpack_require__(1);
6 years ago
6 years ago
var _promise2 = _interopRequireDefault(_promise);
6 years ago
6 years ago
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
6 years ago
6 years ago
var __awaiter = undefined && undefined.__awaiter || function (thisArg, _arguments, P, generator) {
return new (P || (P = _promise2.default))(function (resolve, reject) {
function fulfilled(value) {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
}
function rejected(value) {
try {
step(generator["throw"](value));
} catch (e) {
reject(e);
}
}
function step(result) {
result.done ? resolve(result.value) : new P(function (resolve) {
resolve(result.value);
}).then(fulfilled, rejected);
}
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
6 years ago
};
6 years ago
Object.defineProperty(exports, "__esModule", { value: true });
var Router = __webpack_require__(5);
var segments_1 = __webpack_require__(11);
var anomalyType_1 = __webpack_require__(2);
var analytics_1 = __webpack_require__(9);
function sendSegments(ctx) {
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator2.default.mark(function _callee() {
var anomalyId, anomaly, lastSegmentId, timeFrom, timeTo, segments;
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
anomalyId = ctx.request.query.anomaly_id;
anomaly = anomalyType_1.loadAnomalyById(anomalyId);
6 years ago
6 years ago
if (anomaly === null) {
anomalyId = anomalyType_1.getAnomalyIdByName(anomalyId);
}
lastSegmentId = ctx.request.query.last_segment;
timeFrom = ctx.request.query.from;
timeTo = ctx.request.query.to;
segments = segments_1.getLabeledSegments(anomalyId);
// Id filtering
6 years ago
6 years ago
if (lastSegmentId !== undefined) {
segments = segments.filter(function (el) {
return el.id > lastSegmentId;
});
}
// Time filtering
if (timeFrom !== undefined) {
segments = segments.filter(function (el) {
return el.finish > timeFrom;
});
}
if (timeTo !== undefined) {
segments = segments.filter(function (el) {
return el.start < timeTo;
});
}
ctx.response.body = { segments: segments };
6 years ago
6 years ago
case 11:
case "end":
return _context.stop();
}
}
}, _callee, this);
}));
6 years ago
}
6 years ago
function updateSegments(ctx) {
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator2.default.mark(function _callee2() {
var segmentsUpdate, anomalyId, anomalyName, addedIds;
return _regenerator2.default.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
try {
segmentsUpdate = ctx.request.body;
anomalyId = segmentsUpdate.anomaly_id;
anomalyName = segmentsUpdate.name;
6 years ago
6 years ago
if (anomalyId === undefined) {
anomalyId = anomalyType_1.getAnomalyIdByName(anomalyName.toLowerCase());
}
addedIds = segments_1.insertSegments(anomalyId, segmentsUpdate.added_segments, true);
6 years ago
6 years ago
segments_1.removeSegments(anomalyId, segmentsUpdate.removed_segments);
ctx.response.body = { added_ids: addedIds };
analytics_1.runLearning(anomalyId);
} catch (e) {
ctx.response.status = 500;
ctx.response.body = {
code: 500,
message: 'Internal error'
};
}
6 years ago
6 years ago
case 1:
case "end":
return _context2.stop();
}
}
}, _callee2, this);
}));
}
exports.router = new Router();
exports.router.get('/', sendSegments);
exports.router.patch('/', updateSegments);
6 years ago
/***/ }),
6 years ago
/* 22 */
6 years ago
/***/ (function(module, exports, __webpack_require__) {
"use strict";
6 years ago
Object.defineProperty(exports, "__esModule", { value: true });
var anomalyType_1 = __webpack_require__(2);
var alerts_1 = __webpack_require__(23);
var Router = __webpack_require__(5);
function getAlert(ctx) {
var anomalyId = ctx.request.query.anomaly_id;
var anomaly = anomalyType_1.loadAnomalyById(anomalyId);
if (anomaly == null) {
anomalyId = anomalyType_1.getAnomalyIdByName(anomalyId.toLowerCase());
}
var alertsAnomalies = alerts_1.getAlertsAnomalies();
var pos = alertsAnomalies.indexOf(anomalyId);
var enable = pos !== -1;
ctx.response.body = { enable: enable };
6 years ago
}
6 years ago
function changeAlert(ctx) {
var anomalyId = ctx.request.body.anomaly_id;
var enable = ctx.request.body.enable;
var anomaly = anomalyType_1.loadAnomalyById(anomalyId);
if (anomaly == null) {
anomalyId = anomalyType_1.getAnomalyIdByName(anomalyId.toLowerCase());
6 years ago
}
6 years ago
var alertsAnomalies = alerts_1.getAlertsAnomalies();
var pos = alertsAnomalies.indexOf(anomalyId);
if (enable && pos == -1) {
alertsAnomalies.push(anomalyId);
alerts_1.saveAlertsAnomalies(alertsAnomalies);
} else if (!enable && pos > -1) {
alertsAnomalies.splice(pos, 1);
alerts_1.saveAlertsAnomalies(alertsAnomalies);
6 years ago
}
6 years ago
ctx.response.body = { status: 'OK' };
6 years ago
}
6 years ago
exports.router = new Router();
exports.router.get('/', getAlert);
exports.router.post('/', changeAlert);
6 years ago
/***/ }),
6 years ago
/* 23 */
6 years ago
/***/ (function(module, exports, __webpack_require__) {
"use strict";
6 years ago
var _set = __webpack_require__(24);
6 years ago
6 years ago
var _set2 = _interopRequireDefault(_set);
6 years ago
6 years ago
var _regenerator = __webpack_require__(0);
6 years ago
6 years ago
var _regenerator2 = _interopRequireDefault(_regenerator);
6 years ago
6 years ago
var _getIterator2 = __webpack_require__(10);
6 years ago
6 years ago
var _getIterator3 = _interopRequireDefault(_getIterator2);
6 years ago
6 years ago
var _promise = __webpack_require__(1);
6 years ago
6 years ago
var _promise2 = _interopRequireDefault(_promise);
6 years ago
6 years ago
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
6 years ago
6 years ago
var __awaiter = undefined && undefined.__awaiter || function (thisArg, _arguments, P, generator) {
return new (P || (P = _promise2.default))(function (resolve, reject) {
function fulfilled(value) {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
}
function rejected(value) {
try {
step(generator["throw"](value));
} catch (e) {
reject(e);
}
}
function step(result) {
result.done ? resolve(result.value) : new P(function (resolve) {
resolve(result.value);
}).then(fulfilled, rejected);
}
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
var json_1 = __webpack_require__(6);
var analytics_1 = __webpack_require__(9);
var notification_1 = __webpack_require__(25);
var segments_1 = __webpack_require__(11);
var config_1 = __webpack_require__(3);
var path = __webpack_require__(4);
var fs = __webpack_require__(8);
var ALERTS_DB_PATH = path.join(config_1.ANOMALIES_PATH, "alerts_anomalies.json");
function getAlertsAnomalies() {
if (!fs.existsSync(ALERTS_DB_PATH)) {
saveAlertsAnomalies([]);
}
return json_1.getJsonDataSync(ALERTS_DB_PATH);
}
exports.getAlertsAnomalies = getAlertsAnomalies;
function saveAlertsAnomalies(anomalies) {
return json_1.writeJsonDataSync(ALERTS_DB_PATH, anomalies);
}
exports.saveAlertsAnomalies = saveAlertsAnomalies;
function processAlerts(anomalyId) {
var segments = segments_1.getLabeledSegments(anomalyId);
var currentTime = new Date().getTime();
var activeAlert = activeAlerts.has(anomalyId);
var newActiveAlert = false;
if (segments.length > 0) {
var lastSegment = segments[segments.length - 1];
if (lastSegment.finish >= currentTime - alertTimeout) {
newActiveAlert = true;
}
}
if (!activeAlert && newActiveAlert) {
activeAlerts.add(anomalyId);
notification_1.sendNotification(anomalyId, true);
} else if (activeAlert && !newActiveAlert) {
activeAlerts.delete(anomalyId);
notification_1.sendNotification(anomalyId, false);
}
6 years ago
}
6 years ago
function alertsTick() {
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator2.default.mark(function _callee() {
var alertsAnomalies, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, anomalyId;
6 years ago
6 years ago
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
alertsAnomalies = getAlertsAnomalies();
_iteratorNormalCompletion = true;
_didIteratorError = false;
_iteratorError = undefined;
_context.prev = 4;
_iterator = (0, _getIterator3.default)(alertsAnomalies);
6 years ago
6 years ago
case 6:
if (_iteratorNormalCompletion = (_step = _iterator.next()).done) {
_context.next = 20;
break;
}
6 years ago
6 years ago
anomalyId = _step.value;
_context.prev = 8;
_context.next = 11;
return analytics_1.runPredict(anomalyId);
6 years ago
6 years ago
case 11:
processAlerts(anomalyId);
_context.next = 17;
break;
6 years ago
6 years ago
case 14:
_context.prev = 14;
_context.t0 = _context["catch"](8);
6 years ago
6 years ago
console.error(_context.t0);
6 years ago
6 years ago
case 17:
_iteratorNormalCompletion = true;
_context.next = 6;
break;
6 years ago
6 years ago
case 20:
_context.next = 26;
break;
6 years ago
6 years ago
case 22:
_context.prev = 22;
_context.t1 = _context["catch"](4);
_didIteratorError = true;
_iteratorError = _context.t1;
6 years ago
6 years ago
case 26:
_context.prev = 26;
_context.prev = 27;
6 years ago
6 years ago
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
6 years ago
6 years ago
case 29:
_context.prev = 29;
6 years ago
6 years ago
if (!_didIteratorError) {
_context.next = 32;
break;
}
6 years ago
6 years ago
throw _iteratorError;
6 years ago
6 years ago
case 32:
return _context.finish(29);
6 years ago
6 years ago
case 33:
return _context.finish(26);
6 years ago
6 years ago
case 34:
setTimeout(alertsTick, 5000);
6 years ago
6 years ago
case 35:
case "end":
return _context.stop();
}
}
}, _callee, this, [[4, 22, 26, 34], [8, 14], [27,, 29, 33]]);
}));
}
var alertTimeout = 60000; // ms
var activeAlerts = new _set2.default();
setTimeout(alertsTick, 5000);
6 years ago
6 years ago
/***/ }),
/* 24 */
/***/ (function(module, exports) {
6 years ago
6 years ago
module.exports = require('babel-runtime/core-js/set');
6 years ago
/***/ }),
6 years ago
/* 25 */
6 years ago
/***/ (function(module, exports, __webpack_require__) {
"use strict";
6 years ago
var _regenerator = __webpack_require__(0);
6 years ago
6 years ago
var _regenerator2 = _interopRequireDefault(_regenerator);
6 years ago
6 years ago
var _stringify = __webpack_require__(7);
6 years ago
6 years ago
var _stringify2 = _interopRequireDefault(_stringify);
6 years ago
6 years ago
var _promise = __webpack_require__(1);
6 years ago
6 years ago
var _promise2 = _interopRequireDefault(_promise);
6 years ago
6 years ago
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
6 years ago
6 years ago
var __awaiter = undefined && undefined.__awaiter || function (thisArg, _arguments, P, generator) {
return new (P || (P = _promise2.default))(function (resolve, reject) {
function fulfilled(value) {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
}
function rejected(value) {
try {
step(generator["throw"](value));
} catch (e) {
reject(e);
}
}
function step(result) {
result.done ? resolve(result.value) : new P(function (resolve) {
resolve(result.value);
}).then(fulfilled, rejected);
}
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
var axios_1 = __webpack_require__(26);
var anomalyType_1 = __webpack_require__(2);
function sendNotification(anomalyId, active) {
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator2.default.mark(function _callee() {
var anomalyName, notification, endpoint, data;
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
anomalyName = anomalyType_1.loadAnomalyById(anomalyId).name;
6 years ago
6 years ago
console.log('Notification ' + anomalyName);
notification = {
anomaly: anomalyName,
status: ''
};
6 years ago
6 years ago
if (active) {
notification.status = 'alert';
} else {
notification.status = 'OK';
}
endpoint = process.env.HASTIC_ALERT_ENDPOINT;
6 years ago
6 years ago
if (!(endpoint === undefined)) {
_context.next = 8;
break;
}
6 years ago
6 years ago
console.error("Can't send alert, env HASTIC_ALERT_ENDPOINT is undefined");
return _context.abrupt("return");
6 years ago
6 years ago
case 8:
_context.prev = 8;
_context.next = 11;
return axios_1.default.post(endpoint, {
method: 'POST',
body: (0, _stringify2.default)(notification)
});
6 years ago
6 years ago
case 11:
data = _context.sent;
6 years ago
6 years ago
console.log(data);
_context.next = 18;
break;
6 years ago
6 years ago
case 15:
_context.prev = 15;
_context.t0 = _context["catch"](8);
6 years ago
6 years ago
console.error("Can't send alert to " + endpoint + ". Error: " + _context.t0);
6 years ago
6 years ago
case 18:
case "end":
return _context.stop();
}
}
}, _callee, this, [[8, 15]]);
}));
}
exports.sendNotification = sendNotification;
6 years ago
/***/ }),
6 years ago
/* 26 */
/***/ (function(module, exports) {
6 years ago
6 years ago
module.exports = require('axios');
6 years ago
/***/ }),
6 years ago
/* 27 */
6 years ago
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
6 years ago
var config = __webpack_require__(3);
var fs = __webpack_require__(8);
6 years ago
// see analytics/pattern_detection_model.py with folders available
function maybeCreate(path) {
if (fs.existsSync(path)) {
return;
}
fs.mkdirSync(path);
}
function checkDataFolders() {
var folders = [config.DATA_PATH, config.DATASETS_PATH, config.ANOMALIES_PATH, config.MODELS_PATH, config.METRICS_PATH, config.SEGMENTS_PATH].forEach(maybeCreate);
}
exports.checkDataFolders = checkDataFolders;
/***/ })
6 years ago
/******/ ]);
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIndlYnBhY2s6Ly8vd2VicGFjay9ib290c3RyYXAgNTVhNzY2MjNiNzUwOTAwNzY0NWEiLCJ3ZWJwYWNrOi8vL2V4dGVybmFsIFwicmVxdWlyZSgnYmFiZWwtcnVudGltZS9yZWdlbmVyYXRvcicpXCIiLCJ3ZWJwYWNrOi8vL2V4dGVybmFsIFwicmVxdWlyZSgnYmFiZWwtcnVudGltZS9jb3JlLWpzL3Byb21pc2UnKVw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