|
|
|
@@ -1,12 +1,13 @@
|
|
|
|
|
# SNMPD Custom OID Docker Container
|
|
|
|
|
|
|
|
|
|
This Docker container runs `snmpd` with a custom script that provides a specific OID (`.1.3.6.1.4.1.38446.1.2.4.1.9.1`). The value of this OID increases randomly by a small amount every 4 minutes.
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
## Features
|
|
|
|
|
|
|
|
|
|
- Lightweight Docker container based on Alpine Linux.
|
|
|
|
|
- Custom Python script to generate and update the OID value.
|
|
|
|
|
- Configurable SNMP daemon (`snmpd`) to use the custom script.
|
|
|
|
|
- Dynamic configuration using a `.env` file with Docker environment variables.
|
|
|
|
|
|
|
|
|
|
## Requirements
|
|
|
|
|
|
|
|
|
@@ -17,11 +18,22 @@ This Docker container runs `snmpd` with a custom script that provides a specific
|
|
|
|
|
|
|
|
|
|
- `snmpd`: The SNMP daemon.
|
|
|
|
|
- Python 3: Used to write the custom script.
|
|
|
|
|
- `random`: Python library for generating random numbers.
|
|
|
|
|
- `random`: Python library for generating random numbers (included in Python's standard library).
|
|
|
|
|
|
|
|
|
|
## How to Use
|
|
|
|
|
|
|
|
|
|
### Step 1: Build the Docker Image
|
|
|
|
|
### Step 1: Create a `.env` File
|
|
|
|
|
|
|
|
|
|
Create a `.env` file in the same directory as your `Dockerfile` with the following content:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
SNMP_COMMUNITY=public
|
|
|
|
|
CUSTOM_OID=.1.3.6.1.4.1.38446.1.2.4.1.9.1
|
|
|
|
|
RANGE_MIN=0
|
|
|
|
|
RANGE_MAX=6
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Step 2: Build the Docker Image
|
|
|
|
|
|
|
|
|
|
Navigate to the directory containing the `Dockerfile` and `custom_snmp_script.py`, then run:
|
|
|
|
|
|
|
|
|
@@ -29,15 +41,15 @@ Navigate to the directory containing the `Dockerfile` and `custom_snmp_script.py
|
|
|
|
|
docker build -t snmpd-custom .
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Step 2: Run the Docker Container
|
|
|
|
|
### Step 3: Run the Docker Container
|
|
|
|
|
|
|
|
|
|
Start the Docker container with the following command:
|
|
|
|
|
Start the Docker container with the following command, using the `--env-file` option to pass the environment variables:
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
docker run -d -p 161:161/udp --name snmpd-custom-container snmpd-custom
|
|
|
|
|
docker run -d -p 161:161/udp --name snmpd-custom-container --env-file .env snmpd-custom
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Step 3: 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:
|
|
|
|
|
|
|
|
|
@@ -50,12 +62,13 @@ You should see the value incrementing randomly every 4 minutes.
|
|
|
|
|
## Customization
|
|
|
|
|
|
|
|
|
|
- **Initial Value**: You can change the initial value in the `custom_snmp_script.py` file.
|
|
|
|
|
- **Increment Range**: Modify the range in the script 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.
|
|
|
|
|
- **Community String and OID**: Modify the `.env` file to change the SNMP community string and OID.
|
|
|
|
|
|
|
|
|
|
## Notes
|
|
|
|
|
|
|
|
|
|
- Ensure that the SNMP community string (`public` in the example) matches your configuration.
|
|
|
|
|
- Ensure that the SNMP community string in the `.env` file matches your configuration.
|
|
|
|
|
- The container exposes port 161 for SNMP communication.
|
|
|
|
|
|
|
|
|
|
## License
|
|
|
|
|