Documentation ¶
Overview ¶
Package nut provides a Golang interface for interacting with Network UPS Tools (NUT).
It communicates with NUT over the TCP protocol
Index ¶
- type Client
- func (c *Client) Authenticate(username, password string) (bool, error)
- func (c *Client) Disconnect() (bool, error)
- func (c *Client) GetNetworkProtocolVersion() (string, error)
- func (c *Client) GetUPSList() ([]UPS, error)
- func (c *Client) GetVersion() (string, error)
- func (c *Client) Help() (string, error)
- func (c *Client) ReadResponse(endLine string, multiLineResponse bool) (resp []string, err error)
- func (c *Client) SendCommand(cmd string) (resp []string, err error)
- type Command
- type UPS
- func (u *UPS) CheckIfMaster() (bool, error)
- func (u *UPS) ForceShutdown() (bool, error)
- func (u *UPS) GetClients() ([]string, error)
- func (u *UPS) GetCommandDescription(commandName string) (string, error)
- func (u *UPS) GetCommands() ([]Command, error)
- func (u *UPS) GetDescription() (string, error)
- func (u *UPS) GetNumberOfLogins() (int, error)
- func (u *UPS) GetVariableDescription(variableName string) (string, error)
- func (u *UPS) GetVariableType(variableName string) (string, bool, int, error)
- func (u *UPS) GetVariables() ([]Variable, error)
- func (u *UPS) SendCommand(commandName string) (bool, error)
- func (u *UPS) SetVariable(variableName, value string) (bool, error)
- type Variable
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 ¶
Connect accepts a hostname/IP string and an optional port, then creates a connection to NUT, returning a Client.
func (*Client) Authenticate ¶
Authenticate accepts a username and passwords and uses them to authenticate the existing NUT session.
func (*Client) Disconnect ¶
Disconnect gracefully disconnects from NUT by sending the LOGOUT command.
func (*Client) GetNetworkProtocolVersion ¶
GetNetworkProtocolVersion returns the version of the network protocol currently in use.
func (*Client) GetUPSList ¶
GetUPSList returns a list of all UPSes provided by this NUT instance.
func (*Client) GetVersion ¶
GetVersion returns the the version of the server currently in use.
func (*Client) ReadResponse ¶
ReadResponse is a convenience function for reading newline delimited responses.
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 (*UPS) CheckIfMaster ¶
CheckIfMaster returns true if the session is authenticated with the master permission set.
func (*UPS) ForceShutdown ¶
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 ¶
GetClients returns a list of NUT clients.
func (*UPS) GetCommandDescription ¶
GetCommandDescription returns a string that gives a brief explanation for the given commandName.
func (*UPS) GetCommands ¶
GetCommands returns a slice of Command structs for the UPS.
func (*UPS) GetDescription ¶
GetDescription the value of "desc=" from ups.conf for this UPS. If it is not set, upsd will return "Unavailable".
func (*UPS) GetNumberOfLogins ¶
GetNumberOfLogins returns the number of clients which have done LOGIN for this UPS.
func (*UPS) GetVariableDescription ¶
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 ¶
GetVariableType returns the variable type, writeability and maximum length for the given variableName.
func (*UPS) GetVariables ¶
GetVariables returns a slice of Variable structs for the UPS.
func (*UPS) SendCommand ¶
SendCommand sends a command to the UPS.