fofiwano

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2016 License: MIT Imports: 13 Imported by: 0

README

Watcher and Notifications for File and Folder changes

A small CLI tool that watches folders or files for modifications like added, changed or deleted files. It then sends a notification to a specific endpoint, e.g. a Slack channel, an URL (HTTP request) or execute a command.

It makes use of the github.com/rjeczalik/notify Go library to provide cross-platform filesystem notifications.

Fofiwano is available as pre-built binaries for macOS, Linux, FreeBSD and Windows on the release page.

Create a config file .fofiwano.yml in the current directory or in your $HOME with content like this (see example):

watching:
  # recursive watching ./test
  - target: ./test/...
    notifications:
      - notify: slack
        event: all
        options:
          channel: "#test"
          username: "fofiwano"
          webhook_url: "https://hooks.slack.com/services/..."
          icon_emoji: ":monkey_face:"
          footer: "fofiwano"
      - notify: http
        event: write
        options:
          URL: http://my.endpoint.com

  # only watching ./test2 and NO sub-folders
  - target: ./test2
    notifications:
      - notify: http
        event: write
        options:
          URL: http://test.com

  • target can be a single file or a folder. Add /... to a folder to create a recursive watcher that also reacts to modifications in sub-folders.`
  • notifications is an array of notification providers with their options. Right now only Slack and HTTP (GET) notifications are available! (more to come).
  • event can be one of all, write, create, remove or rename

Hint: You don't have to stick with YAML if you don't like it. You can write your config in every format that Viper supports (JSON, TOML, YAML, HCL, and Java properties config files).

Start your watcher like so:

fofiwano watch

You can also provide the path to your config file with the --config flag:

fofiwano --config ~/.fofiwano.yml watch

Get help about all available flags and commands:

fofiwano --help

Slack Notification

Available options:

          channel: "#test"
          username: "fofiwano"
          webhook_url: "https://hooks.slack.com/services/..."
          icon_emoji: ":monkey_face:"
          footer: "fofiwano"

HTTP Notification

Available options:

          URL: "http://my.endpoint.com"
          method: "GET" # currently only GET
          param_event: "event" # parameter name for event
          param_path: "param" # parameter name for path

Currently only GET is supported. The given URL will be called with the given paramter names like so: http://my.endpoint.com?event=notify.rename&path=/home/myname/files/test.txt

TODO:

  • add more notification providers (command execution)
  • add templates for fine grained control over notification messages
  • add queue for notification events to prevent locks
  • add tests

Similar tools

Tools with similar functionality:

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Watch

func Watch(watches []Watcher)

Watch starts the watcher with the given configuration

Types

type HTTP added in v0.2.0

type HTTP struct {
	URL        string `mapstructure:"url"`
	Method     string `mapstructure:"method"`
	ParamEvent string `mapstructure:"param_event"`
	ParamPath  string `mapstructure:"param_path"`
}

func NewHTTPNotification added in v0.2.0

func NewHTTPNotification(options interface{}) (*HTTP, error)

func (*HTTP) Notify added in v0.2.0

func (notifier *HTTP) Notify(event string, path string) error

NotifyHTTP sends a file change notification to HTTP endpoint

type Notifcation added in v0.2.0

type Notifcation interface {
	Notify(event string, path string) error
}

type Slack added in v0.2.0

type Slack struct {
	slackstatus.Message
}

func NewSlackNotification added in v0.2.0

func NewSlackNotification(options interface{}) (*Slack, error)

func (*Slack) Notify added in v0.2.0

func (slacknotifier *Slack) Notify(event string, path string) error

Slack.Notify sends a file change notification to Slack

type Watcher

type Watcher struct {
	Target        string
	Notifications []WatcherNotify
}

Watcher defines a watcher configuration Target can be a folder or a file, add /... to a folder for recursive watching e.g. ./test/...

type WatcherNotify

type WatcherNotify struct {
	Notify   string
	Event    string
	Options  map[string]string
	Notifier Notifcation
}

WatcherNotify defines a notification type for a watcher

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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