Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix gometalinter issues #24

Merged
merged 6 commits into from
Oct 12, 2019
Merged
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
19 changes: 13 additions & 6 deletions handle_hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ func handleHosts(

}
if len(hostsTable) > 0 {
printHostsTable(hostsTable)
err = printHostsTable(hostsTable)
if err != nil {
debugf("Error: %+v", err)
}
}

}
Expand Down Expand Up @@ -96,7 +99,10 @@ func handleRemoveHosts(
)
}

printHostsTable(hosts)
err = printHostsTable(hosts)
if err != nil {
debugf("Error: %+v", err)
}

if confirmation {
if !confirmHost("removing", removeHost) {
Expand Down Expand Up @@ -147,9 +153,7 @@ func searchHosts(zabbix *Zabbix, hostname string) ([]Host, error) {
return hosts, err
}

func printHostsTable(
hosts []Host,
) error {
func printHostsTable(hosts []Host) error {

var lines = [][]string{}

Expand Down Expand Up @@ -178,6 +182,9 @@ func confirmHost(messages, host string) bool {
host,
)

fmt.Scanln(&value)
_, err := fmt.Scanln(&value)
if err != nil {
debugf("Error: %+v", err)
}
return value == "" || value == "Y" || value == "y"
}
5 changes: 4 additions & 1 deletion handle_latest_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,10 @@ func handleLatestData(
fmt.Println(zabbix.GetNormalGraphURL(matchedItemIDs))

default:
table.Flush()
err = table.Flush()
if err != nil {
debugf("Error: %+v", err)
}
}

return nil
Expand Down
33 changes: 22 additions & 11 deletions handle_maintenances.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@ func handleAddMaintenance(
}
}

printHostsTable(hosts)
err = printHostsTable(hosts)
if err != nil {
debugf("Error: %+v", err)
}

if confirmation {
if !confirmMaintenance("create", addMaintenance) {
Expand Down Expand Up @@ -256,7 +259,10 @@ func handleUpdateMaintenance(
}
}

printHostsTable(hosts)
err = printHostsTable(hosts)
if err != nil {
debugf("Error: %+v", err)
}

if confirmation {
if fromStdin {
Expand Down Expand Up @@ -318,7 +324,10 @@ func handleRemoveMaintenance(
)
}

printMaintenancesTable(maintenances, pattern, extend)
err = printMaintenancesTable(maintenances, pattern, extend)
if err != nil {
debugf("Error: %+v", err)
}

if confirmation {
if !confirmMaintenance("removing", removeMaintenance) {
Expand Down Expand Up @@ -428,16 +437,15 @@ func handleListMaintenances(
)
}

printMaintenancesTable(maintenances, pattern, extend)

err = printMaintenancesTable(maintenances, pattern, extend)
if err != nil {
debugf("Error: %+v", err)
}
return nil
}

func printMaintenancesTable(
maintenances []Maintenance,
pattern string,
extend bool,
) error {
func printMaintenancesTable(maintenances []Maintenance, pattern string,
extend bool) error {

var lines = [][]string{}

Expand Down Expand Up @@ -660,6 +668,9 @@ func confirmMaintenance(messages, maintenance string) bool {
maintenance,
)

fmt.Scanln(&value)
_, err := fmt.Scanln(&value)
if err != nil {
debugf("Error: %+v", err)
}
return value == "" || value == "Y" || value == "y"
}
5 changes: 4 additions & 1 deletion handle_triggers.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,9 @@ func parseParams(args map[string]interface{}) (Params, error) {
func confirmAcknowledge() bool {
var value string
fmt.Fprintf(os.Stderr, "\n:: Proceed with acknowledge? [Y/n]: ")
fmt.Scanln(&value)
_, err := fmt.Scanln(&value)
if err != nil {
debugf("Error: %+v", err)
}
return value == "" || value == "Y" || value == "y"
}
15 changes: 12 additions & 3 deletions handle_users_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ func handleUsersGroups(
found = true
}

table.Flush()
err = table.Flush()
if err != nil {
debugf("Error: %+v", err)
}

if !found || (addUser == "" && removeUser == "") {
return nil
Expand Down Expand Up @@ -222,7 +225,10 @@ func confirmAdding(user string) bool {
"\n:: Proceed with adding user %s to specified groups? [Y/n]: ",
user,
)
fmt.Scanln(&value)
_, err := fmt.Scanln(&value)
if err != nil {
debugf("Error: %+v", err)
}
return value == "" || value == "Y" || value == "y"
}

Expand All @@ -233,6 +239,9 @@ func confirmRemoving(user string) bool {
"\n:: Proceed with removing user %s from specified groups? [Y/n]: ",
user,
)
fmt.Scanln(&value)
_, err := fmt.Scanln(&value)
if err != nil {
debugf("Error: %+v", err)
}
return value == "" || value == "Y" || value == "y"
}
5 changes: 4 additions & 1 deletion history.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ func (history *History) String() string {
}

func (history *History) date() time.Time {
date, _ := strconv.ParseInt(history.Clock, 10, 64)
date, err := strconv.ParseInt(history.Clock, 10, 64)
if err != nil {
debugf("Error: %+v", err)
}
return time.Unix(date, 0)
}

Expand Down
8 changes: 4 additions & 4 deletions hosts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

const (
// https://www.zabbix.com/documentation/3.4/manual/api/reference/host/get
hosts_get = `
hostsGet = `
{
"jsonrpc": "2.0",
"result": [
Expand Down Expand Up @@ -100,7 +100,7 @@ const (
}`

// https://www.zabbix.com/documentation/3.4/manual/api/reference/host/delete
hosts_remove = `
hostsRemove = `
{
"jsonrpc": "2.0",
"result": {
Expand All @@ -118,7 +118,7 @@ func TestHostsGet(t *testing.T) {

testserver := httptest.NewServer(http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, hosts_get)
fmt.Fprint(w, hostsGet)
},
))
defer testserver.Close()
Expand All @@ -143,7 +143,7 @@ func TestHostsRemove(t *testing.T) {

testserver := httptest.NewServer(http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, hosts_remove)
fmt.Fprint(w, hostsRemove)
},
))
defer testserver.Close()
Expand Down
5 changes: 4 additions & 1 deletion httptest.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ func (check *HTTPTest) DateTime() string {
}

func (check *HTTPTest) date() time.Time {
date, _ := strconv.ParseInt(check.NextCheck, 10, 64)
date, err := strconv.ParseInt(check.NextCheck, 10, 64)
if err != nil {
debugf("Error: %+v", err)
}
return time.Unix(date, 0)
}

Expand Down
6 changes: 4 additions & 2 deletions item.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ func (item *Item) getLastClock() string {
return fmt.Sprint(int64(typed))
default:
panic("asdasdasd")
return "0"
}
}

func (item *Item) date() time.Time {
date, _ := strconv.ParseInt(item.getLastClock(), 10, 64)
date, err := strconv.ParseInt(item.getLastClock(), 10, 64)
if err != nil {
debugf("Error: %+v", err)
}
return time.Unix(date, 0)
}

Expand Down
5 changes: 4 additions & 1 deletion maintenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ func (maintenance *Maintenance) GetStatus() string {
}

func (maintenance *Maintenance) GetDateTime(unixtime string) string {
date, _ := strconv.ParseInt(unixtime, 10, 64)
date, err := strconv.ParseInt(unixtime, 10, 64)
if err != nil {
debugf("Error: %+v", err)
}
return time.Unix(date, 0).Format("2006-01-02 15:04:05")
}
12 changes: 6 additions & 6 deletions maintenances_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

const (
// https://www.zabbix.com/documentation/3.4/manual/api/reference/maintenance/get
maintenance_get = `
maintenanceGet = `
{
"jsonrpc": "2.0",
"result": [
Expand Down Expand Up @@ -49,7 +49,7 @@ const (
}`

// https://www.zabbix.com/documentation/3.4/manual/api/reference/maintenance/delete
maintenances_remove = `
maintenancesRemove = `
{
"jsonrpc": "2.0",
"result": {
Expand All @@ -63,7 +63,7 @@ const (
`

// https://www.zabbix.com/documentation/3.4/manual/api/reference/maintenance/create
maintenance_create = `
maintenanceCreate = `
{
"jsonrpc": "2.0",
"result": {
Expand All @@ -81,7 +81,7 @@ func TestMaintenanceGet(t *testing.T) {

testserver := httptest.NewServer(http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, maintenance_get)
fmt.Fprint(w, maintenanceGet)
},
))
defer testserver.Close()
Expand Down Expand Up @@ -109,7 +109,7 @@ func TestMaintenanceRemove(t *testing.T) {

testserver := httptest.NewServer(http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, maintenances_remove)
fmt.Fprint(w, maintenancesRemove)
},
))
defer testserver.Close()
Expand All @@ -135,7 +135,7 @@ func TestMaintenanceCreate(t *testing.T) {

testserver := httptest.NewServer(http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, maintenance_create)
fmt.Fprint(w, maintenanceCreate)
},
))
defer testserver.Close()
Expand Down
4 changes: 2 additions & 2 deletions responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type ResponseLogin struct {
Token string `json:"result"`
}

type ResponseApiVersion struct {
type ResponseAPIVersion struct {
ResponseRaw
Version string `json:"result"`
}
Expand All @@ -46,7 +46,7 @@ type ResponseMaintenances struct {
Data []Maintenance `json:"result"`
}

// Response Create/Delete maintenace
// Response Create/Delete maintenance
type ResponseMaintenancesArray struct {
ResponseRaw
Data Maintenances `json:"result"`
Expand Down
9 changes: 5 additions & 4 deletions search.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ func getSearchPattern(query []string) string {
}

func matchPattern(pattern, target string) bool {
match, _ := regexp.MatchString(
strings.ToLower(pattern),
strings.ToLower(target),
)
match, err := regexp.MatchString(strings.ToLower(pattern),
strings.ToLower(target))
if err != nil {
debugf("Error: %+v", err)
}
return match
}
10 changes: 8 additions & 2 deletions timeperiod.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,17 @@ func (timeperiod *Timeperiod) GetType() string {
}

func (timeperiod *Timeperiod) GetStartDate() string {
date, _ := strconv.ParseInt(timeperiod.StartDate, 10, 64)
date, err := strconv.ParseInt(timeperiod.StartDate, 10, 64)
if err != nil {
debugf("Error: %+v", err)
}
return time.Unix(date, 0).Format("2006-01-02 15:04:05")
}

func (timeperiod *Timeperiod) GetPeriodMinute() int64 {
period, _ := strconv.ParseInt(timeperiod.Period, 10, 64)
period, err := strconv.ParseInt(timeperiod.Period, 10, 64)
if err != nil {
debugf("Error: %+v", err)
}
return (period / 60)
}
10 changes: 8 additions & 2 deletions trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ func (trigger *Trigger) StatusProblem() string {
}

func (trigger *Trigger) Severity() Severity {
value, _ := strconv.Atoi(trigger.Priority)
value, err := strconv.Atoi(trigger.Priority)
if err != nil {
debugf("Error: %+v", err)
}
return Severity(value)
}

Expand Down Expand Up @@ -85,7 +88,10 @@ func (trigger *Trigger) Age() string {
}

func (trigger *Trigger) date() time.Time {
date, _ := strconv.ParseInt(trigger.LastChange, 10, 64)
date, err := strconv.ParseInt(trigger.LastChange, 10, 64)
if err != nil {
debugf("Error: %+v", err)
}
return time.Unix(date, 0)
}

Expand Down
Loading