Skip to content

Commit

Permalink
Merge pull request #3 from isalgueiro/snmpv3
Browse files Browse the repository at this point in the history
Add _some_ SNMP v3 support, and hopefully solve #2
  • Loading branch information
isalgueiro authored Mar 2, 2018
2 parents 96ca8d2 + e2bcf3a commit 515543b
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 11 deletions.
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ otilio:
# SNMP host to query
host: "127.0.0.1"
# SMNP version
# SMNP version: 1, 2c or 3
version: 2c
# SNMP community
Expand All @@ -28,6 +28,32 @@ otilio:
```
This will get oids `1.3.6.1.2.1.1.1.0` and `1.3.6.1.2.1.1.3.0` from SNMP server at localhost and store them in `otilio-YYYY.MM.DD` index in Elasticsearch in fields `sysDescr` and `sysUpTime`.

SNMP V3 configuration example

```
otilio:
# Defines how often an event is sent to the output
period: 1s
# SNMP host to query
host: "127.0.0.1"
port: 10161
# SMNP version
version: 3
# SNMP user security model parameters
# currently only SHA auth and DES encryption supported ¯\_(ツ)_/¯
user: "theuser"
authpass: "theauthpassword"
privpass: "theprivacyencryptionpassword"
# oids to query
# (the starting dot is intended)
oids:
- {oid: ".1.3.6.1.2.1.25.1", name: hrSystem}
```

## Building

Ensure that this folder is at the following location:
Expand Down
3 changes: 2 additions & 1 deletion _meta/beat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ otilio:

# SNMP host to query
host: "127.0.0.1"
port: 161

# SMNP version
# SMNP version: 1, 2c or 3
version: 2c

# SNMP community
Expand Down
15 changes: 13 additions & 2 deletions beater/otilio.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,25 @@ func (bt *Otilio) Run(b *beat.Beat) error {
case <-ticker.C:
// TODO: connect outside the loop with a timeout < bt.config.Period
gosnmp.Default.Target = bt.config.Host
gosnmp.Default.Port = bt.config.Port
gosnmp.Default.Community = bt.config.Community
gosnmp.Default.Version = bt.version
if bt.version == gosnmp.Version3 {
gosnmp.Default.SecurityModel = gosnmp.UserSecurityModel
gosnmp.Default.SecurityParameters = &gosnmp.UsmSecurityParameters{
UserName: bt.config.User,
AuthenticationPassphrase: bt.config.AuthPassword,
PrivacyPassphrase: bt.config.PrivPassword,
AuthenticationProtocol: gosnmp.SHA,
PrivacyProtocol: gosnmp.DES,
}
}
err := gosnmp.Default.Connect()
if err != nil {
logp.Critical("Can't connect to %s: %v", bt.config.Host, err.Error())
return fmt.Errorf("Can't connect to %s", bt.config.Host)
}
defer gosnmp.Default.Conn.Close()
gosnmp.Default.Community = bt.config.Community
gosnmp.Default.Version = bt.version
r, err := gosnmp.Default.Get(bt.oids)
if err != nil {
logp.Err("Can't get oids %v: %v", bt.config.OIDs, err.Error())
Expand Down
17 changes: 12 additions & 5 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,24 @@ package config

import "time"

// Config stores Otilio configuration loaded from .yaml file
type Config struct {
Period time.Duration `config:"period"`
Host string `config:"host"`
Community string `config:"community"`
Version string `config:"version"`
OIDs []map[string]string `config:"oids"`
Period time.Duration `config:"period"`
Host string `config:"host"`
Port uint16 `config:"port"`
Community string `config:"community"`
User string `config:"user"`
AuthPassword string `config:"authpass"`
PrivPassword string `config:"privpass"`
Version string `config:"version"`
OIDs []map[string]string `config:"oids"`
}

// DefaultConfig default configuration
var DefaultConfig = Config{
Period: 1 * time.Second,
Host: "127.0.0.1",
Port: 161,
Community: "public",
Version: "2c",
}
3 changes: 2 additions & 1 deletion otilio.full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ otilio:

# SNMP host to query
host: "127.0.0.1"
port: 161

# SMNP version
# SMNP version: 1, 2c or 3
version: 2c

# SNMP community
Expand Down
79 changes: 79 additions & 0 deletions otilio.snmpv3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
################### Otilio Configuration Example #########################

############################# Otilio ######################################

otilio:
# Defines how often an event is sent to the output
period: 1s

# SNMP host to query
host: "127.0.0.1"
port: 10161

# SMNP version
version: 3

# SNMP user security model parameters
user: "theuser"
authpass: "theauthpassword"
privpass: "theprivacyencryptionpassword"

# oids to query
# (the starting dot is intended)
oids:
- {oid: ".1.3.6.1.2.1.25.1", name: hrSystem}
#================================ General =====================================

# The name of the shipper that publishes the network data. It can be used to group
# all the transactions sent by a single shipper in the web interface.
#name:

# The tags of the shipper are included in their own field with each
# transaction published.
#tags: ["service-X", "web-tier"]

# Optional fields that you can specify to add additional information to the
# output.
#fields:
# env: staging

#================================ Outputs =====================================

# Configure what outputs to use when sending the data collected by the beat.
# Multiple outputs may be used.

#-------------------------- Elasticsearch output ------------------------------
output.elasticsearch:
# Array of hosts to connect to.
hosts: ["localhost:9200"]

# Optional protocol and basic auth credentials.
#protocol: "https"
#username: "elastic"
#password: "changeme"

#----------------------------- Logstash output --------------------------------
#output.logstash:
# The Logstash hosts
#hosts: ["localhost:5044"]

# Optional SSL. By default is off.
# List of root certificates for HTTPS server verifications
#ssl.certificate_authorities: ["/etc/pki/root/ca.pem"]

# Certificate for SSL client authentication
#ssl.certificate: "/etc/pki/client/cert.pem"

# Client Certificate Key
#ssl.key: "/etc/pki/client/cert.key"

#================================ Logging =====================================

# Sets log level. The default log level is info.
# Available log levels are: critical, error, warning, info, debug
#logging.level: debug

# At debug level, you can selectively enable logging only for some components.
# To enable all selectors use ["*"]. Examples of other selectors are "beat",
# "publish", "service".
#logging.selectors: ["*"]
3 changes: 2 additions & 1 deletion otilio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ otilio:

# SNMP host to query
host: "127.0.0.1"
port: 161

# SMNP version
# SMNP version: 1, 2c or 3
version: 2c

# SNMP community
Expand Down
7 changes: 7 additions & 0 deletions tests/snmpv3/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM alpine:3.6
RUN apk add --update net-snmp net-snmp-tools
RUN sed -i 's/agentAddress udp:127.0.0.1:161/agentAddress udp:10161/g' /etc/snmp/snmpd.conf
RUN net-snmp-create-v3-user -ro -A theauthpassword -a SHA -X theprivacyencryptionpassword -x DES theuser
EXPOSE 10161/tcp
RUN rm -rf /var/cache/apk/*
ENTRYPOINT [ "snmpd", "-f" ]
8 changes: 8 additions & 0 deletions tests/snmpv3/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Use this dockerfile to start a testing SNMP v3 server

```
$ docker build .
[...]
Successfully built <image id>
$ docker run -p 10161:10161/udp <image id>
```

0 comments on commit 515543b

Please sign in to comment.