Skip to content

Commit

Permalink
Add option for alerting to data source config.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderzobnin committed Mar 5, 2017
1 parent f805213 commit ca63fbe
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 10 deletions.
10 changes: 7 additions & 3 deletions dist/datasource-zabbix/datasource.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/datasource-zabbix/datasource.js.map

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions dist/datasource-zabbix/partials/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,11 @@ <h3 class="page-heading">Zabbix API details</h3>
</input>
</div>
</div>

<div class="gf-form-group">
<h3 class="page-heading">Alerting</h3>
<gf-form-switch class="gf-form width-8"
label="Enable alerting"
checked="ctrl.current.jsonData.alerting">
</gf-form-switch>
</div>
10 changes: 7 additions & 3 deletions dist/test/datasource-zabbix/datasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ var ZabbixAPIDatasource = function () {
var ttl = instanceSettings.jsonData.cacheTTL || '1h';
this.cacheTTL = utils.parseInterval(ttl);

this.alertingEnabled = instanceSettings.jsonData.alerting;

this.zabbix = new Zabbix(this.url, this.username, this.password, this.basicAuth, this.withCredentials, this.cacheTTL);

// Use custom format for template variables
Expand Down Expand Up @@ -108,9 +110,11 @@ var ZabbixAPIDatasource = function () {
var useTrends = timeFrom <= useTrendsFrom && this.trends;

// Get alerts for current panel
this.alertQuery(options).then(function (alert) {
_this.setPanelAlertState(options.panelId, alert.state);
});
if (this.alertingEnabled) {
this.alertQuery(options).then(function (alert) {
_this.setPanelAlertState(options.panelId, alert.state);
});
}

// Create request for each target
var promises = _lodash2.default.map(options.targets, function (target) {
Expand Down
10 changes: 7 additions & 3 deletions src/datasource-zabbix/datasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class ZabbixAPIDatasource {
var ttl = instanceSettings.jsonData.cacheTTL || '1h';
this.cacheTTL = utils.parseInterval(ttl);

this.alertingEnabled = instanceSettings.jsonData.alerting;

this.zabbix = new Zabbix(this.url, this.username, this.password, this.basicAuth, this.withCredentials, this.cacheTTL);

// Use custom format for template variables
Expand All @@ -58,9 +60,11 @@ class ZabbixAPIDatasource {
let useTrends = (timeFrom <= useTrendsFrom) && this.trends;

// Get alerts for current panel
this.alertQuery(options).then(alert => {
this.setPanelAlertState(options.panelId, alert.state);
});
if (this.alertingEnabled) {
this.alertQuery(options).then(alert => {
this.setPanelAlertState(options.panelId, alert.state);
});
}

// Create request for each target
let promises = _.map(options.targets, target => {
Expand Down
8 changes: 8 additions & 0 deletions src/datasource-zabbix/partials/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,11 @@ <h3 class="page-heading">Zabbix API details</h3>
</input>
</div>
</div>

<div class="gf-form-group">
<h3 class="page-heading">Alerting</h3>
<gf-form-switch class="gf-form width-8"
label="Enable alerting"
checked="ctrl.current.jsonData.alerting">
</gf-form-switch>
</div>

0 comments on commit ca63fbe

Please sign in to comment.