|
|
|
/******/ (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
|
|
|
|
/******/ return __webpack_require__(__webpack_require__.s = 14);
|
|
|
|
/******/ })
|
|
|
|
/************************************************************************/
|
|
|
|
/******/ ([
|
|
|
|
/* 0 */
|
|
|
|
/***/ (function(module, exports) {
|
|
|
|
|
|
|
|
module.exports = require('babel-runtime/regenerator');
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
/* 1 */
|
|
|
|
/***/ (function(module, exports) {
|
|
|
|
|
|
|
|
module.exports = require('babel-runtime/core-js/promise');
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
/* 2 */
|
|
|
|
/***/ (function(module, exports, __webpack_require__) {
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
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);
|
|
|
|
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;
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
/* 3 */
|
|
|
|
/***/ (function(module, exports, __webpack_require__) {
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
var path = __webpack_require__(4);
|
|
|
|
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');
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
/* 4 */
|
|
|
|
/***/ (function(module, exports) {
|
|
|
|
|
|
|
|
module.exports = require('path');
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
/* 5 */
|
|
|
|
/***/ (function(module, exports) {
|
|
|
|
|
|
|
|
module.exports = require('koa-router');
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
/* 6 */
|
|
|
|
/***/ (function(module, exports, __webpack_require__) {
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
|
|
var _stringify = __webpack_require__(7);
|
|
|
|
|
|
|
|
var _stringify2 = _interopRequireDefault(_stringify);
|
|
|
|
|
|
|
|
var _regenerator = __webpack_require__(0);
|
|
|
|
|
|
|
|
var _regenerator2 = _interopRequireDefault(_regenerator);
|
|
|
|
|
|
|
|
var _promise = __webpack_require__(1);
|
|
|
|
|
|
|
|
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 });
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
data = _context.sent;
|
|
|
|
_context.prev = 3;
|
|
|
|
return _context.abrupt("return", JSON.parse(data));
|
|
|
|
|
|
|
|
case 7:
|
|
|
|
_context.prev = 7;
|
|
|
|
_context.t0 = _context["catch"](3);
|
|
|
|
|
|
|
|
console.error(_context.t0);
|
|
|
|
throw new Error('Wrong file format');
|
|
|
|
|
|
|
|
case 11:
|
|
|
|
case "end":
|
|
|
|
return _context.stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, _callee, this, [[3, 7]]);
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
exports.getJsonDataSync = getJsonDataSync;
|
|
|
|
function writeJsonDataSync(filename, data) {
|
|
|
|
fs.writeFileSync(filename, (0, _stringify2.default)(data));
|
|
|
|
}
|
|
|
|
exports.writeJsonDataSync = writeJsonDataSync;
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
/* 7 */
|
|
|
|
/***/ (function(module, exports) {
|
|
|
|
|
|
|
|
module.exports = require('babel-runtime/core-js/json/stringify');
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
/* 8 */
|
|
|
|
/***/ (function(module, exports) {
|
|
|
|
|
|
|
|
module.exports = require('fs');
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
/* 9 */
|
|
|
|
/***/ (function(module, exports, __webpack_require__) {
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
|
|
var _regenerator = __webpack_require__(0);
|
|
|
|
|
|
|
|
var _regenerator2 = _interopRequireDefault(_regenerator);
|
|
|
|
|
|
|
|
var _stringify = __webpack_require__(7);
|
|
|
|
|
|
|
|
var _stringify2 = _interopRequireDefault(_stringify);
|
|
|
|
|
|
|
|
var _promise = __webpack_require__(1);
|
|
|
|
|
|
|
|
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 });
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
case 7:
|
|
|
|
result = _context.sent;
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
result = _context2.sent;
|
|
|
|
|
|
|
|
if (!(result.status === 'failed')) {
|
|
|
|
_context2.next = 8;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return _context2.abrupt("return", []);
|
|
|
|
|
|
|
|
case 8:
|
|
|
|
// Merging segments
|
|
|
|
segments = segments_1.getLabeledSegments(anomalyId);
|
|
|
|
|
|
|
|
if (segments.length > 0 && result.segments.length > 0) {
|
|
|
|
lastOldSegment = segments[segments.length - 1];
|
|
|
|
firstNewSegment = result.segments[0];
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
case 13:
|
|
|
|
case "end":
|
|
|
|
return _context2.stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, _callee2, this);
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
exports.runPredict = runPredict;
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
/* 10 */
|
|
|
|
/***/ (function(module, exports) {
|
|
|
|
|
|
|
|
module.exports = require('babel-runtime/core-js/get-iterator');
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
/* 11 */
|
|
|
|
/***/ (function(module, exports, __webpack_require__) {
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
|
|
var _getIterator2 = __webpack_require__(10);
|
|
|
|
|
|
|
|
var _getIterator3 = _interopRequireDefault(_getIterator2);
|
|
|
|
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
try {
|
|
|
|
for (var _iterator = (0, _getIterator3.default)(segments), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
|
|
var segment = _step.value;
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
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 = [];
|
|
|
|
}
|
|
|
|
return jsonData;
|
|
|
|
}
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
|
|
|
|
try {
|
|
|
|
for (var _iterator2 = (0, _getIterator3.default)(addedSegments), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
|
|
|
var segment = _step2.value;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
try {
|
|
|
|
var _loop = function _loop() {
|
|
|
|
var segmentId = _step3.value;
|
|
|
|
|
|
|
|
segments = segments.filter(function (el) {
|
|
|
|
return el.id !== segmentId;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
saveSegments(anomalyId, segments);
|
|
|
|
}
|
|
|
|
exports.removeSegments = removeSegments;
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
/* 12 */
|
|
|
|
/***/ (function(module, exports) {
|
|
|
|
|
|
|
|
module.exports = require('crypto');
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
/* 13 */
|
|
|
|
/***/ (function(module, exports, __webpack_require__) {
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
|
|
var _stringify = __webpack_require__(7);
|
|
|
|
|
|
|
|
var _stringify2 = _interopRequireDefault(_stringify);
|
|
|
|
|
|
|
|
var _getIterator2 = __webpack_require__(10);
|
|
|
|
|
|
|
|
var _getIterator3 = _interopRequireDefault(_getIterator2);
|
|
|
|
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
try {
|
|
|
|
for (var _iterator = (0, _getIterator3.default)(targets), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
|
|
var target = _step.value;
|
|
|
|
|
|
|
|
metrics.push(saveTarget(target));
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
_didIteratorError = true;
|
|
|
|
_iteratorError = err;
|
|
|
|
} finally {
|
|
|
|
try {
|
|
|
|
if (!_iteratorNormalCompletion && _iterator.return) {
|
|
|
|
_iterator.return();
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
if (_didIteratorError) {
|
|
|
|
throw _iteratorError;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
/* 14 */
|
|
|
|
/***/ (function(module, exports, __webpack_require__) {
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
|
|
var _regenerator = __webpack_require__(0);
|
|
|
|
|
|
|
|
var _regenerator2 = _interopRequireDefault(_regenerator);
|
|
|
|
|
|
|
|
var _promise = __webpack_require__(1);
|
|
|
|
|
|
|
|
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 });
|
|
|
|
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();
|
|
|
|
|
|
|
|
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' };
|
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
/* 15 */
|
|
|
|
/***/ (function(module, exports) {
|
|
|
|
|
|
|
|
module.exports = require('koa');
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
/* 16 */
|
|
|
|
/***/ (function(module, exports) {
|
|
|
|
|
|
|
|
module.exports = require('koa-bodyparser');
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
/* 17 */
|
|
|
|
/***/ (function(module, exports, __webpack_require__) {
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
|
|
var _regenerator = __webpack_require__(0);
|
|
|
|
|
|
|
|
var _regenerator2 = _interopRequireDefault(_regenerator);
|
|
|
|
|
|
|
|
var _promise = __webpack_require__(1);
|
|
|
|
|
|
|
|
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 });
|
|
|
|
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) {
|
|
|
|
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator2.default.mark(function _callee() {
|
|
|
|
var id, name, anomaly;
|
|
|
|
return _regenerator2.default.wrap(function _callee$(_context) {
|
|
|
|
while (1) {
|
|
|
|
switch (_context.prev = _context.next) {
|
|
|
|
case 0:
|
|
|
|
id = ctx.request.query.id;
|
|
|
|
name = ctx.request.query.name;
|
|
|
|
_context.prev = 2;
|
|
|
|
anomaly = void 0;
|
|
|
|
|
|
|
|
if (id !== undefined) {
|
|
|
|
anomaly = anomalyType_1.loadAnomalyById(id);
|
|
|
|
} else {
|
|
|
|
anomaly = anomalyType_1.loadAnomalyByName(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
console.error(_context.t0);
|
|
|
|
// TODO: better send 404 when we know than isn`t found
|
|
|
|
ctx.response.status = 500;
|
|
|
|
ctx.response.body = { error: 'Can`t return anything' };
|
|
|
|
|
|
|
|
case 18:
|
|
|
|
case "end":
|
|
|
|
return _context.stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, _callee, this, [[2, 13]]);
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (id !== undefined) {
|
|
|
|
anomaly = anomalyType_1.loadAnomalyById(id);
|
|
|
|
} else {
|
|
|
|
anomaly = anomalyType_1.loadAnomalyByName(name.toLowerCase());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(anomaly === null)) {
|
|
|
|
_context2.next = 8;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.response.status = 404;
|
|
|
|
return _context2.abrupt("return");
|
|
|
|
|
|
|
|
case 8:
|
|
|
|
ctx.response.body = {
|
|
|
|
name: anomaly.name,
|
|
|
|
metric: anomaly.metric,
|
|
|
|
status: anomaly.status
|
|
|
|
};
|
|
|
|
_context2.next = 16;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 11:
|
|
|
|
_context2.prev = 11;
|
|
|
|
_context2.t0 = _context2["catch"](0);
|
|
|
|
|
|
|
|
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';
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
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'
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
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'
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
exports.router = new Router();
|
|
|
|
exports.router.get('/status', sendAnomalyTypeStatus);
|
|
|
|
exports.router.get('/', getAnomaly);
|
|
|
|
exports.router.post('/', createAnomaly);
|
|
|
|
exports.router.delete('/', deleteAnomaly);
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
/* 18 */
|
|
|
|
/***/ (function(module, exports) {
|
|
|
|
|
|
|
|
module.exports = require('child_process');
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
/* 19 */
|
|
|
|
/***/ (function(module, exports) {
|
|
|
|
|
|
|
|
module.exports = require('lodash');
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
/* 20 */
|
|
|
|
/***/ (function(module, exports) {
|
|
|
|
|
|
|
|
module.exports = require('event-stream');
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
/* 21 */
|
|
|
|
/***/ (function(module, exports, __webpack_require__) {
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
|
|
var _regenerator = __webpack_require__(0);
|
|
|
|
|
|
|
|
var _regenerator2 = _interopRequireDefault(_regenerator);
|
|
|
|
|
|
|
|
var _promise = __webpack_require__(1);
|
|
|
|
|
|
|
|
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 });
|
|
|
|
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);
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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 };
|
|
|
|
|
|
|
|
case 11:
|
|
|
|
case "end":
|
|
|
|
return _context.stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, _callee, this);
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (anomalyId === undefined) {
|
|
|
|
anomalyId = anomalyType_1.getAnomalyIdByName(anomalyName.toLowerCase());
|
|
|
|
}
|
|
|
|
addedIds = segments_1.insertSegments(anomalyId, segmentsUpdate.added_segments, true);
|
|
|
|
|
|
|
|
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'
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
case "end":
|
|
|
|
return _context2.stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, _callee2, this);
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
exports.router = new Router();
|
|
|
|
exports.router.get('/', sendSegments);
|
|
|
|
exports.router.patch('/', updateSegments);
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
/* 22 */
|
|
|
|
/***/ (function(module, exports, __webpack_require__) {
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
|
|
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 };
|
|
|
|
}
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
ctx.response.body = { status: 'OK' };
|
|
|
|
}
|
|
|
|
exports.router = new Router();
|
|
|
|
exports.router.get('/', getAlert);
|
|
|
|
exports.router.post('/', changeAlert);
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
/* 23 */
|
|
|
|
/***/ (function(module, exports, __webpack_require__) {
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
|
|
var _set = __webpack_require__(24);
|
|
|
|
|
|
|
|
var _set2 = _interopRequireDefault(_set);
|
|
|
|
|
|
|
|
var _regenerator = __webpack_require__(0);
|
|
|
|
|
|
|
|
var _regenerator2 = _interopRequireDefault(_regenerator);
|
|
|
|
|
|
|
|
var _getIterator2 = __webpack_require__(10);
|
|
|
|
|
|
|
|
var _getIterator3 = _interopRequireDefault(_getIterator2);
|
|
|
|
|
|
|
|
var _promise = __webpack_require__(1);
|
|
|
|
|
|
|
|
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 });
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function alertsTick() {
|
|
|
|
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator2.default.mark(function _callee() {
|
|
|
|
var alertsAnomalies, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, anomalyId;
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
case 6:
|
|
|
|
if (_iteratorNormalCompletion = (_step = _iterator.next()).done) {
|
|
|
|
_context.next = 20;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
anomalyId = _step.value;
|
|
|
|
_context.prev = 8;
|
|
|
|
_context.next = 11;
|
|
|
|
return analytics_1.runPredict(anomalyId);
|
|
|
|
|
|
|
|
case 11:
|
|
|
|
processAlerts(anomalyId);
|
|
|
|
_context.next = 17;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 14:
|
|
|
|
_context.prev = 14;
|
|
|
|
_context.t0 = _context["catch"](8);
|
|
|
|
|
|
|
|
console.error(_context.t0);
|
|
|
|
|
|
|
|
case 17:
|
|
|
|
_iteratorNormalCompletion = true;
|
|
|
|
_context.next = 6;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 20:
|
|
|
|
_context.next = 26;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 22:
|
|
|
|
_context.prev = 22;
|
|
|
|
_context.t1 = _context["catch"](4);
|
|
|
|
_didIteratorError = true;
|
|
|
|
_iteratorError = _context.t1;
|
|
|
|
|
|
|
|
case 26:
|
|
|
|
_context.prev = 26;
|
|
|
|
_context.prev = 27;
|
|
|
|
|
|
|
|
if (!_iteratorNormalCompletion && _iterator.return) {
|
|
|
|
_iterator.return();
|
|
|
|
}
|
|
|
|
|
|
|
|
case 29:
|
|
|
|
_context.prev = 29;
|
|
|
|
|
|
|
|
if (!_didIteratorError) {
|
|
|
|
_context.next = 32;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw _iteratorError;
|
|
|
|
|
|
|
|
case 32:
|
|
|
|
return _context.finish(29);
|
|
|
|
|
|
|
|
case 33:
|
|
|
|
return _context.finish(26);
|
|
|
|
|
|
|
|
case 34:
|
|
|
|
setTimeout(alertsTick, 5000);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
/* 24 */
|
|
|
|
/***/ (function(module, exports) {
|
|
|
|
|
|
|
|
module.exports = require('babel-runtime/core-js/set');
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
/* 25 */
|
|
|
|
/***/ (function(module, exports, __webpack_require__) {
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
|
|
var _regenerator = __webpack_require__(0);
|
|
|
|
|
|
|
|
var _regenerator2 = _interopRequireDefault(_regenerator);
|
|
|
|
|
|
|
|
var _stringify = __webpack_require__(7);
|
|
|
|
|
|
|
|
var _stringify2 = _interopRequireDefault(_stringify);
|
|
|
|
|
|
|
|
var _promise = __webpack_require__(1);
|
|
|
|
|
|
|
|
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 });
|
|
|
|
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;
|
|
|
|
|
|
|
|
console.log('Notification ' + anomalyName);
|
|
|
|
notification = {
|
|
|
|
anomaly: anomalyName,
|
|
|
|
status: ''
|
|
|
|
};
|
|
|
|
|
|
|
|
if (active) {
|
|
|
|
notification.status = 'alert';
|
|
|
|
} else {
|
|
|
|
notification.status = 'OK';
|
|
|
|
}
|
|
|
|
endpoint = process.env.HASTIC_ALERT_ENDPOINT;
|
|
|
|
|
|
|
|
if (!(endpoint === undefined)) {
|
|
|
|
_context.next = 8;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
console.error("Can't send alert, env HASTIC_ALERT_ENDPOINT is undefined");
|
|
|
|
return _context.abrupt("return");
|
|
|
|
|
|
|
|
case 8:
|
|
|
|
_context.prev = 8;
|
|
|
|
_context.next = 11;
|
|
|
|
return axios_1.default.post(endpoint, {
|
|
|
|
method: 'POST',
|
|
|
|
body: (0, _stringify2.default)(notification)
|
|
|
|
});
|
|
|
|
|
|
|
|
case 11:
|
|
|
|
data = _context.sent;
|
|
|
|
|
|
|
|
console.log(data);
|
|
|
|
_context.next = 18;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 15:
|
|
|
|
_context.prev = 15;
|
|
|
|
_context.t0 = _context["catch"](8);
|
|
|
|
|
|
|
|
console.error("Can't send alert to " + endpoint + ". Error: " + _context.t0);
|
|
|
|
|
|
|
|
case 18:
|
|
|
|
case "end":
|
|
|
|
return _context.stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, _callee, this, [[8, 15]]);
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
exports.sendNotification = sendNotification;
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
/* 26 */
|
|
|
|
/***/ (function(module, exports) {
|
|
|
|
|
|
|
|
module.exports = require('axios');
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
/* 27 */
|
|
|
|
/***/ (function(module, exports, __webpack_require__) {
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
var config = __webpack_require__(3);
|
|
|
|
var fs = __webpack_require__(8);
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
/***/ })
|
|
|
|
/******/ ]);
|
|
|
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIndlYnBhY2s6Ly8vd2VicGFjay9ib290c3RyYXAgNTVhNzY2MjNiNzUwOTAwNzY0NWEiLCJ3ZWJwYWNrOi8vL2V4dGVybmFsIFwicmVxdWlyZSgnYmFiZWwtcnVudGltZS9yZWdlbmVyYXRvcicpXCIiLCJ3ZWJwYWNrOi8vL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