Skip to content

Commit

Permalink
Use new syntax for triggers (required since Zabbix v5.4)
Browse files Browse the repository at this point in the history
  • Loading branch information
pdecat committed Oct 4, 2022
1 parent 40d2e7c commit 7842dd8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 6 additions & 2 deletions base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,19 @@ func testGetAPI(t *testing.T) *zapi.API {
return _api
}

func skipTestIfVersionGreaterThanOrEqual(t *testing.T, comparedVersion, msg string) {
func isVersionGreaterThanOrEqual(t *testing.T, comparedVersion string) (bool, string) {
api := testGetAPI(t)
serverVersion, err := api.Version()
if err != nil {
t.Fatal(err)
}
sVersion, _ := version.NewVersion(serverVersion)
cVersion, _ := version.NewVersion(comparedVersion)
if sVersion.GreaterThanOrEqual(cVersion) {
return sVersion.GreaterThanOrEqual(cVersion), serverVersion
}

func skipTestIfVersionGreaterThanOrEqual(t *testing.T, comparedVersion, msg string) {
if compGreaterThanOrEqual, serverVersion := isVersionGreaterThanOrEqual(t, comparedVersion); compGreaterThanOrEqual {
t.Skipf("Zabbix version %s is greater than or equal to %s which %s, skipping test.", serverVersion, comparedVersion, msg)
}
}
Expand Down
8 changes: 7 additions & 1 deletion trigger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ import (
)

func testCreateTrigger(item *zapi.Item, host *zapi.Host, t *testing.T) *zapi.Trigger {
expression := fmt.Sprintf("{%s:%s.last()}=0", host.Host, item.Key)
var expression string
if compGreaterThanOrEqual, _ := isVersionGreaterThanOrEqual(t, "5.4"); compGreaterThanOrEqual {
expression = fmt.Sprintf("last(/%s/%s)=0", host.Host, item.Key)
} else {
expression = fmt.Sprintf("{%s:%s.last()}=0", host.Host, item.Key)
}

triggers := zapi.Triggers{{
Description: "trigger description",
Expression: expression,
Expand Down

0 comments on commit 7842dd8

Please sign in to comment.