checkconfig

package
v0.0.0-...-701ea4a Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2024 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultBulkMaxRepetitions = uint32(10)

DefaultBulkMaxRepetitions is the default max rep Using too high max repetitions might lead to tooBig SNMP error messages. - Java SNMP and gosnmp (gosnmp.defaultMaxRepetitions) uses 50 - snmp-net uses 10

View Source
const DefaultPingCount int = 2

DefaultPingCount is the default number of pings to send per check run

View Source
const DefaultPingInterval = 10 * time.Millisecond

DefaultPingInterval is the default time to wait between sending ping packets

View Source
const DefaultPingTimeout = 3 * time.Second

DefaultPingTimeout is the default timeout for all pings to return in a check run

Variables

View Source
var LegacyMetadataConfig = profiledefinition.MetadataConfig{
	"device": {
		Fields: map[string]profiledefinition.MetadataField{
			"description": {
				Symbol: profiledefinition.SymbolConfig{
					OID:  "1.3.6.1.2.1.1.1.0",
					Name: "sysDescr",
				},
			},
			"name": {
				Symbol: profiledefinition.SymbolConfig{
					OID:  "1.3.6.1.2.1.1.5.0",
					Name: "sysName",
				},
			},
			"sys_object_id": {
				Symbol: profiledefinition.SymbolConfig{
					OID:  "1.3.6.1.2.1.1.2.0",
					Name: "sysObjectID",
				},
			},
		},
	},
	"interface": {
		Fields: map[string]profiledefinition.MetadataField{
			"name": {
				Symbol: profiledefinition.SymbolConfig{
					OID:  "1.3.6.1.2.1.31.1.1.1.1",
					Name: "ifName",
				},
			},
			"description": {
				Symbol: profiledefinition.SymbolConfig{
					OID:  "1.3.6.1.2.1.2.2.1.2",
					Name: "ifDescr",
				},
			},
			"admin_status": {
				Symbol: profiledefinition.SymbolConfig{
					OID:  "1.3.6.1.2.1.2.2.1.7",
					Name: "ifAdminStatus",
				},
			},
			"oper_status": {
				Symbol: profiledefinition.SymbolConfig{
					OID:  "1.3.6.1.2.1.2.2.1.8",
					Name: "ifOperStatus",
				},
			},
			"alias": {
				Symbol: profiledefinition.SymbolConfig{
					OID:  "1.3.6.1.2.1.31.1.1.1.18",
					Name: "ifAlias",
				},
			},
			"mac_address": {
				Symbol: profiledefinition.SymbolConfig{
					OID:    "1.3.6.1.2.1.2.2.1.6",
					Name:   "ifPhysAddress",
					Format: "mac_address",
				},
			},
		},
		IDTags: profiledefinition.MetricTagConfigList{
			{
				Tag: "interface",
				Symbol: profiledefinition.SymbolConfigCompat{
					OID:  "1.3.6.1.2.1.31.1.1.1.1",
					Name: "ifName",
				},
			},
		},
	},
	"ip_addresses": {
		Fields: map[string]profiledefinition.MetadataField{
			"if_index": {
				Symbol: profiledefinition.SymbolConfig{
					OID:  "1.3.6.1.2.1.4.20.1.2",
					Name: "ipAdEntIfIndex",
				},
			},
			"netmask": {
				Symbol: profiledefinition.SymbolConfig{
					OID:  "1.3.6.1.2.1.4.20.1.3",
					Name: "ipAdEntNetMask",
				},
			},
		},
	},
}

LegacyMetadataConfig contains metadata config used for backward compatibility When users have their own copy of _base.yaml and _generic_if.yaml files they won't have the new profile based metadata definitions for device and interface resources The LegacyMetadataConfig is used as fallback to provide metadata definitions for those resources.

