Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to fix zabbix-6.2 at 20220707 #2

Merged
merged 16 commits into from
Jul 7, 2022
Merged
4 changes: 2 additions & 2 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

strategy:
matrix:
node-version: [16.x]
node-version: [16]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
Expand All @@ -25,7 +25,7 @@ jobs:
uses: actions/setup-go@v3
with:
# The Go version to download (if necessary) and use. Supports semver spec and ranges.
go-version: 1.17 # optional
go-version: 1.18 # optional
# Path to the go.mod file.

- name: Use Node.js ${{ matrix.node-version }}
Expand Down
21 changes: 0 additions & 21 deletions pkg/zabbix/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,28 +390,7 @@ func (ds *Zabbix) GetAllHosts(ctx context.Context, groupids []string) ([]Host, e
err = convertTo(result, &hosts)
return hosts, err
}
/*
func (ds *Zabbix) GetAllGroups(ctx context.Context) ([]Group, error) {
params := ZabbixAPIParams{
"output": []string{"name"},
"sortfield": "name",
"real_hosts": true,
}

result, err := ds.Request(ctx, &ZabbixAPIRequest{Method: "hostgroup.get", Params: params})
if err != nil {
return nil, err
}

var groups []Group
err = convertTo(result, &groups)
return groups, err
}




*/
func (ds *Zabbix) GetAllGroups(ctx context.Context) ([]Group, error) {
params := ZabbixAPIParams{}
if ds.version >= 62 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ export class ZabbixAPIConnector {
return semver.gte(this.version, '5.4.0');
}

isZabbix62OrHigher() {
return semver.gte(this.version, '6.2.0');
}


////////////////////////////////
// Zabbix API method wrappers //
////////////////////////////////
Expand Down Expand Up @@ -139,14 +144,14 @@ export class ZabbixAPIConnector {

let paramL: any;
console.log("get groups");
if (semver.gte(this.version, '6.2.0'))
if (this.isZabbix62OrHigher())
{
paramL = {
output: ['name'],
sortfield: 'name',
with_monitored_hosts: true
};
console.log("6.2.0");
console.log(this.version);
}

else
Expand All @@ -158,24 +163,34 @@ export class ZabbixAPIConnector {
};
console.log(this.version);
}

console.log("getGroups request paramL");
console.log(paramL);
console.log("getGroups request response");
console.log(this.request('hostgroup.get', paramL));

const params = paramL;

return this.request('hostgroup.get', params);
return this.request('hostgroup.get', paramL);
}

getHosts(groupids) {
const params: any = {
output: ['name', 'host'],
sortfield: 'name'
};
if (groupids) {
console.log("getHosts groupids");
console.log(groupids);

if (groupids != null) {
params.groupids = groupids;
}
let reqret: any;
console.log(params);
reqret = this.request('host.get', params);
console.log(reqret);

console.log("getHosts request paramL");
console.log(params);
console.log("getHosts request response");
console.log(this.request('host.get', params));

return reqret
}

Expand Down Expand Up @@ -522,7 +537,7 @@ export class ZabbixAPIConnector {
console.log("get triggers by id");
console.log(this.version);

if (semver.gte(this.version, '6.2.0'))
if (this.isZabbix62OrHigher())
{
console.log("gte works");
paramL = {
Expand Down Expand Up @@ -560,9 +575,7 @@ export class ZabbixAPIConnector {
};
}

const params = paramL;

return this.request('trigger.get', params).then(utils.mustArray);
return this.request('trigger.get', paramL).then(utils.mustArray);
}

async getTriggers(groupids, hostids, applicationids, options) {
Expand All @@ -574,7 +587,7 @@ export class ZabbixAPIConnector {
let paramL: any;
console.log("get triggers");
console.log(this.version);
if (semver.gte(this.version, '6.2.0'))
if (this.isZabbix62OrHigher())
{
console.log("gte works 2");
paramL = {
Expand Down Expand Up @@ -622,24 +635,22 @@ export class ZabbixAPIConnector {
};
}

const params = paramL;

if (showTriggers === ShowProblemTypes.Problems) {
params.filter.value = 1;
paramL.filter.value = 1;
} else if (showTriggers === ShowProblemTypes.Recent || showTriggers === ShowProblemTypes.History) {
params.filter.value = [0, 1];
paramL.filter.value = [0, 1];
}

if (maintenance) {
params.maintenance = true;
paramL.maintenance = true;
}

if (timeFrom || timeTo) {
params.lastChangeSince = timeFrom;
params.lastChangeTill = timeTo;
paramL.lastChangeSince = timeFrom;
paramL.lastChangeTill = timeTo;
}

return this.request('trigger.get', params);
return this.request('trigger.get', paramL);
}

getEvents(objectids, timeFrom, timeTo, showEvents, limit) {
Expand Down Expand Up @@ -776,7 +787,7 @@ export class ZabbixAPIConnector {
let paramL: any;
console.log("get host alerts");
console.log(this.version);
if (semver.gte(this.version, '6.2.0'))
if (this.isZabbix62OrHigher())
{
console.log("gte hosts alerts works");
paramL = {
Expand Down Expand Up @@ -812,22 +823,20 @@ export class ZabbixAPIConnector {
};
}

const params = paramL;

if (count && acknowledged !== 0 && acknowledged !== 1) {
params.countOutput = true;
paramL.countOutput = true;
}

if (applicationids && applicationids.length) {
params.applicationids = applicationids;
paramL.applicationids = applicationids;
}

if (timeFrom || timeTo) {
params.lastChangeSince = timeFrom;
params.lastChangeTill = timeTo;
paramL.lastChangeSince = timeFrom;
paramL.lastChangeTill = timeTo;
}

return this.request('trigger.get', params)
return this.request('trigger.get', paramL)
.then((triggers) => {
if (!count || acknowledged === 0 || acknowledged === 1) {
triggers = filterTriggersByAcknowledge(triggers, acknowledged);
Expand Down Expand Up @@ -928,4 +937,4 @@ export class ZabbixAPIError {
toString() {
return this.name + " " + this.data;
}
}
}