Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions action.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ type ActionGetParams struct {
//
// ErrNotFound is returned if the search result set is empty.
// An error is returned if a transport, parsing or API error occurs.
func (c *Session) GetActions(params ActionGetParams) ([]Action, error) {
func (s *Session) GetActions(params ActionGetParams) ([]Action, error) {
actions := make([]jAction, 0)
err := c.Get("action.get", params, &actions)
err := s.Get("action.get", params, &actions)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ type AlertGetParams struct {
//
// ErrNotFound is returned if the search result set is empty.
// An error is returned if a transport, parsing or API error occurs.
func (c *Session) GetAlerts(params AlertGetParams) ([]Alert, error) {
func (s *Session) GetAlerts(params AlertGetParams) ([]Alert, error) {
alerts := make([]jAlert, 0)
err := c.Get("alert.get", params, &alerts)
err := s.Get("alert.get", params, &alerts)
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions bool.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package zabbix

import (
"errors"
"fmt"
)

Expand All @@ -14,7 +13,7 @@ func (bit *ZBXBoolean) UnmarshalJSON(data []byte) error {
} else if asString == "0" || asString == "false" {
*bit = false
} else {
return errors.New(fmt.Sprintf("Boolean unmarshal error: invalid input %s", asString))
return fmt.Errorf("boolean unmarshal error: invalid input %s", asString)
}
return nil
}
4 changes: 2 additions & 2 deletions client_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package zabbix

import (
"fmt"
"io/ioutil"
"os"
"testing"
)

Expand All @@ -13,7 +13,7 @@ const (
)

func prepareTemporaryDir(t *testing.T) (dir string, success bool) {
tempDir, err := ioutil.TempDir("", "zabbix-session-test")
tempDir, err := os.MkdirTemp("", "zabbix-session-test")

if err != nil {
t.Fatalf("cannot create a temporary dir for session cache: %v", err)
Expand Down
2 changes: 1 addition & 1 deletion debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

// debug caches the value of environment variable ZBX_DEBUG from program start.
var debug bool = (os.Getenv("ZBX_DEBUG") == "1")
var debug = (os.Getenv("ZBX_DEBUG") == "1")

// dprintf prints formatted debug message to STDERR if the ZBX_DEBUG environment
// variable is set to "1".
Expand Down
1 change: 0 additions & 1 deletion doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,5 @@ through to v3.0 without introducing limitations to the native API methods.
}

For more information see: https://github.com/cavaliercoder/go-zabbix

*/
package zabbix
4 changes: 2 additions & 2 deletions event.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ type EventGetParams struct {
//
// ErrEventNotFound is returned if the search result set is empty.
// An error is returned if a transport, parsing or API error occurs.
func (c *Session) GetEvents(params EventGetParams) ([]Event, error) {
func (s *Session) GetEvents(params EventGetParams) ([]Event, error) {
events := make([]jEvent, 0)
err := c.Get("event.get", params, &events)
err := s.Get("event.get", params, &events)
if err != nil {
return nil, err
}
Expand Down
20 changes: 10 additions & 10 deletions file_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package zabbix
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"time"
)
Expand All @@ -12,14 +11,15 @@ import (
cachedSessionData represents a model of cached session.

Example:
{
"createdAt": 1530056885,
"session": {
"url": "...",
"token": "...",
"apiVersion": "..."

{
"createdAt": 1530056885,
"session": {
"url": "...",
"token": "...",
"apiVersion": "..."
}
}
}
*/
type cachedSessionContainer struct {
CreatedAt int64 `json:"createdAt"`
Expand Down Expand Up @@ -63,12 +63,12 @@ func (c *SessionFileCache) SaveSession(session *Session) error {
return err
}

return ioutil.WriteFile(c.filePath, []byte(serialized), os.FileMode(c.filePermissions))
return os.WriteFile(c.filePath, []byte(serialized), os.FileMode(c.filePermissions))
}

// GetSession returns cached Zabbix session
func (c *SessionFileCache) GetSession() (*Session, error) {
contents, err := ioutil.ReadFile(c.filePath)
contents, err := os.ReadFile(c.filePath)

if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions history.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ type HistoryGetParams struct {
//
// ErrEventNotFound is returned if the search result set is empty.
// An error is returned if a transport, parsing or API error occurs.
func (c *Session) GetHistories(params HistoryGetParams) ([]History, error) {
func (s *Session) GetHistories(params HistoryGetParams) ([]History, error) {
histories := make([]jHistory, 0)
err := c.Get("history.get", params, &histories)
err := s.Get("history.get", params, &histories)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions host.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ type HostGetParams struct {
//
// ErrEventNotFound is returned if the search result set is empty.
// An error is returned if a transport, parsing or API error occurs.
func (c *Session) GetHosts(params HostGetParams) ([]Host, error) {
func (s *Session) GetHosts(params HostGetParams) ([]Host, error) {
hosts := make([]Host, 0)
err := c.Get("host.get", params, &hosts)
err := s.Get("host.get", params, &hosts)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions host_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ type HostInterfaceGetParams struct {
//
// ErrEventNotFound is returned if the search result set is empty.
// An error is returned if a transport, parsing or API error occurs.
func (c *Session) GetHostInterfaces(params HostInterfaceGetParams) ([]HostInterface, error) {
func (s *Session) GetHostInterfaces(params HostInterfaceGetParams) ([]HostInterface, error) {
hostInterfaces := make([]HostInterface, 0)
err := c.Get("hostinterface.get", params, &hostInterfaces)
err := s.Get("hostinterface.get", params, &hostInterfaces)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions hostgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ type HostgroupGetParams struct {
//
// ErrEventNotFound is returned if the search result set is empty.
// An error is returned if a transport, parsing or API error occurs.
func (c *Session) GetHostgroups(params HostgroupGetParams) ([]Hostgroup, error) {
func (s *Session) GetHostgroups(params HostgroupGetParams) ([]Hostgroup, error) {
hostgroups := make([]jHostgroup, 0)
err := c.Get("hostgroup.get", params, &hostgroups)
err := s.Get("hostgroup.get", params, &hostgroups)
if err != nil {
return nil, err
}
Expand Down
1 change: 0 additions & 1 deletion hostgroup_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ func (c *jHostgroup) Hostgroup() (*Hostgroup, error) {
if hosts, err := c.Hosts.Hosts(); err == nil {
hostgroup.Hosts = hosts
}

}

return hostgroup, nil
Expand Down
4 changes: 2 additions & 2 deletions item.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ type ItemGetParams struct {
//
// ErrEventNotFound is returned if the search result set is empty.
// An error is returned if a transport, parsing or API error occurs.
func (c *Session) GetItems(params ItemGetParams) ([]Item, error) {
func (s *Session) GetItems(params ItemGetParams) ([]Item, error) {
items := make([]jItem, 0)
err := c.Get("item.get", params, &items)
err := s.Get("item.get", params, &items)
if err != nil {
return nil, err
}
Expand Down
12 changes: 6 additions & 6 deletions item_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import (
// jItem is a private map for the Zabbix API Host object.
// See: https://www.zabbix.com/documentation/4.0/manual/api/reference/item/get
type jItem struct {
HostID string `json:"hostid,omitempty"`
ItemID string `json:"itemid"`
ItemName string `json:"name"`
ItemDescr string `json:"description,omitempty"`
LastClock string `json:"lastclock,omitempty"`
LastValue string `json:"lastvalue,omitempty"`
HostID string `json:"hostid,omitempty"`
ItemID string `json:"itemid"`
ItemName string `json:"name"`
ItemDescr string `json:"description,omitempty"`
LastClock string `json:"lastclock,omitempty"`
LastValue string `json:"lastvalue,omitempty"`
LastValueType string `json:"value_type"`
}

Expand Down
22 changes: 11 additions & 11 deletions maintenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
type MaintenanceType int
type TagsEvaltype int

var ErrMaintenanceHostNotFound = errors.New("Failed to find ID by host name")
var ErrMaintenanceHostNotFound = errors.New("failed to find ID by host name")

const (
withDataCollection MaintenanceType = iota
Expand Down Expand Up @@ -131,7 +131,7 @@ func (m *MaintenanceCreateParams) FillHostIDs(session *Session) error {
err = ErrMaintenanceHostNotFound
for _, name := range m.HostNames {
for _, host := range hosts {
if strings.ToUpper(strings.Trim(host.Hostname, " ")) == strings.ToUpper(strings.Trim(name, " ")) {
if strings.EqualFold(strings.Trim(host.Hostname, " "), strings.Trim(name, " ")) {
m.HostIDs = append(m.HostIDs, host.HostID)

err = nil
Expand All @@ -142,14 +142,14 @@ func (m *MaintenanceCreateParams) FillHostIDs(session *Session) error {
return err
}

func (c *MaintenanceCreateParams) FillFields(Object *Maintenance) *MaintenanceCreateParams {
c.ActiveSince = Object.ActiveSince.Unix()
c.ActiveTill = Object.ActiveSince.Add(time.Hour * time.Duration(Object.ServicePeriod)).Unix()
c.Description = Object.Description
c.MaintenanceID = Object.MaintenanceID
c.Name = Object.Name
c.TagsEvaltype = int(Object.Type)
c.MaintenanceType = int(Object.ActionEvalTypeAndOr)
func (m *MaintenanceCreateParams) FillFields(Object *Maintenance) *MaintenanceCreateParams {
m.ActiveSince = Object.ActiveSince.Unix()
m.ActiveTill = Object.ActiveSince.Add(time.Hour * time.Duration(Object.ServicePeriod)).Unix()
m.Description = Object.Description
m.MaintenanceID = Object.MaintenanceID
m.Name = Object.Name
m.TagsEvaltype = int(Object.Type)
m.MaintenanceType = int(Object.ActionEvalTypeAndOr)

return c
return m
}
3 changes: 1 addition & 2 deletions select_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ type SelectQuery interface{}
//
// For example, for a Host search query:
//
// query := SelectFields{ "hostid", "host", "name" }
//
// query := SelectFields{ "hostid", "host", "name" }
type SelectFields []string

const (
Expand Down
Loading