From 4abc40e8c204c94f7c68a954b39de8167a6361d7 Mon Sep 17 00:00:00 2001 From: Egor Kovetskiy Date: Thu, 7 Feb 2019 17:17:16 +0300 Subject: [PATCH] get rid of archived hierr-go package --- handle_latest_data.go | 6 +++--- handle_triggers.go | 14 +++++++------- handle_users_groups.go | 18 +++++++++--------- main.go | 4 ++-- responses.go | 4 ++-- zabbix.go | 30 +++++++++++++++--------------- 6 files changed, 38 insertions(+), 38 deletions(-) diff --git a/handle_latest_data.go b/handle_latest_data.go index 20e7c60..732db86 100644 --- a/handle_latest_data.go +++ b/handle_latest_data.go @@ -6,7 +6,7 @@ import ( "os" "text/tabwriter" - "github.com/zazab/hierr" + "github.com/reconquest/karma-go" ) func handleLatestData( @@ -50,7 +50,7 @@ func handleLatestData( ) if err != nil { - return hierr.Errorf( + return karma.Format( err, "can't obtain zabbix hosts", ) @@ -112,7 +112,7 @@ func handleLatestData( ) if err != nil { - return hierr.Errorf( + return karma.Format( err, "can't obtain zabbix items", ) diff --git a/handle_triggers.go b/handle_triggers.go index f096119..652eb61 100644 --- a/handle_triggers.go +++ b/handle_triggers.go @@ -6,8 +6,8 @@ import ( "strings" "text/tabwriter" + "github.com/reconquest/karma-go" "github.com/simplereach/timeutils" - "github.com/zazab/hierr" ) type ExtendedOutput int @@ -56,7 +56,7 @@ func handleTriggers( }, ) if err != nil { - return hierr.Errorf( + return karma.Format( err, "can't obtain zabbix triggers", ) @@ -67,7 +67,7 @@ func handleTriggers( if extended != ExtendedOutputNone { history, err = getTriggerItemsHistory(zabbix, triggers) if err != nil { - return hierr.Errorf( + return karma.Format( err, `can't obtain history for items of triggers`, ) @@ -140,7 +140,7 @@ func handleTriggers( ) if err != nil { - return hierr.Errorf( + return karma.Format( err, "can't acknowledge triggers %s", identifiers, @@ -169,7 +169,7 @@ func getTriggerItemsHistory( "itemids": itemIDs, }) if err != nil { - return nil, hierr.Errorf( + return nil, karma.Format( err, `can't obtain items of triggers`, ) @@ -185,7 +185,7 @@ func getTriggerItemsHistory( "limit": 1, }) if err != nil { - return hierr.Errorf( + return karma.Format( err, `can't obtain history (type '%s') for item '%s'`, item.ValueType, @@ -260,7 +260,7 @@ func parseParams(args map[string]interface{}) (Params, error) { func parseDateTime(value string) (int64, error) { date, err := timeutils.ParseDateString(value) if err != nil { - return 0, hierr.Errorf(err, "can't parse datetime '%s'", value) + return 0, karma.Format(err, "can't parse datetime '%s'", value) } return date.Unix(), nil diff --git a/handle_users_groups.go b/handle_users_groups.go index bc337c1..45a10eb 100644 --- a/handle_users_groups.go +++ b/handle_users_groups.go @@ -7,7 +7,7 @@ import ( "strings" "text/tabwriter" - "github.com/zazab/hierr" + "github.com/reconquest/karma-go" ) func handleUsersGroups( @@ -37,7 +37,7 @@ func handleUsersGroups( ) if err != nil { - return hierr.Errorf( + return karma.Format( err, "can't obtain users groups %s", groups, ) @@ -80,7 +80,7 @@ func handleUsersGroups( user, err := getUser(zabbix, addUser) if err != nil { - return hierr.Errorf( + return karma.Format( err, "can't obtain user '%s'", addUser, ) @@ -94,7 +94,7 @@ func handleUsersGroups( ) if err != nil { - return hierr.Errorf( + return karma.Format( err, "can't add user '%s' to specified users groups", user.Alias, @@ -110,7 +110,7 @@ func handleUsersGroups( user, err := getUser(zabbix, removeUser) if err != nil { - return hierr.Errorf( + return karma.Format( err, "can't obtain user '%s'", removeUser, ) @@ -124,7 +124,7 @@ func handleUsersGroups( ) if err != nil { - return hierr.Errorf( + return karma.Format( err, "can't remove user '%s' from specified users groups", removeUser, @@ -142,7 +142,7 @@ func getUser(zabbix *Zabbix, username string) (User, error) { }, }) if err != nil { - return User{}, hierr.Errorf( + return User{}, karma.Format( err, "can't obtain user with specified name", ) } @@ -172,7 +172,7 @@ func getUsersGroups(zabbix *Zabbix, groups []string) ([]UserGroup, error) { usersgroups, err := zabbix.GetUsersGroups(params) if err != nil { - return nil, hierr.Errorf( + return nil, karma.Format( err, "can't obtain zabbix users groups", ) @@ -195,7 +195,7 @@ func getUsersGroups(zabbix *Zabbix, groups []string) ([]UserGroup, error) { }, ) if err != nil { - return nil, hierr.Errorf( + return nil, karma.Format( err, "can't obtain users from specified groups %q", usersIdentifiers, diff --git a/main.go b/main.go index 6ff323b..6b012bf 100644 --- a/main.go +++ b/main.go @@ -6,7 +6,7 @@ import ( "github.com/kovetskiy/godocs" "github.com/kovetskiy/lorg" "github.com/kovetskiy/spinner-go" - "github.com/zazab/hierr" + "github.com/reconquest/karma-go" ) var ( @@ -42,7 +42,7 @@ func main() { config, err := NewConfig(args["--config"].(string)) if err != nil { fatalln( - hierr.Errorf( + karma.Format( err, "problem with configuration", ), diff --git a/responses.go b/responses.go index 93457aa..cdeea41 100644 --- a/responses.go +++ b/responses.go @@ -1,6 +1,6 @@ package main -import "github.com/reconquest/hierr-go" +import "github.com/reconquest/karma-go" type Response interface { Error() error @@ -17,7 +17,7 @@ type ResponseRaw struct { func (response *ResponseRaw) Error() error { if response.Err.Data != "" && response.Err.Message != "" { - return hierr.Push( + return karma.Push( response.Err.Message, response.Err.Data, ) diff --git a/zabbix.go b/zabbix.go index d1fdad9..611cddd 100644 --- a/zabbix.go +++ b/zabbix.go @@ -12,7 +12,7 @@ import ( "sync/atomic" "time" - "github.com/zazab/hierr" + "github.com/reconquest/karma-go" ) const ( @@ -59,7 +59,7 @@ func NewZabbix( err = zabbix.restoreSession(sessionFile) if err != nil { - return nil, hierr.Errorf( + return nil, karma.Format( err, "can't restore zabbix session using file '%s'", sessionFile, @@ -72,7 +72,7 @@ func NewZabbix( if zabbix.session == "" { err = zabbix.Login(username, password) if err != nil { - return nil, hierr.Errorf( + return nil, karma.Format( err, "can't authorize user '%s' in zabbix server", username, @@ -88,7 +88,7 @@ func NewZabbix( // always rewrite session file, it will change modify date err = zabbix.saveSession(sessionFile) if err != nil { - return nil, hierr.Errorf( + return nil, karma.Format( err, "can't save zabbix session to file '%s'", ) @@ -103,14 +103,14 @@ func (zabbix *Zabbix) restoreSession(path string) error { path, os.O_CREATE|os.O_RDWR, 0600, ) if err != nil { - return hierr.Errorf( + return karma.Format( err, "can't open session file", ) } stat, err := file.Stat() if err != nil { - return hierr.Errorf( + return karma.Format( err, "can't stat session file", ) } @@ -118,7 +118,7 @@ func (zabbix *Zabbix) restoreSession(path string) error { if time.Now().Sub(stat.ModTime()).Seconds() < ZabbixSessionTTL { session, err := ioutil.ReadAll(file) if err != nil { - return hierr.Errorf( + return karma.Format( err, "can't read session file", ) } @@ -134,7 +134,7 @@ func (zabbix *Zabbix) restoreSession(path string) error { func (zabbix *Zabbix) saveSession(path string) error { err := ioutil.WriteFile(path, []byte(zabbix.session), 0600) if err != nil { - return hierr.Errorf( + return karma.Format( err, "can't write session file", ) @@ -271,7 +271,7 @@ func (zabbix *Zabbix) AddUserToGroups( &ResponseRaw{}, ) if err != nil { - return hierr.Errorf( + return karma.Format( err, "can't update usergroup %s", group.Name, ) @@ -304,7 +304,7 @@ func (zabbix *Zabbix) RemoveUserFromGroups( &ResponseRaw{}, ) if err != nil { - return hierr.Errorf( + return karma.Format( err, "can't update usergroup %s", group.Name, ) @@ -410,7 +410,7 @@ func (zabbix *Zabbix) call( buffer, err := json.Marshal(request) if err != nil { - return hierr.Errorf( + return karma.Format( err, "can't encode request to JSON", ) @@ -422,7 +422,7 @@ func (zabbix *Zabbix) call( bytes.NewReader(buffer), ) if err != nil { - return hierr.Errorf( + return karma.Format( err, "can't create http request", ) @@ -434,7 +434,7 @@ func (zabbix *Zabbix) call( resource, err := zabbix.client.Do(payload) if err != nil { - return hierr.Errorf( + return karma.Format( err, "http request to zabbix api failed", ) @@ -442,7 +442,7 @@ func (zabbix *Zabbix) call( body, err := ioutil.ReadAll(resource.Body) if err != nil { - return hierr.Errorf( + return karma.Format( err, "can't read zabbix api response body", ) @@ -479,7 +479,7 @@ func (zabbix *Zabbix) call( err = response.Error() if err != nil { - return hierr.Errorf( + return karma.Format( err, "zabbix returned error while working with api method %s", method,