Browse Source

Case-sensitive anomaly name #41

pull/1/head
rozetko 6 years ago
parent
commit
a4fb03f488
  1. 8
      server/src/routes/alerts.ts
  2. 12
      server/src/routes/anomalies.ts
  3. 6
      server/src/routes/segments.ts

8
server/src/routes/alerts.ts

@ -6,10 +6,10 @@ import * as Router from 'koa-router';
function getAlert(ctx: Router.IRouterContext) {
let anomalyId: AnomalyId = ctx.request.query.anomaly_id;
let anomalyId: AnomalyId = ctx.request.query.anomaly_id.toLowerCase();
let anomaly = loadAnomalyById(anomalyId)
if(anomaly == null) {
anomalyId = getAnomalyIdByName(anomalyId.toLowerCase());
anomalyId = getAnomalyIdByName(anomalyId);
}
let alertsAnomalies = getAlertsAnomalies();
@ -22,12 +22,12 @@ function getAlert(ctx: Router.IRouterContext) {
function changeAlert(ctx: Router.IRouterContext) {
let anomalyId: AnomalyId = ctx.request.body.anomaly_id;
let anomalyId: AnomalyId = ctx.request.body.anomaly_id.toLowerCase();
let enable: boolean = ctx.request.body.enable;
let anomaly = loadAnomalyById(anomalyId)
if(anomaly == null) {
anomalyId = getAnomalyIdByName(anomalyId.toLowerCase());
anomalyId = getAnomalyIdByName(anomalyId);
}
let alertsAnomalies = getAlertsAnomalies();

12
server/src/routes/anomalies.ts

@ -12,7 +12,7 @@ import { saveTargets } from '../services/metrics';
async function sendAnomalyTypeStatus(ctx: Router.IRouterContext) {
let id = ctx.request.query.id;
let name = ctx.request.query.name;
let name = ctx.request.query.name.toLowerCase();
try {
let anomaly: Anomaly;
if(id !== undefined) {
@ -40,13 +40,13 @@ async function sendAnomalyTypeStatus(ctx: Router.IRouterContext) {
async function getAnomaly(ctx: Router.IRouterContext) {
try {
let id = ctx.request.query.id;
let name = ctx.request.query.name;
let name = ctx.request.query.name.toLowerCase();
let anomaly:Anomaly;
if(id !== undefined) {
anomaly = loadAnomalyById(id);
} else {
anomaly = loadAnomalyByName(name.toLowerCase());
anomaly = loadAnomalyByName(name);
}
if(anomaly === null) {
ctx.response.status = 404;
@ -75,7 +75,7 @@ async function createAnomaly(ctx: Router.IRouterContext) {
};
const anomaly:Anomaly = {
name: body.name,
name: body.name.toLowerCase(),
panelUrl: body.panelUrl,
pattern: body.pattern.toLowerCase(),
metric: metric,
@ -108,12 +108,12 @@ async function createAnomaly(ctx: Router.IRouterContext) {
function deleteAnomaly(ctx: Router.IRouterContext) {
try {
let id = ctx.request.query.id;
let name = ctx.request.query.name;
let name = ctx.request.query.name.toLowerCase();
if(id !== undefined) {
removeAnomaly(id);
} else {
removeAnomaly(name.toLowerCase());
removeAnomaly(name);
}
ctx.response.body = {

6
server/src/routes/segments.ts

@ -15,7 +15,7 @@ import { runLearning } from '../services/analytics';
async function sendSegments(ctx: Router.IRouterContext) {
let anomalyId: AnomalyId = ctx.request.query.anomaly_id;
let anomalyId: AnomalyId = ctx.request.query.anomaly_id.toLowerCase();
let anomaly:Anomaly = loadAnomalyById(anomalyId);
if(anomaly === null) {
anomalyId = getAnomalyIdByName(anomalyId);
@ -50,10 +50,10 @@ async function updateSegments(ctx: Router.IRouterContext) {
let segmentsUpdate = ctx.request.body;
let anomalyId = segmentsUpdate.anomaly_id;
let anomalyName = segmentsUpdate.name;
let anomalyName = segmentsUpdate.name.toLowerCase();
if(anomalyId === undefined) {
anomalyId = getAnomalyIdByName(anomalyName.toLowerCase());
anomalyId = getAnomalyIdByName(anomalyName);
}
let addedIds = insertSegments(anomalyId, segmentsUpdate.added_segments, true);

Loading…
Cancel
Save