Skip to content

Commit

Permalink
Merge pull request #149 from 0x2142/dev
Browse files Browse the repository at this point in the history
Release v0.3.5
  • Loading branch information
0x2142 authored Oct 8, 2024
2 parents f892c80 + 686e8b9 commit a94b447
Show file tree
Hide file tree
Showing 30 changed files with 702 additions and 137 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Matt Schmitz
Copyright (c) 2023-2024 Matt Schmitz

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
28 changes: 8 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<div align="center">

[![Static Badge](https://img.shields.io/badge/Project-Documentation-blue)](https://frigate-notify.0x2142.com) [![GitHub Repo stars](https://img.shields.io/github/stars/0x2142/frigate-notify)]() [![GitHub release (with filter)](https://img.shields.io/github/v/release/0x2142/frigate-notify)](https://github.com/0x2142/frigate-notify/releases) [![Static Badge](https://img.shields.io/badge/Docker-latest-blue)](https://github.com/0x2142/frigate-notify/pkgs/container/frigate-notify)
[![Static Badge](https://img.shields.io/badge/Documentation-blue)](https://frigate-notify.0x2142.com) &nbsp;&nbsp; [![GitHub Repo stars](https://img.shields.io/github/stars/0x2142/frigate-notify)]() &nbsp;&nbsp; [![GitHub release (with filter)](https://img.shields.io/github/v/release/0x2142/frigate-notify)](https://github.com/0x2142/frigate-notify/releases) &nbsp;&nbsp; [![Static Badge](https://img.shields.io/badge/Docker-latest-blue)](https://github.com/0x2142/frigate-notify/pkgs/container/frigate-notify) &nbsp;&nbsp; [![BuyMeACoffee](https://img.shields.io/badge/Buy%20Me%20a%20Coffee-blue?style=flat&logo=buy-me-a-coffee&logoColor=white)](https://www.buymeacoffee.com/0x2142)

</div>

Expand All @@ -14,11 +14,13 @@ Currently Frigate only supports notifications through Home Assistant, which I'm

## Features

**Event Polling**
### Event Polling

- MQTT
- Direct via Frigate API

**Notification Methods**
### Notification Methods

- Discord
- Gotify
- SMTP
Expand All @@ -27,9 +29,9 @@ Currently Frigate only supports notifications through Home Assistant, which I'm
- Ntfy
- Generic Webhook

**Other**
- Aliveness monitor via HTTP GET (for use with tools like [HealthChecks](https://github.com/healthchecks/healthchecks) or [Uptime Kuma](https://github.com/louislam/uptime-kuma))
### Other

- Aliveness monitor via HTTP GET (for use with tools like [HealthChecks](https://github.com/healthchecks/healthchecks) or [Uptime Kuma](https://github.com/louislam/uptime-kuma))

## Installation

Expand All @@ -43,21 +45,7 @@ The sample config contains inline descriptions for each field. For additional de

## Screenshots

**Discord**

![Discord](/screenshots/discord.png)

**Gotify**

![Gotify](/screenshots/gotify.png)

**SMTP**

![SMTP](/screenshots/smtp.png)

**Telegram**

![Telegram](/screenshots/telegram.png)
For example screenshots of app notifications, see [here](https://github.com/0x2142/frigate-notify/tree/main/screenshots)

## Changelog

Expand Down
37 changes: 31 additions & 6 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import (
)

type Config struct {
Frigate Frigate `fig:"frigate"`
Alerts Alerts `fig:"alerts"`
Monitor Monitor `fig:"monitor"`
Frigate *Frigate `fig:"frigate" validate:"required"`
Alerts *Alerts `fig:"alerts" validate:"required"`
Monitor Monitor `fig:"monitor"`
}

type Frigate struct {
Expand All @@ -32,7 +32,7 @@ type Frigate struct {
WebAPI WebAPI `fig:"webapi"`
MQTT MQTT `fig:"mqtt"`
Cameras Cameras `fig:"cameras"`
Version int
Version int // Internal use only
}

type StartupCheck struct {
Expand Down Expand Up @@ -83,6 +83,7 @@ type General struct {
SnapBbox bool `fig:"snap_bbox" default:false`
SnapTimestamp bool `fig:"snap_timestamp" default:false`
SnapCrop bool `fig:"snap_crop" default:false`
NotifyOnce bool `fig:"notify_once" default:false`
}

type Quiet struct {
Expand Down Expand Up @@ -123,8 +124,10 @@ type SMTP struct {
TLS bool `fig:"tls" default:false`
User string `fig:"user" default:""`
Password string `fig:"password" default:""`
From string `fig:"from" default:""`
Recipient string `fig:"recipient" default:""`
Template string `fig:"template" default:""`
Insecure bool `fig:"ignoressl" default:false`
}

type Telegram struct {
Expand Down Expand Up @@ -169,6 +172,8 @@ type Webhook struct {
Enabled bool `fig:"enabled" default:false`
Server string `fig:"server" default:""`
Insecure bool `fig:"ignoressl" default:false`
Method string `fig:"method" default:"POST"`
Params []map[string]string `fix:"params"`
Headers []map[string]string `fig:"headers"`
Template map[string]interface{} `fig:"template"`
}
Expand Down Expand Up @@ -245,7 +250,7 @@ func validateConfig() {

// Check if Frigate server URL contains protocol, assume HTTP if not specified
if !strings.Contains(ConfigData.Frigate.Server, "http://") && !strings.Contains(ConfigData.Frigate.Server, "https://") {
log.Warn().Msg("No protocol specified on Frigate Server. Assuming http://. If this is incorrect, please adjust the config file.")
log.Warn().Msgf("No protocol specified on Frigate server URL, so we'll try http://%s. If this is incorrect, please adjust the config file.", ConfigData.Frigate.Server)
ConfigData.Frigate.Server = fmt.Sprintf("http://%s", ConfigData.Frigate.Server)
}

Expand All @@ -260,7 +265,7 @@ func validateConfig() {
ConfigData.Frigate.StartupCheck.Interval = 30
}
for current_attempt < ConfigData.Frigate.StartupCheck.Attempts {
response, err = util.HTTPGet(statsAPI, ConfigData.Frigate.Insecure, ConfigData.Frigate.Headers...)
response, err = util.HTTPGet(statsAPI, ConfigData.Frigate.Insecure, "", ConfigData.Frigate.Headers...)
if err != nil {
log.Warn().
Err(err).
Expand Down Expand Up @@ -342,6 +347,9 @@ func validateConfig() {
log.Debug().Msgf("Events without a snapshot: %v", strings.ToLower(ConfigData.Alerts.General.NoSnap))
}

// Notify_Once
log.Debug().Msgf("Notify only once per event: %v", ConfigData.Alerts.General.NotifyOnce)

// Check Zone filtering config
if strings.ToLower(ConfigData.Alerts.Zones.Unzoned) != "allow" && strings.ToLower(ConfigData.Alerts.Zones.Unzoned) != "drop" {
configErrors = append(configErrors, "Option for unzoned events must be 'allow' or 'drop'")
Expand Down Expand Up @@ -406,7 +414,9 @@ func validateConfig() {
}

// Check / Load alerting configuration
var alertingEnabled bool
if ConfigData.Alerts.Discord.Enabled {
alertingEnabled = true
log.Debug().Msg("Discord alerting enabled.")
if ConfigData.Alerts.Discord.Webhook == "" {
configErrors = append(configErrors, "No Discord webhook specified!")
Expand All @@ -417,6 +427,7 @@ func validateConfig() {
}
}
if ConfigData.Alerts.Gotify.Enabled {
alertingEnabled = true
log.Debug().Msg("Gotify alerting enabled.")
// Check if Gotify server URL contains protocol, assume HTTP if not specified
if !strings.Contains(ConfigData.Alerts.Gotify.Server, "http://") && !strings.Contains(ConfigData.Alerts.Gotify.Server, "https://") {
Expand All @@ -435,6 +446,7 @@ func validateConfig() {
}
}
if ConfigData.Alerts.SMTP.Enabled {
alertingEnabled = true
log.Debug().Msg("SMTP alerting enabled.")
if ConfigData.Alerts.SMTP.Server == "" {
configErrors = append(configErrors, "No SMTP server specified!")
Expand All @@ -448,12 +460,17 @@ func validateConfig() {
if ConfigData.Alerts.SMTP.Port == 0 {
ConfigData.Alerts.SMTP.Port = 25
}
// Copy `user` to `from` if `from` not explicitly configured
if ConfigData.Alerts.SMTP.From == "" && ConfigData.Alerts.SMTP.User != "" {
ConfigData.Alerts.SMTP.From = ConfigData.Alerts.SMTP.User
}
// Check template syntax
if msg := checkTemplate("SMTP", ConfigData.Alerts.SMTP.Template); msg != "" {
configErrors = append(configErrors, msg)
}
}
if ConfigData.Alerts.Telegram.Enabled {
alertingEnabled = true
log.Debug().Msg("Telegram alerting enabled.")
if ConfigData.Alerts.Telegram.ChatID == 0 {
configErrors = append(configErrors, "No Telegram Chat ID specified!")
Expand All @@ -467,6 +484,7 @@ func validateConfig() {
}
}
if ConfigData.Alerts.Pushover.Enabled {
alertingEnabled = true
log.Debug().Msg("Pushover alerting enabled.")
if ConfigData.Alerts.Pushover.Token == "" {
configErrors = append(configErrors, "No Pushover API token specified!")
Expand Down Expand Up @@ -497,6 +515,7 @@ func validateConfig() {
// Deprecation warning
// TODO: Remove misspelled Ntfy config with v0.4.0 or later
if ConfigData.Alerts.Nfty.Enabled {
alertingEnabled = true
log.Warn().Msg("Config for 'nfty' will be deprecated due to misspelling. Please update config to 'ntfy'")
// Copy data to new Ntfy struct
ConfigData.Alerts.Ntfy.Enabled = ConfigData.Alerts.Nfty.Enabled
Expand All @@ -507,6 +526,7 @@ func validateConfig() {
ConfigData.Alerts.Ntfy.Template = ConfigData.Alerts.Nfty.Template
}
if ConfigData.Alerts.Ntfy.Enabled {
alertingEnabled = true
log.Debug().Msg("Ntfy alerting enabled.")
if ConfigData.Alerts.Ntfy.Server == "" {
configErrors = append(configErrors, "No Ntfy server specified!")
Expand All @@ -520,12 +540,17 @@ func validateConfig() {
}
}
if ConfigData.Alerts.Webhook.Enabled {
alertingEnabled = true
log.Debug().Msg("Webhook alerting enabled.")
if ConfigData.Alerts.Webhook.Server == "" {
configErrors = append(configErrors, "No Webhook server specified!")
}
}

if !alertingEnabled {
configErrors = append(configErrors, "No alerting methods have been configured. Please check config file syntax!")
}

// Validate monitoring config
if ConfigData.Monitor.Enabled {
log.Debug().Msg("App monitoring enabled.")
Expand Down
12 changes: 12 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## [v0.3.5](https://github.com/0x2142/frigate-notify/releases/tag/v0.3.5) - Oct 08 2024
- Fixed issue where built-in alert templates were not being included in binary releases
- Fixed issue where a notification may not be sent if previous event update from Frigate did not contain a snapshot
- Fixed issue where Gotify snapshot was not using `public_url` if configured
- Added `from` & `ignoressl` config items to `smtp` notifier
- Added ability to send `webhook` notifications via HTTP GET requests
- Added support for URL parameters with `webhook` notifications
- Added option to only generate a [single notification](https://frigate-notify.0x2142.com/latest/config/file/#general) per Frigate event
- Allow use of [template variables](https://frigate-notify.0x2142.com/latest/config/templates/#title-template) within alert `title` config
- New options to set specific [log level](https://frigate-notify.0x2142.com/latest/config/options/) & additional `trace` level logs for troubleshooting
- Minor enhancements to config file validation

## [v0.3.4](https://github.com/0x2142/frigate-notify/releases/tag/v0.3.4) - Aug 15 2024
- Fixed issue where `unzoned: drop` config would drop all notifications

Expand Down
23 changes: 23 additions & 0 deletions docs/config/file.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ frigate:

- **title** (Optional - Default: `Frigate Alert`)
- Title of alert messages that are generated (Email subject, etc)
- Title value can utilize [template variables](./templates.md#available-variables)
- **timeformat** (Optional - Default: `2006-01-02 15:04:05 -0700 MST`)
- Optionally set a custom date/time format for notifications
- This utilizes Golang's [reference time](https://go.dev/src/time/format.go) for formatting
Expand All @@ -140,6 +141,9 @@ frigate:
- **snap_crop** (Optional - Default: `false`)
- Crops snapshot when retrieved from Frigate
- Note: Per [Frigate docs](https://docs.frigate.video/integrations/api/#get-apieventsidsnapshotjpg), only applied when event is in progress
- **notify_once** (Optional - Default: `false`)
- By default, each Frigate event may generate several notifications as the object changes zones, etc
- Set this to `true` to only notify once per event

```yaml title="Config File Snippet"
alerts:
Expand All @@ -150,6 +154,7 @@ alerts:
snap_bbox:
snap_timestamp:
snap_crop:
notify_once:
```

### Quiet Hours
Expand Down Expand Up @@ -320,12 +325,17 @@ alerts:
- **password** (Optional)
- Password of SMTP user
- Required if `user` is set
- **from** (Optional)
- Set sender address for outgoing messages
- If left blank but authentication is configured, then `user` will be used
- **recipient** (Required)
- Comma-separated list of email recipients
- Required if this alerting method is enabled
- **template** (Optional)
- Optionally specify a custom notification template
- For more information on template syntax, see [Alert Templates](./templates.md#alert-templates)
- **ignoressl** (Optional - Default: `false`)
- Set to `true` to allow self-signed certificates

```yaml title="Config File Snippet"
alerts:
Expand All @@ -334,10 +344,12 @@ alerts:
server: smtp.your.domain.tld
port: 587
tls: true
from: test_user@your.domain.tld
user: test_user@your.domain.tld
password: test_pass
recipient: nvr_group@your.domain.tld, someone_else@your.domain.tld
template:
ignoressl:
```

### Telegram
Expand Down Expand Up @@ -500,13 +512,22 @@ alerts:
- Required if this alerting method is enabled
- **ignoressl** (Optional - Default: `false`)
- Set to `true` to allow self-signed certificates
- **method** (Optional - Default: `POST`)
- Set HTTP method for webhook notifications
- Supports `GET` and `POST`
- **params** (Optional)
- Set optional HTTP params that will be appended to URL
- Params can utilize [template variables](./templates.md#available-variables)
- Format: `param: value`
- Example: `token: abcd1234`
- **headers** (Optional)
- Send additional HTTP headers to webhook receiver
- Header values can utilize [template variables](./templates.md#available-variables)
- Header format: `Header: Value`
- Example: `Authorization: Basic abcd1234`
- **template** (Optional)
- Optionally specify a custom notification template
- Only applies when `method` is `POST`
- For more information on template syntax, see [Alert Templates](./templates.md#alert-templates)
- Note: Webhook templates **must** be valid JSON

Expand All @@ -515,6 +536,8 @@ alerts:
enabled: false
server:
ignoressl:
method:
params:
headers:
template:
```
Expand Down
13 changes: 7 additions & 6 deletions docs/config/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

The following options are available as command line flags or environment variables:

| Flag | Environment Variable | Description |
|----------|----------------------|----------------------------------------------------|
| -c | FN_CONFIGFILE | Specify alternate config file location |
| -debug | FN_DEBUG | Set to `true` to enable debug logging |
| -jsonlog | FN_JSONLOG | Set to `true` to enable logging in JSON |
| -nocolor | FN_NOCOLOR | Set to `true` to disable color for console logging |
| Flag | Environment Variable | Description |
|-------------|----------------------|----------------------------------------------------------------------------------------------------------|
| -c | FN_CONFIGFILE | Specify alternate config file location |
| -debug | FN_DEBUG | Set to `true` to enable debug logging (Overrides -loglevel) |
| -loglevel | FN_LOGLEVEL | Specify desired log level: `panic`, `fatal`, `error`, `warn`, `info`, `debug`, `trace` (Default: `info`) |
| -jsonlog | FN_JSONLOG | Set to `true` to enable logging in JSON |
| -nocolor | FN_NOCOLOR | Set to `true` to disable color for console logging |
3 changes: 3 additions & 0 deletions docs/config/sample.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ alerts:
snap_bbox:
snap_timestamp:
snap_crop:
notify_once:

quiet:
start:
Expand Down Expand Up @@ -114,6 +115,8 @@ alerts:
enabled: false
server:
ignoressl:
method:
params:
headers:
template:

Expand Down
Loading

0 comments on commit a94b447

Please sign in to comment.