Files
grafana-zabbix/src/panel-triggers/utils.ts
Alexander Zobnin 8499d726b2 Fix Explore button, fixes #1240
Also pass dashboard time range to the explore view.
2021-08-09 17:55:37 +03:00

35 lines
1.1 KiB
TypeScript

import _ from 'lodash';
import moment from 'moment';
import { DataQuery } from '@grafana/data';
import * as utils from '../datasource-zabbix/utils';
import { ProblemDTO } from 'datasource-zabbix/types';
export function isNewProblem(problem: ProblemDTO, highlightNewerThan: string): boolean {
try {
const highlightIntervalMs = utils.parseInterval(highlightNewerThan);
const durationSec = (Date.now() - problem.timestamp * 1000);
return durationSec < highlightIntervalMs;
} catch (e) {
return false;
}
}
const DEFAULT_TIME_FORMAT = "DD MMM YYYY HH:mm:ss";
export function formatLastChange(lastchangeUnix: number, customFormat?: string) {
const timestamp = moment.unix(lastchangeUnix);
const format = customFormat || DEFAULT_TIME_FORMAT;
const lastchange = timestamp.format(format);
return lastchange;
}
export const getNextRefIdChar = (queries: DataQuery[]): string => {
const letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
return _.find(letters, refId => {
return _.every(queries, other => {
return other.refId !== refId;
});
});
};