grafana/public/app/features/alerting/getAlertingValidationMessage.ts
Dominik Prokop 9b7748ec13
Chore: Reorg packages (#20111)
Primarily- moving majority of the types and utils from @grafana/ui to @grafana/data

* Move types from grafana-ui to grafana-data

* Move valueFormats to grafana-data

* Move utils from grafana-ui to grafana-data

* Update imports in grafana-ui

* revert data's tsconfig change

* Update imports in grafana-runtime

* Fix import paths in grafana-ui

* Move rxjs to devDeps

* Core import updates batch 1

* Import updates batch 2

* Imports fix batch 3

* Imports fixes batch i don't know

* Fix imorts in grafana-toolkit

* Fix imports after master merge
2019-10-31 10:48:05 +01:00

50 lines
1.4 KiB
TypeScript

import { DataQuery } from '@grafana/data';
import { DataSourceSrv } from '@grafana/runtime';
import { DataTransformerConfig } from '@grafana/data';
export const getDefaultCondition = () => ({
type: 'query',
query: { params: ['A', '5m', 'now'] },
reducer: { type: 'avg', params: [] as any[] },
evaluator: { type: 'gt', params: [null] as any[] },
operator: { type: 'and' },
});
export const getAlertingValidationMessage = async (
transformations: DataTransformerConfig[],
targets: DataQuery[],
datasourceSrv: DataSourceSrv,
datasourceName: string
): Promise<string> => {
if (targets.length === 0) {
return 'Could not find any metric queries';
}
if (transformations && transformations.length) {
return 'Transformations are not supported in alert queries';
}
let alertingNotSupported = 0;
let templateVariablesNotSupported = 0;
for (const target of targets) {
const dsName = target.datasource || datasourceName;
const ds = await datasourceSrv.get(dsName);
if (!ds.meta.alerting) {
alertingNotSupported++;
} else if (ds.targetContainsTemplate && ds.targetContainsTemplate(target)) {
templateVariablesNotSupported++;
}
}
if (alertingNotSupported === targets.length) {
return 'The datasource does not support alerting queries';
}
if (templateVariablesNotSupported === targets.length) {
return 'Template variables are not supported in alert queries';
}
return '';
};