Skip to content

Commit

Permalink
Merge pull request #93 from 0x2142/dev
Browse files Browse the repository at this point in the history
Release v0.3.1
  • Loading branch information
0x2142 authored Jun 11, 2024
2 parents 66f7388 + 33c14d7 commit d363ece
Show file tree
Hide file tree
Showing 21 changed files with 181 additions and 68 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Currently Frigate only supports notifications through Home Assistant, which I'm
- SMTP
- Telegram
- Pushover
- Nfty
- Ntfy
- Generic Webhook

**Other**
Expand Down
60 changes: 48 additions & 12 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"html/template"
"os"
"path/filepath"
"strconv"
"strings"
"time"

Expand All @@ -30,6 +31,7 @@ type Frigate struct {
WebAPI WebAPI `fig:"webapi"`
MQTT MQTT `fig:"mqtt"`
Cameras Cameras `fig:"cameras"`
Version int
}

type StartupCheck struct {
Expand Down Expand Up @@ -67,12 +69,14 @@ type Alerts struct {
Telegram Telegram `fig:"telegram"`
Pushover Pushover `fig:"pushover"`
Nfty Nfty `fig:"nfty"`
Ntfy Ntfy `fig:"ntfy"`
Webhook Webhook `fig:"webhook"`
}

type General struct {
Title string `fig:"title" default:"Frigate Alert"`
TimeFormat string `fig:"timeformat" default: ""`
TimeFormat string `fig:"timeformat" default:""`
NoSnap string `fig:"nosnap" default:"allow"`
}

type Zones struct {
Expand Down Expand Up @@ -130,12 +134,23 @@ type Pushover struct {
Template string `fig:"template" default:""`
}

// DEPRECATED: Misspelling of Ntfy
type Nfty struct {
Enabled bool `fig:"enabled" default:false`
Server string `fig:"server" default:""`
Topic string `fig:"topic" default:""`
Insecure bool `fig:"ignoressl" default:false`
Template string `fig:"template" default:""`
Enabled bool `fig:"enabled" default:false`
Server string `fig:"server" default:""`
Topic string `fig:"topic" default:""`
Insecure bool `fig:"ignoressl" default:false`
Headers []map[string]string `fig:"headers"`
Template string `fig:"template" default:""`
}

type Ntfy struct {
Enabled bool `fig:"enabled" default:false`
Server string `fig:"server" default:""`
Topic string `fig:"topic" default:""`
Insecure bool `fig:"ignoressl" default:false`
Headers []map[string]string `fig:"headers"`
Template string `fig:"template" default:""`
}

type Webhook struct {
Expand Down Expand Up @@ -247,6 +262,8 @@ func validateConfig() {
log.Info().Msgf("Successfully connected to %v", ConfigData.Frigate.Server)
if stats.Service.Version != "" {
log.Debug().Msgf("Frigate server is running version %v", stats.Service.Version)
// Save major version number
ConfigData.Frigate.Version, _ = strconv.Atoi(strings.Split(stats.Service.Version, ".")[1])
}

// Check Public / External URL if set
Expand Down Expand Up @@ -278,6 +295,13 @@ func validateConfig() {
}
}

// Check action on no snapshot available
if strings.ToLower(ConfigData.Alerts.General.NoSnap) != "allow" && strings.ToLower(ConfigData.Alerts.General.NoSnap) != "drop" {
configErrors = append(configErrors, "Option for nosnap must be 'allow' or 'drop'")
} else {
log.Debug().Msgf("Events without a snapshot: %v", strings.ToLower(ConfigData.Alerts.General.NoSnap))
}

// 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 @@ -409,16 +433,28 @@ func validateConfig() {
configErrors = append(configErrors, msg)
}
}
// Deprecation warning
// TODO: Remove misspelled Ntfy config with v0.4.0 or later
if ConfigData.Alerts.Nfty.Enabled {
log.Debug().Msg("Nfty alerting enabled.")
if ConfigData.Alerts.Nfty.Server == "" {
configErrors = append(configErrors, "No Nfty server specified!")
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
ConfigData.Alerts.Ntfy.Server = ConfigData.Alerts.Nfty.Server
ConfigData.Alerts.Ntfy.Topic = ConfigData.Alerts.Nfty.Topic
ConfigData.Alerts.Ntfy.Insecure = ConfigData.Alerts.Nfty.Insecure
ConfigData.Alerts.Ntfy.Headers = ConfigData.Alerts.Nfty.Headers
ConfigData.Alerts.Ntfy.Template = ConfigData.Alerts.Nfty.Template
}
if ConfigData.Alerts.Ntfy.Enabled {
log.Debug().Msg("Ntfy alerting enabled.")
if ConfigData.Alerts.Ntfy.Server == "" {
configErrors = append(configErrors, "No Ntfy server specified!")
}
if ConfigData.Alerts.Nfty.Topic == "" {
configErrors = append(configErrors, "No Nfty topic specified!")
if ConfigData.Alerts.Ntfy.Topic == "" {
configErrors = append(configErrors, "No Ntfy topic specified!")
}
// Check template syntax
if msg := checkTemplate("Nfty", ConfigData.Alerts.Nfty.Template); msg != "" {
if msg := checkTemplate("Ntfy", ConfigData.Alerts.Ntfy.Template); msg != "" {
configErrors = append(configErrors, msg)
}
}
Expand Down
14 changes: 13 additions & 1 deletion docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## [v0.3.1](https://github.com/0x2142/frigate-notify/releases/tag/v0.3.1) - Jun 11 2024

- Fix misspelling for Ntfy
- Currently config will accept either `nfty` or `ntfy`, but in a future release `nfty` will be removed
- ⚠️ **Note**: If you are using `nfty`, please update your config to the correct spelling: `ntfy`
- Fix issue where Ntfy action button would use local Frigate URL even if `public_url` was configured
- Fix camera links for Frigate 0.14.0+
- Add support for sending HTTP headers with Ntfy notifications
- Added [config file](https://frigate-notify.0x2142.com/latest/config/file/#general) option to drop events that don't have a snapshot image
- Move "No snapshot available" message into notification templates
- Add support for disabling colored console logging via [config options](https://frigate-notify.0x2142.com/latest/config/options/)

## [v0.3.0](https://github.com/0x2142/frigate-notify/releases/tag/v0.3.0) - Jun 03 2024

- Reworked & reduced logging, added [debug option](https://frigate-notify.0x2142.com/latest/config/options/)
Expand All @@ -13,7 +25,7 @@

## [v0.2.8](https://github.com/0x2142/frigate-notify/releases/tag/v0.2.8) - May 15 2024

- Add support for notifications via [Nfty](https://frigate-notify.0x2142.com/latest/config/file/#nfty)
- Add support for notifications via [Ntfy](https://frigate-notify.0x2142.com/latest/config/file/#ntfy)
- Add ability to send additional HTTP [headers](https://frigate-notify.0x2142.com/latest/config/file/#frigate) to Frigate
- Add new `public_url` config item for Frigate
- This will be used in notification links & should be configured if Frigate is accessible via the internet
Expand Down
27 changes: 21 additions & 6 deletions docs/config/file.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,17 @@ frigate:
- This utilizes Golang's [reference time](https://go.dev/src/time/format.go) for formatting
- See [this](https://www.geeksforgeeks.org/time-formatting-in-golang) guide for help
- Example below uses RFC1123 format
- **nosnap** (Optional - Default: `allow`)
- Specify what to do with events that have no snapshot image
- By default, these events will be sent & notification message will say "No snapshot available"
- Set to `drop` to silently drop these events & not send notifications

```yaml title="Config File Snippet"
alerts:
general:
title: Frigate Alert
timeformat: Mon, 02 Jan 2006 15:04:05 MST
nosnap:
```

### Zones
Expand Down Expand Up @@ -277,6 +282,11 @@ alerts:

### Telegram

!!! note
There is an [issue](https://github.com/0x2142/frigate-notify/issues/54#issuecomment-2148564526) with Telegram alerts if you use URL-embedded credentials for your Frigate links, for example: `https://user:[email protected]`

Telegram appears to incorrectly process these URLs, which will cause the camera & clip links to become unclickable within Telegram.

In order to use Telegram for alerts, a bot token & chat ID are required.

To obtain a bot token, follow [this](https://core.telegram.org/bots#how-do-i-create-a-bot) doc to message @BotFather.
Expand Down Expand Up @@ -366,29 +376,34 @@ alerts:
template:
```

### Nfty
### Ntfy

- **enabled** (Optional - Default: `false`)
- Set to `true` to enable alerting via Nfty
- Set to `true` to enable alerting via Ntfy
- **server** (Required)
- Full URL of the desired Nfty server
- Full URL of the desired Ntfy server
- Required if this alerting method is enabled
- **topic** (Required)
- Destination topic that will receive alert notifications
- Required if this alerting method is enabled
- **ignoressl** (Optional - Default: `false`)
- Set to `true` to allow self-signed certificates
- **headers** (Optional)
- Send additional HTTP headers to Ntfy server
- Header format: `Header: Value`
- Example: `Authorization: Basic abcd1234`
- **template** (Optional)
- Optionally specify a custom notification template
- For more information on template syntax, see [Alert Templates](./templates.md#alert-templates)

```yaml title="Config File Snippet"
alerts:
nfty:
ntfy:
enabled: true
server: https://nfty.your.domain.tld
server: https://ntfy.your.domain.tld
topic: frigate
ignoressl: true
headers:
template:
```

Expand Down Expand Up @@ -432,7 +447,7 @@ alerts:
- For more information on template syntax, see [Alert Templates](./templates.md#alert-templates)
- Note: Webhook templates **must** be valid JSON

``` title="Config File Snippet"
```yaml title="Config File Snippet"
webhook:
enabled: false
server:
Expand Down
11 changes: 6 additions & 5 deletions docs/config/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

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 |
| 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 |
4 changes: 3 additions & 1 deletion docs/config/sample.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ alerts:
general:
title:
timeformat:
nosnap:

zones:
unzoned: allow
Expand Down Expand Up @@ -87,11 +88,12 @@ alerts:
ttl:
template:

nfty:
ntfy:
enabled: false
server:
topic:
ignoressl:
headers:
template:

webhook:
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Currently Frigate only supports notifications through Home Assistant, which I'm
- SMTP
- Telegram
- Pushover
- Nfty
- Ntfy
- Generic Webhook

**Other**
Expand Down
2 changes: 2 additions & 0 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Both methods below will require a [configuration file](config/file.md) to be pro

A Docker image is built with every release. Those images can be found [here](https://github.com/0x2142/frigate-notify/pkgs/container/frigate-notify).

Each image is assigned a version tag upon release. Using the `latest` tag is recommended & will ensure you pull down the most recent version of the app. If needed, prior releases can be used by specifying the individual release tag, like `v0.3.0`. Additionally, there is an image built regularly from the latest development branch, which is tagged as `dev`. While the `dev` image may contain the latest fixes & features, it is not recommended for most users and may be unstable.

The app can be run as a container with the bundled [docker-compose.yml](https://github.com/0x2142/frigate-notify/blob/main/docker-compose.yml) file:

```yaml
Expand Down
17 changes: 12 additions & 5 deletions example-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ alerts:
# Optionally modify default time format in notifications
# Use Golang's reference time format, or see docs for more info
timeformat:
# Allow notification of events without a snapshot
# Set to `drop` to disallow this
nosnap: allow

zones:
# Allow notifications for events outside a zone
Expand Down Expand Up @@ -151,16 +154,20 @@ alerts:
# Custom notification template, if desired
template:

# Nfty Config
nfty:
# Set to true to enable alerting via nfty
# Ntfy Config
ntfy:
# Set to true to enable alerting via ntfy
enabled: false
# URL of Nfty server
# URL of Ntfy server
server:
# Nfty topic for notifications
# Ntfy topic for notifications
topic:
# Set to true if using SSL & a self-signed certificate
ignoressl:
# List of HTTP headers to send to Ntfy, in format Header: Value
headers:
# Example:
# - Authorization: Basic abcd1234
# Custom notification template, if desired
template:

Expand Down
11 changes: 8 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,36 @@ import (
"github.com/0x2142/frigate-notify/util"
)

var APP_VER = "v0.3.0"
var APP_VER = "v0.3.1"
var debug, debugenv bool
var jsonlog, jsonlogenv bool
var nocolor, nocolorenv bool
var configFile string

func main() {
// Parse flags
flag.StringVar(&configFile, "c", "", "Configuration file location (default \"./config.yml\")")
flag.BoolVar(&debug, "debug", false, "Enable debug logging")
flag.BoolVar(&jsonlog, "jsonlog", false, "Enable JSON logging")
flag.BoolVar(&nocolor, "nocolor", false, "Disable color on console logging")
flag.Parse()

// Set up logging
_, jsonlogenv = os.LookupEnv("FN_JSONLOG")
if jsonlog || jsonlogenv {
zerolog.TimeFieldFormat = "2006/01/02 15:04:05"
zerolog.TimeFieldFormat = "2006/01/02 15:04:05 -0700"
} else {
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: "2006/01/02 15:04:05"})
_, nocolorenv = os.LookupEnv("FN_NOCOLOR")
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: "2006/01/02 15:04:05 -0700", NoColor: nocolorenv || nocolor})
}
zerolog.SetGlobalLevel(zerolog.InfoLevel)

// Enable debug logging if set
_, debugenv = os.LookupEnv("FN_DEBUG")
if debug || debugenv {
zerolog.SetGlobalLevel(zerolog.DebugLevel)
// Add calling module to debug logs
log.Logger = log.With().Caller().Logger()
log.Debug().Msg("Debug logging enabled")
}

Expand Down
11 changes: 6 additions & 5 deletions models/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ type Event struct {

// Additional custom fields
type ExtraFields struct {
FormattedTime string
TopScorePercent string
ZoneList string
LocalURL string
PublicURL string
FormattedTime string
TopScorePercent string
ZoneList string
LocalURL string
PublicURL string
FrigateMajorVersion int
}
Loading

0 comments on commit d363ece

Please sign in to comment.