-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from testainers/dev
Version 0.0.2.
- Loading branch information
Showing
6 changed files
with
293 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,226 @@ | ||
#! /bin/bash | ||
set -e | ||
set -x | ||
|
||
docker build . --no-cache -t snmpd-container-test | ||
# set -e | ||
# set -x | ||
|
||
docker run --rm --name snmpd -p 5161:161/udp -d snmpd-container-test | ||
CODE=0 | ||
|
||
# Name of the image | ||
IMAGE_NAME="snmpd-container-test" | ||
|
||
# Name of the container | ||
CONTAINER_NAME="snmpd" | ||
|
||
# Host bind address | ||
HOST="localhost" | ||
|
||
# Host bind port | ||
PORT=5161 | ||
|
||
# OID for snmpwalk | ||
WALK=".1.3.6.1.2.1.1" | ||
|
||
# OID for snmpget and snmpgetnext | ||
GET=".1.3.6.1.2.1.1.6.0" | ||
|
||
############### | ||
# Build Image # | ||
############### | ||
|
||
docker build . --no-cache -t "$IMAGE_NAME" | ||
|
||
SNMP_V3_USER="testainers" | ||
|
||
########### | ||
# SNMPv2c # | ||
########### | ||
|
||
echo "SNMPv2c" | ||
docker run --rm --name "$CONTAINER_NAME" -p "$PORT:161/udp" -d "$IMAGE_NAME" | ||
sleep 2 | ||
|
||
# SNMPv2c - Walk | ||
echo "SNMPv2c - Walk" | ||
snmpwalk -v 2c -c public "$HOST:$PORT" "$WALK" >/dev/null 2>&1 | ||
|
||
if [ $? -ne 0 ]; then | ||
echo "Error: SNMPv2c Walk" | ||
CODE=10 | ||
fi | ||
|
||
# SNMPv2c - Get | ||
echo "SNMPv2c - Get" | ||
RESULT=$(snmpget -v2c -c public -Ovq "$HOST:$PORT" "$GET" | tr -d '"') | ||
|
||
if [ "$RESULT" != "At flying circus" ]; then | ||
echo "Error: $RESULT" | ||
CODE=11 | ||
fi | ||
|
||
# SNMPv2c - GetNext | ||
echo "SNMPv2c - GetNext" | ||
RESULT=$(snmpgetnext -v2c -c public -Ovq "$HOST:$PORT" "$GET") | ||
|
||
if [ "$RESULT" != "72" ]; then | ||
echo "Error: $RESULT" | ||
CODE=12 | ||
fi | ||
|
||
# SNMPv3 - Get - Need to fail | ||
echo "SNMPv3 - Get" | ||
snmpget -v3 -Ovq -u "$SNMP_V3_USER" -l noAuthNoPriv \ | ||
"$HOST:$PORT" "$GET" >/dev/null 2>&1 | ||
|
||
if [ $? -eq 0 ]; then | ||
echo "Error: $RESULT" | ||
CODE=13 | ||
fi | ||
|
||
# Stop Container | ||
echo "Stop Container" | ||
docker stop -t 1 "$CONTAINER_NAME" | ||
sleep 2 | ||
|
||
############################## | ||
# SNMPv3 NO auth and NO priv # | ||
############################## | ||
|
||
# TODO: Add test for SNMPv3 with noAuthNoPriv | ||
|
||
################################ | ||
# SNMPv3 with auth and NO priv # | ||
################################ | ||
|
||
SNMP_V3_AUTH_PROTOCOL="SHA" | ||
# SNMP_V3_AUTH_PWD=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 12 | head -n 1) | ||
SNMP_V3_AUTH_PWD="a1b2c3d4e5f6" | ||
|
||
echo "SNMPv3 with auth and NO priv" | ||
docker run --rm --name "$CONTAINER_NAME" -p "$PORT:161/udp" -d \ | ||
-e SNMP_V3_USER=$SNMP_V3_USER \ | ||
-e SNMP_V3_AUTH_PROTOCOL=$SNMP_V3_AUTH_PROTOCOL \ | ||
-e SNMP_V3_AUTH_PWD=$SNMP_V3_AUTH_PWD \ | ||
"$IMAGE_NAME" | ||
sleep 2 | ||
|
||
# SNMPv3 - Walk | ||
echo "SNMPv3 - Walk" | ||
snmpwalk -v3 -On -u "$SNMP_V3_USER" \ | ||
-l authNoPriv \ | ||
-a "$SNMP_V3_AUTH_PROTOCOL" \ | ||
-A "$SNMP_V3_AUTH_PWD" \ | ||
"$HOST:$PORT" "$WALK" >/dev/null 2>&1 | ||
|
||
if [ $? -ne 0 ]; then | ||
echo "Error: SNMPv3 Walk" | ||
CODE=30 | ||
fi | ||
|
||
# SNMPv3 - Get | ||
echo "SNMPv3 - Get" | ||
RESULT=$(snmpget -v3 -Ovq -u "$SNMP_V3_USER" \ | ||
-l authNoPriv \ | ||
-a "$SNMP_V3_AUTH_PROTOCOL" \ | ||
-A "$SNMP_V3_AUTH_PWD" \ | ||
"$HOST:$PORT" "$GET" | tr -d '"') | ||
|
||
if [ "$RESULT" != "At flying circus" ]; then | ||
echo "Error: $RESULT" | ||
CODE=31 | ||
fi | ||
|
||
# SNMPv3 - GetNext | ||
echo "SNMPv3 - GetNext" | ||
RESULT=$(snmpgetnext -v3 -Ovq -u "$SNMP_V3_USER" \ | ||
-l authNoPriv \ | ||
-a "$SNMP_V3_AUTH_PROTOCOL" \ | ||
-A "$SNMP_V3_AUTH_PWD" \ | ||
"$HOST:$PORT" "$GET") | ||
|
||
if [ "$RESULT" != "72" ]; then | ||
echo "Error: $RESULT" | ||
CODE=32 | ||
fi | ||
|
||
# Stop Container | ||
echo "Stop Container" | ||
docker stop -t 1 "$CONTAINER_NAME" | ||
|
||
sleep 2 | ||
|
||
##################################### | ||
# SNMPv3 with auth and with privacy # | ||
##################################### | ||
|
||
SNMP_V3_PRIV_PROTOCOL="AES" | ||
# SNMP_V3_PRIV_PWD=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 12 | head -n 1) | ||
SNMP_V3_PRIV_PWD="f6e5d4c3b2a1" | ||
|
||
echo "SNMPv3 with auth and with privacy" | ||
docker run --rm --name "$CONTAINER_NAME" -p "$PORT:161/udp" -d \ | ||
-e SNMP_V3_USER=$SNMP_V3_USER \ | ||
-e SNMP_V3_AUTH_PROTOCOL=$SNMP_V3_AUTH_PROTOCOL \ | ||
-e SNMP_V3_AUTH_PWD=$SNMP_V3_AUTH_PWD \ | ||
-e SNMP_V3_PRIV_PROTOCOL=$SNMP_V3_PRIV_PROTOCOL \ | ||
-e SNMP_V3_PRIV_PWD=$SNMP_V3_PRIV_PWD \ | ||
"$IMAGE_NAME" | ||
sleep 2 | ||
|
||
# SNMPv3 - Walk | ||
echo "SNMPv3 - Walk" | ||
snmpwalk -v3 -On -u "$SNMP_V3_USER" \ | ||
-l authPriv \ | ||
-a "$SNMP_V3_AUTH_PROTOCOL" \ | ||
-A "$SNMP_V3_AUTH_PWD" \ | ||
-x "$SNMP_V3_PRIV_PROTOCOL" \ | ||
-X "$SNMP_V3_PRIV_PWD" \ | ||
"$HOST:$PORT" "$WALK" >/dev/null 2>&1 | ||
|
||
if [ $? -ne 0 ]; then | ||
echo "Error: SNMPv3 Walk" | ||
CODE=40 | ||
fi | ||
|
||
# SNMPv3 - Get | ||
echo "SNMPv3 - Get" | ||
RESULT=$(snmpget -v3 -Ovq -u "$SNMP_V3_USER" \ | ||
-l authPriv \ | ||
-a "$SNMP_V3_AUTH_PROTOCOL" \ | ||
-A "$SNMP_V3_AUTH_PWD" \ | ||
-x "$SNMP_V3_PRIV_PROTOCOL" \ | ||
-X "$SNMP_V3_PRIV_PWD" \ | ||
"$HOST:$PORT" "$GET" | tr -d '"') | ||
|
||
if [ "$RESULT" != "At flying circus" ]; then | ||
echo "Error: $RESULT" | ||
CODE=41 | ||
fi | ||
|
||
# SNMPv3 - GetNext | ||
echo "SNMPv3 - GetNext" | ||
RESULT=$(snmpgetnext -v3 -Ovq -u "$SNMP_V3_USER" \ | ||
-l authPriv \ | ||
-a "$SNMP_V3_AUTH_PROTOCOL" \ | ||
-A "$SNMP_V3_AUTH_PWD" \ | ||
-x "$SNMP_V3_PRIV_PROTOCOL" \ | ||
-X "$SNMP_V3_PRIV_PWD" \ | ||
"$HOST:$PORT" "$GET") | ||
|
||
if [ "$RESULT" != "72" ]; then | ||
echo "Error: $RESULT" | ||
CODE=42 | ||
fi | ||
|
||
# Stop container | ||
echo "Stop Container" | ||
docker stop -t 1 "$CONTAINER_NAME" | ||
|
||
sleep 2 | ||
|
||
snmpwalk -v 2c -c public localhost:5161 . | ||
################ | ||
# Remove Image # | ||
################ | ||
|
||
docker stop -t 1 snmpd | ||
docker image rm "$IMAGE_NAME" | ||
|
||
docker image rm snmpd-container-test | ||
exit $CODE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
version: 0.0.1 | ||
version: 0.0.2 |