Skip to content

Commit

Permalink
Add name to triggers data frame, fixes #1441
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderzobnin committed Mar 21, 2023
1 parent dd67988 commit 418fe7a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/datasource/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ export class ZabbixDatasource extends DataSourceApi<ZabbixMetricsQuery, ZabbixDS
.then((problems) => problemsHandler.addTriggerHostProxy(problems, proxies));

return problemsPromises.then((problems) => {
const problemsDataFrame = problemsHandler.toDataFrame(problems);
const problemsDataFrame = problemsHandler.toDataFrame(problems, target);
return problemsDataFrame;
});
}
Expand Down
5 changes: 3 additions & 2 deletions src/datasource/problemsHandler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import _ from 'lodash';
import * as utils from './utils';
import { DataFrame, Field, FieldType, ArrayVector } from '@grafana/data';
import { ZBXProblem, ZBXTrigger, ProblemDTO, ZBXEvent } from './types';
import { ZBXProblem, ZBXTrigger, ProblemDTO, ZBXEvent, ZabbixMetricsQuery } from './types';

export function joinTriggersWithProblems(problems: ZBXProblem[], triggers: ZBXTrigger[]): ProblemDTO[] {
const problemDTOList: ProblemDTO[] = [];
Expand Down Expand Up @@ -172,7 +172,7 @@ export function sortProblems(problems: ProblemDTO[], target) {
return problems;
}

export function toDataFrame(problems: any[]): DataFrame {
export function toDataFrame(problems: any[], query: ZabbixMetricsQuery): DataFrame {
const problemsField: Field<any> = {
name: 'Problems',
type: FieldType.other,
Expand All @@ -186,6 +186,7 @@ export function toDataFrame(problems: any[]): DataFrame {

const response: DataFrame = {
name: 'problems',
refId: query?.refId || 'A',
fields: [problemsField],
length: problems.length,
};
Expand Down
3 changes: 3 additions & 0 deletions src/datasource/responseHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ export function handleSLAResponse(itservice, slaProperty, slaObject) {

function handleTriggersResponse(triggers: ZBXTrigger[], groups: ZBXGroup[], timeRange: number[], target) {
if (!_.isArray(triggers)) {
// Handling count mode
let triggersCount = null;
try {
triggersCount = Number(triggers);
Expand All @@ -622,6 +623,7 @@ function handleTriggersResponse(triggers: ZBXTrigger[], groups: ZBXGroup[], time
}

const frame = new MutableDataFrame({
name: `Count ${target.refId}`,
refId: target.refId,
fields: [
{ name: TIME_SERIES_TIME_FIELD_NAME, type: FieldType.time, values: new ArrayVector([timeRange[1] * 1000]) },
Expand All @@ -634,6 +636,7 @@ function handleTriggersResponse(triggers: ZBXTrigger[], groups: ZBXGroup[], time
} else {
const stats = getTriggerStats(triggers);
const frame = new MutableDataFrame({
name: `Triggers ${target.refId}`,
refId: target.refId,
fields: [{ name: 'Host group', type: FieldType.string, values: new ArrayVector() }],
});
Expand Down

0 comments on commit 418fe7a

Please sign in to comment.