Agents Monitoring API
Overview
The Agents Monitoring API is a Go-based REST API that allows agents to send their IP addresses, retrieve IP-related details (such as ASN and ISP), and manage agent information. The API uses SQLite for storage and integrates with an external IP lookup service (ip-api.com).
Features
- Accepts IP address submissions from agents.
- Retrieves and stores Autonomous System Number (ASN) and Internet Service Provider (ISP) details.
- Provides endpoints to list all agents and fetch details of a specific agent.
- Supports Docker and
.env configuration.
API Endpoints
| Method |
Endpoint |
Description |
POST |
/agents |
Register an agent's IP address |
GET |
/agents |
Get a list of all registered agents |
GET |
/agents/{id} |
Get details (ASN, ISP) of a specific agent |
๐น Example: Register an Agent
Request:
curl -X POST "http://localhost:8080/agents" \
-H "Content-Type: application/json" \
-d '{"ip_address": "8.8.8.8"}'
๐น Example: Get a List of Agents
Request:
curl -X GET "http://localhost:8080/agents"
Response:
[
{
"id": 1,
"ip_address": "8.8.8.8",
},
{
"id": 2,
"ip_address": "1.1,1.1",
}
]
๐น Example: Get Details of a Specific Agent
Request:
curl -X GET "http://localhost:8080/agents/1"
Response:
{
"id": 1,
"ip_address": "8.8.8.8",
"asn": "15169",
"isp": "Google LLC"
}
Running the API
Create a .env file
PORT=8080
DATABASE_URL=database.sqlite
RATE_LIMIT=100
install dependencies
go mod tidy
๐น Using Docker
- Clone the repository:
git clone https://github.com/Shaughny/obkio-test.git
- Start with docker:
make docker-run
- Read the logs:
make logs
4.Stop the container:
make docker-stop
๐น Using Local Go Installation
- Clone the repository:
git clone https://github.com/Shaughny/obkio-test.git
-
Make sure go is installed on your machine.
-
Run the API:
make run
go run ./cmd/api/
๐น Running Tests
make test
๐น All make commands
make help
๐น Docker Without using make
- Clone the repository:
docker compose up -d --build
- Stop the container:
docker compose down
Removing binaries and database
make clean