-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.sh
More file actions
76 lines (59 loc) · 1.44 KB
/
Copy pathentrypoint.sh
File metadata and controls
76 lines (59 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env bash
set -euo pipefail
COMMUNITY="${SNMP_COMMUNITY:-public}"
SYSLOCATION="${SNMP_LOCATION:-lab}"
SYSCONTACT="${SNMP_CONTACT:-n/a}"
DEBUG_LEVEL="${DEBUG_LEVEL:-0}"
# Extract --name and --debug-level if provided
DEVICE_NAME="switch-01"
ARGS=("$@")
for ((i=0; i<${#ARGS[@]}; i++)); do
case "${ARGS[$i]}" in
--name)
if [[ $((i+1)) -lt ${#ARGS[@]} ]]; then
DEVICE_NAME="${ARGS[$((i+1))]}"
fi
;;
--debug-level)
if [[ $((i+1)) -lt ${#ARGS[@]} ]]; then
DEBUG_LEVEL="${ARGS[$((i+1))]}"
fi
;;
esac
done
mkdir -p /var/agentx
cat > /etc/snmp/snmpd.conf <<EOF
agentAddress udp:161
rocommunity ${COMMUNITY}
sysLocation ${SYSLOCATION}
sysContact ${SYSCONTACT}
sysName ${DEVICE_NAME}
master agentx
agentxsocket /var/agentx/master
dontLogTCPWrappersConnects yes
EOF
SNMPD_OPTS="-f -C -c /etc/snmp/snmpd.conf"
if [[ "${DEBUG_LEVEL}" -ge 1 ]]; then
echo "[*] Starting snmpd (AgentX master), debug_level=${DEBUG_LEVEL}"
fi
if [[ "${DEBUG_LEVEL}" -ge 2 ]]; then
SNMPD_OPTS+=" -Lo"
else
# Completely quiet
SNMPD_OPTS+=" -LS0-6d"
fi
snmpd ${SNMPD_OPTS} &
SNMPD_PID=$!
for _ in $(seq 1 50); do
[[ -S /var/agentx/master ]] && break
sleep 0.1
done
if [[ ! -S /var/agentx/master ]]; then
echo "[!] AgentX socket not found, exiting"
kill "${SNMPD_PID}" || true
exit 1
fi
if [[ "${DEBUG_LEVEL}" -ge 1 ]]; then
echo "[*] Starting AgentX subagent"
fi
exec /usr/local/bin/agentx_switch "$@"