Skip to content

Commit

Permalink
added test for snmp
Browse files Browse the repository at this point in the history
  • Loading branch information
yseto committed Aug 26, 2022
1 parent 56c4e53 commit 9aeb899
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mackerel-plugin-snmp/rule.txt
@@ -0,0 +1,2 @@
snmp.hrSystemNumUsers >=0
snmp.hrSystemProcesses >=0
34 changes: 34 additions & 0 deletions mackerel-plugin-snmp/test.sh
@@ -0,0 +1,34 @@
#!/bin/sh

prog=$(basename "$0")
if ! [ -S /var/run/docker.sock ]
then
echo "$prog: there are no running docker" >&2
exit 2
fi

cd "$(dirname "$0")" || exit
PATH=$(pwd):$PATH
plugin=$(basename "$(pwd)")
if ! which "$plugin" >/dev/null
then
echo "$prog: $plugin is not installed" >&2
exit 2
fi

image=local/test-$plugin
# mackerel-plugin-snmp is disallowed --port option.
port=161

docker build -t $image testdata/

docker run --name "test-$plugin" -v $(pwd)/testdata/snmpd.conf:/etc/snmp/snmpd.conf:ro -p $port:161/udp -d $image
trap 'docker stop test-$plugin; docker rm test-$plugin; exit 1' 1 2 3 15
sleep 10

$plugin '.1.3.6.1.2.1.25.1.5.0:hrSystemNumUsers:0:0' '.1.3.6.1.2.1.25.1.6.0:hrSystemProcesses:0:0' | graphite-metric-test -f rule.txt
status=$?

docker stop "test-$plugin"
docker rm "test-$plugin"
exit $status
8 changes: 8 additions & 0 deletions mackerel-plugin-snmp/testdata/Dockerfile
@@ -0,0 +1,8 @@
FROM alpine:3.16

RUN apk add --update net-snmp net-snmp-tools

EXPOSE 161

CMD ["snmpd", "-V", "-f", "-c", "/etc/snmp/snmpd.conf"]

4 changes: 4 additions & 0 deletions mackerel-plugin-snmp/testdata/snmpd.conf
@@ -0,0 +1,4 @@
view systemonly included .1.3.6.1.2.1.1
view systemonly included .1.3.6.1.2.1.25.1

rocommunity public default -V systemonly

0 comments on commit 9aeb899

Please sign in to comment.