Documentation
¶
Index ¶
- func LoadMibsFromPath(paths []string, log telegraf.Logger, loader MibLoader) error
- func NewGosmiTranslator(paths []string, log telegraf.Logger) (*gosmiTranslator, error)
- func NewNetsnmpTranslator(log telegraf.Logger) *netsnmpTranslator
- type ClientConfig
- type Connection
- type Field
- type GosmiMibLoader
- type GosnmpWrapper
- type Logger
- type MibEntry
- type MibLoader
- type RTable
- type RTableRow
- type Table
- type Translator
- type TranslatorPlugin
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LoadMibsFromPath ¶
LoadMibsFromPath will give all found folders to gosmi and load in all modules found in the folders
func NewGosmiTranslator ¶
func NewNetsnmpTranslator ¶
Types ¶
type ClientConfig ¶
type ClientConfig struct {
// Timeout to wait for a response.
Timeout config.Duration `toml:"timeout"`
Retries int `toml:"retries"`
Version uint8 `toml:"version"`
UnconnectedUDPSocket bool `toml:"unconnected_udp_socket"`
GosnmpDebugLogger telegraf.Logger `toml:"-"`
// Parameters for Version 1 & 2
Community string `toml:"community"`
// Parameters for Version 2 & 3
MaxRepetitions uint32 `toml:"max_repetitions"`
// Parameters for Version 3
ContextName string `toml:"context_name"`
SecLevel string `toml:"sec_level"`
SecName string `toml:"sec_name"`
AuthProtocol string `toml:"auth_protocol"`
AuthPassword config.Secret `toml:"auth_password"`
PrivProtocol string `toml:"priv_protocol"`
PrivPassword config.Secret `toml:"priv_password"`
EngineID string `toml:"-"`
EngineBoots uint32 `toml:"-"`
EngineTime uint32 `toml:"-"`
// Path to mib files
Path []string `toml:"path"`
Translator string `toml:"-"`
}
func DefaultClientConfig ¶
func DefaultClientConfig() *ClientConfig
type Connection ¶
type Connection interface {
Host() string
// BulkWalkAll(string) ([]gosnmp.SnmpPDU, error)
Walk(string, gosnmp.WalkFunc) error
Get(oids []string) (*gosnmp.SnmpPacket, error)
Reconnect() error
Close() error
}
Connection is an interface which wraps a *gosnmp.GoSNMP object. We interact through an interface so we can mock it out in tests.
type Field ¶
type Field struct {
// Name will be the name of the field.
Name string
// OID is prefix for this field. The plugin will perform a walk through all
// OIDs with this as their parent. For each value found, the plugin will strip
// off the OID prefix, and use the remainder as the index. For multiple fields
// to show up in the same row, they must share the same index.
Oid string
// OidIndexSuffix is the trailing sub-identifier on a table record OID that will be stripped off to get the record's index.
OidIndexSuffix string
// OidIndexLength specifies the length of the index in OID path segments. It can be used to remove sub-identifiers that vary in content or length.
OidIndexLength int
// IsTag controls whether this OID is output as a tag or a value.
IsTag bool
// Conversion controls any type conversion that is done on the value.
// "float"/"float(0)" will convert the value into a float.
// "float(X)" will convert the value into a float, and then move the decimal before Xth right-most digit.
// "int" will convert the value into an integer.
// "hwaddr" will convert a 6-byte string to a MAC address.
// "ipaddr" will convert the value to an IPv4 or IPv6 address.
// "enum"/"enum(1)" will convert the value according to its syntax. (Only supported with gosmi translator)
// "displayhint" will format the value according to the textual convention. (Only supported with gosmi translator)
Conversion string
// Translate tells if the value of the field should be snmptranslated
Translate bool
// Secondary index table allows to merge data from two tables with different index
// that this filed will be used to join them. There can be only one secondary index table.
SecondaryIndexTable bool
// This field is using secondary index, and will be later merged with primary index
// using SecondaryIndexTable. SecondaryIndexTable and SecondaryIndexUse are exclusive.
SecondaryIndexUse bool
// Controls if entries from secondary table should be added or not if joining
// index is present or not. I set to true, means that join is outer, and
// index is prepended with "Secondary." for missing values to avoid overlapping
// indexes from both tables.
// Can be set per field or globally with SecondaryIndexTable, global true overrides
// per field false.
SecondaryOuterJoin bool
// contains filtered or unexported fields
}
Field holds the configuration for a Field to look up.
func (*Field) Init ¶
func (f *Field) Init(tr Translator) error
Init converts OID names to numbers, and sets the .Name attribute if unset.
type GosmiMibLoader ¶
type GosmiMibLoader struct{}
type GosnmpWrapper ¶
GosnmpWrapper wraps a *gosnmp.GoSNMP object so we can use it as a snmpConnection.
func NewWrapper ¶
func NewWrapper(s ClientConfig) (GosnmpWrapper, error)
func (GosnmpWrapper) Get ¶ added in v1.40.2
func (gs GosnmpWrapper) Get(oids []string) (*gosnmp.SnmpPacket, error)
Get wraps GoSNMP.Get() and reconnects first if the connection was closed.
func (GosnmpWrapper) Host ¶
func (gs GosnmpWrapper) Host() string
Host returns the value of GoSNMP.Target.
func (GosnmpWrapper) Reconnect ¶
func (gs GosnmpWrapper) Reconnect() error
Reconnect connects again if the connection was closed. An SNMPv3 session keeps the engine ID discovered on the first request, so it is reset to discover the engine ID again, as the agent may have restarted with a new one.
func (*GosnmpWrapper) SetAgent ¶
func (gs *GosnmpWrapper) SetAgent(agent string) error
SetAgent takes a url (scheme://host:port) and sets the wrapped GoSNMP struct's corresponding fields. This shouldn't be called after using the wrapped GoSNMP struct, for example after connecting.
type RTable ¶
type RTable struct {
// Name is the name of the field, copied from Table.Name.
Name string
// Time is the time the table was built.
Time time.Time
// Rows are the rows that were found, one row for each table OID index found.
Rows []RTableRow
}
RTable is the resulting table built from a Table.
type RTableRow ¶
type RTableRow struct {
// Tags are all the Field values which had IsTag=true.
Tags map[string]string
// Fields are all the Field values which had IsTag=false.
Fields map[string]any
}
RTableRow is the resulting row containing all the OID values which shared the same index.
type Table ¶
type Table struct {
// Name will be the name of the measurement.
Name string
// Which tags to inherit from the top-level config.
InheritTags []string
// Adds each row's table index as a tag.
IndexAsTag bool
// Fields is the tags and values to look up.
Fields []Field `toml:"field"`
// OID for automatic field population.
// If provided, init() will populate Fields with all the table columns of the
// given OID.
Oid string
// contains filtered or unexported fields
}
Table holds the configuration for a SNMP table.
func (Table) Build ¶
func (t Table) Build(gs Connection, walk bool) (*RTable, error)
Build retrieves all the fields specified in the table and constructs the RTable.
func (*Table) Init ¶
func (t *Table) Init(tr Translator) error
Init builds & initializes the nested fields.
type Translator ¶
type Translator interface {
SnmpTranslate(oid string) (
mibName string, oidNum string, oidText string,
conversion string,
err error,
)
SnmpTable(oid string) (
mibName string, oidNum string, oidText string,
fields []Field,
err error,
)
SnmpFormatEnum(oid string, value any, full bool) (
formatted string,
err error,
)
SnmpFormatDisplayHint(oid string, value any) (
formatted string,
err error,
)
}
type TranslatorPlugin ¶
type TranslatorPlugin interface {
SetTranslator(name string) // Agent calls this on inputs before Init
}