Chore: convert ZabbixAPIConnector to TS
This commit is contained in:
@@ -14,6 +14,19 @@ const DEFAULT_ZABBIX_VERSION = '3.0.0';
|
|||||||
* Wraps API calls and provides high-level methods.
|
* Wraps API calls and provides high-level methods.
|
||||||
*/
|
*/
|
||||||
export class ZabbixAPIConnector {
|
export class ZabbixAPIConnector {
|
||||||
|
url: any;
|
||||||
|
username: any;
|
||||||
|
password: any;
|
||||||
|
auth: string;
|
||||||
|
requestOptions: { basicAuth: any; withCredentials: any; };
|
||||||
|
loginPromise: any;
|
||||||
|
loginErrorCount: number;
|
||||||
|
maxLoginAttempts: number;
|
||||||
|
zabbixAPICore: ZabbixAPICore;
|
||||||
|
getTrend: (items: any, timeFrom: any, timeTill: any) => Promise<any[]>;
|
||||||
|
version: any;
|
||||||
|
getVersionPromise: any;
|
||||||
|
|
||||||
constructor(api_url, username, password, basicAuth, withCredentials) {
|
constructor(api_url, username, password, basicAuth, withCredentials) {
|
||||||
this.url = api_url;
|
this.url = api_url;
|
||||||
this.username = username;
|
this.username = username;
|
||||||
@@ -132,7 +145,7 @@ export class ZabbixAPIConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getGroups() {
|
getGroups() {
|
||||||
var params = {
|
const params = {
|
||||||
output: ['name'],
|
output: ['name'],
|
||||||
sortfield: 'name',
|
sortfield: 'name',
|
||||||
real_hosts: true
|
real_hosts: true
|
||||||
@@ -142,7 +155,7 @@ export class ZabbixAPIConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getHosts(groupids) {
|
getHosts(groupids) {
|
||||||
var params = {
|
const params: any = {
|
||||||
output: ['name', 'host'],
|
output: ['name', 'host'],
|
||||||
sortfield: 'name'
|
sortfield: 'name'
|
||||||
};
|
};
|
||||||
@@ -154,7 +167,7 @@ export class ZabbixAPIConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getApps(hostids) {
|
getApps(hostids) {
|
||||||
var params = {
|
const params = {
|
||||||
output: 'extend',
|
output: 'extend',
|
||||||
hostids: hostids
|
hostids: hostids
|
||||||
};
|
};
|
||||||
@@ -170,7 +183,7 @@ export class ZabbixAPIConnector {
|
|||||||
* @return {[type]} array of items
|
* @return {[type]} array of items
|
||||||
*/
|
*/
|
||||||
getItems(hostids, appids, itemtype) {
|
getItems(hostids, appids, itemtype) {
|
||||||
var params = {
|
const params: any = {
|
||||||
output: [
|
output: [
|
||||||
'name', 'key_',
|
'name', 'key_',
|
||||||
'value_type',
|
'value_type',
|
||||||
@@ -203,7 +216,7 @@ export class ZabbixAPIConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getItemsByIDs(itemids) {
|
getItemsByIDs(itemids) {
|
||||||
var params = {
|
const params = {
|
||||||
itemids: itemids,
|
itemids: itemids,
|
||||||
output: [
|
output: [
|
||||||
'name', 'key_',
|
'name', 'key_',
|
||||||
@@ -221,7 +234,7 @@ export class ZabbixAPIConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getMacros(hostids) {
|
getMacros(hostids) {
|
||||||
var params = {
|
const params = {
|
||||||
output: 'extend',
|
output: 'extend',
|
||||||
hostids: hostids
|
hostids: hostids
|
||||||
};
|
};
|
||||||
@@ -230,7 +243,7 @@ export class ZabbixAPIConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getGlobalMacros() {
|
getGlobalMacros() {
|
||||||
var params = {
|
const params = {
|
||||||
output: 'extend',
|
output: 'extend',
|
||||||
globalmacro: true
|
globalmacro: true
|
||||||
};
|
};
|
||||||
@@ -239,7 +252,7 @@ export class ZabbixAPIConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getLastValue(itemid) {
|
getLastValue(itemid) {
|
||||||
var params = {
|
const params = {
|
||||||
output: ['lastvalue'],
|
output: ['lastvalue'],
|
||||||
itemids: itemid
|
itemids: itemid
|
||||||
};
|
};
|
||||||
@@ -258,10 +271,10 @@ export class ZabbixAPIConnector {
|
|||||||
getHistory(items, timeFrom, timeTill) {
|
getHistory(items, timeFrom, timeTill) {
|
||||||
|
|
||||||
// Group items by value type and perform request for each value type
|
// Group items by value type and perform request for each value type
|
||||||
let grouped_items = _.groupBy(items, 'value_type');
|
const grouped_items = _.groupBy(items, 'value_type');
|
||||||
let promises = _.map(grouped_items, (items, value_type) => {
|
const promises = _.map(grouped_items, (items, value_type) => {
|
||||||
let itemids = _.map(items, 'itemid');
|
const itemids = _.map(items, 'itemid');
|
||||||
let params = {
|
const params: any = {
|
||||||
output: 'extend',
|
output: 'extend',
|
||||||
history: value_type,
|
history: value_type,
|
||||||
itemids: itemids,
|
itemids: itemids,
|
||||||
@@ -293,10 +306,10 @@ export class ZabbixAPIConnector {
|
|||||||
getTrend_ZBXNEXT1193(items, timeFrom, timeTill) {
|
getTrend_ZBXNEXT1193(items, timeFrom, timeTill) {
|
||||||
|
|
||||||
// Group items by value type and perform request for each value type
|
// Group items by value type and perform request for each value type
|
||||||
let grouped_items = _.groupBy(items, 'value_type');
|
const grouped_items = _.groupBy(items, 'value_type');
|
||||||
let promises = _.map(grouped_items, (items, value_type) => {
|
const promises = _.map(grouped_items, (items, value_type) => {
|
||||||
let itemids = _.map(items, 'itemid');
|
const itemids = _.map(items, 'itemid');
|
||||||
let params = {
|
const params: any = {
|
||||||
output: 'extend',
|
output: 'extend',
|
||||||
trend: value_type,
|
trend: value_type,
|
||||||
itemids: itemids,
|
itemids: itemids,
|
||||||
@@ -317,10 +330,10 @@ export class ZabbixAPIConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getTrend_30(items, time_from, time_till, value_type) {
|
getTrend_30(items, time_from, time_till, value_type) {
|
||||||
var self = this;
|
const self = this;
|
||||||
var itemids = _.map(items, 'itemid');
|
const itemids = _.map(items, 'itemid');
|
||||||
|
|
||||||
var params = {
|
const params: any = {
|
||||||
output: ["itemid",
|
output: ["itemid",
|
||||||
"clock",
|
"clock",
|
||||||
value_type
|
value_type
|
||||||
@@ -338,7 +351,7 @@ export class ZabbixAPIConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getITService(serviceids) {
|
getITService(serviceids) {
|
||||||
var params = {
|
const params = {
|
||||||
output: 'extend',
|
output: 'extend',
|
||||||
serviceids: serviceids
|
serviceids: serviceids
|
||||||
};
|
};
|
||||||
@@ -355,9 +368,9 @@ export class ZabbixAPIConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getTriggers(groupids, hostids, applicationids, options) {
|
getTriggers(groupids, hostids, applicationids, options) {
|
||||||
let {showTriggers, maintenance, timeFrom, timeTo} = options;
|
const {showTriggers, maintenance, timeFrom, timeTo} = options;
|
||||||
|
|
||||||
let params = {
|
const params: any = {
|
||||||
output: 'extend',
|
output: 'extend',
|
||||||
groupids: groupids,
|
groupids: groupids,
|
||||||
hostids: hostids,
|
hostids: hostids,
|
||||||
@@ -397,7 +410,7 @@ export class ZabbixAPIConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getEvents(objectids, timeFrom, timeTo, showEvents, limit) {
|
getEvents(objectids, timeFrom, timeTo, showEvents, limit) {
|
||||||
var params = {
|
const params: any = {
|
||||||
output: 'extend',
|
output: 'extend',
|
||||||
time_from: timeFrom,
|
time_from: timeFrom,
|
||||||
time_till: timeTo,
|
time_till: timeTo,
|
||||||
@@ -417,7 +430,7 @@ export class ZabbixAPIConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getAcknowledges(eventids) {
|
getAcknowledges(eventids) {
|
||||||
var params = {
|
const params = {
|
||||||
output: 'extend',
|
output: 'extend',
|
||||||
eventids: eventids,
|
eventids: eventids,
|
||||||
preservekeys: true,
|
preservekeys: true,
|
||||||
@@ -433,7 +446,7 @@ export class ZabbixAPIConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getExtendedEventData(eventids) {
|
getExtendedEventData(eventids) {
|
||||||
var params = {
|
const params = {
|
||||||
output: 'extend',
|
output: 'extend',
|
||||||
eventids: eventids,
|
eventids: eventids,
|
||||||
preservekeys: true,
|
preservekeys: true,
|
||||||
@@ -462,7 +475,7 @@ export class ZabbixAPIConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getAlerts(itemids, timeFrom, timeTo) {
|
getAlerts(itemids, timeFrom, timeTo) {
|
||||||
var params = {
|
const params: any = {
|
||||||
output: 'extend',
|
output: 'extend',
|
||||||
itemids: itemids,
|
itemids: itemids,
|
||||||
expandDescription: true,
|
expandDescription: true,
|
||||||
@@ -486,8 +499,8 @@ export class ZabbixAPIConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getHostAlerts(hostids, applicationids, options) {
|
getHostAlerts(hostids, applicationids, options) {
|
||||||
let {minSeverity, acknowledged, count, timeFrom, timeTo} = options;
|
const {minSeverity, acknowledged, count, timeFrom, timeTo} = options;
|
||||||
let params = {
|
const params: any = {
|
||||||
output: 'extend',
|
output: 'extend',
|
||||||
hostids: hostids,
|
hostids: hostids,
|
||||||
min_severity: minSeverity,
|
min_severity: minSeverity,
|
||||||
@@ -528,7 +541,7 @@ export class ZabbixAPIConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getProxies() {
|
getProxies() {
|
||||||
var params = {
|
const params = {
|
||||||
output: ['proxyid', 'host'],
|
output: ['proxyid', 'host'],
|
||||||
};
|
};
|
||||||
|
|
||||||
Reference in New Issue
Block a user