watcher

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	Type        EventType `json:"type"`
	Path        string    `json:"path"`
	OldPath     string    `json:"old_path,omitempty"`
	Timestamp   time.Time `json:"timestamp"`
	Checksum    string    `json:"checksum,omitempty"`
	OldChecksum string    `json:"old_checksum,omitempty"`
	Size        int64     `json:"size,omitempty"`
	Error       string    `json:"error,omitempty"`
}

Event represents a file change event

type EventType

type EventType string

EventType defines types of file events

const (
	EventCreated   EventType = "created"
	EventModified  EventType = "modified"
	EventDeleted   EventType = "deleted"
	EventRenamed   EventType = "renamed"
	EventPermError EventType = "perm_error"
)

type Handler

type Handler func(event Event)

Handler is called when an event occurs

type UnauthorizedChangeReporter

type UnauthorizedChangeReporter struct {
	Events    []Event   `json:"events"`
	Timestamp time.Time `json:"timestamp"`
	Severity  string    `json:"severity"`
}

UnauthorizedChangeReporter reports unauthorized changes

func NewUnauthorizedChangeReporter

func NewUnauthorizedChangeReporter(events []Event, severity string) *UnauthorizedChangeReporter

NewUnauthorizedChangeReporter creates a reporter for unauthorized changes

func (*UnauthorizedChangeReporter) Summary

func (r *UnauthorizedChangeReporter) Summary() string

Summary returns a summary of the changes

func (*UnauthorizedChangeReporter) ToJSON

func (r *UnauthorizedChangeReporter) ToJSON() (string, error)

ToJSON converts the report to JSON

type Watcher

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

Watcher monitors file changes for unauthorized modifications

func NewWatcher

func NewWatcher(opts *WatcherOptions) (*Watcher, error)

NewWatcher creates a new file watcher

func (*Watcher) AddHandler

func (w *Watcher) AddHandler(handler Handler)

AddHandler adds an event handler

func (*Watcher) ExportChecksums

func (w *Watcher) ExportChecksums() (string, error)

ExportChecksums exports checksums to JSON

func (*Watcher) ForceChecksum

func (w *Watcher) ForceChecksum(path string, checksum string)

ForceChecksum forces a checksum for a path

func (*Watcher) GetCurrentChecksums

func (w *Watcher) GetCurrentChecksums() map[string]string

GetCurrentChecksums returns a copy of current checksums

func (*Watcher) IgnorePath

func (w *Watcher) IgnorePath(path string)

IgnorePath adds a path to ignore

func (*Watcher) ImportChecksums

func (w *Watcher) ImportChecksums(jsonData string) error

ImportChecksums imports checksums from JSON

func (*Watcher) IsRunning

func (w *Watcher) IsRunning() bool

IsRunning returns whether the watcher is running

func (*Watcher) Scan

func (w *Watcher) Scan() ([]Event, error)

Scan performs a single scan and returns detected changes

func (*Watcher) Start

func (w *Watcher) Start() error

Start starts the watcher

func (*Watcher) Stop

func (w *Watcher) Stop() error

Stop stops the watcher

func (*Watcher) UnignorePath

func (w *Watcher) UnignorePath(path string)

UnignorePath removes a path from ignore list

func (*Watcher) Verify

func (w *Watcher) Verify() (map[string]bool, error)

Verify verifies all files match their checksums

type WatcherOptions

type WatcherOptions struct {
	BasePath    string
	Interval    time.Duration
	IgnorePaths []string
}

WatcherOptions for configuring the watcher

func DefaultWatcherOptions

func DefaultWatcherOptions() *WatcherOptions

DefaultWatcherOptions returns default watcher options

Jump to

Keyboard shortcuts

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