nut

package module
v0.0.0-...-bd8f121 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2022 License: MIT Imports: 7 Imported by: 12

README

GoDoc

go.nut

go.nut is a Golang library for interacting with NUT (Network UPS Tools)

Getting started

import "github.com/robbiet480/go.nut"

Check out the examples in example_test.go. For full documentation, see the Godocs.

Other resources

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Make sure golint and go vet run successfully.
  4. go fmt your code!
  5. Commit your changes (git commit -am "Add some feature")
  6. Push to the branch (git push origin my-new-feature)
  7. Create a new Pull Request

License

MIT

Documentation

Overview

Package nut provides a Golang interface for interacting with Network UPS Tools (NUT).

It communicates with NUT over the TCP protocol

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Version         string
	ProtocolVersion string
	Hostname        net.Addr
	// contains filtered or unexported fields
}

Client contains information about the NUT server as well as the connection.

func Connect

func Connect(hostname string, _port ...int) (Client, error)

Connect accepts a hostname/IP string and an optional port, then creates a connection to NUT, returning a Client.

func (*Client) Authenticate

func (c *Client) Authenticate(username, password string) (bool, error)

Authenticate accepts a username and passwords and uses them to authenticate the existing NUT session.

func (*Client) Disconnect

func (c *Client) Disconnect() (bool, error)

Disconnect gracefully disconnects from NUT by sending the LOGOUT command.

func (*Client) GetNetworkProtocolVersion

func (c *Client) GetNetworkProtocolVersion() (string, error)

GetNetworkProtocolVersion returns the version of the network protocol currently in use.

func (*Client) GetUPSList

func (c *Client) GetUPSList() ([]UPS, error)

GetUPSList returns a list of all UPSes provided by this NUT instance.

func (*Client) GetVersion

func (c *Client) GetVersion() (string, error)

GetVersion returns the the version of the server currently in use.

func (*Client) Help

func (c *Client) Help() (string, error)

Help returns a list of the commands supported by NUT.

func (*Client) ReadResponse

func (c *Client) ReadResponse(endLine string, multiLineResponse bool) (resp []string, err error)

ReadResponse is a convenience function for reading newline delimited responses.

func (*Client) SendCommand

func (c *Client) SendCommand(cmd string) (resp []string, err error)

SendCommand sends the string cmd to the device, and returns the response.

type Command

type Command struct {
	Name        string
	Description string
}

Command describes an available command for a UPS.

type UPS

type UPS struct {
	Name           string
	Description    string
	Master         bool
	NumberOfLogins int
	Clients        []string
	Variables      []Variable
	Commands       []Command
	// contains filtered or unexported fields
}

UPS contains information about a specific UPS provided by the NUT instance.

func NewUPS

func NewUPS(name string, client *Client) (UPS, error)

NewUPS takes a UPS name and NUT client and returns an instantiated UPS struct.

func (*UPS) CheckIfMaster

func (u *UPS) CheckIfMaster() (bool, error)

CheckIfMaster returns true if the session is authenticated with the master permission set.

func (*UPS) ForceShutdown

func (u *UPS) ForceShutdown() (bool, error)

ForceShutdown sets the FSD flag on the UPS.

This requires "upsmon master" in upsd.users, or "FSD" action granted in upsd.users

upsmon in master mode is the primary user of this function. It sets this "forced shutdown" flag on any UPS when it plans to power it off. This is done so that slave systems will know about it and shut down before the power disappears.

Setting this flag makes "FSD" appear in a STATUS request for this UPS. Finding "FSD" in a status request should be treated just like a "OB LB".

It should be noted that FSD is currently a latch - once set, there is no way to clear it short of restarting upsd or dropping then re-adding it in the ups.conf. This may cause issues when upsd is running on a system that is not shut down due to the UPS event.

func (*UPS) GetClients

func (u *UPS) GetClients() ([]string, error)

GetClients returns a list of NUT clients.

func (*UPS) GetCommandDescription

func (u *UPS) GetCommandDescription(commandName string) (string, error)

GetCommandDescription returns a string that gives a brief explanation for the given commandName.

func (*UPS) GetCommands

func (u *UPS) GetCommands() ([]Command, error)

GetCommands returns a slice of Command structs for the UPS.

func (*UPS) GetDescription

func (u *UPS) GetDescription() (string, error)

GetDescription the value of "desc=" from ups.conf for this UPS. If it is not set, upsd will return "Unavailable".

func (*UPS) GetNumberOfLogins

func (u *UPS) GetNumberOfLogins() (int, error)

GetNumberOfLogins returns the number of clients which have done LOGIN for this UPS.

func (*UPS) GetVariableDescription

func (u *UPS) GetVariableDescription(variableName string) (string, error)

GetVariableDescription returns a string that gives a brief explanation for the given variableName. upsd may return "Unavailable" if the file which provides this description is not installed.

func (*UPS) GetVariableType

func (u *UPS) GetVariableType(variableName string) (string, bool, int, error)

GetVariableType returns the variable type, writeability and maximum length for the given variableName.

func (*UPS) GetVariables

func (u *UPS) GetVariables() ([]Variable, error)

GetVariables returns a slice of Variable structs for the UPS.

func (*UPS) SendCommand

func (u *UPS) SendCommand(commandName string) (bool, error)

SendCommand sends a command to the UPS.

func (*UPS) SetVariable

func (u *UPS) SetVariable(variableName, value string) (bool, error)

SetVariable sets the given variableName to the given value on the UPS.

type Variable

type Variable struct {
	Name          string
	Value         interface{}
	Type          string
	Description   string
	Writeable     bool
	MaximumLength int
	OriginalType  string
}

Variable describes a single variable related to a UPS.

Jump to

Keyboard shortcuts

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