addons/isl-server/src/alerts.tsblame
View source
b69ab311/**
b69ab312 * Copyright (c) Meta Platforms, Inc. and affiliates.
b69ab313 *
b69ab314 * This source code is licensed under the MIT license found in the
b69ab315 * LICENSE file in the root directory of this source tree.
b69ab316 */
b69ab317
b69ab318import type {Alert} from 'isl/src/types';
b69ab319
b69ab3110/** Given raw json output from `sl config`, parse Alerts */
b69ab3111export function parseAlerts(rawConfigs: Array<{name: string; value: unknown}>): Array<Alert> {
b69ab3112 // we get back configs with their keys as prefixes
b69ab3113 // [ {name: "alerts.S11111.title", value: "alert 1"}, {name: "alerts.S22222.title", value: "alert 2"}, ...]
b69ab3114 const alertMap = new Map<string, Partial<Alert>>();
b69ab3115 for (const entry of Object.values(rawConfigs)) {
b69ab3116 const {name, value} = entry;
b69ab3117 const [, key, suffix] = name.split('.');
b69ab3118 if (!suffix) {
b69ab3119 continue;
b69ab3120 }
b69ab3121 const existing = alertMap.get(key) ?? {key};
b69ab3122 (existing as {[key: string]: unknown})[suffix] =
b69ab3123 suffix === 'show-in-isl' ? value == 'true' : value;
b69ab3124 alertMap.set(key, existing);
b69ab3125 }
b69ab3126
b69ab3127 return [...alertMap.values()].filter(
b69ab3128 (entry): entry is Alert =>
b69ab3129 !!entry.title &&
b69ab3130 !!entry.description &&
b69ab3131 !!entry.severity &&
b69ab3132 !!entry.url &&
b69ab3133 entry['show-in-isl'] === true,
b69ab3134 );
b69ab3135}