Merge branch 'panel-triggers' into grafana-3.0
This commit is contained in:
@@ -28,6 +28,19 @@ function (angular, _, utils) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Build trigger query in asynchronous manner
|
||||
*/
|
||||
this.buildTriggerQuery = function (groupFilter, hostFilter, appFilter) {
|
||||
if (this.cache._initialized) {
|
||||
return $q.when(self.buildTriggerQueryFromCache(groupFilter, hostFilter, appFilter));
|
||||
} else {
|
||||
return this.cache.refresh().then(function() {
|
||||
return self.buildTriggerQueryFromCache(groupFilter, hostFilter, appFilter);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
this.filterGroups = function(groupFilter) {
|
||||
return self.cache.getGroups().then(function(groupList) {
|
||||
return groupList;
|
||||
@@ -309,6 +322,60 @@ function (angular, _, utils) {
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Build query - convert target filters to array of Zabbix items
|
||||
*/
|
||||
this.buildTriggerQueryFromCache = function (groupFilter, hostFilter, appFilter) {
|
||||
var promises = [
|
||||
this.filterGroups(groupFilter).then(function(groups) {
|
||||
return _.filter(groups, function(group) {
|
||||
if (utils.isRegex(groupFilter)) {
|
||||
return utils.buildRegex(groupFilter).test(group.name);
|
||||
} else {
|
||||
return group.name === groupFilter;
|
||||
}
|
||||
});
|
||||
}),
|
||||
this.filterHosts(groupFilter).then(function(hosts) {
|
||||
return _.filter(hosts, function(host) {
|
||||
if (utils.isRegex(hostFilter)) {
|
||||
return utils.buildRegex(hostFilter).test(host.name);
|
||||
} else {
|
||||
return host.name === hostFilter;
|
||||
}
|
||||
});
|
||||
}),
|
||||
this.filterApplications(groupFilter, hostFilter).then(function(apps) {
|
||||
return _.filter(apps, function(app) {
|
||||
if (utils.isRegex(appFilter)) {
|
||||
return utils.buildRegex(appFilter).test(app.name);
|
||||
} else {
|
||||
return app.name === appFilter;
|
||||
}
|
||||
});
|
||||
})
|
||||
];
|
||||
|
||||
return $q.all(promises).then(function(results) {
|
||||
var filteredGroups = results[0];
|
||||
var filteredHosts = results[1];
|
||||
var filteredApps = results[2];
|
||||
var query = {};
|
||||
|
||||
if (appFilter) {
|
||||
query.applicationids = _.flatten(_.map(filteredApps, 'applicationids'));
|
||||
}
|
||||
if (hostFilter) {
|
||||
query.hostids = _.map(filteredHosts, 'hostid');
|
||||
}
|
||||
if (groupFilter) {
|
||||
query.groupids = _.map(filteredGroups, 'groupid');
|
||||
}
|
||||
|
||||
return query;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert Zabbix API history.get response to Grafana format
|
||||
*
|
||||
|
||||
@@ -296,49 +296,44 @@ function (angular, _) {
|
||||
return this.request('service.getsla', params);
|
||||
};
|
||||
|
||||
p.getTriggers = function(limit, sortfield, groupids, hostids, applicationids, name) {
|
||||
p.getTriggers = function(groupids, hostids, applicationids, showEvents) {
|
||||
var params = {
|
||||
output: 'extend',
|
||||
expandDescription: true,
|
||||
expandData: true,
|
||||
monitored: true,
|
||||
//only_true: true,
|
||||
filter: {
|
||||
value: 1
|
||||
},
|
||||
search : {
|
||||
description: name
|
||||
},
|
||||
searchWildcardsEnabled: false,
|
||||
groupids: groupids,
|
||||
hostids: hostids,
|
||||
applicationids: applicationids,
|
||||
limit: limit,
|
||||
sortfield: 'lastchange',
|
||||
sortorder: 'DESC'
|
||||
expandDescription: true,
|
||||
expandData: true,
|
||||
monitored: true,
|
||||
skipDependent: true,
|
||||
//only_true: true,
|
||||
filter: {
|
||||
value: showEvents
|
||||
},
|
||||
selectGroups: ['name'],
|
||||
selectHosts: ['name'],
|
||||
selectItems: ['name', 'key_', 'lastvalue'],
|
||||
selectLastEvent: 'extend'
|
||||
};
|
||||
|
||||
if (sortfield) {
|
||||
params.sortfield = sortfield;
|
||||
}
|
||||
|
||||
return this.request('trigger.get', params);
|
||||
};
|
||||
|
||||
p.getAcknowledges = function(triggerids, from) {
|
||||
p.getAcknowledges = function(eventids) {
|
||||
var params = {
|
||||
output: 'extend',
|
||||
objectids: triggerids,
|
||||
acknowledged: true,
|
||||
eventids: eventids,
|
||||
preservekeys: true,
|
||||
select_acknowledges: 'extend',
|
||||
sortfield: 'clock',
|
||||
sortorder: 'DESC',
|
||||
time_from: from
|
||||
sortorder: 'DESC'
|
||||
};
|
||||
|
||||
return this.request('event.get', params)
|
||||
.then(function (events) {
|
||||
return _.flatten(_.map(events, 'acknowledges'));
|
||||
return _.filter(events, function(event) {
|
||||
return event.acknowledges.length;
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user