Update config naming and doc
This commit is contained in:
+2
-2
@@ -204,7 +204,7 @@ Update notification status
|
||||
|
||||
### Hierarchy (highest to lowest priority)
|
||||
1. Environment variables (prefixed with `NOTIFIER_`)
|
||||
2. Configuration file (config.yaml)
|
||||
2. Configuration file (notifier.config)
|
||||
3. Default values
|
||||
|
||||
### Example Environment Variables
|
||||
@@ -296,7 +296,7 @@ NOTIFIER_NOTIFIERS_SLACK_WEBHOOK_URL=https://hooks.slack.com/...
|
||||
3. Add configuration struct to `internal/config/`
|
||||
4. Register in factory during initialization
|
||||
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
|
||||
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@ WORKDIR /app
|
||||
COPY --from=builder /build/server /app/
|
||||
|
||||
# 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
|
||||
RUN mkdir -p /var/lib/notifier && \
|
||||
|
||||
@@ -118,7 +118,7 @@ docker-build:
|
||||
# Run Docker container
|
||||
docker-run:
|
||||
@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:
|
||||
|
||||
+76
-19
@@ -149,20 +149,30 @@ curl http://localhost:8080/api/v1/notifications/{notification-id}
|
||||
## Testing with Other Notifiers
|
||||
|
||||
### SMTP (Email)
|
||||
Update `config.yaml`:
|
||||
Update `notifier.config` with named accounts:
|
||||
```yaml
|
||||
notifiers:
|
||||
smtp:
|
||||
host: "smtp.gmail.com"
|
||||
port: 587
|
||||
username: "your-email@gmail.com"
|
||||
password: "your-app-password"
|
||||
from: "notifications@yourservice.com"
|
||||
use_tls: true
|
||||
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
|
||||
work:
|
||||
host: "smtp.company.com"
|
||||
port: 587
|
||||
username: "you@company.com"
|
||||
password: "your-work-password"
|
||||
from: "notifications@company.com"
|
||||
use_tls: true
|
||||
```
|
||||
|
||||
Then send:
|
||||
```bash
|
||||
# Uses default account (personal)
|
||||
curl -X POST http://localhost:8080/api/v1/notifications \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
@@ -171,20 +181,38 @@ curl -X POST http://localhost:8080/api/v1/notifications \
|
||||
"body": "This is a test email!",
|
||||
"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
|
||||
Update `config.yaml`:
|
||||
Update `notifier.config` with named workspaces:
|
||||
```yaml
|
||||
notifiers:
|
||||
slack:
|
||||
webhook_url: "https://hooks.slack.com/services/YOUR/WEBHOOK/URL"
|
||||
username: "Notifier Bot"
|
||||
icon_emoji: ":bell:"
|
||||
main:
|
||||
webhook_url: "https://hooks.slack.com/services/YOUR/WEBHOOK/URL"
|
||||
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:
|
||||
```bash
|
||||
# Uses default workspace (main)
|
||||
curl -X POST http://localhost:8080/api/v1/notifications \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
@@ -193,18 +221,36 @@ curl -X POST http://localhost:8080/api/v1/notifications \
|
||||
"body": "Application deployed successfully to production!",
|
||||
"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
|
||||
Update `config.yaml`:
|
||||
Update `notifier.config` with named servers:
|
||||
```yaml
|
||||
notifiers:
|
||||
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:
|
||||
```bash
|
||||
# Uses default server (public)
|
||||
curl -X POST http://localhost:8080/api/v1/notifications \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
@@ -216,6 +262,17 @@ curl -X POST http://localhost:8080/api/v1/notifications \
|
||||
"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
|
||||
@@ -230,8 +287,8 @@ export NOTIFIER_NOTIFIERS_SMTP_PASSWORD=secret
|
||||
./bin/restserver
|
||||
```
|
||||
|
||||
### Using config.yaml
|
||||
Create or modify `config.yaml` in the project root:
|
||||
### Using notifier.config
|
||||
Create or modify `notifier.config` in the project root:
|
||||
```yaml
|
||||
server:
|
||||
rest_port: 8080
|
||||
@@ -255,7 +312,7 @@ docker build -t notifier:latest .
|
||||
### Run with Docker
|
||||
```bash
|
||||
docker run -p 8080:8080 \
|
||||
-v $(pwd)/config.yaml:/app/config.yaml \
|
||||
-v $(pwd)/notifier.config:/app/notifier.config \
|
||||
notifier:latest
|
||||
```
|
||||
|
||||
@@ -296,18 +353,18 @@ kubectl port-forward svc/notifier-rest 8080:8080
|
||||
|
||||
### Server won't start
|
||||
- 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`
|
||||
|
||||
### Notifications not sending
|
||||
- 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 Slack: Verify webhook URL is correct
|
||||
- For Ntfy: Ensure topic name is valid
|
||||
|
||||
### Queue filling up
|
||||
- Increase worker count in config.yaml
|
||||
- Increase worker count in notifier.config
|
||||
- Check if notifiers are failing
|
||||
- Review retry configuration
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ curl http://localhost:8080/api/v1/stats
|
||||
|
||||
### Basic Setup
|
||||
|
||||
Create `config.yaml` in the project root:
|
||||
Create `notifier.config` in the project root:
|
||||
|
||||
```yaml
|
||||
server:
|
||||
@@ -111,19 +111,34 @@ notifiers:
|
||||
|
||||
### Email Notifications (SMTP)
|
||||
|
||||
Supports multiple email accounts with named instances:
|
||||
|
||||
```yaml
|
||||
notifiers:
|
||||
smtp:
|
||||
host: "smtp.gmail.com"
|
||||
port: 587
|
||||
username: "your-email@gmail.com"
|
||||
password: "your-app-password"
|
||||
from: "notifications@yourservice.com"
|
||||
use_tls: true
|
||||
# Personal account (default)
|
||||
personal:
|
||||
host: "smtp.gmail.com"
|
||||
port: 587
|
||||
username: "your-email@gmail.com"
|
||||
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:**
|
||||
```bash
|
||||
# Uses default account (personal)
|
||||
curl -X POST http://localhost:8080/api/v1/notifications \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
@@ -132,20 +147,47 @@ curl -X POST http://localhost:8080/api/v1/notifications \
|
||||
"body": "Thanks for signing up",
|
||||
"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
|
||||
|
||||
Supports multiple workspaces with named instances:
|
||||
|
||||
```yaml
|
||||
notifiers:
|
||||
slack:
|
||||
webhook_url: "https://hooks.slack.com/services/YOUR/WEBHOOK/URL"
|
||||
username: "Notifier Bot"
|
||||
icon_emoji: ":bell:"
|
||||
# Main workspace (default)
|
||||
main:
|
||||
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:**
|
||||
```bash
|
||||
# Uses default workspace (main)
|
||||
curl -X POST http://localhost:8080/api/v1/notifications \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
@@ -154,20 +196,45 @@ curl -X POST http://localhost:8080/api/v1/notifications \
|
||||
"body": "v2.0 deployed to production",
|
||||
"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
|
||||
|
||||
Supports multiple ntfy servers with named instances:
|
||||
|
||||
```yaml
|
||||
notifiers:
|
||||
ntfy:
|
||||
server_url: "https://ntfy.sh"
|
||||
token: "tk_your_access_token" # Optional, for private topics
|
||||
default_topic: "myapp-alerts"
|
||||
# Public ntfy.sh server (default)
|
||||
public:
|
||||
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:**
|
||||
```bash
|
||||
# Uses default server (public)
|
||||
curl -X POST http://localhost:8080/api/v1/notifications \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
@@ -181,6 +248,17 @@ curl -X POST http://localhost:8080/api/v1/notifications \
|
||||
"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.).
|
||||
@@ -302,7 +380,7 @@ docker run -d \
|
||||
--name notifier \
|
||||
-p 8080:8080 \
|
||||
-p 50051:50051 \
|
||||
-v $(pwd)/config.yaml:/app/config.yaml:ro \
|
||||
-v $(pwd)/notifier.config:/app/notifier.config:ro \
|
||||
notifier:latest
|
||||
```
|
||||
|
||||
@@ -437,7 +515,7 @@ notifier/
|
||||
│ └── kustomization.yaml
|
||||
├── docs/
|
||||
│ └── NTFY_GUIDE.md # Ntfy integration guide
|
||||
├── config.yaml # Default configuration
|
||||
├── notifier.config # Default configuration
|
||||
├── docker-compose.yaml
|
||||
├── Dockerfile
|
||||
├── Makefile
|
||||
@@ -474,7 +552,7 @@ make help # Show all available targets
|
||||
2. Implement `domain.Notifier` interface
|
||||
3. Add config struct to `internal/config/config.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
|
||||
|
||||
Example:
|
||||
|
||||
+1
-1
@@ -64,7 +64,7 @@ func main() {
|
||||
|
||||
// Check if any notifiers are registered
|
||||
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())
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ services:
|
||||
- "9090:9090" # Metrics (future)
|
||||
- "8081:8081" # Health check (future)
|
||||
volumes:
|
||||
- ./config.yaml:/app/config.yaml:ro
|
||||
- ./notifier.config:/app/notifier.config:ro
|
||||
- notifier-data:/var/lib/notifier
|
||||
environment:
|
||||
- NOTIFIER_SERVER_MODE=both
|
||||
|
||||
@@ -66,8 +66,8 @@ func Load(configPath string) (*Config, error) {
|
||||
setDefaults(v)
|
||||
|
||||
// Configure viper
|
||||
v.SetConfigName("config")
|
||||
v.SetConfigType("yaml")
|
||||
v.SetConfigName("notifier")
|
||||
v.SetConfigType("config")
|
||||
|
||||
if configPath != "" {
|
||||
v.AddConfigPath(configPath)
|
||||
|
||||
+26
-1
@@ -5,7 +5,7 @@ metadata:
|
||||
labels:
|
||||
app: notifier
|
||||
data:
|
||||
config.yaml: |
|
||||
notifier.config: |
|
||||
server:
|
||||
grpc_port: 50051
|
||||
rest_port: 8080
|
||||
@@ -25,6 +25,31 @@ data:
|
||||
notifiers:
|
||||
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:
|
||||
level: "info"
|
||||
format: "json"
|
||||
|
||||
+2
-2
@@ -45,8 +45,8 @@ spec:
|
||||
value: "local"
|
||||
volumeMounts:
|
||||
- name: config
|
||||
mountPath: /app/config.yaml
|
||||
subPath: config.yaml
|
||||
mountPath: /app/notifier.config
|
||||
subPath: notifier.config
|
||||
readOnly: true
|
||||
- name: queue-storage
|
||||
mountPath: /var/lib/notifier
|
||||
|
||||
Reference in New Issue
Block a user