Update config naming and doc

This commit is contained in:
2025-10-17 20:36:29 -07:00
parent eb9e107f65
commit c15f1a50ca
11 changed files with 206 additions and 46 deletions
+2 -2
View File
@@ -204,7 +204,7 @@ Update notification status
### Hierarchy (highest to lowest priority) ### Hierarchy (highest to lowest priority)
1. Environment variables (prefixed with `NOTIFIER_`) 1. Environment variables (prefixed with `NOTIFIER_`)
2. Configuration file (config.yaml) 2. Configuration file (notifier.config)
3. Default values 3. Default values
### Example Environment Variables ### Example Environment Variables
@@ -296,7 +296,7 @@ NOTIFIER_NOTIFIERS_SLACK_WEBHOOK_URL=https://hooks.slack.com/...
3. Add configuration struct to `internal/config/` 3. Add configuration struct to `internal/config/`
4. Register in factory during initialization 4. Register in factory during initialization
5. Update protobuf and REST API types 5. Update protobuf and REST API types
6. Add configuration example to `config.yaml` 6. Add configuration example to `notifier.config`
### Adding a New Queue Implementation ### Adding a New Queue Implementation
+1 -1
View File
@@ -36,7 +36,7 @@ WORKDIR /app
COPY --from=builder /build/server /app/ COPY --from=builder /build/server /app/
# Copy default config (can be overridden with volume mount) # Copy default config (can be overridden with volume mount)
COPY config.yaml /app/config.yaml COPY notifier.config /app/notifier.config
# Create directory for queue persistence # Create directory for queue persistence
RUN mkdir -p /var/lib/notifier && \ RUN mkdir -p /var/lib/notifier && \
+1 -1
View File
@@ -118,7 +118,7 @@ docker-build:
# Run Docker container # Run Docker container
docker-run: docker-run:
@echo "Running Docker container..." @echo "Running Docker container..."
docker run -p 8080:8080 -p 50051:50051 -v $(PWD)/config.yaml:/app/config.yaml notifier:latest docker run -p 8080:8080 -p 50051:50051 -v $(PWD)/notifier.config:/app/notifier.config notifier:latest
# Clean build artifacts # Clean build artifacts
clean: clean:
+76 -19
View File
@@ -149,20 +149,30 @@ curl http://localhost:8080/api/v1/notifications/{notification-id}
## Testing with Other Notifiers ## Testing with Other Notifiers
### SMTP (Email) ### SMTP (Email)
Update `config.yaml`: Update `notifier.config` with named accounts:
```yaml ```yaml
notifiers: notifiers:
smtp: smtp:
host: "smtp.gmail.com" personal:
port: 587 host: "smtp.gmail.com"
username: "your-email@gmail.com" port: 587
password: "your-app-password" username: "your-email@gmail.com"
from: "notifications@yourservice.com" password: "your-app-password"
use_tls: true from: "your-email@gmail.com"
use_tls: true
default: true
work:
host: "smtp.company.com"
port: 587
username: "you@company.com"
password: "your-work-password"
from: "notifications@company.com"
use_tls: true
``` ```
Then send: Then send:
```bash ```bash
# Uses default account (personal)
curl -X POST http://localhost:8080/api/v1/notifications \ curl -X POST http://localhost:8080/api/v1/notifications \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d '{ -d '{
@@ -171,20 +181,38 @@ curl -X POST http://localhost:8080/api/v1/notifications \
"body": "This is a test email!", "body": "This is a test email!",
"recipients": ["recipient@example.com"] "recipients": ["recipient@example.com"]
}' }'
# Specify account explicitly
curl -X POST http://localhost:8080/api/v1/notifications \
-H "Content-Type: application/json" \
-d '{
"type": "email",
"account": "work",
"subject": "Test Email",
"body": "This is a test email!",
"recipients": ["recipient@example.com"]
}'
``` ```
### Slack ### Slack
Update `config.yaml`: Update `notifier.config` with named workspaces:
```yaml ```yaml
notifiers: notifiers:
slack: slack:
webhook_url: "https://hooks.slack.com/services/YOUR/WEBHOOK/URL" main:
username: "Notifier Bot" webhook_url: "https://hooks.slack.com/services/YOUR/WEBHOOK/URL"
icon_emoji: ":bell:" username: "Notifier Bot"
icon_emoji: ":bell:"
default: true
team-a:
webhook_url: "https://hooks.slack.com/services/TEAM-A/WEBHOOK/URL"
username: "Team A Bot"
icon_emoji: ":rocket:"
``` ```
Then send: Then send:
```bash ```bash
# Uses default workspace (main)
curl -X POST http://localhost:8080/api/v1/notifications \ curl -X POST http://localhost:8080/api/v1/notifications \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d '{ -d '{
@@ -193,18 +221,36 @@ curl -X POST http://localhost:8080/api/v1/notifications \
"body": "Application deployed successfully to production!", "body": "Application deployed successfully to production!",
"recipients": ["#alerts"] "recipients": ["#alerts"]
}' }'
# Specify workspace explicitly
curl -X POST http://localhost:8080/api/v1/notifications \
-H "Content-Type: application/json" \
-d '{
"type": "slack",
"account": "team-a",
"subject": "Deployment Alert",
"body": "Application deployed successfully!",
"recipients": ["#alerts"]
}'
``` ```
### Ntfy ### Ntfy
Update `config.yaml`: Update `notifier.config` with named servers:
```yaml ```yaml
notifiers: notifiers:
ntfy: ntfy:
server_url: "https://ntfy.sh" public:
server_url: "https://ntfy.sh"
default: true
private:
server_url: "https://ntfy.mycompany.com"
username: "your-username"
password: "your-password"
``` ```
Then send: Then send:
```bash ```bash
# Uses default server (public)
curl -X POST http://localhost:8080/api/v1/notifications \ curl -X POST http://localhost:8080/api/v1/notifications \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d '{ -d '{
@@ -216,6 +262,17 @@ curl -X POST http://localhost:8080/api/v1/notifications \
"tags": ["warning", "skull"] "tags": ["warning", "skull"]
} }
}' }'
# Specify server explicitly
curl -X POST http://localhost:8080/api/v1/notifications \
-H "Content-Type: application/json" \
-d '{
"type": "ntfy",
"account": "private",
"subject": "Mobile Alert",
"body": "This will appear on your phone!",
"recipients": ["mytopic"]
}'
``` ```
## Configuration ## Configuration
@@ -230,8 +287,8 @@ export NOTIFIER_NOTIFIERS_SMTP_PASSWORD=secret
./bin/restserver ./bin/restserver
``` ```
### Using config.yaml ### Using notifier.config
Create or modify `config.yaml` in the project root: Create or modify `notifier.config` in the project root:
```yaml ```yaml
server: server:
rest_port: 8080 rest_port: 8080
@@ -255,7 +312,7 @@ docker build -t notifier:latest .
### Run with Docker ### Run with Docker
```bash ```bash
docker run -p 8080:8080 \ docker run -p 8080:8080 \
-v $(pwd)/config.yaml:/app/config.yaml \ -v $(pwd)/notifier.config:/app/notifier.config \
notifier:latest notifier:latest
``` ```
@@ -296,18 +353,18 @@ kubectl port-forward svc/notifier-rest 8080:8080
### Server won't start ### Server won't start
- Check if port 8080 is already in use: `lsof -i :8080` - Check if port 8080 is already in use: `lsof -i :8080`
- Check config.yaml syntax - Check notifier.config syntax
- Verify all dependencies are installed: `go mod tidy` - Verify all dependencies are installed: `go mod tidy`
### Notifications not sending ### Notifications not sending
- Check server logs for errors - Check server logs for errors
- Verify the notifier is enabled in config.yaml - Verify the notifier is enabled in notifier.config
- For SMTP: Verify credentials and allow less secure apps - For SMTP: Verify credentials and allow less secure apps
- For Slack: Verify webhook URL is correct - For Slack: Verify webhook URL is correct
- For Ntfy: Ensure topic name is valid - For Ntfy: Ensure topic name is valid
### Queue filling up ### Queue filling up
- Increase worker count in config.yaml - Increase worker count in notifier.config
- Check if notifiers are failing - Check if notifiers are failing
- Review retry configuration - Review retry configuration
+94 -16
View File
@@ -90,7 +90,7 @@ curl http://localhost:8080/api/v1/stats
### Basic Setup ### Basic Setup
Create `config.yaml` in the project root: Create `notifier.config` in the project root:
```yaml ```yaml
server: server:
@@ -111,19 +111,34 @@ notifiers:
### Email Notifications (SMTP) ### Email Notifications (SMTP)
Supports multiple email accounts with named instances:
```yaml ```yaml
notifiers: notifiers:
smtp: smtp:
host: "smtp.gmail.com" # Personal account (default)
port: 587 personal:
username: "your-email@gmail.com" host: "smtp.gmail.com"
password: "your-app-password" port: 587
from: "notifications@yourservice.com" username: "your-email@gmail.com"
use_tls: true password: "your-app-password"
from: "personal@gmail.com"
use_tls: true
default: true
# Work account
work:
host: "smtp.company.com"
port: 587
username: "you@company.com"
password: "your-work-password"
from: "notifications@company.com"
use_tls: true
``` ```
**Usage:** **Usage:**
```bash ```bash
# Uses default account (personal)
curl -X POST http://localhost:8080/api/v1/notifications \ curl -X POST http://localhost:8080/api/v1/notifications \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d '{ -d '{
@@ -132,20 +147,47 @@ curl -X POST http://localhost:8080/api/v1/notifications \
"body": "Thanks for signing up", "body": "Thanks for signing up",
"recipients": ["user@example.com"] "recipients": ["user@example.com"]
}' }'
# Specify account explicitly
curl -X POST http://localhost:8080/api/v1/notifications \
-H "Content-Type: application/json" \
-d '{
"type": "email",
"account": "work",
"subject": "Welcome!",
"body": "Thanks for signing up",
"recipients": ["user@example.com"]
}'
``` ```
### Slack Notifications ### Slack Notifications
Supports multiple workspaces with named instances:
```yaml ```yaml
notifiers: notifiers:
slack: slack:
webhook_url: "https://hooks.slack.com/services/YOUR/WEBHOOK/URL" # Main workspace (default)
username: "Notifier Bot" main:
icon_emoji: ":bell:" webhook_url: "https://hooks.slack.com/services/YOUR/WEBHOOK/URL"
username: "Notifier Bot"
icon_emoji: ":bell:"
default: true
# Team workspace
team-a:
webhook_url: "https://hooks.slack.com/services/TEAM-A/WEBHOOK/URL"
username: "Team A Bot"
icon_emoji: ":rocket:"
# Channel-specific webhooks
webhooks:
"#alerts": "https://hooks.slack.com/services/ALERTS/WEBHOOK"
"#monitoring": "https://hooks.slack.com/services/MONITORING/WEBHOOK"
``` ```
**Usage:** **Usage:**
```bash ```bash
# Uses default workspace (main)
curl -X POST http://localhost:8080/api/v1/notifications \ curl -X POST http://localhost:8080/api/v1/notifications \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d '{ -d '{
@@ -154,20 +196,45 @@ curl -X POST http://localhost:8080/api/v1/notifications \
"body": "v2.0 deployed to production", "body": "v2.0 deployed to production",
"recipients": ["#alerts"] "recipients": ["#alerts"]
}' }'
# Specify workspace explicitly
curl -X POST http://localhost:8080/api/v1/notifications \
-H "Content-Type: application/json" \
-d '{
"type": "slack",
"account": "team-a",
"subject": "Deployment Complete",
"body": "v2.0 deployed to production",
"recipients": ["#alerts"]
}'
``` ```
### Ntfy Push Notifications ### Ntfy Push Notifications
Supports multiple ntfy servers with named instances:
```yaml ```yaml
notifiers: notifiers:
ntfy: ntfy:
server_url: "https://ntfy.sh" # Public ntfy.sh server (default)
token: "tk_your_access_token" # Optional, for private topics public:
default_topic: "myapp-alerts" server_url: "https://ntfy.sh"
token: "tk_your_access_token" # Optional, for private topics
default_topic: "myapp-alerts"
default: true
# Private self-hosted server
private:
server_url: "https://ntfy.mycompany.com"
username: "your-username"
password: "your-password"
default_topic: "company-alerts"
insecure_skip_verify: false # Set true for self-signed certs
``` ```
**Usage:** **Usage:**
```bash ```bash
# Uses default server (public)
curl -X POST http://localhost:8080/api/v1/notifications \ curl -X POST http://localhost:8080/api/v1/notifications \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d '{ -d '{
@@ -181,6 +248,17 @@ curl -X POST http://localhost:8080/api/v1/notifications \
"click": "https://dashboard.example.com" "click": "https://dashboard.example.com"
} }
}' }'
# Specify server explicitly
curl -X POST http://localhost:8080/api/v1/notifications \
-H "Content-Type: application/json" \
-d '{
"type": "ntfy",
"account": "private",
"subject": "Critical Alert",
"body": "Server CPU at 95%",
"recipients": ["alerts"]
}'
``` ```
See [docs/NTFY_GUIDE.md](docs/NTFY_GUIDE.md) for advanced ntfy features (action buttons, attachments, delays, etc.). See [docs/NTFY_GUIDE.md](docs/NTFY_GUIDE.md) for advanced ntfy features (action buttons, attachments, delays, etc.).
@@ -302,7 +380,7 @@ docker run -d \
--name notifier \ --name notifier \
-p 8080:8080 \ -p 8080:8080 \
-p 50051:50051 \ -p 50051:50051 \
-v $(pwd)/config.yaml:/app/config.yaml:ro \ -v $(pwd)/notifier.config:/app/notifier.config:ro \
notifier:latest notifier:latest
``` ```
@@ -437,7 +515,7 @@ notifier/
│ └── kustomization.yaml │ └── kustomization.yaml
├── docs/ ├── docs/
│ └── NTFY_GUIDE.md # Ntfy integration guide │ └── NTFY_GUIDE.md # Ntfy integration guide
├── config.yaml # Default configuration ├── notifier.config # Default configuration
├── docker-compose.yaml ├── docker-compose.yaml
├── Dockerfile ├── Dockerfile
├── Makefile ├── Makefile
@@ -474,7 +552,7 @@ make help # Show all available targets
2. Implement `domain.Notifier` interface 2. Implement `domain.Notifier` interface
3. Add config struct to `internal/config/config.go` 3. Add config struct to `internal/config/config.go`
4. Register in `cmd/server/main.go` 4. Register in `cmd/server/main.go`
5. Update `config.yaml` with example config 5. Update `notifier.config` with example config
6. Add tests 6. Add tests
Example: Example:
+1 -1
View File
@@ -64,7 +64,7 @@ func main() {
// Check if any notifiers are registered // Check if any notifiers are registered
if len(factory.SupportedTypes()) == 0 { if len(factory.SupportedTypes()) == 0 {
logger.Fatal("No notifiers configured. Please enable at least one notifier in config.yaml") logger.Fatal("No notifiers configured. Please enable at least one notifier in notifier.config")
} }
logger.Infof("Supported notification types: %v", factory.SupportedTypes()) logger.Infof("Supported notification types: %v", factory.SupportedTypes())
+1 -1
View File
@@ -12,7 +12,7 @@ services:
- "9090:9090" # Metrics (future) - "9090:9090" # Metrics (future)
- "8081:8081" # Health check (future) - "8081:8081" # Health check (future)
volumes: volumes:
- ./config.yaml:/app/config.yaml:ro - ./notifier.config:/app/notifier.config:ro
- notifier-data:/var/lib/notifier - notifier-data:/var/lib/notifier
environment: environment:
- NOTIFIER_SERVER_MODE=both - NOTIFIER_SERVER_MODE=both
+2 -2
View File
@@ -66,8 +66,8 @@ func Load(configPath string) (*Config, error) {
setDefaults(v) setDefaults(v)
// Configure viper // Configure viper
v.SetConfigName("config") v.SetConfigName("notifier")
v.SetConfigType("yaml") v.SetConfigType("config")
if configPath != "" { if configPath != "" {
v.AddConfigPath(configPath) v.AddConfigPath(configPath)
+26 -1
View File
@@ -5,7 +5,7 @@ metadata:
labels: labels:
app: notifier app: notifier
data: data:
config.yaml: | notifier.config: |
server: server:
grpc_port: 50051 grpc_port: 50051
rest_port: 8080 rest_port: 8080
@@ -25,6 +25,31 @@ data:
notifiers: notifiers:
stdout: true stdout: true
# SMTP email configuration (supports multiple accounts)
smtp:
personal:
host: "smtp.gmail.com"
port: 587
username: "your-email@gmail.com"
password: "your-app-password"
from: "your-email@gmail.com"
use_tls: true
default: true
# Slack configuration (supports multiple workspaces)
slack:
main:
webhook_url: "https://hooks.slack.com/services/YOUR/WEBHOOK/URL"
username: "Notifier Bot"
icon_emoji: ":bell:"
default: true
# Ntfy configuration (supports multiple servers)
ntfy:
public:
server_url: "https://ntfy.sh"
default: true
logging: logging:
level: "info" level: "info"
format: "json" format: "json"
+2 -2
View File
@@ -45,8 +45,8 @@ spec:
value: "local" value: "local"
volumeMounts: volumeMounts:
- name: config - name: config
mountPath: /app/config.yaml mountPath: /app/notifier.config
subPath: config.yaml subPath: notifier.config
readOnly: true readOnly: true
- name: queue-storage - name: queue-storage
mountPath: /var/lib/notifier mountPath: /var/lib/notifier
View File