lb112x

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 10, 2021 License: MIT Imports: 11 Imported by: 0

README

LB112X Utility

Library and command line utility for interacting with Netgear LB112X LTE Modems.

Tested only with LB1120!

CLI Utility

View the usage by running the utility with no arguments.

$ lb112xutil
NAME:
   lb112xutil - Utility for woring with Netgear LB112X LTE Modems

USAGE:
   lb112xutil [global options] command [command options] [arguments...]

VERSION:
   development

COMMANDS:
   status, stat  Display status of a LB112X device.
   export        Export LB112x device metrics to Prometheus. Blocks until killed.
   testcfg       Test Prometheus exporter configuration.
   help, h       Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --help, -h     show help (default: false)
   --version, -v  print the version (default: false)

Use the status command to get the current status of the device. The admin password can be provided as an environment variable to keep it secret.

$ export LB112X_ADMIN_PASSWORD=ThisIsAPassword
$ lb112xutil status
Device
 Model:         LB1120
 IMEI:          123456789101112
Network
 Name:          AT&T
 IP:            10.180.2.2
 IPv6:          2600:0000:1111:2222:3333:4444:5555:6666
Signal
 Bars:          3
 RSSI:          -75
 Temperature:   30°C
 Temp Critical: false

Prometheus Exporter

The CLI includes a Prometheus exporter for LB112x devices. Since each device requires authentication credentials, the exporter must me configured ahead of time with the devices it will export. This can be done with a YAML file which might look like:

---
global:
  timeout: 10s
devices:
  - url: http://192.168.5.1
    password: SuperSecretPassword
  - url: http://192.168.6.1
    password: CantGuessMe
    timeout: 15s

See export/config.go for the exact fields. The exporter itself can be started using the lb112xutil export command. The target key for scraping is the URL value for each device.

$ lb112xutil export
NAME:
   lb112xutil export - Export LB112x device metrics to Prometheus. Blocks until killed.

USAGE:
   lb112xutil export [command options] [arguments...]

OPTIONS:
   --config value, -f value  Configuration file for Prometheus Exporter
   --listen value, -L value  Local ip:port from which to serve Prometheus metrics. (default: ":9112")
   --help, -h                show help (default: false)

Once running, Prometheus can be configured to scrape the LB112x devices with the following static config, using relabels:

scrape_configs:
  - job_name: lb112x
    metrics_path: /scrape
    static_configs:
      - targets:
          - http://192.168.5.1
          - http://192.168.6.1
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        # The host:port of the exporter, started above.
        replacement: 127.0.0.1:9112

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrFailedAuthentication = errors.New("failed to log in")

Functions

func DefaultTransport

func DefaultTransport() http.RoundTripper

DefaultTransport for HTTP requests to the LB112X API. Useful for wrapping the transport from outside the library.

Types

type APIModel

type APIModel struct {
	General GeneralInfo `json:"general"`
	Power   PowerInfo   `json:"power"`
	Session SessionInfo `json:"session"`
	WWAN    WWANInfo    `json:"wwan"`
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client for communicating with the LB112X API.

func New

func New(url, password string, opts ...Option) *Client

New LB112X API Client.

func (*Client) Authenticate

func (c *Client) Authenticate(ctx context.Context) error

Authenticate with the API.

func (*Client) GetSession

func (c *Client) GetSession(ctx context.Context) (*SessionInfo, error)

GetSession information from the LB112X API.

func (*Client) Poll

func (c *Client) Poll(ctx context.Context) (*APIModel, error)

Poll the LB112X API.

type GeneralInfo

type GeneralInfo struct {
	Model             string `json:"model"`
	VersionMajor      int    `json:"verMajor"`
	VersionMinor      int    `json:"verMinor"`
	HardwareVersion   string `json:"HWversion"`
	FirmwareVersion   string `json:"FWversion"`
	AppVersion        string `json:"appVersion"`
	WebAppVersion     string `json:"webAppVersion"`
	APIVersion        string `json:"apiVersion"`
	BootloaderVersion string `json:"BLversion"`
	IMEI              string `json:"IMEI"`
	Temperature       int    `json:"devTemperature"`
}

type Option

type Option func(*initOptions)

Option for the creation of the LB112X API Client.

func WithClientTimeout

func WithClientTimeout(ttl time.Duration) Option

WithClientTimeout while connecting to the LB112X API.

func WithCookieJar

func WithCookieJar(jar http.CookieJar) Option

WithCookieJar for use by the HTTP client communicating with the LB112X API.

func WithRoundTripper

func WithRoundTripper(rt http.RoundTripper) Option

WithRoundTripper for HTTP requests to the LB112X API.

type PowerInfo

type PowerInfo struct {
	DeviceTempCritical bool   `json:"deviceTempCritical"`
	ResetRequired      string `json:"resetRequired"`
}

type SessionInfo

type SessionInfo struct {
	UserRole      string `json:"userRole"`
	Language      string `json:"lang"`
	SecurityToken string `json:"secToken"`
}

type SignalStrenthInfo

type SignalStrenthInfo struct {
	RSSI int `json:"rssi"`
	RSCP int `json:"rscp"`
	ECIO int `json:"ecio"`
	RSRP int `json:"rsrp"`
	RSRQ int `json:"rsrq"`
	Bars int `json:"bars"`
	SINR int `json:"SINR"`
}

type WWANInfo

type WWANInfo struct {
	IP                     string            `json:"IP"`
	IPv6                   string            `json:"IPv6"`
	RegisterNetworkDisplay string            `json:"registerNetworkDisplay"`
	SignalStrenth          SignalStrenthInfo `json:"signalStrength"`
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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