Skip to content

Commit

Permalink
AlertSrv is deprecated in Grafana 5.4+ #137 (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
rozetko committed Jan 25, 2019
1 parent 7c0f740 commit dd9ef71
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
35 changes: 20 additions & 15 deletions src/module.ts
Expand Up @@ -145,8 +145,7 @@ class GraphCtrl extends MetricsPanelCtrl {
private keybindingSrv,
private backendSrv: BackendSrv,
private popoverSrv,
private contextSrv,
private alertSrv: AlertSrv
private contextSrv
) {
super($scope, $injector);

Expand All @@ -157,7 +156,7 @@ class GraphCtrl extends MetricsPanelCtrl {

this.processor = new DataProcessor(this.panel);

this.analyticService = new AnalyticService(this.backendURL, $http, this.backendSrv, this.alertSrv);
this.analyticService = new AnalyticService(this.backendURL, $http);

this.runBackendConnectivityCheck();

Expand Down Expand Up @@ -227,21 +226,25 @@ class GraphCtrl extends MetricsPanelCtrl {

async runBackendConnectivityCheck() {
if(this.backendURL === '' || this.backendURL === undefined) {
this.alertSrv.set(
`Dashboard variable $${BACKEND_VARIABLE_NAME} is missing`,
`Please set $${BACKEND_VARIABLE_NAME}`,
'warning', 4000
appEvents.emit(
'alert-warning',
[
`Dashboard variable $${BACKEND_VARIABLE_NAME} is missing`,
`Please set $${BACKEND_VARIABLE_NAME}`
]
);
return;
}

let connected = await this.analyticService.isBackendOk();
if(connected) {
this.updateAnalyticUnitTypes();
this.alertSrv.set(
'Connected to Hastic server',
`Hastic server: "${this.backendURL}"`,
'success', 4000
appEvents.emit(
'alert-success',
[
'Connected to Hastic server',
`Hastic server: "${this.backendURL}"`
]
);
}
}
Expand Down Expand Up @@ -516,10 +519,12 @@ class GraphCtrl extends MetricsPanelCtrl {
panelUrl
);
} catch(e) {
this.alertSrv.set(
'Error while saving analytic unit',
e.message,
'error', 7000
appEvents.emit(
'alert-error',
[
'Error while saving analytic unit',
e.message
]
);
}
this.$scope.$digest();
Expand Down
17 changes: 8 additions & 9 deletions src/services/analytic_service.ts
Expand Up @@ -5,18 +5,15 @@ import { SegmentsSet } from '../models/segment_set';
import { AnalyticUnitId, AnalyticUnit, AnalyticSegment } from '../models/analytic_unit';
import { ServerInfo } from '../models/info';
import { Threshold } from '../models/threshold';
import { BackendSrv } from 'grafana/app/core/services/backend_srv';
import { AlertSrv } from 'grafana/app/core/services/alert_srv';
import { appEvents } from 'grafana/app/core/core';


export class AnalyticService {
private _isUp = false;

constructor(
private _backendURL: string,
private $http,
private _backendSrv: BackendSrv,
private _alertSrv: AlertSrv
private $http
) {
this.isBackendOk();
}
Expand Down Expand Up @@ -202,10 +199,12 @@ export class AnalyticService {
}

private displayConnectionAlert() {
this._alertSrv.set(
'No connection to Hastic server',
`Hastic server: "${this._backendURL}"`,
'warning', 4000
appEvents.emit(
'alert-success',
[
'No connection to Hastic server',
`Hastic server: "${this._backendURL}"`,
]
);
}

Expand Down

0 comments on commit dd9ef71

Please sign in to comment.