11import _ from 'lodash' ;
22import moment from 'moment' ;
3+ import semver from 'semver' ;
34import * as utils from '../utils' ;
45import responseHandler from '../responseHandler' ;
56import { CachingProxy } from './proxy/cachingProxy' ;
@@ -29,7 +30,7 @@ const REQUESTS_TO_CACHE = [
2930
3031const REQUESTS_TO_BIND = [
3132 'getHistory' , 'getTrend' , 'getMacros' , 'getItemsByIDs' , 'getEvents' , 'getAlerts' , 'getHostAlerts' ,
32- 'getAcknowledges' , 'getITService' , 'getVersion' , ' acknowledgeEvent', 'getProxies' , 'getEventAlerts' ,
33+ 'getAcknowledges' , 'getITService' , 'acknowledgeEvent' , 'getProxies' , 'getEventAlerts' ,
3334 'getExtendedEventData' , 'getScripts' , 'executeScript' , 'getValueMappings'
3435] ;
3536
@@ -40,6 +41,7 @@ export class Zabbix implements ZabbixConnector {
4041 getHistoryDB : any ;
4142 dbConnector : any ;
4243 getTrendsDB : any ;
44+ version : string ;
4345
4446 getHistory : ( items , timeFrom , timeTill ) => Promise < any > ;
4547 getTrend : ( items , timeFrom , timeTill ) => Promise < any > ;
@@ -54,7 +56,6 @@ export class Zabbix implements ZabbixConnector {
5456 getEventAlerts : ( eventids ) => Promise < any > ;
5557 getExtendedEventData : ( eventids ) => Promise < any > ;
5658 getMacros : ( hostids : any [ ] ) => Promise < any > ;
57- getVersion : ( ) => Promise < string > ;
5859 getValueMappings : ( ) => Promise < any > ;
5960
6061 constructor ( options ) {
@@ -168,6 +169,17 @@ export class Zabbix implements ZabbixConnector {
168169 } ) ;
169170 }
170171
172+ async getVersion ( ) {
173+ if ( ! this . version ) {
174+ this . version = await this . zabbixAPI . initVersion ( ) ;
175+ }
176+ return this . version ;
177+ }
178+
179+ supportsApplications ( ) {
180+ return this . version ? semver . lt ( this . version , '5.4.0' ) : true ;
181+ }
182+
171183 getItemsFromTarget ( target , options ) {
172184 const parts = [ 'group' , 'host' , 'application' , 'item' ] ;
173185 const filters = _ . map ( parts , p => target [ p ] . filter ) ;
@@ -218,19 +230,27 @@ export class Zabbix implements ZabbixConnector {
218230 /**
219231 * Get list of applications belonging to given groups and hosts.
220232 */
221- getAllApps ( groupFilter , hostFilter ) {
233+ async getAllApps ( groupFilter , hostFilter ) {
234+ await this . getVersion ( ) ;
235+ if ( ! this . supportsApplications ( ) ) {
236+ return [ ] ;
237+ }
238+
222239 return this . getHosts ( groupFilter , hostFilter )
223240 . then ( hosts => {
224241 const hostids = _ . map ( hosts , 'hostid' ) ;
225242 return this . zabbixAPI . getApps ( hostids ) ;
226243 } ) ;
227244 }
228245
229- getApps ( groupFilter ?, hostFilter ?, appFilter ?) : Promise < AppsResponse > {
246+ async getApps ( groupFilter ?, hostFilter ?, appFilter ?) : Promise < AppsResponse > {
247+ await this . getVersion ( ) ;
248+ const skipAppFilter = ! this . supportsApplications ( ) ;
249+
230250 return this . getHosts ( groupFilter , hostFilter )
231251 . then ( hosts => {
232252 const hostids = _ . map ( hosts , 'hostid' ) ;
233- if ( appFilter ) {
253+ if ( appFilter && ! skipAppFilter ) {
234254 return this . zabbixAPI . getApps ( hostids )
235255 . then ( apps => filterByQuery ( apps , appFilter ) ) ;
236256 } else {
0 commit comments