View Source
var TopologyMetadataConfig = profiledefinition.MetadataConfig{
	"lldp_remote": {
		Fields: map[string]profiledefinition.MetadataField{
			"chassis_id_type": {
				Symbol: profiledefinition.SymbolConfig{
					OID:  "1.0.8802.1.1.2.1.4.1.1.4",
					Name: "lldpRemChassisIdSubtype",
				},
			},
			"chassis_id": {
				Symbol: profiledefinition.SymbolConfig{
					OID:  "1.0.8802.1.1.2.1.4.1.1.5",
					Name: "lldpRemChassisId",
				},
			},
			"interface_id_type": {
				Symbol: profiledefinition.SymbolConfig{
					OID:  "1.0.8802.1.1.2.1.4.1.1.6",
					Name: "lldpRemPortIdSubtype",
				},
			},
			"interface_id": {
				Symbol: profiledefinition.SymbolConfig{
					OID:  "1.0.8802.1.1.2.1.4.1.1.7",
					Name: "lldpRemPortId",
				},
			},
			"interface_desc": {
				Symbol: profiledefinition.SymbolConfig{
					OID:  "1.0.8802.1.1.2.1.4.1.1.8",
					Name: "lldpRemPortDesc",
				},
			},
			"device_name": {
				Symbol: profiledefinition.SymbolConfig{
					OID:  "1.0.8802.1.1.2.1.4.1.1.9",
					Name: "lldpRemSysName",
				},
			},
			"device_desc": {
				Symbol: profiledefinition.SymbolConfig{
					OID:  "1.0.8802.1.1.2.1.4.1.1.10",
					Name: "lldpRemSysDesc",
				},
			},
		},
	},
	"lldp_remote_management": {
		Fields: map[string]profiledefinition.MetadataField{
			"interface_id_type": {
				Symbol: profiledefinition.SymbolConfig{
					OID:  "1.0.8802.1.1.2.1.4.2.1.3",
					Name: "lldpRemManAddrIfSubtype",
				},
			},
		},
	},
	"lldp_local": {
		Fields: map[string]profiledefinition.MetadataField{
			"interface_id_type": {
				Symbol: profiledefinition.SymbolConfig{
					OID:  "1.0.8802.1.1.2.1.3.7.1.2",
					Name: "lldpLocPortIdSubtype",
				},
			},
			"interface_id": {
				Symbol: profiledefinition.SymbolConfig{
					OID:  "1.0.8802.1.1.2.1.3.7.1.3",
					Name: "lldpLocPortID",
				},
			},
		},
	},
	"cdp_remote": {
		Fields: map[string]profiledefinition.MetadataField{
			"device_desc": {
				Symbol: profiledefinition.SymbolConfig{
					OID:  "1.3.6.1.4.1.9.9.23.1.2.1.1.5",
					Name: "cdpCacheVersion",
				},
			},
			"device_id": {
				Symbol: profiledefinition.SymbolConfig{
					OID:  "1.3.6.1.4.1.9.9.23.1.2.1.1.6",
					Name: "cdpCacheDeviceId",
				},
			},
			"interface_id": {
				Symbol: profiledefinition.SymbolConfig{
					OID:  "1.3.6.1.4.1.9.9.23.1.2.1.1.7",
					Name: "cdpCacheDevicePort",
				},
			},
			"device_name": {
				Symbol: profiledefinition.SymbolConfig{
					OID:  "1.3.6.1.4.1.9.9.23.1.2.1.1.17",
					Name: "cdpCacheSysName",
				},
			},
			"device_address_type": {
				Symbol: profiledefinition.SymbolConfig{
					OID:  "1.3.6.1.4.1.9.9.23.1.2.1.1.19",
					Name: "cdpCachePrimaryMgmtAddrType",
				},
			},
			"device_address": {
				Symbol: profiledefinition.SymbolConfig{
					OID:  "1.3.6.1.4.1.9.9.23.1.2.1.1.20",
					Name: "cdpCachePrimaryMgmtAddr",
				},
			},
		},
	},
}

TopologyMetadataConfig represent the metadata needed for topology

Functions

func BuildMetricTagsFromValue

func BuildMetricTagsFromValue(metricTag *profiledefinition.MetricTagConfig, value string) []string

BuildMetricTagsFromValue returns tags based on MetricTagConfig and a value

func GetMappedValue

func GetMappedValue(index string, mapping map[string]string) (string, error)

GetMappedValue retrieves mapped value from a given mapping. If mapping is empty, it will return the index.

func RegexReplaceValue

func RegexReplaceValue(value string, pattern *regexp.Regexp, normalizedTemplate string) string

RegexReplaceValue replaces a value using a regex and template

Types

type Boolean

type Boolean bool

Boolean can unmarshal yaml string or bool value

func (*Boolean) UnmarshalYAML

func (b *Boolean) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML unmarshalls Boolean

type CheckConfig

