Fix problems list panel error in new Grafana version
This commit is contained in:
@@ -12,6 +12,7 @@ import { ProblemDTO, ZBXTag } from '../../../datasource-zabbix/types';
|
|||||||
import { ModalController } from '../../../components';
|
import { ModalController } from '../../../components';
|
||||||
import { DataSourceRef } from '@grafana/data';
|
import { DataSourceRef } from '@grafana/data';
|
||||||
import { Tooltip } from '@grafana/ui';
|
import { Tooltip } from '@grafana/ui';
|
||||||
|
import { getDataSourceSrv } from '@grafana/runtime';
|
||||||
|
|
||||||
interface AlertCardProps {
|
interface AlertCardProps {
|
||||||
problem: ProblemDTO;
|
problem: ProblemDTO;
|
||||||
@@ -48,6 +49,12 @@ export default class AlertCard extends PureComponent<AlertCardProps> {
|
|||||||
const lastchange = formatLastChange(problem.timestamp, panelOptions.customLastChangeFormat && panelOptions.lastChangeFormat);
|
const lastchange = formatLastChange(problem.timestamp, panelOptions.customLastChangeFormat && panelOptions.lastChangeFormat);
|
||||||
const age = moment.unix(problem.timestamp).fromNow(true);
|
const age = moment.unix(problem.timestamp).fromNow(true);
|
||||||
|
|
||||||
|
let dsName: string = (problem.datasource as string);
|
||||||
|
if ((problem.datasource as DataSourceRef)?.uid) {
|
||||||
|
const dsInstance = getDataSourceSrv().getInstanceSettings((problem.datasource as DataSourceRef).uid);
|
||||||
|
dsName = dsInstance.name;
|
||||||
|
}
|
||||||
|
|
||||||
let newProblem = false;
|
let newProblem = false;
|
||||||
if (panelOptions.highlightNewerThan) {
|
if (panelOptions.highlightNewerThan) {
|
||||||
newProblem = isNewProblem(problem, panelOptions.highlightNewerThan);
|
newProblem = isNewProblem(problem, panelOptions.highlightNewerThan);
|
||||||
@@ -87,7 +94,7 @@ export default class AlertCard extends PureComponent<AlertCardProps> {
|
|||||||
<EventTag
|
<EventTag
|
||||||
key={tag.tag + tag.value}
|
key={tag.tag + tag.value}
|
||||||
tag={tag}
|
tag={tag}
|
||||||
datasource={problem.datasource}
|
datasource={dsName}
|
||||||
highlight={tag.tag === problem.correlation_tag}
|
highlight={tag.tag === problem.correlation_tag}
|
||||||
onClick={this.handleTagClick}
|
onClick={this.handleTagClick}
|
||||||
/>
|
/>
|
||||||
@@ -125,7 +132,7 @@ export default class AlertCard extends PureComponent<AlertCardProps> {
|
|||||||
<div className="alert-rule-item__time zabbix-trigger-source">
|
<div className="alert-rule-item__time zabbix-trigger-source">
|
||||||
<span>
|
<span>
|
||||||
<i className="fa fa-database"></i>
|
<i className="fa fa-database"></i>
|
||||||
{problem.datasource}
|
{dsName}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { ProblemsPanelOptions, GFTimeRange } from '../../types';
|
|||||||
import { AckProblemData } from '../AckModal';
|
import { AckProblemData } from '../AckModal';
|
||||||
import AlertCard from './AlertCard';
|
import AlertCard from './AlertCard';
|
||||||
import { ProblemDTO, ZBXTag } from '../../../datasource-zabbix/types';
|
import { ProblemDTO, ZBXTag } from '../../../datasource-zabbix/types';
|
||||||
|
import { DataSourceRef } from '@grafana/data';
|
||||||
|
|
||||||
export interface AlertListProps {
|
export interface AlertListProps {
|
||||||
problems: ProblemDTO[];
|
problems: ProblemDTO[];
|
||||||
@@ -67,9 +68,9 @@ export default class AlertList extends PureComponent<AlertListProps, AlertListSt
|
|||||||
<div className="triggers-panel-container" key="alertListContainer">
|
<div className="triggers-panel-container" key="alertListContainer">
|
||||||
<section className="card-section card-list-layout-list">
|
<section className="card-section card-list-layout-list">
|
||||||
<ol className={alertListClass}>
|
<ol className={alertListClass}>
|
||||||
{currentProblems.map(problem =>
|
{currentProblems.map((problem, index) =>
|
||||||
<AlertCard
|
<AlertCard
|
||||||
key={`${problem.triggerid}-${problem.eventid}-${problem.datasource}`}
|
key={`${problem.triggerid}-${problem.eventid}-${(problem.datasource as DataSourceRef)?.uid || problem.datasource}-${index}`}
|
||||||
problem={problem}
|
problem={problem}
|
||||||
panelOptions={panelOptions}
|
panelOptions={panelOptions}
|
||||||
onTagClick={this.handleTagClick}
|
onTagClick={this.handleTagClick}
|
||||||
|
|||||||
Reference in New Issue
Block a user