Skip to content

Commit

Permalink
Problems: Able to select tags evaluation type, fixes #1600
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderzobnin committed Aug 1, 2023
1 parent e338124 commit 7af3dca
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/datasource/components/QueryEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { InlineField, InlineFieldRow, Select } from '@grafana/ui';
import * as c from '../constants';
import { migrate, DS_QUERY_SCHEMA } from '../migrations';
import { ZabbixDatasource } from '../datasource';
import { ShowProblemTypes, ZabbixDSOptions, ZabbixMetricsQuery, ZabbixQueryOptions } from '../types';
import { ShowProblemTypes, ZabbixDSOptions, ZabbixMetricsQuery, ZabbixQueryOptions, ZabbixTagEvalType } from '../types';
import { MetricsQueryEditor } from './QueryEditor/MetricsQueryEditor';
import { QueryFunctionsEditor } from './QueryEditor/QueryFunctionsEditor';
import { QueryOptionsEditor } from './QueryEditor/QueryOptionsEditor';
Expand Down Expand Up @@ -68,6 +68,7 @@ const getDefaultQuery: () => Partial<ZabbixMetricsQuery> = () => ({
tags: { filter: '' },
proxy: { filter: '' },
textFilter: '',
evaltype: ZabbixTagEvalType.AndOr,
options: {
showDisabledItems: false,
skipEmptyValues: false,
Expand Down
16 changes: 15 additions & 1 deletion src/datasource/components/QueryEditor/ProblemsQueryEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { QueryEditorRow } from './QueryEditorRow';
import { MetricPicker } from '../../../components';
import { getVariableOptions } from './utils';
import { ZabbixDatasource } from '../../datasource';
import { ZabbixMetricsQuery } from '../../types';
import { ZabbixMetricsQuery, ZabbixTagEvalType } from '../../types';

const showProblemsOptions: Array<SelectableValue<string>> = [
{ label: 'Problems', value: 'problems' },
Expand All @@ -25,6 +25,11 @@ const severityOptions: Array<SelectableValue<number>> = [
{ value: 5, label: 'Disaster' },
];

const evaltypeOptions: Array<SelectableValue<ZabbixTagEvalType>> = [
{ label: 'AND/OR', value: ZabbixTagEvalType.AndOr },
{ label: 'OR', value: ZabbixTagEvalType.Or },
];

export interface Props {
query: ZabbixMetricsQuery;
datasource: ZabbixDatasource;
Expand Down Expand Up @@ -206,6 +211,15 @@ export const ProblemsQueryEditor = ({ query, datasource, onChange }: Props) => {
onBlur={onTextFilterChange('tags')}
/>
</InlineField>
<InlineField>
<Select
isSearchable={false}
width={15}
value={query.evaltype}
options={evaltypeOptions}
onChange={onPropChange('evaltype')}
/>
</InlineField>
</QueryEditorRow>
<QueryEditorRow>
<InlineField label="Show" labelWidth={12}>
Expand Down
4 changes: 4 additions & 0 deletions src/datasource/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,10 @@ export class ZabbixDatasource extends DataSourceApi<ZabbixMetricsQuery, ZabbixDS
problemsOptions.tags = tags;
}

if (target?.evaltype) {
problemsOptions.evaltype = target?.evaltype;
}

if (target.options?.acknowledged === 0 || target.options?.acknowledged === 1) {
problemsOptions.acknowledged = !!target.options?.acknowledged;
}
Expand Down
6 changes: 6 additions & 0 deletions src/datasource/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export interface ZabbixMetricsQuery extends DataQuery {
tags?: { filter: string };
triggers?: { minSeverity: number; acknowledged: number; count: boolean };
countTriggersBy?: 'problems' | 'items' | '';
evaltype?: ZabbixTagEvalType;
functions?: MetricFunc[];
options?: ZabbixQueryOptions;
// Problems
Expand Down Expand Up @@ -415,3 +416,8 @@ export enum ZabbixAuthType {
UserLogin = 'userLogin',
Token = 'token',
}

export enum ZabbixTagEvalType {
AndOr = '0',
Or = '2',
}
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ export class ZabbixAPIConnector {
}

getProblems(groupids, hostids, applicationids, options): Promise<ZBXProblem[]> {
const { timeFrom, timeTo, recent, severities, limit, acknowledged, tags } = options;
const { timeFrom, timeTo, recent, severities, limit, acknowledged, tags, evaltype } = options;

const params: any = {
output: 'extend',
Expand All @@ -492,7 +492,7 @@ export class ZabbixAPIConnector {
object: '0',
sortfield: ['eventid'],
sortorder: 'DESC',
evaltype: '2',
evaltype: '0',
// preservekeys: '1',
groupids,
hostids,
Expand All @@ -512,6 +512,10 @@ export class ZabbixAPIConnector {
params.tags = tags;
}

if (evaltype) {
params.evaltype = evaltype;
}

if (limit) {
params.limit = limit;
}
Expand Down

0 comments on commit 7af3dca

Please sign in to comment.