Make wifi collector fail gracefully if metrics not available

This commit is contained in:
Matt Layher 2017-01-12 12:41:35 -05:00
commit d3089f2ce8
No known key found for this signature in database
GPG key ID: 77BFE531397EDE94
6 changed files with 101 additions and 26 deletions

View file

@ -36,6 +36,7 @@ type client struct {
// genl is an interface over generic netlink, so netlink interactions can
// be stubbed in tests.
type genl interface {
Close() error
GetFamily(name string) (genetlink.Family, error)
Execute(m genetlink.Message, family uint16, flags netlink.HeaderFlags) ([]genetlink.Message, error)
}
@ -66,6 +67,11 @@ func initClient(c genl) (*client, error) {
}, nil
}
// Close closes the client's generic netlink connection.
func (c *client) Close() error {
return c.c.Close()
}
// Interfaces requests that nl80211 return a list of all WiFi interfaces present
// on this system.
func (c *client) Interfaces() ([]*Interface, error) {
@ -117,7 +123,12 @@ func (c *client) StationInfo(ifi *Interface) (*StationInfo, error) {
return nil, err
}
if len(msgs) > 1 {
switch len(msgs) {
case 0:
return nil, os.ErrNotExist
case 1:
break
default:
return nil, errMultipleMessages
}