import { CdFormGroup } from '../app/shared/forms/cd-form-group';
import { Permission } from '../app/shared/models/permissions';
import {
- PrometheusAlert,
- PrometheusNotification,
- PrometheusNotificationAlert
+ AlertmanagerAlert,
+ AlertmanagerNotification,
+ AlertmanagerNotificationAlert,
+ PrometheusRule
} from '../app/shared/models/prometheus-alerts';
import { _DEV_ } from '../unit-test-configuration';
return this.tableActions;
}
+ // Overwrite if needed
+ createSelection(): object {
+ return {};
+ }
+
testScenarios({
fn,
empty,
}) {
this.testScenario(
// 'multiple selections'
- [{}, {}],
+ [this.createSelection(), this.createSelection()],
fn,
_.isUndefined(multiple) ? empty : multiple
);
+ const executing = this.createSelection();
+ executing['cdExecuting'] = 'someAction';
this.testScenario(
// 'select executing item'
- [{ cdExecuting: 'someAction' }],
+ [executing],
fn,
_.isUndefined(singleExecuting) ? single : singleExecuting
);
- this.testScenario([{}], fn, single); // 'select non-executing item'
+ this.testScenario([this.createSelection()], fn, single); // 'select non-executing item'
this.testScenario([], fn, empty); // 'no selection'
}
}
export class PrometheusHelper {
- createAlert(name, state = 'active', timeMultiplier = 1) {
+ createSilence(id) {
+ return {
+ id: id,
+ createdBy: `Creator of ${id}`,
+ comment: `A comment for ${id}`,
+ startsAt: new Date('2022-02-22T22:22:00').toISOString(),
+ endsAt: new Date('2022-02-23T22:22:00').toISOString(),
+ matchers: [
+ {
+ name: 'job',
+ value: 'someJob',
+ isRegex: true
+ }
+ ]
+ };
+ }
+
+ createRule(name, severity, alerts: any[]): PrometheusRule {
+ return {
+ name: name,
+ labels: {
+ severity: severity
+ },
+ alerts: alerts
+ } as PrometheusRule;
+ }
+
+ createAlert(name, state = 'active', timeMultiplier = 1): AlertmanagerAlert {
return {
fingerprint: name,
status: { state },
labels: {
- alertname: name
+ alertname: name,
+ instance: 'someInstance',
+ job: 'someJob',
+ severity: 'someSeverity'
},
annotations: {
summary: `${name} is ${state}`
},
generatorURL: `http://${name}`,
startsAt: new Date(new Date('2022-02-22').getTime() * timeMultiplier).toString()
- } as PrometheusAlert;
+ } as AlertmanagerAlert;
}
- createNotificationAlert(name, status = 'firing') {
+ createNotificationAlert(name, status = 'firing'): AlertmanagerNotificationAlert {
return {
status: status,
labels: {
summary: `${name} is ${status}`
},
generatorURL: `http://${name}`
- } as PrometheusNotificationAlert;
+ } as AlertmanagerNotificationAlert;
}
- createNotification(alertNumber = 1, status = 'firing') {
+ createNotification(alertNumber = 1, status = 'firing'): AlertmanagerNotification {
const alerts = [];
for (let i = 0; i < alertNumber; i++) {
alerts.push(this.createNotificationAlert('alert' + i, status));
}
- return { alerts, status } as PrometheusNotification;
+ return { alerts, status } as AlertmanagerNotification;
}
createLink(url) {