Golang-based Watchdog service for OBA REST API servers
Go 1.23 or higher
The watchdog service can be configured using either:
- A local JSON configuration file (
--config-file
). - A remote JSON configuration URL (
--config-url
).- Using a remote configuration allows you to dynamically add, remove, or update server configurations at runtime.
The JSON configuration file should contain an array of ObaServer
objects, each representing an OBA server to be monitored. Example:
[
{
"name": "Test Server 1",
"id": 1,
"oba_base_url": "https://test1.example.com",
"oba_api_key": "test-key-1",
"gtfs_url": "https://gtfs1.example.com",
"trip_update_url": "https://trip1.example.com",
"vehicle_position_url": "https://vehicle1.example.com",
"gtfs_rt_api_key": "api-key-1",
"gtfs_rt_api_value": "api-value-1",
"agency_id": "agency-1"
},
{
"name": "Test Server 2",
"id": 2,
"oba_base_url": "https://test2.example.com",
"oba_api_key": "test-key-2",
"gtfs_url": "https://gtfs2.example.com",
"trip_update_url": "https://trip2.example.com",
"vehicle_position_url": "https://vehicle2.example.com",
"gtfs_rt_api_key": "api-key-2",
"gtfs_rt_api_value": "api-value-2",
"agency_id": "agency-2"
}
]
- Either copy or rename
config.json.template
toconfig.json
in the same folder. - Update
config.json
with your OBA server values.
Note: The config.json
file is ignored by Git to prevent accidental commits of sensitive configuration data.
- Create a
config.json
file based on theconfig.json.template
format. - Fill in your OBA server values in
config.json
. - Host it publicly and point the app to its URL.
To enable Sentry error tracking, set the SENTRY_DSN
environment variable with your Sentry DSN.
export SENTRY_DSN="your_sentry_dsn"
go run ./cmd/watchdog/ --config-file ./config.json
To load the configuration from a remote URL that requires basic authentication, follow these steps:
Before running the application, set the CONFIG_AUTH_USER
and CONFIG_AUTH_PASS
environment variables with the username and password for authentication.
export CONFIG_AUTH_USER="your_username"
export CONFIG_AUTH_PASS="your_password"
set CONFIG_AUTH_USER=your_username
set CONFIG_AUTH_PASS=your_password
Use the --config-url flag to specify the remote configuration URL. For example:
go run ./cmd/watchdog/ \
--config-url http://example.com/config.json
You can also run the application using Docker. Here’s how:
First, build the Docker image for the application. Navigate to the root of the project directory and run:
docker build -t watchdog .
docker run -d \
--name watchdog \
-e CONFIG_AUTH_USER=admin \
-e CONFIG_AUTH_PASS=password \
-v ./config.json:/app/config.json \
-p 4000:4000 \
watchdog \
--config-file /app/config.json
docker run -d \
--name watchdog \
-e CONFIG_AUTH_USER=admin \
-e CONFIG_AUTH_PASS=password \
-p 4000:4000 \
watchdog \
--config-url http://example.com/config.json
go test ./...
Follow these steps:
- Open the file
integration_servers.json.template
inside theinternal/integration
package. - Rename it to
integration_servers.json
. - Fill in your OBA server configuration values.
Then run:
go test -tags=integration ./internal/integration -integration-config ./integration_servers.json
Note:
- The
integration_servers.json
file is ignored by Git to prevent accidental commits of sensitive data. - You can point to any config file by passing its path using the -integration-config flag.