-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·90 lines (69 loc) · 2.21 KB
/
entrypoint.sh
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/sh
echo "ENTRYPOINT"
create_user() {
echo "Creating SNMPv3 user $SNMP_V3_USER with NO auth and NO priv"
echo "$SNMP_V3_USER_TYPE $SNMP_V3_USER" >'/usr/share/snmp/snmpd.conf'
}
create_user_auth() {
echo "Creating SNMPv3 user $SNMP_V3_USER with auth $SNMP_V3_AUTH_PROTOCOL and NO priv"
echo "createUser $SNMP_V3_USER $SNMP_V3_AUTH_PROTOCOL \"$SNMP_V3_AUTH_PWD\"" \
>'/var/lib/net-snmp/snmpd.conf'
echo "$SNMP_V3_USER_TYPE $SNMP_V3_USER" >'/usr/share/snmp/snmpd.conf'
}
create_user_auth_priv() {
echo "Creating SNMPv3 user $SNMP_V3_USER with auth $SNMP_V3_AUTH_PROTOCOL and priv $SNMP_V3_PRIV_PROTOCOL"
echo "createUser $SNMP_V3_USER $SNMP_V3_AUTH_PROTOCOL \"$SNMP_V3_AUTH_PWD\" $SNMP_V3_PRIV_PROTOCOL \"$SNMP_V3_PRIV_PWD\"" \
>'/var/lib/net-snmp/snmpd.conf'
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 [ -n "$SNMP_LOCATION" ]; then
export SNMP_LOCATION="sysLocation $SNMP_LOCATION"
else
export SNMP_LOCATION=""
fi
if [ -n "$SNMP_CONTACT" ]; then
export SNMP_CONTACT="sysContact $SNMP_CONTACT"
else
export SNMP_CONTACT=""
fi
if [ -z "$SNMP_SERVICES" ]; then
export SNMP_SERVICES="72"
fi
if [ -z "$SNMP_V3_USER_TYPE" ]; then
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'"
export SNMP_V3_USER_TYPE="rouser"
fi
if [ -z "$SNMP_V3_AUTH_PROTOCOL" ]; then
export SNMP_V3_AUTH_PROTOCOL="SHA"
fi
if [ -z "$SNMP_V3_PRIV_PROTOCOL" ]; then
export SNMP_V3_PRIV_PROTOCOL="AES"
fi
if [ -n "$SNMP_V3_USER" ]; then
if [ -n "$SNMP_V3_AUTH_PWD" ]; then
if [ -n "$SNMP_V3_PRIV_PWD" ]; then
create_user_auth_priv
else
echo "SNMP_V3_PRIV_PWD is not set"
create_user_auth
fi
else
echo "SNMP_V3_AUTH_PWD is not set"
create_user
fi
else
echo "SNMP_V3_USER is not set"
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