becs

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Sync

func Sync(c *util.ConfigRoot, name string, reporter jobevent.Reporter) error

Sync fetches ibos elements from BECS, reconciles Netbox devices that have a non-zero becs_oid custom field against them, then runs netbox.Sync so factum sees the result. If name is set, only that device is created/updated/deleted (the full BECS tree is still loaded — parent/opaque lookup walks it).

Types

type Client

type Client struct {
	URL       string
	Username  string
	Password  string
	SessionID string
	// contains filtered or unexported fields
}

Client talks to the BECS JSON-RPC API. Objects from the last LoadTree (plus any ancestors fetched while walking parents) live in memory — there is no on-disk cache; the API is fast enough without one.

func NewClient

func NewClient(url, username, password string) *Client

func NewClientFromSettings

func NewClientFromSettings(s *models.Settings) (*Client, error)

func (*Client) Call

func (c *Client) Call(method string, params map[string]any) (json.RawMessage, error)

func (*Client) Devices

func (c *Client) Devices(domain string) ([]*Device, error)

Devices returns every ibos element-attach as a Device. LoadTree must have been called first.

func (*Client) GetElement

func (c *Client) GetElement(name string, rootOID int) (*Device, error)

GetElement loads the tree (if needed) and returns the named ibos element. Name is matched case-insensitively against the short name.

func (*Client) GetObject

func (c *Client) GetObject(oid int) (*Object, error)

GetObject returns one object, from the in-memory map or via objectFind.

func (*Client) Index

func (c *Client) Index(objs []Object)

Index replaces the in-memory object map and rebuilds parent/child links. Used by LoadTree and by tests that feed a fixture.

func (*Client) Interfaces

func (c *Client) Interfaces(elementOID int) (map[string]*Interface, error)

Interfaces returns the interfaces of an element-attach, keyed by name.

func (*Client) LoadTree

func (c *Client) LoadTree(rootOID int) error

LoadTree fetches the object tree starting at rootOID (walkdown 0 = unlimited, matching the Python client) and indexes it in memory. If the client already has objects (e.g. tests that called Index), it is a no-op so a later Devices/GetElement call does not hit the API.

func (*Client) Login

func (c *Client) Login() error

func (*Client) Logout

func (c *Client) Logout()

func (*Client) ObjectTreeFind

func (c *Client) ObjectTreeFind(oid int, classmask string, walkdown int) ([]Object, error)

func (*Client) SearchOpaque

func (c *Client) SearchOpaque(oid int, name string) (string, error)

SearchOpaque walks from oid toward the root and returns the first opaque value with the given name. Does not handle arrays.

func (*Client) SearchParent

func (c *Client) SearchParent(oid int) (string, error)

SearchParent walks from oid toward the root. A "parents" opaque wins; otherwise the first ancestor element-attach (skipping the starting object) is used.

type Device

type Device struct {
	OID              int
	Name             string // FQDN when a default domain is configured
	ShortName        string
	Manufacturer     string
	Model            string
	Role             string
	Platform         string
	Enabled          bool
	AlarmTimeperiod  string
	AlarmDestination string
	ConnectionMethod string
	Parents          []string
	Interfaces       map[string]*Interface
	InterfacesOID    map[int]*Interface
}

Device is a BECS element-attach mapped to the Netbox device shape.

type Interface

type Interface struct {
	OID     int
	Name    string
	Role    string
	Enabled bool
	Prefix4 []Prefix
}

type Object

type Object struct {
	OID         int         `json:"oid"`
	ParentOID   int         `json:"parentoid"`
	Class       string      `json:"class"`
	Name        string      `json:"name"`
	ElementType string      `json:"elementtype"`
	Role        string      `json:"role"`
	Flags       string      `json:"flags"`
	Parameters  []Parameter `json:"parameters"`
	Opaque      []Opaque    `json:"opaque"`
	Resource    *Resource   `json:"resource"`
	ChildrenOID []int       `json:"-"`
}

Object is one BECS object (element-attach, interface, resource-inet, or a folder fetched while walking parents).

type Opaque

type Opaque struct {
	Name   string        `json:"name"`
	Values []OpaqueValue `json:"values"`
}

type OpaqueValue

type OpaqueValue struct {
	Value string `json:"value"`
}

type Parameter

type Parameter struct {
	Name   string           `json:"name"`
	Values []ParameterValue `json:"values"`
}

type ParameterValue

type ParameterValue struct {
	Value string `json:"value"`
}

type Prefix

type Prefix struct {
	Address string // CIDR
	OID     int
}

type Resource

type Resource struct {
	RCParentOID int    `json:"rcparentoid"`
	Address     string `json:"address"`
	PrefixLen   int    `json:"prefixlen"`
}

type Syncer

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

Jump to

Keyboard shortcuts

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