zabbix-tools / go-zabbix

Go bindings for the Zabbix API
GNU General Public License v2.0
106 stars 70 forks source link

EventIDs filter not working #43

Open deqlz opened 3 years ago

deqlz commented 3 years ago
OS: Windows 10 Corporate (20H2)
Zabbix: 4.4.3
Сonnection: via Checkpoint VPN

I am trying to get an Event with a given event_id from Zabbix. An event with this id exists and is currently active. Connection to Zabbix is successful. Moreover, if I remove the EventIDs filter, it finds more than 600 events. But (!) I cannot access some of them directly from the Zabbix web interface under the same user.

Code:

session, err := zabbix.NewSession("zabbix_url/api_jsonrpc.php", "user", "password")
if err != nil {
    panic(err)
}

var event_ids []string = []string{"2589270"}
params := zabbix.EventGetParams{
    EventIDs:               event_ids,
}
events, err := session.GetEvents(params)
fmt.Println(events)

Out:

[]

Errors:

2021/07/06 18:49:09 Error getting events: No results were found matching the given search parameters
2021/07/06 18:49:09 No events found
2021/07/06 18:49:09 Validated 0 Events

What could be the problem?

At the same time, everything works correctly from curl: screenshot

deqlz commented 3 years ago

Code:

jparams, err := json.Marshal(params)
os.Stdout.Write(jparams)

Returns:

{"eventids":["2589270"],"object":0,"acknowledged":false}

It has been empirically established that the problem lies in the acknowledged parameter. If it is set to false, the event is not found. If it is set to true, the event is found. Curl exhibits the same behavior. The problem is that the acknowledged parameter is set by default to either true or false. And I cannot remove it.
As planned by zabbix api (I guess), if this parameter is set to false, all events should be returned. If the parameter is set to true, then only acknowledged events should be returned. But it doesn't work as intended.