-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathexample_test.go
51 lines (43 loc) · 1.12 KB
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package zabbix_test
import (
"log"
http "github.com/vadv/gopher-lua-libs/http"
inspect "github.com/vadv/gopher-lua-libs/inspect"
zabbix "github.com/vadv/gopher-lua-libs/zabbix"
lua "github.com/yuin/gopher-lua"
)
// example zabbix
func Example_package() {
state := lua.NewState()
zabbix.Preload(state)
http.Preload(state)
inspect.Preload(state)
source := `
local zabbix = require("zabbix")
local inspect = require("inspect")
local http = require("http")
local client = http.client({proxy="http://proxy"})
local zbx = zabbix.new({url="http://zabbix.url"}, client)
local err = zbx:login()
-- if err then error(err) end
local response, err = zbx:request("trigger.get",
{
selectHosts = "extend", selectItems = "extend", selectLastEvent="extend",
output = "extend", sortfield = "priority",
filter = {
sortorder="DESC", value="1", status=0
},
expandData = "1"
}
)
-- if err then error(err) end
for k, v in pairs( response ) do
print(inspect(v))
print(v.description)
end
zbx:logout()
`
if err := state.DoString(source); err != nil {
log.Fatal(err.Error())
}
}