type CheckConfig struct {
	Name            string
	IPAddress       string
	Port            uint16
	CommunityString string
	SnmpVersion     string
	Timeout         int
	Retries         int
	User            string
	AuthProtocol    string
	AuthKey         string
	PrivProtocol    string
	PrivKey         string
	ContextName     string
	OidConfig       OidConfig
	// RequestedMetrics are the metrics explicitly requested by config.
	RequestedMetrics []profiledefinition.MetricsConfig
	// RequestedMetricTags are the tags explicitly requested by config.
	RequestedMetricTags []profiledefinition.MetricTagConfig
	// Metrics combines RequestedMetrics with profile metrics.
	Metrics  []profiledefinition.MetricsConfig
	Metadata profiledefinition.MetadataConfig
	// MetricTags combines RequestedMetricTags with profile metric tags.
	MetricTags            []profiledefinition.MetricTagConfig
	OidBatchSize          int
	BulkMaxRepetitions    uint32
	ProfileProvider       profile.Provider
	ProfileTags           []string
	ProfileName           string
	ExtraTags             []string
	InstanceTags          []string
	CollectDeviceMetadata bool
	CollectTopology       bool
	UseDeviceIDAsHostname bool
	DeviceID              string
	DeviceIDTags          []string
	ResolvedSubnetName    string
	Namespace             string
	AutodetectProfile     bool
	MinCollectionInterval time.Duration

	Network                  string
	DiscoveryWorkers         int
	Workers                  int
	DiscoveryInterval        int
	IgnoredIPAddresses       map[string]bool
	DiscoveryAllowedFailures int
	InterfaceConfigs         []snmpintegration.InterfaceConfig

	PingEnabled bool
	PingConfig  pinger.Config
}

CheckConfig holds config needed for an integration instance to run

func NewCheckConfig

func NewCheckConfig(rawInstance integration.Data, rawInitConfig integration.Data) (*CheckConfig, error)

NewCheckConfig builds a new check config

func (*CheckConfig) Copy

func (c *CheckConfig) Copy() *CheckConfig

Copy makes a copy of CheckConfig

func (*CheckConfig) CopyWithNewIP

func (c *CheckConfig) CopyWithNewIP(ipAddress string) *CheckConfig

CopyWithNewIP makes a copy of CheckConfig with new IP

func (*CheckConfig) DeviceDigest

func (c *CheckConfig) DeviceDigest(address string) DeviceDigest

DeviceDigest returns a hash value representing the minimal configs used to connect to the device. DeviceDigest is used for device discovery.

func (*CheckConfig) GetNetworkTags

func (c *CheckConfig) GetNetworkTags() []string

GetNetworkTags returns network tags network tags are not part of the static tags since we don't want the deviceID to change if the network/subnet changes e.g. 10.0.0.0/29 to 10.0.0.0/30

func (*CheckConfig) GetProfileDef

func (c *CheckConfig) GetProfileDef() *profiledefinition.ProfileDefinition

GetProfileDef returns the autodetected profile definition if there is one, the active profile if it exists, or nil if neither is true.

func (*CheckConfig) GetStaticTags

func (c *CheckConfig) GetStaticTags() []string

GetStaticTags return static tags built from configuration

func (*CheckConfig) IsDiscovery

func (c *CheckConfig) IsDiscovery() bool

IsDiscovery return weather it's a network/autodiscovery config or not

func (*CheckConfig) IsIPIgnored

func (c *CheckConfig) IsIPIgnored(ip net.IP) bool

IsIPIgnored checks the given IP against ignoredIPAddresses

func (*CheckConfig) RebuildMetadataMetricsAndTags

func (c *CheckConfig) RebuildMetadataMetricsAndTags()

RebuildMetadataMetricsAndTags rebuilds c.Metrics, c.Metadata, c.MetricTags, and c.OidConfig by merging data from requested metrics/tags and the current profile.

func (*CheckConfig) SetProfile

func (c *CheckConfig) SetProfile(profileName string) error

SetProfile refreshes config based on profile

func (*CheckConfig) ToString

func (c *CheckConfig) ToString() string

ToString used for logging CheckConfig without sensitive information

func (*CheckConfig) UpdateDeviceIDAndTags

func (c *CheckConfig) UpdateDeviceIDAndTags()

UpdateDeviceIDAndTags updates DeviceID and DeviceIDTags

type DeviceDigest

type DeviceDigest string

DeviceDigest is the digest of a minimal config used for autodiscovery

type InitConfig

type InitConfig struct {
	Profiles              profile.ProfileConfigMap          `yaml:"profiles"`
	GlobalMetrics         []profiledefinition.MetricsConfig `yaml:"global_metrics"`
	OidBatchSize          Number                            `yaml:"oid_batch_size"`
	BulkMaxRepetitions    Number                            `yaml:"bulk_max_repetitions"`
	CollectDeviceMetadata Boolean                           `yaml:"collect_device_metadata"`
	CollectTopology       Boolean                           `yaml:"collect_topology"`
	UseDeviceIDAsHostname Boolean                           `yaml:"use_device_id_as_hostname"`
	MinCollectionInterval int                               `yaml:"min_collection_interval"`
	Namespace             string                            `yaml:"namespace"`
	PingConfig            snmpintegration.PackedPingConfig  `yaml:"ping"`
}

InitConfig is used to deserialize integration init config

type InstanceConfig

type InstanceConfig struct {
	Name                  string                              `yaml:"name"`
	IPAddress             string                              `yaml:"ip_address"`
	Port                  Number                              `yaml:"port"`
	CommunityString       string                              `yaml:"community_string"`
	SnmpVersion           string                              `yaml:"snmp_version"`
	Timeout               Number                              `yaml:"timeout"`
	Retries               Number                              `yaml:"retries"`
	User                  string                              `yaml:"user"`
	AuthProtocol          string                              `yaml:"authProtocol"`
	AuthKey               string                              `yaml:"authKey"`
	PrivProtocol          string                              `yaml:"privProtocol"`
	PrivKey               string                              `yaml:"privKey"`
	ContextName           string                              `yaml:"context_name"`
	Metrics               []profiledefinition.MetricsConfig   `yaml:"metrics"`     // SNMP metrics definition
	MetricTags            []profiledefinition.MetricTagConfig `yaml:"metric_tags"` // SNMP metric tags definition
	Profile               string                              `yaml:"profile"`
	UseGlobalMetrics      bool                                `yaml:"use_global_metrics"`
	CollectDeviceMetadata *Boolean                            `yaml:"collect_device_metadata"`
	CollectTopology       *Boolean                            `yaml:"collect_topology"`
	UseDeviceIDAsHostname *Boolean                            `yaml:"use_device_id_as_hostname"`
	PingConfig            snmpintegration.PackedPingConfig    `yaml:"ping"`

	// ExtraTags is a workaround to pass tags from snmp listener to snmp integration via AD template
	// (see cmd/agent/dist/conf.d/snmp.d/auto_conf.yaml) that only works with strings.
	// TODO: deprecated extra tags in favour of using autodiscovery listener Service.GetTags()
	ExtraTags string `yaml:"extra_tags"` // comma separated tags

	// Tags are just static tags from the instance that is common to all integrations.
	// Normally, the Agent will enrich metrics with the metrics with those tags.
	// See https://github.com/DataDog/datadog-agent/blob/1e8321ff089d04ccce3987b84f8b75630d7a18c0/pkg/collector/corechecks/checkbase.go#L131-L139
	// But we need to deserialize here since we need them for NDM metadata.
	Tags []string `yaml:"tags"` // used for device metadata

	// The oid_batch_size indicates how many OIDs are retrieved in a single Get or GetBulk call
	OidBatchSize Number `yaml:"oid_batch_size"`
	// The bulk_max_repetitions config indicates how many rows of the table are to be retrieved in a single GetBulk call
	BulkMaxRepetitions Number `yaml:"bulk_max_repetitions"`

	MinCollectionInterval int `yaml:"min_collection_interval"`
	// To accept min collection interval from snmp_listener, we need to accept it as string.
	// Using extra_min_collection_interval, we can accept both string and integer value.
	ExtraMinCollectionInterval Number `yaml:"extra_min_collection_interval"`

	Network                  string   `yaml:"network_address"`
	IgnoredIPAddresses       []string `yaml:"ignored_ip_addresses"`
	DiscoveryInterval        int      `yaml:"discovery_interval"`
	DiscoveryAllowedFailures int      `yaml:"discovery_allowed_failures"`
	DiscoveryWorkers         int      `yaml:"discovery_workers"`
	Workers                  int      `yaml:"workers"`
	Namespace                string   `yaml:"namespace"`

	// `interface_configs` option is not supported by SNMP corecheck autodiscovery (`network_address`)
	// it's only supported for single device instance (`ip_address`)
	InterfaceConfigs InterfaceConfigs `yaml:"interface_configs"`
}

InstanceConfig is used to deserialize integration instance config

type InterfaceConfigs

type InterfaceConfigs []snmpintegration.InterfaceConfig

InterfaceConfigs can unmarshal yaml []snmpintegration.InterfaceConfig or interface configs in json format Example of interface configs in json format: `[{"match_field":"name","match_value":"eth0","in_speed":25,"out_speed":10}]`

func (*InterfaceConfigs) UnmarshalYAML

func (ic *InterfaceConfigs) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML unmarshalls InterfaceConfigs

type Number

type Number int

Number can unmarshal yaml string or integer

func (*Number) UnmarshalYAML

func (n *Number) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML unmarshalls Number

type OidConfig

type OidConfig struct {
	// ScalarOids are all scalar oids to fetch
	ScalarOids []string
	// ColumnOids are all column oids to fetch
	ColumnOids []string
}

OidConfig holds configs for OIDs to fetch

Jump to

Keyboard shortcuts

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