Skip to content

Commit

Permalink
Merge pull request #3 from testainers/dev
Browse files Browse the repository at this point in the history
Version 0.0.3.
  • Loading branch information
edufolly authored Apr 27, 2024
2 parents d47c3a7 + f0959df commit 7638049
Show file tree
Hide file tree
Showing 7 changed files with 259 additions and 139 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
etc/snmp/snmpd_default.conf
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM alpine:${ALPINE_VERSION:-3.19}

RUN apk add --update --no-cache net-snmp net-snmp-tools
RUN apk add --update --no-cache net-snmp net-snmp-tools envsubst

COPY entrypoint.sh /usr/local/bin/

Expand Down
42 changes: 29 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,37 +31,53 @@ Obrigado pelo seu apoio contínuo!

## Environment Variables

| Variable | Options | Default |
|-----------------------|-----------------|---------|
| SNMP_V3_USER | -- | -- |
| SNMP_V3_USER_TYPE | rouser - rwuser | rouser |
| SNMP_V3_AUTH_PROTOCOL | MD5 - SHA | SHA |
| SNMP_V3_AUTH_PWD | -- | -- |
| SNMP_V3_PRIV_PROTOCOL | DES - AES | AES |
| SNMP_V3_PRIV_PWD | -- | -- |
| Variable | Options | Default |
|-----------------------|-----------------|--------------------------------|
| SNMP_COMMUNITY | -- | public |
| SNMP_LOCATION | -- | At flying circus |
| SNMP_CONTACT | -- | Testainers <[email protected]> |
| SNMP_SERVICES | -- | 72 |
| SNMP_V3_USER | -- | -- |
| SNMP_V3_USER_TYPE | rouser - rwuser | rouser |
| SNMP_V3_AUTH_PROTOCOL | MD5 - SHA | SHA |
| SNMP_V3_AUTH_PWD | -- | -- |
| SNMP_V3_PRIV_PROTOCOL | DES - AES | AES |
| SNMP_V3_PRIV_PWD | -- | -- |

## How to Use

### Only SNMPv2c

Run:

```shell
docker run --rm --name snmpd -p 5161:161/udp -d testainers/snmpd-container:latest
docker run -d --rm --name snmpd -p 5161:161/udp testainers/snmpd-container:latest
```

## How to Connect
Test:

```shell
snmpwalk -v2c -c public 127.0.0.1:5161 .
```

---

## Build
## Local Image Build

Build:

```shell
docker build . --no-cache -t snmpd-container
```

## Run
Run:

```shell
docker run -d --rm --name snmpd -p 5161:161/udp snmpd-container
```

Access:

```shell
docker run --rm --name snmpd -p 5161:161/udp -d snmpd-container
docker exec -it snmpd sh
```
28 changes: 24 additions & 4 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,38 @@ create_user_auth_priv() {
echo "$SNMP_V3_USER_TYPE $SNMP_V3_USER priv" >'/usr/share/snmp/snmpd.conf'
}

if [ -z "$SNMP_COMMUNITY" ]; then
export SNMP_COMMUNITY="public"
fi

if [ -z "$SNMP_LOCATION" ]; then
export SNMP_LOCATION="At flying circus"
fi

if [ -z "$SNMP_CONTACT" ]; then
export SNMP_CONTACT="Testainers <[email protected]>"
fi

if [ -z "$SNMP_SERVICES" ]; then
export SNMP_SERVICES="72"
fi

if [ -z "$SNMP_V3_USER_TYPE" ]; then
SNMP_V3_USER_TYPE="rouser"
export SNMP_V3_USER_TYPE="rouser"
fi

if [ "$SNMP_V3_USER_TYPE" != "rwuser" ] && [ "$SNMP_V3_USER_TYPE" != "rouser" ]; then
echo "SNMP_V3_USER_TYPE is not correct"
echo "Updating from '$SNMP_V3_USER_TYPE' to 'rouser'"
SNMP_V3_USER_TYPE="rouser"
export SNMP_V3_USER_TYPE="rouser"
fi

if [ -z "$SNMP_V3_AUTH_PROTOCOL" ]; then
SNMP_V3_AUTH_PROTOCOL="SHA"
export SNMP_V3_AUTH_PROTOCOL="SHA"
fi

if [ -z "$SNMP_V3_PRIV_PROTOCOL" ]; then
SNMP_V3_PRIV_PROTOCOL="AES"
export SNMP_V3_PRIV_PROTOCOL="AES"
fi

if [ -n "$SNMP_V3_USER" ]; then
Expand All @@ -61,6 +77,10 @@ else
echo "User not created"
fi

envsubst <'/etc/snmp/snmpd.template.conf' >'/etc/snmp/snmpd.conf'

rm -f '/etc/snmp/snmpd.template.conf'

### Start snmpd.
# /usr/sbin/snmpd -f -Lo -C -c /etc/snmp/snmpd.conf
/usr/sbin/snmpd -f -Lo
18 changes: 9 additions & 9 deletions etc/snmp/snmpd.conf → etc/snmp/snmpd.template.conf
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ view systemonly included .1.3.6.1.2.1.1
view systemonly included .1.3.6.1.2.1.25.1

# Full access from the local host
#rocommunity public localhost
#rocommunity ${SNMP_COMMUNITY} localhost
# Default access to basic system info
#rocommunity public default -V systemonly
#rocommunity ${SNMP_COMMUNITY} default -V systemonly

# Full access from an example network
# Adjust this network address to match your local
# settings, change the community string,
# and check the 'agentAddress' setting above
#rocommunity secret 10.0.0.0/16

rocommunity public default
rocommunity ${SNMP_COMMUNITY} default

# Full read-only access for SNMPv3
#rouser authOnlyUser
Expand All @@ -77,10 +77,10 @@ rocommunity public default

# Note that setting these values here, results in the corresponding MIB objects being 'read-only'
# See snmpd.conf(5) for more details
sysLocation At flying circus
sysContact Testainers <[email protected]>
sysLocation ${SNMP_LOCATION}
sysContact ${SNMP_CONTACT}
# Application + End-to-End layers
sysServices 72
sysServices ${SNMP_SERVICES}


#
Expand Down Expand Up @@ -126,11 +126,11 @@ load 12 10 5
#

# send SNMPv1 traps
trapsink localhost public
trapsink localhost ${SNMP_COMMUNITY}
# send SNMPv2c traps
#trap2sink localhost public
#trap2sink localhost ${SNMP_COMMUNITY}
# send SNMPv2c INFORMs
#informsink localhost public
#informsink localhost ${SNMP_COMMUNITY}

# Note that you typically only want *one* of these three lines
# Uncommenting two (or all three) will result in multiple copies of each notification.
Expand Down
Loading

0 comments on commit 7638049

Please sign in to comment.