add env config
This commit is contained in:
2
.env
Normal file
2
.env
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
SNMP_COMMUNITY=public
|
||||||
|
CUSTOM_OID=.1.3.6.1.4.1.38446.1.2.4.1.9.1
|
||||||
@@ -14,10 +14,10 @@ COPY custom_snmp_script.py /usr/local/bin/custom_snmp_script.py
|
|||||||
RUN chmod +x /usr/local/bin/custom_snmp_script.py
|
RUN chmod +x /usr/local/bin/custom_snmp_script.py
|
||||||
|
|
||||||
# Configure snmpd to use the custom script
|
# Configure snmpd to use the custom script
|
||||||
RUN echo "extend .1.3.6.1.4.1.38446.1.2.4.1.9.1 /usr/local/bin/custom_snmp_script.py" >> /etc/snmp/snmpd.conf
|
RUN echo "extend customOID /usr/local/bin/custom_snmp_script.py" >> /etc/snmp/snmpd.conf
|
||||||
|
|
||||||
# Expose the SNMP port
|
# Expose the SNMP port
|
||||||
EXPOSE 161/udp
|
EXPOSE 161/udp
|
||||||
|
|
||||||
# Start snmpd
|
# Start snmpd with environment variables
|
||||||
CMD ["snmpd", "-f"]
|
CMD ["sh", "-c", "snmpd -f -c /etc/snmp/snmpd.conf -Lf /dev/null -p /var/run/snmpd.pid -a -x $SNMP_COMMUNITY"]
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
import os
|
||||||
import random
|
import random
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
# Read the OID from the environment variable
|
||||||
|
oid = os.getenv('CUSTOM_OID', '.1.3.6.1.4.1.38446.1.2.4.1.9.1')
|
||||||
|
|
||||||
# Initial value
|
# Initial value
|
||||||
value = 1385062
|
value = 1385062
|
||||||
|
|
||||||
@@ -10,7 +14,7 @@ while True:
|
|||||||
value += random.randint(0, 6)
|
value += random.randint(0, 6)
|
||||||
|
|
||||||
# Output the value in the required format
|
# Output the value in the required format
|
||||||
print(f"INTEGER: {value}")
|
print(f"{oid} = INTEGER: {value}")
|
||||||
|
|
||||||
# Wait for 4 minutes
|
# Wait for 4 minutes
|
||||||
time.sleep(240)
|
time.sleep(240)
|
||||||
|
|||||||
Reference in New Issue
Block a user