Help us shape the future of Go! Take the 2026 Go Developer Survey

zabbix

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 11, 2024 License: BSD-3-Clause Imports: 14 Imported by: 0

README

zabbix GoDoc

Usage

local zabbix = require("zabbix")
local inspect = require("inspect")
local http = require("http")

local client = http.client({proxy="http://proxy", insecure_ssl=true, basic_auth_user="", basic_auth_password=""}) -- override default http client
local zbx = zabbix.new({url="https://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

local item_id = 0
for k, v in pairs(response) do
    if v.hosts and v.hosts[1] and v.items and v.items[1] and v.items[1].value_type == "3" then
        -- print(inspect(v))
        item_id = v.items[1].itemid
        print(v.hosts[1].host, v.description)
    end
end

local err = zbx:save_graph(item_id, "./test/test.png")
if err then error(err) end

Documentation

Overview

Package zabbix implements zabbix api bot for lua.

Example (Package)

example zabbix

package main

import (
	"log"

	http "github.com/lovercode/gopher-lua-libs/http"
	inspect "github.com/lovercode/gopher-lua-libs/inspect"

	zabbix "github.com/lovercode/gopher-lua-libs/zabbix"

	lua "github.com/yuin/gopher-lua"
)

func main() {
	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())
	}
}

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApiVersion

func ApiVersion(L *lua.LState) int

ApiVersion lua zabbix_bot_ud:api_version() returns (string, err)

func Loader

func Loader(L *lua.LState) int

Loader is the module loader function.

func Login

func Login(L *lua.LState) int

Login lua zabbix_bot_ud:login() return error

func Logout

func Logout(L *lua.LState) int

Logout lua zabbix_bot_ud:logout() return error

func NewBot

func NewBot(L *lua.LState) int

NewBot lua zabbix.bot(config table, http_ud.client) return zabbix_bot_ud

config = {
   url = "http://zabbix.url",
   user = "user",
   password = "password",
   debug = true,
}

func Preload

func Preload(L *lua.LState)

Preload adds zabbix to the given Lua state's package.preload table. After it has been preloaded, it can be loaded using require:

local zabbix = require("zabbix")

func Request

func Request(L *lua.LState) int

Request lua zabbix_bot_ud:request(method, params={}) returns (table, err)

func SaveGraph

func SaveGraph(L *lua.LState) int

SaveGraph lua zabbix_bot_ud:save_graph(itemID, filename, {period, width, height}) return err default graph settings {period = 3600, width = 500, height = 300}

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL