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) { 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) let anomaly = loadAnomalyById(anomalyId)
if(anomaly == null) { if(anomaly == null) {
anomalyId = getAnomalyIdByName(anomalyId.toLowerCase()); anomalyId = getAnomalyIdByName(anomalyId);
} }
let alertsAnomalies = getAlertsAnomalies(); let alertsAnomalies = getAlertsAnomalies();
@ -22,12 +22,12 @@ function getAlert(ctx: Router.IRouterContext) {
function changeAlert(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 enable: boolean = ctx.request.body.enable;
let anomaly = loadAnomalyById(anomalyId) let anomaly = loadAnomalyById(anomalyId)
if(anomaly == null) { if(anomaly == null) {
anomalyId = getAnomalyIdByName(anomalyId.toLowerCase()); anomalyId = getAnomalyIdByName(anomalyId);
} }
let alertsAnomalies = getAlertsAnomalies(); let alertsAnomalies = getAlertsAnomalies();

12
server/src/routes/anomalies.ts

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

6
server/src/routes/segments.ts

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

Loading…
Cancel
Save