@grafana/alerting
Version:
Grafana Alerting Library – Build vertical integrations on top of the industry-leading alerting solution
39 lines (36 loc) • 1.55 kB
JavaScript
import { isEmpty, countBy } from 'lodash';
;
const CAN_USE_ANNOTATION = "grafana.com/canUse";
function isUsableContactPoint(contactPoint) {
var _a, _b;
const canUse = (_b = (_a = contactPoint.metadata) == null ? void 0 : _a.annotations) == null ? void 0 : _b[CAN_USE_ANNOTATION];
return canUse === "true";
}
function getContactPointInUseRoutes(contactPoint) {
var _a, _b;
const value = (_b = (_a = contactPoint.metadata) == null ? void 0 : _a.annotations) == null ? void 0 : _b["grafana.com/inUse/routes"];
return Number(value) || 0;
}
function getContactPointInUseRules(contactPoint) {
var _a, _b;
const value = (_b = (_a = contactPoint.metadata) == null ? void 0 : _a.annotations) == null ? void 0 : _b["grafana.com/inUse/rules"];
return Number(value) || 0;
}
function getContactPointInUse(contactPoint) {
return {
routes: getContactPointInUseRoutes(contactPoint),
rules: getContactPointInUseRules(contactPoint)
};
}
function getContactPointDescription(contactPoint) {
if (isEmpty(contactPoint.spec.integrations)) {
return "<empty contact point>";
}
const integrationCounts = countBy(contactPoint.spec.integrations, (integration) => integration.type);
const description = Object.entries(integrationCounts).map(([type, count]) => {
return count > 1 ? `${type} (${count})` : type;
}).join(", ");
return description;
}
export { getContactPointDescription, getContactPointInUse, getContactPointInUseRoutes, getContactPointInUseRules, isUsableContactPoint };
//# sourceMappingURL=utils.mjs.map