alerts

package
v0.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 23, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package alerts decides when to notify the user that their network usage has crossed a configured threshold (a daily total cap, or a per-app daily cap). It is pure logic — posting the actual macOS notification is the caller's job — and it de-duplicates so each threshold fires at most once per calendar day.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigPath

func ConfigPath() string

ConfigPath returns the on-disk path for the alert config, or "" if it can't be determined (~/Library/Application Support/netscope/alerts.json on macOS).

func Save

func Save(path string, cfg Config) error

Save writes the config to path, creating the parent directory if needed.

Types

type Alert

type Alert struct {
	Title string
	Body  string
}

Alert is a single notification to post.

type Checker

type Checker struct {
	// contains filtered or unexported fields
}

Checker evaluates thresholds against today's totals and remembers what it has already fired today so it doesn't repeat. Safe for concurrent use.

func New

func New(cfg Config) *Checker

New returns a Checker with the given initial config.

func (*Checker) Check

func (c *Checker) Check(day string, totalBytes int64, perApp map[string]int64) []Alert

Check evaluates the thresholds for the given day (e.g. "2026-06-19") against today's total bytes and per-app bytes, returning any alerts to post now. Each threshold fires at most once per day; the day rolling over resets that.

func (*Checker) CheckUpload added in v0.5.0

func (c *Checker) CheckUpload(day string, totalUpload int64, perAppUpload map[string]int64) []Alert

CheckUpload evaluates the upload-watch thresholds (privacy) for the day against today's total upload and per-app upload bytes. Like Check, each threshold fires at most once per day. Shares the day/fired state with Check.

func (*Checker) Config

func (c *Checker) Config() Config

Config returns the current thresholds.

func (*Checker) SetConfig

func (c *Checker) SetConfig(cfg Config)

SetConfig replaces the thresholds and clears the per-day fired state, so new thresholds are evaluated cleanly against the current totals.

type Config

type Config struct {
	DailyTotalBytes int64 `json:"dailyTotalBytes"` // alert when today's total crosses this
	PerAppBytes     int64 `json:"perAppBytes"`     // alert when any one app crosses this today
	// Upload watch (privacy): uploads are data leaving your machine — surprise
	// backups, cloud sync, exfiltration. Zero disables.
	DailyUploadBytes  int64 `json:"dailyUploadBytes"`  // alert when today's total upload crosses this
	PerAppUploadBytes int64 `json:"perAppUploadBytes"` // alert when any one app's upload crosses this today
}

Config holds the user's alert thresholds, in bytes. A zero value disables that threshold.

func Load

func Load(path string) Config

Load reads the config from path; a missing or unreadable file yields a zero (all-disabled) Config rather than an error.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL