chore(inputs.snmp_legacy)!: Remove deprecated plugin (#14864)
This commit is contained in:
parent
c7c8020dd3
commit
179b836858
|
|
@ -1,5 +0,0 @@
|
||||||
//go:build !custom || inputs || inputs.snmp_legacy
|
|
||||||
|
|
||||||
package all
|
|
||||||
|
|
||||||
import _ "github.com/influxdata/telegraf/plugins/inputs/snmp_legacy" // register plugin
|
|
||||||
|
|
@ -1,628 +0,0 @@
|
||||||
# SNMP Legacy Input Plugin
|
|
||||||
|
|
||||||
**Deprecated in version 1.0. Use [SNMP input plugin][]**
|
|
||||||
|
|
||||||
The SNMP input plugin gathers metrics from SNMP agents
|
|
||||||
|
|
||||||
## Global configuration options <!-- @/docs/includes/plugin_config.md -->
|
|
||||||
|
|
||||||
In addition to the plugin-specific configuration settings, plugins support
|
|
||||||
additional global and plugin configuration settings. These settings are used to
|
|
||||||
modify metrics, tags, and field or create aliases and configure ordering, etc.
|
|
||||||
See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
|
|
||||||
|
|
||||||
[CONFIGURATION.md]: ../../../docs/CONFIGURATION.md#plugins
|
|
||||||
|
|
||||||
## Configuration
|
|
||||||
|
|
||||||
```toml @sample.conf
|
|
||||||
[[inputs.snmp_legacy]]
|
|
||||||
## Use 'oids.txt' file to translate oids to names
|
|
||||||
## To generate 'oids.txt' you need to run:
|
|
||||||
## snmptranslate -m all -Tz -On | sed -e 's/"//g' > /tmp/oids.txt
|
|
||||||
## Or if you have an other MIB folder with custom MIBs
|
|
||||||
## snmptranslate -M /mycustommibfolder -Tz -On -m all | sed -e 's/"//g' > oids.txt
|
|
||||||
snmptranslate_file = "/tmp/oids.txt"
|
|
||||||
[[inputs.snmp.host]]
|
|
||||||
address = "192.168.2.2:161"
|
|
||||||
# SNMP community
|
|
||||||
community = "public" # default public
|
|
||||||
# SNMP version (1, 2 or 3)
|
|
||||||
# Version 3 not supported yet
|
|
||||||
version = 2 # default 2
|
|
||||||
# SNMP response timeout
|
|
||||||
timeout = 2.0 # default 2.0
|
|
||||||
# SNMP request retries
|
|
||||||
retries = 2 # default 2
|
|
||||||
# Which get/bulk do you want to collect for this host
|
|
||||||
collect = ["mybulk", "sysservices", "sysdescr"]
|
|
||||||
# Simple list of OIDs to get, in addition to "collect"
|
|
||||||
get_oids = []
|
|
||||||
[[inputs.snmp.host]]
|
|
||||||
address = "192.168.2.3:161"
|
|
||||||
community = "public"
|
|
||||||
version = 2
|
|
||||||
timeout = 2.0
|
|
||||||
retries = 2
|
|
||||||
collect = ["mybulk"]
|
|
||||||
get_oids = [
|
|
||||||
"ifNumber",
|
|
||||||
".1.3.6.1.2.1.1.3.0",
|
|
||||||
]
|
|
||||||
[[inputs.snmp.get]]
|
|
||||||
name = "ifnumber"
|
|
||||||
oid = "ifNumber"
|
|
||||||
[[inputs.snmp.get]]
|
|
||||||
name = "interface_speed"
|
|
||||||
oid = "ifSpeed"
|
|
||||||
instance = "0"
|
|
||||||
[[inputs.snmp.get]]
|
|
||||||
name = "sysuptime"
|
|
||||||
oid = ".1.3.6.1.2.1.1.3.0"
|
|
||||||
unit = "second"
|
|
||||||
[[inputs.snmp.bulk]]
|
|
||||||
name = "mybulk"
|
|
||||||
max_repetition = 127
|
|
||||||
oid = ".1.3.6.1.2.1.1"
|
|
||||||
[[inputs.snmp.bulk]]
|
|
||||||
name = "ifoutoctets"
|
|
||||||
max_repetition = 127
|
|
||||||
oid = "ifOutOctets"
|
|
||||||
[[inputs.snmp.host]]
|
|
||||||
address = "192.168.2.13:161"
|
|
||||||
#address = "127.0.0.1:161"
|
|
||||||
community = "public"
|
|
||||||
version = 2
|
|
||||||
timeout = 2.0
|
|
||||||
retries = 2
|
|
||||||
#collect = ["mybulk", "sysservices", "sysdescr", "systype"]
|
|
||||||
collect = ["sysuptime" ]
|
|
||||||
[[inputs.snmp.host.table]]
|
|
||||||
name = "iftable3"
|
|
||||||
include_instances = ["enp5s0", "eth1"]
|
|
||||||
# SNMP TABLEs
|
|
||||||
# table without mapping neither subtables
|
|
||||||
[[inputs.snmp.table]]
|
|
||||||
name = "iftable1"
|
|
||||||
oid = ".1.3.6.1.2.1.31.1.1.1"
|
|
||||||
# table without mapping but with subtables
|
|
||||||
[[inputs.snmp.table]]
|
|
||||||
name = "iftable2"
|
|
||||||
oid = ".1.3.6.1.2.1.31.1.1.1"
|
|
||||||
sub_tables = [".1.3.6.1.2.1.2.2.1.13"]
|
|
||||||
# table with mapping but without subtables
|
|
||||||
[[inputs.snmp.table]]
|
|
||||||
name = "iftable3"
|
|
||||||
oid = ".1.3.6.1.2.1.31.1.1.1"
|
|
||||||
# if empty. get all instances
|
|
||||||
mapping_table = ".1.3.6.1.2.1.31.1.1.1.1"
|
|
||||||
# if empty, get all subtables
|
|
||||||
# table with both mapping and subtables
|
|
||||||
[[inputs.snmp.table]]
|
|
||||||
name = "iftable4"
|
|
||||||
oid = ".1.3.6.1.2.1.31.1.1.1"
|
|
||||||
# if empty get all instances
|
|
||||||
mapping_table = ".1.3.6.1.2.1.31.1.1.1.1"
|
|
||||||
# if empty get all subtables
|
|
||||||
# sub_tables could be not "real subtables"
|
|
||||||
sub_tables=[".1.3.6.1.2.1.2.2.1.13", "bytes_recv", "bytes_send"]
|
|
||||||
```
|
|
||||||
|
|
||||||
In the previous example, the plugin will gather value of OIDS:
|
|
||||||
|
|
||||||
- `.1.3.6.1.2.1.2.2.1.4.1`
|
|
||||||
|
|
||||||
### Simple example
|
|
||||||
|
|
||||||
In this example, Telegraf gathers value of OIDS:
|
|
||||||
|
|
||||||
- named **ifnumber**
|
|
||||||
- named **interface_speed**
|
|
||||||
|
|
||||||
With **inputs.snmp.get** section the plugin gets the oid number:
|
|
||||||
|
|
||||||
- **ifnumber** => `.1.3.6.1.2.1.2.1.0`
|
|
||||||
- **interface_speed** => *ifSpeed*
|
|
||||||
|
|
||||||
As you can see *ifSpeed* is not a valid OID. In order to get
|
|
||||||
the valid OID, the plugin uses `snmptranslate_file` to match the OID:
|
|
||||||
|
|
||||||
- **ifnumber** => `.1.3.6.1.2.1.2.1.0`
|
|
||||||
- **interface_speed** => *ifSpeed* => `.1.3.6.1.2.1.2.2.1.5`
|
|
||||||
|
|
||||||
Also as the plugin will append `instance` to the corresponding OID:
|
|
||||||
|
|
||||||
- **ifnumber** => `.1.3.6.1.2.1.2.1.0`
|
|
||||||
- **interface_speed** => *ifSpeed* => `.1.3.6.1.2.1.2.2.1.5.1`
|
|
||||||
|
|
||||||
In this example, the plugin will gather value of OIDS:
|
|
||||||
|
|
||||||
- `.1.3.6.1.2.1.2.1.0`
|
|
||||||
- `.1.3.6.1.2.1.2.2.1.5.1`
|
|
||||||
|
|
||||||
```toml
|
|
||||||
# Simple example
|
|
||||||
[[inputs.snmp]]
|
|
||||||
## Use 'oids.txt' file to translate oids to names
|
|
||||||
## To generate 'oids.txt' you need to run:
|
|
||||||
## snmptranslate -m all -Tz -On | sed -e 's/"//g' > /tmp/oids.txt
|
|
||||||
## Or if you have an other MIB folder with custom MIBs
|
|
||||||
## snmptranslate -M /mycustommibfolder -Tz -On -m all | sed -e 's/"//g' > oids.txt
|
|
||||||
snmptranslate_file = "/tmp/oids.txt"
|
|
||||||
[[inputs.snmp.host]]
|
|
||||||
address = "127.0.0.1:161"
|
|
||||||
# SNMP community
|
|
||||||
community = "public" # default public
|
|
||||||
# SNMP version (1, 2 or 3)
|
|
||||||
# Version 3 not supported yet
|
|
||||||
version = 2 # default 2
|
|
||||||
# Which get/bulk do you want to collect for this host
|
|
||||||
collect = ["ifnumber", "interface_speed"]
|
|
||||||
|
|
||||||
[[inputs.snmp.get]]
|
|
||||||
name = "ifnumber"
|
|
||||||
oid = ".1.3.6.1.2.1.2.1.0"
|
|
||||||
|
|
||||||
[[inputs.snmp.get]]
|
|
||||||
name = "interface_speed"
|
|
||||||
oid = "ifSpeed"
|
|
||||||
instance = "1"
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
### Simple bulk example
|
|
||||||
|
|
||||||
In this example, Telegraf gathers value of OIDS:
|
|
||||||
|
|
||||||
- named **ifnumber**
|
|
||||||
- named **interface_speed**
|
|
||||||
- named **if_out_octets**
|
|
||||||
|
|
||||||
With **inputs.snmp.get** section the plugin gets oid number:
|
|
||||||
|
|
||||||
- **ifnumber** => `.1.3.6.1.2.1.2.1.0`
|
|
||||||
- **interface_speed** => *ifSpeed*
|
|
||||||
|
|
||||||
With **inputs.snmp.bulk** section the plugin gets the oid number:
|
|
||||||
|
|
||||||
- **if_out_octets** => *ifOutOctets*
|
|
||||||
|
|
||||||
As you can see *ifSpeed* and *ifOutOctets* are not a valid OID.
|
|
||||||
In order to get the valid OID, the plugin uses `snmptranslate_file`
|
|
||||||
to match the OID:
|
|
||||||
|
|
||||||
- **ifnumber** => `.1.3.6.1.2.1.2.1.0`
|
|
||||||
- **interface_speed** => *ifSpeed* => `.1.3.6.1.2.1.2.2.1.5`
|
|
||||||
- **if_out_octets** => *ifOutOctets* => `.1.3.6.1.2.1.2.2.1.16`
|
|
||||||
|
|
||||||
Also, the plugin will append `instance` to the corresponding OID:
|
|
||||||
|
|
||||||
- **ifnumber** => `.1.3.6.1.2.1.2.1.0`
|
|
||||||
- **interface_speed** => *ifSpeed* => `.1.3.6.1.2.1.2.2.1.5.1`
|
|
||||||
|
|
||||||
And **if_out_octets** is a bulk request, the plugin will gathers all
|
|
||||||
OIDS in the table.
|
|
||||||
|
|
||||||
- `.1.3.6.1.2.1.2.2.1.16.1`
|
|
||||||
- `.1.3.6.1.2.1.2.2.1.16.2`
|
|
||||||
- `.1.3.6.1.2.1.2.2.1.16.3`
|
|
||||||
- `.1.3.6.1.2.1.2.2.1.16.4`
|
|
||||||
- `.1.3.6.1.2.1.2.2.1.16.5`
|
|
||||||
- `...`
|
|
||||||
|
|
||||||
In this example, the plugin will gather value of OIDS:
|
|
||||||
|
|
||||||
- `.1.3.6.1.2.1.2.1.0`
|
|
||||||
- `.1.3.6.1.2.1.2.2.1.5.1`
|
|
||||||
- `.1.3.6.1.2.1.2.2.1.16.1`
|
|
||||||
- `.1.3.6.1.2.1.2.2.1.16.2`
|
|
||||||
- `.1.3.6.1.2.1.2.2.1.16.3`
|
|
||||||
- `.1.3.6.1.2.1.2.2.1.16.4`
|
|
||||||
- `.1.3.6.1.2.1.2.2.1.16.5`
|
|
||||||
- `...`
|
|
||||||
|
|
||||||
```toml
|
|
||||||
# Simple bulk example
|
|
||||||
[[inputs.snmp]]
|
|
||||||
## Use 'oids.txt' file to translate oids to names
|
|
||||||
## To generate 'oids.txt' you need to run:
|
|
||||||
## snmptranslate -m all -Tz -On | sed -e 's/"//g' > /tmp/oids.txt
|
|
||||||
## Or if you have an other MIB folder with custom MIBs
|
|
||||||
## snmptranslate -M /mycustommibfolder -Tz -On -m all | sed -e 's/"//g' > oids.txt
|
|
||||||
snmptranslate_file = "/tmp/oids.txt"
|
|
||||||
[[inputs.snmp.host]]
|
|
||||||
address = "127.0.0.1:161"
|
|
||||||
# SNMP community
|
|
||||||
community = "public" # default public
|
|
||||||
# SNMP version (1, 2 or 3)
|
|
||||||
# Version 3 not supported yet
|
|
||||||
version = 2 # default 2
|
|
||||||
# Which get/bulk do you want to collect for this host
|
|
||||||
collect = ["interface_speed", "if_number", "if_out_octets"]
|
|
||||||
|
|
||||||
[[inputs.snmp.get]]
|
|
||||||
name = "interface_speed"
|
|
||||||
oid = "ifSpeed"
|
|
||||||
instance = "1"
|
|
||||||
|
|
||||||
[[inputs.snmp.get]]
|
|
||||||
name = "if_number"
|
|
||||||
oid = "ifNumber"
|
|
||||||
|
|
||||||
[[inputs.snmp.bulk]]
|
|
||||||
name = "if_out_octets"
|
|
||||||
oid = "ifOutOctets"
|
|
||||||
```
|
|
||||||
|
|
||||||
### Table example
|
|
||||||
|
|
||||||
In this example, we remove collect attribute to the host section,
|
|
||||||
but you can still use it in combination of the following part.
|
|
||||||
|
|
||||||
Note: This example is like a bulk request a but using an
|
|
||||||
other configuration
|
|
||||||
|
|
||||||
Telegraf gathers value of OIDS of the table:
|
|
||||||
|
|
||||||
- named **iftable1**
|
|
||||||
|
|
||||||
With **inputs.snmp.table** section the plugin gets oid number:
|
|
||||||
|
|
||||||
- **iftable1** => `.1.3.6.1.2.1.31.1.1.1`
|
|
||||||
|
|
||||||
Also **iftable1** is a table, the plugin will gathers all
|
|
||||||
OIDS in the table and in the subtables
|
|
||||||
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.1`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.1.1`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.1.2`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.1.3`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.1.4`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.1....`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.2`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.2....`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.3`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.3....`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.4`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.4....`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.5`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.5....`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.6....`
|
|
||||||
- `...`
|
|
||||||
|
|
||||||
```toml
|
|
||||||
# Table example
|
|
||||||
[[inputs.snmp]]
|
|
||||||
## Use 'oids.txt' file to translate oids to names
|
|
||||||
## To generate 'oids.txt' you need to run:
|
|
||||||
## snmptranslate -m all -Tz -On | sed -e 's/"//g' > /tmp/oids.txt
|
|
||||||
## Or if you have an other MIB folder with custom MIBs
|
|
||||||
## snmptranslate -M /mycustommibfolder -Tz -On -m all | sed -e 's/"//g' > oids.txt
|
|
||||||
snmptranslate_file = "/tmp/oids.txt"
|
|
||||||
[[inputs.snmp.host]]
|
|
||||||
address = "127.0.0.1:161"
|
|
||||||
# SNMP community
|
|
||||||
community = "public" # default public
|
|
||||||
# SNMP version (1, 2 or 3)
|
|
||||||
# Version 3 not supported yet
|
|
||||||
version = 2 # default 2
|
|
||||||
# Which get/bulk do you want to collect for this host
|
|
||||||
# Which table do you want to collect
|
|
||||||
[[inputs.snmp.host.table]]
|
|
||||||
name = "iftable1"
|
|
||||||
|
|
||||||
# table without mapping neither subtables
|
|
||||||
# This is like bulk request
|
|
||||||
[[inputs.snmp.table]]
|
|
||||||
name = "iftable1"
|
|
||||||
oid = ".1.3.6.1.2.1.31.1.1.1"
|
|
||||||
```
|
|
||||||
|
|
||||||
### Table with subtable example
|
|
||||||
|
|
||||||
In this example, we remove collect attribute to the host section,
|
|
||||||
but you can still use it in combination of the following part.
|
|
||||||
|
|
||||||
Note: This example is like a bulk request a but using an
|
|
||||||
other configuration
|
|
||||||
|
|
||||||
Telegraf gathers value of OIDS of the table:
|
|
||||||
|
|
||||||
- named **iftable2**
|
|
||||||
|
|
||||||
With **inputs.snmp.table** section *AND* **sub_tables** attribute,
|
|
||||||
the plugin will get OIDS from subtables:
|
|
||||||
|
|
||||||
- **iftable2** => `.1.3.6.1.2.1.2.2.1.13`
|
|
||||||
|
|
||||||
Also **iftable2** is a table, the plugin will gathers all
|
|
||||||
OIDS in subtables:
|
|
||||||
|
|
||||||
- `.1.3.6.1.2.1.2.2.1.13.1`
|
|
||||||
- `.1.3.6.1.2.1.2.2.1.13.2`
|
|
||||||
- `.1.3.6.1.2.1.2.2.1.13.3`
|
|
||||||
- `.1.3.6.1.2.1.2.2.1.13.4`
|
|
||||||
- `.1.3.6.1.2.1.2.2.1.13....`
|
|
||||||
|
|
||||||
```toml
|
|
||||||
# Table with subtable example
|
|
||||||
[[inputs.snmp]]
|
|
||||||
## Use 'oids.txt' file to translate oids to names
|
|
||||||
## To generate 'oids.txt' you need to run:
|
|
||||||
## snmptranslate -m all -Tz -On | sed -e 's/"//g' > /tmp/oids.txt
|
|
||||||
## Or if you have an other MIB folder with custom MIBs
|
|
||||||
## snmptranslate -M /mycustommibfolder -Tz -On -m all | sed -e 's/"//g' > oids.txt
|
|
||||||
snmptranslate_file = "/tmp/oids.txt"
|
|
||||||
[[inputs.snmp.host]]
|
|
||||||
address = "127.0.0.1:161"
|
|
||||||
# SNMP community
|
|
||||||
community = "public" # default public
|
|
||||||
# SNMP version (1, 2 or 3)
|
|
||||||
# Version 3 not supported yet
|
|
||||||
version = 2 # default 2
|
|
||||||
# Which table do you want to collect
|
|
||||||
[[inputs.snmp.host.table]]
|
|
||||||
name = "iftable2"
|
|
||||||
|
|
||||||
# table without mapping but with subtables
|
|
||||||
[[inputs.snmp.table]]
|
|
||||||
name = "iftable2"
|
|
||||||
sub_tables = [".1.3.6.1.2.1.2.2.1.13"]
|
|
||||||
# note
|
|
||||||
# oid attribute is useless
|
|
||||||
```
|
|
||||||
|
|
||||||
### Table with mapping example
|
|
||||||
|
|
||||||
In this example, we remove collect attribute to the host section,
|
|
||||||
but you can still use it in combination of the following part.
|
|
||||||
|
|
||||||
Telegraf gathers value of OIDS of the table:
|
|
||||||
|
|
||||||
- named **iftable3**
|
|
||||||
|
|
||||||
With **inputs.snmp.table** section the plugin gets oid number:
|
|
||||||
|
|
||||||
- **iftable3** => `.1.3.6.1.2.1.31.1.1.1`
|
|
||||||
|
|
||||||
Also **iftable2** is a table, the plugin will gathers all
|
|
||||||
OIDS in the table and in the subtables
|
|
||||||
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.1`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.1.1`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.1.2`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.1.3`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.1.4`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.1....`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.2`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.2....`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.3`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.3....`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.4`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.4....`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.5`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.5....`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.6....`
|
|
||||||
- `...`
|
|
||||||
|
|
||||||
But the **include_instances** attribute will filter which OIDS
|
|
||||||
will be gathered; As you see, there is an other attribute, `mapping_table`.
|
|
||||||
`include_instances` and `mapping_table` permit to build a hash table
|
|
||||||
to filter only OIDS you want.
|
|
||||||
Let's say, we have the following data on SNMP server:
|
|
||||||
|
|
||||||
- OID: `.1.3.6.1.2.1.31.1.1.1.1.1` has as value: `enp5s0`
|
|
||||||
- OID: `.1.3.6.1.2.1.31.1.1.1.1.2` has as value: `enp5s1`
|
|
||||||
- OID: `.1.3.6.1.2.1.31.1.1.1.1.3` has as value: `enp5s2`
|
|
||||||
- OID: `.1.3.6.1.2.1.31.1.1.1.1.4` has as value: `eth0`
|
|
||||||
- OID: `.1.3.6.1.2.1.31.1.1.1.1.5` has as value: `eth1`
|
|
||||||
|
|
||||||
The plugin will build the following hash table:
|
|
||||||
|
|
||||||
| instance name | instance id |
|
|
||||||
|---------------|-------------|
|
|
||||||
| `enp5s0` | `1` |
|
|
||||||
| `enp5s1` | `2` |
|
|
||||||
| `enp5s2` | `3` |
|
|
||||||
| `eth0` | `4` |
|
|
||||||
| `eth1` | `5` |
|
|
||||||
|
|
||||||
With the **include_instances** attribute, the plugin will gather
|
|
||||||
the following OIDS:
|
|
||||||
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.1.1`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.1.5`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.2.1`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.2.5`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.3.1`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.3.5`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.4.1`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.4.5`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.5.1`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.5.5`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.6.1`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.6.5`
|
|
||||||
- `...`
|
|
||||||
|
|
||||||
Note: the plugin will add instance name as tag *instance*
|
|
||||||
|
|
||||||
```toml
|
|
||||||
# Simple table with mapping example
|
|
||||||
[[inputs.snmp]]
|
|
||||||
## Use 'oids.txt' file to translate oids to names
|
|
||||||
## To generate 'oids.txt' you need to run:
|
|
||||||
## snmptranslate -m all -Tz -On | sed -e 's/"//g' > /tmp/oids.txt
|
|
||||||
## Or if you have an other MIB folder with custom MIBs
|
|
||||||
## snmptranslate -M /mycustommibfolder -Tz -On -m all | sed -e 's/"//g' > oids.txt
|
|
||||||
snmptranslate_file = "/tmp/oids.txt"
|
|
||||||
[[inputs.snmp.host]]
|
|
||||||
address = "127.0.0.1:161"
|
|
||||||
# SNMP community
|
|
||||||
community = "public" # default public
|
|
||||||
# SNMP version (1, 2 or 3)
|
|
||||||
# Version 3 not supported yet
|
|
||||||
version = 2 # default 2
|
|
||||||
# Which table do you want to collect
|
|
||||||
[[inputs.snmp.host.table]]
|
|
||||||
name = "iftable3"
|
|
||||||
include_instances = ["enp5s0", "eth1"]
|
|
||||||
|
|
||||||
# table with mapping but without subtables
|
|
||||||
[[inputs.snmp.table]]
|
|
||||||
name = "iftable3"
|
|
||||||
oid = ".1.3.6.1.2.1.31.1.1.1"
|
|
||||||
# if empty. get all instances
|
|
||||||
mapping_table = ".1.3.6.1.2.1.31.1.1.1.1"
|
|
||||||
# if empty, get all subtables
|
|
||||||
```
|
|
||||||
|
|
||||||
### Table with both mapping and subtable example
|
|
||||||
|
|
||||||
In this example, we remove collect attribute to the host section,
|
|
||||||
but you can still use it in combination of the following part.
|
|
||||||
|
|
||||||
Telegraf gathers value of OIDS of the table:
|
|
||||||
|
|
||||||
- named **iftable4**
|
|
||||||
|
|
||||||
With **inputs.snmp.table** section *AND* **sub_tables** attribute,
|
|
||||||
the plugin will get OIDS from subtables:
|
|
||||||
|
|
||||||
- **iftable4** => `.1.3.6.1.2.1.31.1.1.1`
|
|
||||||
|
|
||||||
Also **iftable2** is a table, the plugin will gathers all
|
|
||||||
OIDS in the table and in the subtables
|
|
||||||
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.6.1
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.6.2`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.6.3`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.6.4`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.6....`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.10.1`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.10.2`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.10.3`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.10.4`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.10....`
|
|
||||||
|
|
||||||
But the **include_instances** attribute will filter which OIDS
|
|
||||||
will be gathered; As you see, there is an other attribute, `mapping_table`.
|
|
||||||
`include_instances` and `mapping_table` permit to build a hash table
|
|
||||||
to filter only OIDS you want.
|
|
||||||
Let's say, we have the following data on SNMP server:
|
|
||||||
|
|
||||||
- OID: `.1.3.6.1.2.1.31.1.1.1.1.1` has as value: `enp5s0`
|
|
||||||
- OID: `.1.3.6.1.2.1.31.1.1.1.1.2` has as value: `enp5s1`
|
|
||||||
- OID: `.1.3.6.1.2.1.31.1.1.1.1.3` has as value: `enp5s2`
|
|
||||||
- OID: `.1.3.6.1.2.1.31.1.1.1.1.4` has as value: `eth0`
|
|
||||||
- OID: `.1.3.6.1.2.1.31.1.1.1.1.5` has as value: `eth1`
|
|
||||||
|
|
||||||
The plugin will build the following hash table:
|
|
||||||
|
|
||||||
| instance name | instance id |
|
|
||||||
|---------------|-------------|
|
|
||||||
| `enp5s0` | `1` |
|
|
||||||
| `enp5s1` | `2` |
|
|
||||||
| `enp5s2` | `3` |
|
|
||||||
| `eth0` | `4` |
|
|
||||||
| `eth1` | `5` |
|
|
||||||
|
|
||||||
With the **include_instances** attribute, the plugin will gather
|
|
||||||
the following OIDS:
|
|
||||||
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.6.1`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.6.5`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.10.1`
|
|
||||||
- `.1.3.6.1.2.1.31.1.1.1.10.5`
|
|
||||||
|
|
||||||
Note: the plugin will add instance name as tag *instance*
|
|
||||||
|
|
||||||
```toml
|
|
||||||
# Table with both mapping and subtable example
|
|
||||||
[[inputs.snmp]]
|
|
||||||
## Use 'oids.txt' file to translate oids to names
|
|
||||||
## To generate 'oids.txt' you need to run:
|
|
||||||
## snmptranslate -m all -Tz -On | sed -e 's/"//g' > /tmp/oids.txt
|
|
||||||
## Or if you have an other MIB folder with custom MIBs
|
|
||||||
## snmptranslate -M /mycustommibfolder -Tz -On -m all | sed -e 's/"//g' > oids.txt
|
|
||||||
snmptranslate_file = "/tmp/oids.txt"
|
|
||||||
[[inputs.snmp.host]]
|
|
||||||
address = "127.0.0.1:161"
|
|
||||||
# SNMP community
|
|
||||||
community = "public" # default public
|
|
||||||
# SNMP version (1, 2 or 3)
|
|
||||||
# Version 3 not supported yet
|
|
||||||
version = 2 # default 2
|
|
||||||
# Which table do you want to collect
|
|
||||||
[[inputs.snmp.host.table]]
|
|
||||||
name = "iftable4"
|
|
||||||
include_instances = ["enp5s0", "eth1"]
|
|
||||||
|
|
||||||
# table with both mapping and subtables
|
|
||||||
[[inputs.snmp.table]]
|
|
||||||
name = "iftable4"
|
|
||||||
# if empty get all instances
|
|
||||||
mapping_table = ".1.3.6.1.2.1.31.1.1.1.1"
|
|
||||||
# if empty get all subtables
|
|
||||||
# sub_tables could be not "real subtables"
|
|
||||||
sub_tables=[".1.3.6.1.2.1.2.2.1.13", "bytes_recv", "bytes_send"]
|
|
||||||
# note
|
|
||||||
# oid attribute is useless
|
|
||||||
|
|
||||||
# SNMP SUBTABLES
|
|
||||||
[[inputs.snmp.subtable]]
|
|
||||||
name = "bytes_recv"
|
|
||||||
oid = ".1.3.6.1.2.1.31.1.1.1.6"
|
|
||||||
unit = "octets"
|
|
||||||
|
|
||||||
[[inputs.snmp.subtable]]
|
|
||||||
name = "bytes_send"
|
|
||||||
oid = ".1.3.6.1.2.1.31.1.1.1.10"
|
|
||||||
unit = "octets"
|
|
||||||
```
|
|
||||||
|
|
||||||
### Configuration notes
|
|
||||||
|
|
||||||
- In **inputs.snmp.table** section, the `oid` attribute is useless if
|
|
||||||
the `sub_tables` attributes is defined
|
|
||||||
|
|
||||||
- In **inputs.snmp.subtable** section, you can put a name from `snmptranslate_file`
|
|
||||||
as `oid` attribute instead of a valid OID
|
|
||||||
|
|
||||||
## Metrics
|
|
||||||
|
|
||||||
With the last example (Table with both mapping and subtable example):
|
|
||||||
|
|
||||||
- ifHCOutOctets
|
|
||||||
- ifHCOutOctets
|
|
||||||
- ifInDiscards
|
|
||||||
- ifInDiscards
|
|
||||||
- ifHCInOctets
|
|
||||||
- ifHCInOctets
|
|
||||||
|
|
||||||
### Tags
|
|
||||||
|
|
||||||
With the last example (Table with both mapping and subtable example):
|
|
||||||
|
|
||||||
- ifHCOutOctets
|
|
||||||
- host
|
|
||||||
- instance
|
|
||||||
- unit
|
|
||||||
- ifInDiscards
|
|
||||||
- host
|
|
||||||
- instance
|
|
||||||
- ifHCInOctets
|
|
||||||
- host
|
|
||||||
- instance
|
|
||||||
- unit
|
|
||||||
|
|
||||||
## Example Output
|
|
||||||
|
|
||||||
With the last example (Table with both mapping and subtable example):
|
|
||||||
|
|
||||||
```text
|
|
||||||
ifHCOutOctets,host=127.0.0.1,instance=enp5s0,unit=octets ifHCOutOctets=10565628i 1456878706044462901
|
|
||||||
ifInDiscards,host=127.0.0.1,instance=enp5s0 ifInDiscards=0i 1456878706044510264
|
|
||||||
ifHCInOctets,host=127.0.0.1,instance=enp5s0,unit=octets ifHCInOctets=76351777i 1456878706044531312
|
|
||||||
```
|
|
||||||
|
|
||||||
[SNMP input plugin]: /plugins/inputs/snmp
|
|
||||||
|
|
@ -1,90 +0,0 @@
|
||||||
[[inputs.snmp_legacy]]
|
|
||||||
## Use 'oids.txt' file to translate oids to names
|
|
||||||
## To generate 'oids.txt' you need to run:
|
|
||||||
## snmptranslate -m all -Tz -On | sed -e 's/"//g' > /tmp/oids.txt
|
|
||||||
## Or if you have an other MIB folder with custom MIBs
|
|
||||||
## snmptranslate -M /mycustommibfolder -Tz -On -m all | sed -e 's/"//g' > oids.txt
|
|
||||||
snmptranslate_file = "/tmp/oids.txt"
|
|
||||||
[[inputs.snmp.host]]
|
|
||||||
address = "192.168.2.2:161"
|
|
||||||
# SNMP community
|
|
||||||
community = "public" # default public
|
|
||||||
# SNMP version (1, 2 or 3)
|
|
||||||
# Version 3 not supported yet
|
|
||||||
version = 2 # default 2
|
|
||||||
# SNMP response timeout
|
|
||||||
timeout = 2.0 # default 2.0
|
|
||||||
# SNMP request retries
|
|
||||||
retries = 2 # default 2
|
|
||||||
# Which get/bulk do you want to collect for this host
|
|
||||||
collect = ["mybulk", "sysservices", "sysdescr"]
|
|
||||||
# Simple list of OIDs to get, in addition to "collect"
|
|
||||||
get_oids = []
|
|
||||||
[[inputs.snmp.host]]
|
|
||||||
address = "192.168.2.3:161"
|
|
||||||
community = "public"
|
|
||||||
version = 2
|
|
||||||
timeout = 2.0
|
|
||||||
retries = 2
|
|
||||||
collect = ["mybulk"]
|
|
||||||
get_oids = [
|
|
||||||
"ifNumber",
|
|
||||||
".1.3.6.1.2.1.1.3.0",
|
|
||||||
]
|
|
||||||
[[inputs.snmp.get]]
|
|
||||||
name = "ifnumber"
|
|
||||||
oid = "ifNumber"
|
|
||||||
[[inputs.snmp.get]]
|
|
||||||
name = "interface_speed"
|
|
||||||
oid = "ifSpeed"
|
|
||||||
instance = "0"
|
|
||||||
[[inputs.snmp.get]]
|
|
||||||
name = "sysuptime"
|
|
||||||
oid = ".1.3.6.1.2.1.1.3.0"
|
|
||||||
unit = "second"
|
|
||||||
[[inputs.snmp.bulk]]
|
|
||||||
name = "mybulk"
|
|
||||||
max_repetition = 127
|
|
||||||
oid = ".1.3.6.1.2.1.1"
|
|
||||||
[[inputs.snmp.bulk]]
|
|
||||||
name = "ifoutoctets"
|
|
||||||
max_repetition = 127
|
|
||||||
oid = "ifOutOctets"
|
|
||||||
[[inputs.snmp.host]]
|
|
||||||
address = "192.168.2.13:161"
|
|
||||||
#address = "127.0.0.1:161"
|
|
||||||
community = "public"
|
|
||||||
version = 2
|
|
||||||
timeout = 2.0
|
|
||||||
retries = 2
|
|
||||||
#collect = ["mybulk", "sysservices", "sysdescr", "systype"]
|
|
||||||
collect = ["sysuptime" ]
|
|
||||||
[[inputs.snmp.host.table]]
|
|
||||||
name = "iftable3"
|
|
||||||
include_instances = ["enp5s0", "eth1"]
|
|
||||||
# SNMP TABLEs
|
|
||||||
# table without mapping neither subtables
|
|
||||||
[[inputs.snmp.table]]
|
|
||||||
name = "iftable1"
|
|
||||||
oid = ".1.3.6.1.2.1.31.1.1.1"
|
|
||||||
# table without mapping but with subtables
|
|
||||||
[[inputs.snmp.table]]
|
|
||||||
name = "iftable2"
|
|
||||||
oid = ".1.3.6.1.2.1.31.1.1.1"
|
|
||||||
sub_tables = [".1.3.6.1.2.1.2.2.1.13"]
|
|
||||||
# table with mapping but without subtables
|
|
||||||
[[inputs.snmp.table]]
|
|
||||||
name = "iftable3"
|
|
||||||
oid = ".1.3.6.1.2.1.31.1.1.1"
|
|
||||||
# if empty. get all instances
|
|
||||||
mapping_table = ".1.3.6.1.2.1.31.1.1.1.1"
|
|
||||||
# if empty, get all subtables
|
|
||||||
# table with both mapping and subtables
|
|
||||||
[[inputs.snmp.table]]
|
|
||||||
name = "iftable4"
|
|
||||||
oid = ".1.3.6.1.2.1.31.1.1.1"
|
|
||||||
# if empty get all instances
|
|
||||||
mapping_table = ".1.3.6.1.2.1.31.1.1.1.1"
|
|
||||||
# if empty get all subtables
|
|
||||||
# sub_tables could be not "real subtables"
|
|
||||||
sub_tables=[".1.3.6.1.2.1.2.2.1.13", "bytes_recv", "bytes_send"]
|
|
||||||
|
|
@ -1,710 +0,0 @@
|
||||||
//go:generate ../../../tools/readme_config_includer/generator
|
|
||||||
package snmp_legacy
|
|
||||||
|
|
||||||
import (
|
|
||||||
_ "embed"
|
|
||||||
"fmt"
|
|
||||||
"net"
|
|
||||||
"os"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/gosnmp/gosnmp"
|
|
||||||
|
|
||||||
"github.com/influxdata/telegraf"
|
|
||||||
"github.com/influxdata/telegraf/plugins/inputs"
|
|
||||||
)
|
|
||||||
|
|
||||||
//go:embed sample.conf
|
|
||||||
var sampleConfig string
|
|
||||||
|
|
||||||
// Snmp is a snmp plugin
|
|
||||||
type Snmp struct {
|
|
||||||
Host []Host
|
|
||||||
Get []Data
|
|
||||||
Bulk []Data
|
|
||||||
Table []Table
|
|
||||||
Subtable []Subtable
|
|
||||||
SnmptranslateFile string
|
|
||||||
|
|
||||||
Log telegraf.Logger `toml:"-"`
|
|
||||||
|
|
||||||
nameToOid map[string]string
|
|
||||||
initNode Node
|
|
||||||
subTableMap map[string]Subtable
|
|
||||||
}
|
|
||||||
|
|
||||||
type Host struct {
|
|
||||||
Address string
|
|
||||||
Community string
|
|
||||||
// SNMP version. Default 2
|
|
||||||
Version int
|
|
||||||
// SNMP timeout, in seconds. 0 means no timeout
|
|
||||||
Timeout float64
|
|
||||||
// SNMP retries
|
|
||||||
Retries int
|
|
||||||
// Data to collect (list of Data names)
|
|
||||||
Collect []string
|
|
||||||
// easy get oids
|
|
||||||
GetOids []string
|
|
||||||
// Table
|
|
||||||
Table []HostTable
|
|
||||||
// Oids
|
|
||||||
internalGetOids []Data
|
|
||||||
bulkOids []Data
|
|
||||||
tables []HostTable
|
|
||||||
// array of processed oids
|
|
||||||
// to skip oid duplication
|
|
||||||
processedOids []string
|
|
||||||
|
|
||||||
OidInstanceMapping map[string]map[string]string
|
|
||||||
}
|
|
||||||
|
|
||||||
type Table struct {
|
|
||||||
// name = "iftable"
|
|
||||||
Name string
|
|
||||||
// oid = ".1.3.6.1.2.1.31.1.1.1"
|
|
||||||
Oid string
|
|
||||||
//if empty get all instances
|
|
||||||
//mapping_table = ".1.3.6.1.2.1.31.1.1.1.1"
|
|
||||||
MappingTable string
|
|
||||||
// if empty get all subtables
|
|
||||||
// sub_tables could be not "real subtables"
|
|
||||||
//sub_tables=[".1.3.6.1.2.1.2.2.1.13", "bytes_recv", "bytes_send"]
|
|
||||||
SubTables []string
|
|
||||||
}
|
|
||||||
|
|
||||||
type HostTable struct {
|
|
||||||
// name = "iftable"
|
|
||||||
Name string
|
|
||||||
// Includes only these instances
|
|
||||||
// include_instances = ["eth0", "eth1"]
|
|
||||||
IncludeInstances []string
|
|
||||||
// Excludes only these instances
|
|
||||||
// exclude_instances = ["eth20", "eth21"]
|
|
||||||
ExcludeInstances []string
|
|
||||||
// From Table struct
|
|
||||||
oid string
|
|
||||||
mappingTable string
|
|
||||||
subTables []string
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO find better names
|
|
||||||
type Subtable struct {
|
|
||||||
//name = "bytes_send"
|
|
||||||
Name string
|
|
||||||
//oid = ".1.3.6.1.2.1.31.1.1.1.10"
|
|
||||||
Oid string
|
|
||||||
//unit = "octets"
|
|
||||||
Unit string
|
|
||||||
}
|
|
||||||
|
|
||||||
type Data struct {
|
|
||||||
Name string
|
|
||||||
// OID (could be numbers or name)
|
|
||||||
Oid string
|
|
||||||
// Unit
|
|
||||||
Unit string
|
|
||||||
// SNMP getbulk max repetition
|
|
||||||
MaxRepetition uint32 `toml:"max_repetition"`
|
|
||||||
// SNMP Instance (default 0)
|
|
||||||
// (only used with GET request and if
|
|
||||||
// OID is a name from snmptranslate file)
|
|
||||||
Instance string
|
|
||||||
// OID (only number) (used for computation)
|
|
||||||
rawOid string
|
|
||||||
}
|
|
||||||
|
|
||||||
type Node struct {
|
|
||||||
id string
|
|
||||||
name string
|
|
||||||
subnodes map[string]Node
|
|
||||||
}
|
|
||||||
|
|
||||||
func fillnode(parentNode Node, oidName string, ids []string) {
|
|
||||||
// ids = ["1", "3", "6", ...]
|
|
||||||
id, ids := ids[0], ids[1:]
|
|
||||||
node, ok := parentNode.subnodes[id]
|
|
||||||
if !ok {
|
|
||||||
node = Node{
|
|
||||||
id: id,
|
|
||||||
name: "",
|
|
||||||
subnodes: make(map[string]Node),
|
|
||||||
}
|
|
||||||
if len(ids) == 0 {
|
|
||||||
node.name = oidName
|
|
||||||
}
|
|
||||||
parentNode.subnodes[id] = node
|
|
||||||
}
|
|
||||||
if len(ids) > 0 {
|
|
||||||
fillnode(node, oidName, ids)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func findNodeName(node Node, ids []string) (oidName string, instance string) {
|
|
||||||
// ids = ["1", "3", "6", ...]
|
|
||||||
if len(ids) == 1 {
|
|
||||||
return node.name, ids[0]
|
|
||||||
}
|
|
||||||
id, ids := ids[0], ids[1:]
|
|
||||||
// Get node
|
|
||||||
subnode, ok := node.subnodes[id]
|
|
||||||
if ok {
|
|
||||||
return findNodeName(subnode, ids)
|
|
||||||
}
|
|
||||||
// We got a node
|
|
||||||
// Get node name
|
|
||||||
if node.name != "" && len(ids) == 0 && id == "0" {
|
|
||||||
// node with instance 0
|
|
||||||
return node.name, "0"
|
|
||||||
} else if node.name != "" && len(ids) == 0 && id != "0" {
|
|
||||||
// node with an instance
|
|
||||||
return node.name, id
|
|
||||||
} else if node.name != "" && len(ids) > 0 {
|
|
||||||
// node with subinstances
|
|
||||||
return node.name, strings.Join(ids, ".")
|
|
||||||
}
|
|
||||||
// return an empty node name
|
|
||||||
return node.name, ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*Snmp) SampleConfig() string {
|
|
||||||
return sampleConfig
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Snmp) Gather(acc telegraf.Accumulator) error {
|
|
||||||
// TODO put this in cache on first run
|
|
||||||
// Create subtables mapping
|
|
||||||
if len(s.subTableMap) == 0 {
|
|
||||||
s.subTableMap = make(map[string]Subtable)
|
|
||||||
for _, sb := range s.Subtable {
|
|
||||||
s.subTableMap[sb.Name] = sb
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// TODO put this in cache on first run
|
|
||||||
// Create oid tree
|
|
||||||
if s.SnmptranslateFile != "" && len(s.initNode.subnodes) == 0 {
|
|
||||||
s.nameToOid = make(map[string]string)
|
|
||||||
s.initNode = Node{
|
|
||||||
id: "1",
|
|
||||||
name: "",
|
|
||||||
subnodes: make(map[string]Node),
|
|
||||||
}
|
|
||||||
|
|
||||||
data, err := os.ReadFile(s.SnmptranslateFile)
|
|
||||||
if err != nil {
|
|
||||||
s.Log.Errorf("Reading SNMPtranslate file error: %s", err.Error())
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, line := range strings.Split(string(data), "\n") {
|
|
||||||
oids := strings.Fields(line)
|
|
||||||
if len(oids) == 2 && oids[1] != "" {
|
|
||||||
oidName := oids[0]
|
|
||||||
oid := oids[1]
|
|
||||||
fillnode(s.initNode, oidName, strings.Split(oid, "."))
|
|
||||||
s.nameToOid[oidName] = oid
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Fetching data
|
|
||||||
for _, host := range s.Host {
|
|
||||||
// Set default args
|
|
||||||
if len(host.Address) == 0 {
|
|
||||||
host.Address = "127.0.0.1:161"
|
|
||||||
}
|
|
||||||
if host.Community == "" {
|
|
||||||
host.Community = "public"
|
|
||||||
}
|
|
||||||
if host.Timeout <= 0 {
|
|
||||||
host.Timeout = 2.0
|
|
||||||
}
|
|
||||||
if host.Retries <= 0 {
|
|
||||||
host.Retries = 2
|
|
||||||
}
|
|
||||||
// Prepare host
|
|
||||||
// Get Easy GET oids
|
|
||||||
for _, oidstring := range host.GetOids {
|
|
||||||
oid := Data{}
|
|
||||||
if val, ok := s.nameToOid[oidstring]; ok {
|
|
||||||
// TODO should we add the 0 instance ?
|
|
||||||
oid.Name = oidstring
|
|
||||||
oid.Oid = val
|
|
||||||
oid.rawOid = "." + val + ".0"
|
|
||||||
} else {
|
|
||||||
oid.Name = oidstring
|
|
||||||
oid.Oid = oidstring
|
|
||||||
if oidstring[:1] != "." {
|
|
||||||
oid.rawOid = "." + oidstring
|
|
||||||
} else {
|
|
||||||
oid.rawOid = oidstring
|
|
||||||
}
|
|
||||||
}
|
|
||||||
host.internalGetOids = append(host.internalGetOids, oid)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, oidName := range host.Collect {
|
|
||||||
// Get GET oids
|
|
||||||
for _, oid := range s.Get {
|
|
||||||
if oid.Name == oidName {
|
|
||||||
if val, ok := s.nameToOid[oid.Oid]; ok {
|
|
||||||
// TODO should we add the 0 instance ?
|
|
||||||
if oid.Instance != "" {
|
|
||||||
oid.rawOid = "." + val + "." + oid.Instance
|
|
||||||
} else {
|
|
||||||
oid.rawOid = "." + val + ".0"
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
oid.rawOid = oid.Oid
|
|
||||||
}
|
|
||||||
host.internalGetOids = append(host.internalGetOids, oid)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Get GETBULK oids
|
|
||||||
for _, oid := range s.Bulk {
|
|
||||||
if oid.Name == oidName {
|
|
||||||
if val, ok := s.nameToOid[oid.Oid]; ok {
|
|
||||||
oid.rawOid = "." + val
|
|
||||||
} else {
|
|
||||||
oid.rawOid = oid.Oid
|
|
||||||
}
|
|
||||||
host.bulkOids = append(host.bulkOids, oid)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Table
|
|
||||||
for _, hostTable := range host.Table {
|
|
||||||
for _, snmpTable := range s.Table {
|
|
||||||
if hostTable.Name == snmpTable.Name {
|
|
||||||
table := hostTable
|
|
||||||
table.oid = snmpTable.Oid
|
|
||||||
table.mappingTable = snmpTable.MappingTable
|
|
||||||
table.subTables = snmpTable.SubTables
|
|
||||||
host.tables = append(host.tables, table)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Launch Mapping
|
|
||||||
// TODO put this in cache on first run
|
|
||||||
// TODO save mapping and computed oids
|
|
||||||
// to do it only the first time
|
|
||||||
// only if len(s.OidInstanceMapping) == 0
|
|
||||||
if len(host.OidInstanceMapping) >= 0 {
|
|
||||||
if err := host.SNMPMap(s.nameToOid, s.subTableMap); err != nil {
|
|
||||||
s.Log.Errorf("Mapping error for host %q: %s", host.Address, err.Error())
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Launch Get requests
|
|
||||||
if err := host.SNMPGet(acc, s.initNode); err != nil {
|
|
||||||
s.Log.Errorf("Error for host %q: %s", host.Address, err.Error())
|
|
||||||
}
|
|
||||||
if err := host.SNMPBulk(acc, s.initNode); err != nil {
|
|
||||||
s.Log.Errorf("Error for host %q: %s", host.Address, err.Error())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *Host) SNMPMap(
|
|
||||||
nameToOid map[string]string,
|
|
||||||
subTableMap map[string]Subtable,
|
|
||||||
) error {
|
|
||||||
if h.OidInstanceMapping == nil {
|
|
||||||
h.OidInstanceMapping = make(map[string]map[string]string)
|
|
||||||
}
|
|
||||||
// Get snmp client
|
|
||||||
snmpClient, err := h.GetSNMPClient()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
// Deconnection
|
|
||||||
defer snmpClient.Conn.Close()
|
|
||||||
// Prepare OIDs
|
|
||||||
for _, table := range h.tables {
|
|
||||||
// We don't have mapping
|
|
||||||
if table.mappingTable == "" {
|
|
||||||
if len(table.subTables) == 0 {
|
|
||||||
// If We don't have mapping table
|
|
||||||
// neither subtables list
|
|
||||||
// This is just a bulk request
|
|
||||||
oid := Data{}
|
|
||||||
oid.Oid = table.oid
|
|
||||||
if val, ok := nameToOid[oid.Oid]; ok {
|
|
||||||
oid.rawOid = "." + val
|
|
||||||
} else {
|
|
||||||
oid.rawOid = oid.Oid
|
|
||||||
}
|
|
||||||
h.bulkOids = append(h.bulkOids, oid)
|
|
||||||
} else {
|
|
||||||
// If We don't have mapping table
|
|
||||||
// but we have subtables
|
|
||||||
// This is a bunch of bulk requests
|
|
||||||
// For each subtable ...
|
|
||||||
for _, sb := range table.subTables {
|
|
||||||
// ... we create a new Data (oid) object
|
|
||||||
oid := Data{}
|
|
||||||
// Looking for more information about this subtable
|
|
||||||
ssb, exists := subTableMap[sb]
|
|
||||||
if exists {
|
|
||||||
// We found a subtable section in config files
|
|
||||||
oid.Oid = ssb.Oid
|
|
||||||
oid.rawOid = ssb.Oid
|
|
||||||
oid.Unit = ssb.Unit
|
|
||||||
} else {
|
|
||||||
// We did NOT find a subtable section in config files
|
|
||||||
oid.Oid = sb
|
|
||||||
oid.rawOid = sb
|
|
||||||
}
|
|
||||||
// TODO check oid validity
|
|
||||||
|
|
||||||
// Add the new oid to bulkOids list
|
|
||||||
h.bulkOids = append(h.bulkOids, oid)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// We have a mapping table
|
|
||||||
// We need to query this table
|
|
||||||
// To get mapping between instance id
|
|
||||||
// and instance name
|
|
||||||
oidAsked := table.mappingTable
|
|
||||||
oidNext := oidAsked
|
|
||||||
needMoreRequests := true
|
|
||||||
// Set max repetition
|
|
||||||
maxRepetition := uint32(32)
|
|
||||||
// Launch requests
|
|
||||||
for needMoreRequests {
|
|
||||||
// Launch request
|
|
||||||
result, err3 := snmpClient.GetBulk([]string{oidNext}, 0, maxRepetition)
|
|
||||||
if err3 != nil {
|
|
||||||
return err3
|
|
||||||
}
|
|
||||||
|
|
||||||
lastOid := ""
|
|
||||||
for _, variable := range result.Variables {
|
|
||||||
lastOid = variable.Name
|
|
||||||
if !strings.HasPrefix(variable.Name, oidAsked) {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
switch variable.Type {
|
|
||||||
// handle instance names
|
|
||||||
case gosnmp.OctetString:
|
|
||||||
// Check if instance is in includes instances
|
|
||||||
getInstances := true
|
|
||||||
if len(table.IncludeInstances) > 0 {
|
|
||||||
getInstances = false
|
|
||||||
for _, instance := range table.IncludeInstances {
|
|
||||||
if instance == string(variable.Value.([]byte)) {
|
|
||||||
getInstances = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Check if instance is in excludes instances
|
|
||||||
if len(table.ExcludeInstances) > 0 {
|
|
||||||
getInstances = true
|
|
||||||
for _, instance := range table.ExcludeInstances {
|
|
||||||
if instance == string(variable.Value.([]byte)) {
|
|
||||||
getInstances = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// We don't want this instance
|
|
||||||
if !getInstances {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// remove oid table from the complete oid
|
|
||||||
// in order to get the current instance id
|
|
||||||
key := strings.Replace(variable.Name, oidAsked, "", 1)
|
|
||||||
|
|
||||||
if len(table.subTables) == 0 {
|
|
||||||
// We have a mapping table
|
|
||||||
// but no subtables
|
|
||||||
// This is just a bulk request
|
|
||||||
|
|
||||||
// Building mapping table
|
|
||||||
mapping := map[string]string{strings.Trim(key, "."): string(variable.Value.([]byte))}
|
|
||||||
_, exists := h.OidInstanceMapping[table.oid]
|
|
||||||
if exists {
|
|
||||||
h.OidInstanceMapping[table.oid][strings.Trim(key, ".")] = string(variable.Value.([]byte))
|
|
||||||
} else {
|
|
||||||
h.OidInstanceMapping[table.oid] = mapping
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add table oid in bulk oid list
|
|
||||||
oid := Data{}
|
|
||||||
oid.Oid = table.oid
|
|
||||||
if val, ok := nameToOid[oid.Oid]; ok {
|
|
||||||
oid.rawOid = "." + val
|
|
||||||
} else {
|
|
||||||
oid.rawOid = oid.Oid
|
|
||||||
}
|
|
||||||
h.bulkOids = append(h.bulkOids, oid)
|
|
||||||
} else {
|
|
||||||
// We have a mapping table
|
|
||||||
// and some subtables
|
|
||||||
// This is a bunch of get requests
|
|
||||||
// This is the best case :)
|
|
||||||
|
|
||||||
// For each subtable ...
|
|
||||||
for _, sb := range table.subTables {
|
|
||||||
// ... we create a new Data (oid) object
|
|
||||||
oid := Data{}
|
|
||||||
// Looking for more information about this subtable
|
|
||||||
ssb, exists := subTableMap[sb]
|
|
||||||
if exists {
|
|
||||||
// We found a subtable section in config files
|
|
||||||
oid.Oid = ssb.Oid + key
|
|
||||||
oid.rawOid = ssb.Oid + key
|
|
||||||
oid.Unit = ssb.Unit
|
|
||||||
oid.Instance = string(variable.Value.([]byte))
|
|
||||||
} else {
|
|
||||||
// We did NOT find a subtable section in config files
|
|
||||||
oid.Oid = sb + key
|
|
||||||
oid.rawOid = sb + key
|
|
||||||
oid.Instance = string(variable.Value.([]byte))
|
|
||||||
}
|
|
||||||
// TODO check oid validity
|
|
||||||
|
|
||||||
// Add the new oid to internalGetOids list
|
|
||||||
h.internalGetOids = append(h.internalGetOids, oid)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Determine if we need more requests
|
|
||||||
if strings.HasPrefix(lastOid, oidAsked) {
|
|
||||||
needMoreRequests = true
|
|
||||||
oidNext = lastOid
|
|
||||||
} else {
|
|
||||||
needMoreRequests = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Mapping finished
|
|
||||||
|
|
||||||
// Create newoids based on mapping
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *Host) SNMPGet(acc telegraf.Accumulator, initNode Node) error {
|
|
||||||
// Get snmp client
|
|
||||||
snmpClient, err := h.GetSNMPClient()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
// Deconnection
|
|
||||||
defer snmpClient.Conn.Close()
|
|
||||||
// Prepare OIDs
|
|
||||||
oidsList := make(map[string]Data)
|
|
||||||
for _, oid := range h.internalGetOids {
|
|
||||||
oidsList[oid.rawOid] = oid
|
|
||||||
}
|
|
||||||
oidsNameList := make([]string, 0, len(oidsList))
|
|
||||||
for _, oid := range oidsList {
|
|
||||||
oidsNameList = append(oidsNameList, oid.rawOid)
|
|
||||||
}
|
|
||||||
|
|
||||||
// gosnmp.MAX_OIDS == 60
|
|
||||||
// TODO use gosnmp.MAX_OIDS instead of hard coded value
|
|
||||||
maxOids := 60
|
|
||||||
// limit 60 (MAX_OIDS) oids by requests
|
|
||||||
for i := 0; i < len(oidsList); i = i + maxOids {
|
|
||||||
// Launch request
|
|
||||||
maxIndex := i + maxOids
|
|
||||||
if i+maxOids > len(oidsList) {
|
|
||||||
maxIndex = len(oidsList)
|
|
||||||
}
|
|
||||||
result, err3 := snmpClient.Get(oidsNameList[i:maxIndex]) // Get() accepts up to g.MAX_OIDS
|
|
||||||
if err3 != nil {
|
|
||||||
return err3
|
|
||||||
}
|
|
||||||
// Handle response
|
|
||||||
h.HandleResponse(oidsList, result, acc, initNode)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *Host) SNMPBulk(acc telegraf.Accumulator, initNode Node) error {
|
|
||||||
// Get snmp client
|
|
||||||
snmpClient, err := h.GetSNMPClient()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
// Deconnection
|
|
||||||
defer snmpClient.Conn.Close()
|
|
||||||
// Prepare OIDs
|
|
||||||
oidsList := make(map[string]Data)
|
|
||||||
for _, oid := range h.bulkOids {
|
|
||||||
oidsList[oid.rawOid] = oid
|
|
||||||
}
|
|
||||||
oidsNameList := make([]string, 0, len(oidsList))
|
|
||||||
for _, oid := range oidsList {
|
|
||||||
oidsNameList = append(oidsNameList, oid.rawOid)
|
|
||||||
}
|
|
||||||
// TODO Trying to make requests with more than one OID
|
|
||||||
// to reduce the number of requests
|
|
||||||
for _, oid := range oidsNameList {
|
|
||||||
oidAsked := oid
|
|
||||||
needMoreRequests := true
|
|
||||||
// Set max repetition
|
|
||||||
maxRepetition := oidsList[oid].MaxRepetition
|
|
||||||
if maxRepetition <= 0 {
|
|
||||||
maxRepetition = 32
|
|
||||||
}
|
|
||||||
// Launch requests
|
|
||||||
for needMoreRequests {
|
|
||||||
// Launch request
|
|
||||||
result, err3 := snmpClient.GetBulk([]string{oid}, 0, maxRepetition)
|
|
||||||
if err3 != nil {
|
|
||||||
return err3
|
|
||||||
}
|
|
||||||
// Handle response
|
|
||||||
lastOid := h.HandleResponse(oidsList, result, acc, initNode)
|
|
||||||
// Determine if we need more requests
|
|
||||||
if strings.HasPrefix(lastOid, oidAsked) {
|
|
||||||
needMoreRequests = true
|
|
||||||
oid = lastOid
|
|
||||||
} else {
|
|
||||||
needMoreRequests = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *Host) GetSNMPClient() (*gosnmp.GoSNMP, error) {
|
|
||||||
// Prepare Version
|
|
||||||
var version gosnmp.SnmpVersion
|
|
||||||
if h.Version == 1 {
|
|
||||||
version = gosnmp.Version1
|
|
||||||
} else if h.Version == 3 {
|
|
||||||
version = gosnmp.Version3
|
|
||||||
} else {
|
|
||||||
version = gosnmp.Version2c
|
|
||||||
}
|
|
||||||
// Prepare host and port
|
|
||||||
host, portStr, err := net.SplitHostPort(h.Address)
|
|
||||||
if err != nil {
|
|
||||||
portStr = "161"
|
|
||||||
}
|
|
||||||
// convert port_str to port in uint16
|
|
||||||
port64, err := strconv.ParseUint(portStr, 10, 16)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
port := uint16(port64)
|
|
||||||
// Get SNMP client
|
|
||||||
snmpClient := &gosnmp.GoSNMP{
|
|
||||||
Target: host,
|
|
||||||
Port: port,
|
|
||||||
Community: h.Community,
|
|
||||||
Version: version,
|
|
||||||
Timeout: time.Duration(h.Timeout) * time.Second,
|
|
||||||
Retries: h.Retries,
|
|
||||||
}
|
|
||||||
// Connection
|
|
||||||
err2 := snmpClient.Connect()
|
|
||||||
if err2 != nil {
|
|
||||||
return nil, err2
|
|
||||||
}
|
|
||||||
// Return snmpClient
|
|
||||||
return snmpClient, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *Host) HandleResponse(
|
|
||||||
oids map[string]Data,
|
|
||||||
result *gosnmp.SnmpPacket,
|
|
||||||
acc telegraf.Accumulator,
|
|
||||||
initNode Node,
|
|
||||||
) string {
|
|
||||||
var lastOid string
|
|
||||||
for _, variable := range result.Variables {
|
|
||||||
lastOid = variable.Name
|
|
||||||
nextresult:
|
|
||||||
// Get only oid wanted
|
|
||||||
for oidKey, oid := range oids {
|
|
||||||
// Skip oids already processed
|
|
||||||
for _, processedOid := range h.processedOids {
|
|
||||||
if variable.Name == processedOid {
|
|
||||||
break nextresult
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// If variable.Name is the same as oid_key
|
|
||||||
// OR
|
|
||||||
// the result is SNMP table which "." comes right after oid_key.
|
|
||||||
// ex: oid_key: .1.3.6.1.2.1.2.2.1.16, variable.Name: .1.3.6.1.2.1.2.2.1.16.1
|
|
||||||
if variable.Name == oidKey || strings.HasPrefix(variable.Name, oidKey+".") {
|
|
||||||
switch variable.Type {
|
|
||||||
// handle Metrics
|
|
||||||
case gosnmp.Boolean, gosnmp.Integer, gosnmp.Counter32, gosnmp.Gauge32,
|
|
||||||
gosnmp.TimeTicks, gosnmp.Counter64, gosnmp.Uinteger32, gosnmp.OctetString:
|
|
||||||
// Prepare tags
|
|
||||||
tags := make(map[string]string)
|
|
||||||
if oid.Unit != "" {
|
|
||||||
tags["unit"] = oid.Unit
|
|
||||||
}
|
|
||||||
// Get name and instance
|
|
||||||
var oidName string
|
|
||||||
var instance string
|
|
||||||
// Get oidname and instance from translate file
|
|
||||||
oidName, instance = findNodeName(initNode,
|
|
||||||
strings.Split(variable.Name[1:], "."))
|
|
||||||
// Set instance tag
|
|
||||||
// From mapping table
|
|
||||||
mapping, inMappingNoSubTable := h.OidInstanceMapping[oidKey]
|
|
||||||
if inMappingNoSubTable {
|
|
||||||
// filter if the instance in not in OidInstanceMapping mapping map
|
|
||||||
instanceName, exists := mapping[instance]
|
|
||||||
if !exists {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
tags["instance"] = instanceName
|
|
||||||
} else if oid.Instance != "" {
|
|
||||||
// From config files
|
|
||||||
tags["instance"] = oid.Instance
|
|
||||||
} else if instance != "" {
|
|
||||||
// Using last id of the current oid, ie:
|
|
||||||
// with .1.3.6.1.2.1.31.1.1.1.10.3
|
|
||||||
// instance is 3
|
|
||||||
tags["instance"] = instance
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set name
|
|
||||||
var fieldName string
|
|
||||||
if oidName != "" {
|
|
||||||
// Set fieldname as oid name from translate file
|
|
||||||
fieldName = oidName
|
|
||||||
} else {
|
|
||||||
// Set fieldname as oid name from inputs.snmp.get section
|
|
||||||
// Because the result oid is equal to inputs.snmp.get section
|
|
||||||
fieldName = oid.Name
|
|
||||||
}
|
|
||||||
tags["snmp_host"], _, _ = net.SplitHostPort(h.Address)
|
|
||||||
fields := make(map[string]interface{})
|
|
||||||
fields[fieldName] = variable.Value
|
|
||||||
|
|
||||||
h.processedOids = append(h.processedOids, variable.Name)
|
|
||||||
acc.AddFields(fieldName, fields, tags)
|
|
||||||
case gosnmp.NoSuchObject, gosnmp.NoSuchInstance:
|
|
||||||
// Oid not found
|
|
||||||
acc.AddError(fmt.Errorf("oid %q not found", oidKey))
|
|
||||||
default:
|
|
||||||
// delete other data
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return lastOid
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
inputs.Add("snmp_legacy", func() telegraf.Input {
|
|
||||||
return &Snmp{}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue