diff --git a/src/ups/ups.go b/src/ups/ups.go index c27419b..c6f9e78 100644 --- a/src/ups/ups.go +++ b/src/ups/ups.go @@ -29,27 +29,28 @@ func init() { } func UpsConnect() { - var username, password string + var port int + var host, username, password string var connectErr, authenticationError error var u nut.UPS - upsClient, connectErr = nut.Connect(config.GetString("Ups.Host"), config.GetInt("Ups.Port")) + host = config.GetString("Ups.Host") + port = config.GetInt("Ups.Port") + upsClient, connectErr = nut.Connect(host, port) if connectErr != nil { syslog.Err(connectErr.Error()) return } - if username = config.GetString("Ups.Username"); username == "" { - return - } - if password = config.GetString("Ups.Password"); password == "" { - return - } + username = config.GetString("Ups.Username") + password = config.GetString("Ups.Password") - _, authenticationError = upsClient.Authenticate(username, password) - if authenticationError != nil { - syslog.Err(authenticationError.Error()) - return + if username != "" && password != "" { + _, authenticationError = upsClient.Authenticate(username, password) + if authenticationError != nil { + syslog.Err(authenticationError.Error()) + return + } } upsList, listErr := upsClient.GetUPSList()