🚀 DAY 2 OF LAUNCH WEEK: Unify Your Security Stack with Socket Basics.Learn more →
Socket
Book a DemoInstallSign in
Socket

github.com/ichenhe/syncthing-hook

Package Overview
Dependencies
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/ichenhe/syncthing-hook

Source
Go
Version
v0.2.0
Version published
Created
Source

Syncthing Hook

Release Go Report Card Build State

Do you want to notify your programs to reload when a file is updated? Maybe also need to limit the trigger frequency? That is what SyncthingHook does.

This project adds hook function to Syncthing (open source file synchronization program), but works as a standalone program. The basic principle is to constantly request the Syncthing API to get the latest events and perform specified actions. So SynchingHook is compatible with Syncthing on any platform, and can even listen to remote service.

Features:

  • Single executable file, which is very easy to deploy.
  • Supports many kinds of event, including Syncthing native event and extra event.
  • Supports multiple filters depending on the kind of event.

Quick Start

  • Download the executable file from the release page.
  • Copy the example config file and write your version.
  • Run it with profile: ./SyncthingHook --profile /path/to/config.yaml

Configuration

Profile

SyncthingHook relies on configuration file (profile), which specifies events of interest and corresponding actions. You must specify the path of profile by one of the following ways (highest to lowest priority):

  • Command line argument: --profile /path/to/profile
  • Environment variable: STHOOK_PROFILE=/path/to/profile

Please refer to config/config.example.sthook.yaml for the format of profile. The detailed specification is also given through conofig/sthook.schema.json (json-schema).

Other Configuration Methods

Priority

The priority of different configuration methods from high to low is as follows:

  • Command line arguments
  • Environment variables
  • Profile

The value of the high-priority configuration method will override the configuration elsewhere, even if its value is empty "".

Supported Configuration Items

⚠️ Warning: do not configure other items expect those listed below by command line arguments or environment as it may lead to undefined behavior and fail at any time!

Some items in profile can be configured by command line arguments or environment variables. The following table lists all of them:

Config ItemCommand Line ArgumentEnvironment Variable
syncthing.url--syncthing.urlSTHOOK_SYNCTHING_URL
syncthing.apikey--syncthing.apikeySTHOOK_SYNCTHING_APIKEY

For example:

./sthook --syncthing.url http://localhost:8384 --syncthing.apikey aaabbbccc

Events

EventDescription
st:ConfigSavedSyncthing doc
st:DeviceConnectedSyncthing doc
st:DeviceDisconnectedSyncthing doc
st:DeviceDiscoveredSyncthing doc
st:DevicePausedSyncthing doc
st:DeviceResumedSyncthing doc
st:DownloadProgressSyncthing doc
st:FailureSyncthing doc
st:FolderCompletionSyncthing doc
st:FolderErrorsSyncthing doc
st:FolderPausedSyncthing doc
st:FolderResumedSyncthing doc
st:FolderScanProgressSyncthing doc
st:FolderSummarySyncthing doc
st:FolderWatchStateChangedSyncthing doc
st:ItemFinishedSyncthing doc
st:ItemStartedSyncthing doc
st:ListenAddressesChangedSyncthing doc
st:LocalChangeDetectedSyncthing doc
st:LocalIndexUpdatedSyncthing doc
st:LoginAttemptSyncthing doc
st:PendingDevicesChangedSyncthing doc
st:PendingFoldersChangedSyncthing doc
st:RemoteChangeDetectedSyncthing doc
st:RemoteDownloadProgressSyncthing doc
st:RemoteIndexUpdatedSyncthing doc
st:StartingSyncthing doc
st:StartupCompleteSyncthing doc
st:StateChangedSyncthing doc
ex:LocalFolderContentChangeDetectedBased on st:LocalChangeDetected, with file path matcher.

Common Parameters

Unless otherwise noted, the following parameters apply to all events:

NameTypeDefaultDescription
toleranceint640How long to wait before triggering this event (ms). Typically used to get only the latest event. 0 means no waiting.
cooldownint640The maximum frequency in millisecond that this event can be triggered. 0 indicates no limitation.

Example:

hooks:
  - event-type: "st:FolderCompletion"
    parameter:
      tolerance: 500
      cooldown: 3000

ex:LocalFolderContentChangeDetected

This event based on st:LocalChangeDetected. It will be triggered only when the folder id equals the given one and the file belongs to the given path (equal or subdirectory). Path pattern / matches all events.

Parameters:

NameTypeDefaultDescription
st-folderstringFolder-id in Syncthing. Cannot be omitted.
pathstring/Path to the target directory, must start with /.

Actions

The only action type currently supported is exec. However, since it can run any command, you may do whatever you want (e.g. run a python script).

Example:

action:
  type: "exec"
  cmd: [ "python", "do.py" ]
  # cmd: [ "python do.py" ] BAD!

Please note:

  • The first element of cmd must be the program, which means you can't put parameters in it.
  • SyncthingHook won't wait for the command to return. So it may execute the command (triggered by next event) while the previous one is still running.

FAQs

Package last updated on 31 Oct 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts