SNMP custom port
This commit is contained in:
2
.env
2
.env
@@ -2,4 +2,4 @@ SNMP_COMMUNITY=public
|
|||||||
CUSTOM_OID=.1.3.6.1.4.1.38446.1.2.4.1.9.1
|
CUSTOM_OID=.1.3.6.1.4.1.38446.1.2.4.1.9.1
|
||||||
RANGE_MIN=0
|
RANGE_MIN=0
|
||||||
RANGE_MAX=6
|
RANGE_MAX=6
|
||||||
|
SNMP_PORT=161
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ 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 customOID /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 using an environment variable
|
||||||
EXPOSE 161/udp
|
EXPOSE 161/udp
|
||||||
|
|
||||||
# Start snmpd with environment variables
|
# Start snmpd with environment variables
|
||||||
CMD ["sh", "-c", "snmpd -f -c /etc/snmp/snmpd.conf -Lf /dev/null -p /var/run/snmpd.pid -a -x $SNMP_COMMUNITY"]
|
CMD ["sh", "-c", "snmpd -f -c /etc/snmp/snmpd.conf -Lf /dev/null -p /var/run/snmpd.pid -a -x $SNMP_COMMUNITY -p $SNMP_PORT"]
|
||||||
|
|||||||
16
README.md
16
README.md
@@ -1,6 +1,6 @@
|
|||||||
# SNMPD Custom OID Docker Container
|
# SNMPD Custom OID Docker Container
|
||||||
|
|
||||||
This Docker container runs `snmpd` with a custom script that provides a specific OID. The value of this OID increases randomly by a small amount every 4 minutes. The SNMP community string, OID, and increment range can be configured using a `.env` file.
|
This Docker container runs `snmpd` with a custom script that provides a specific OID. The value of this OID increases randomly by a small amount every 4 minutes. The SNMP community string, OID, increment range, and port can be configured using a `.env` file.
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
@@ -31,6 +31,7 @@ SNMP_COMMUNITY=public
|
|||||||
CUSTOM_OID=.1.3.6.1.4.1.38446.1.2.4.1.9.1
|
CUSTOM_OID=.1.3.6.1.4.1.38446.1.2.4.1.9.1
|
||||||
RANGE_MIN=0
|
RANGE_MIN=0
|
||||||
RANGE_MAX=6
|
RANGE_MAX=6
|
||||||
|
SNMP_PORT=161
|
||||||
```
|
```
|
||||||
|
|
||||||
### Step 2: Build the Docker Image
|
### Step 2: Build the Docker Image
|
||||||
@@ -46,9 +47,11 @@ docker build -t snmpd-custom .
|
|||||||
Start the Docker container with the following command, using the `--env-file` option to pass the environment variables:
|
Start the Docker container with the following command, using the `--env-file` option to pass the environment variables:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker run -d -p 161:161/udp --name snmpd-custom-container --env-file .env snmpd-custom
|
docker run -d -p ${SNMP_PORT}:${SNMP_PORT}/udp --name snmpd-custom-container --env-file .env snmpd-custom
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Replace `${SNMP_PORT}` with the actual port number you want to use, or use the value from your `.env` file.
|
||||||
|
|
||||||
### Step 4: Verify the Setup
|
### Step 4: Verify the Setup
|
||||||
|
|
||||||
You can verify that the container is running and the SNMP daemon is providing the custom OID by using an SNMP client to query the OID:
|
You can verify that the container is running and the SNMP daemon is providing the custom OID by using an SNMP client to query the OID:
|
||||||
@@ -65,13 +68,18 @@ You should see the value incrementing randomly every 4 minutes.
|
|||||||
- **Increment Range**: Modify the `RANGE_MIN` and `RANGE_MAX` in the `.env` file to change how much the value increments.
|
- **Increment Range**: Modify the `RANGE_MIN` and `RANGE_MAX` in the `.env` file to change how much the value increments.
|
||||||
- **Update Interval**: Adjust the sleep interval in the script to change the frequency of updates.
|
- **Update Interval**: Adjust the sleep interval in the script to change the frequency of updates.
|
||||||
- **Community String and OID**: Modify the `.env` file to change the SNMP community string and OID.
|
- **Community String and OID**: Modify the `.env` file to change the SNMP community string and OID.
|
||||||
|
- **SNMP Port**: Modify the `SNMP_PORT` in the `.env` file to change the port on which `snmpd` listens.
|
||||||
|
|
||||||
## Notes
|
## Notes
|
||||||
|
|
||||||
- Ensure that the SNMP community string in the `.env` file matches your configuration.
|
- Ensure that the SNMP community string and port in the `.env` file match your configuration.
|
||||||
- The container exposes port 161 for SNMP communication.
|
- The container exposes the specified SNMP port for communication.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
This project is licensed under the MIT License.
|
This project is licensed under the MIT License.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
Feel free to contribute or modify the setup to fit your specific needs!
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user