https://github.com/foiovituh/hash-watcher
Monitors, detects, and notifies changes in files (using SHA-256) đ
https://github.com/foiovituh/hash-watcher
file-change-detection file-changes file-monitoring go hash hash-watcher io sha256 slack slack-channels slack-notifications
Last synced: about 1 month ago
JSON representation
Monitors, detects, and notifies changes in files (using SHA-256) đ
- Host: GitHub
- URL: https://github.com/foiovituh/hash-watcher
- Owner: foiovituh
- License: mit
- Created: 2024-07-08T23:39:57.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-10T00:54:15.000Z (almost 2 years ago)
- Last Synced: 2025-02-05T22:36:46.530Z (over 1 year ago)
- Topics: file-change-detection, file-changes, file-monitoring, go, hash, hash-watcher, io, sha256, slack, slack-channels, slack-notifications
- Language: Go
- Homepage:
- Size: 54.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
# HashWatcher đ


Monitors, detects, and notifies changes in files (using SHA-256)
Scenarios where HashWatcher can be useful:
- Security Monitoring: Detect unauthorized changes to critical system or configuration files.
- Configuration Management: Track changes in configuration files to ensure they are intentional and documented.
- Software Development: Monitor source code or project files for unexpected modifications
## Summary đ
- [HashWatcher đ](#hashwatcher-)
- [Summary đ](#summary-)
- [How does it work? đĄ](#how-does-it-work-)
- [Requirements đ](#requirements-)
- [Quick usage guide đ](#quick-usage-guide-)
- [Build:](#build)
- [Configuring targets:](#configuring-targets)
- [Usage example:](#usage-example)
- [Slack app đŦ](#slack-app-)
- [Main steps:](#main-steps)
- [Future plans đ](#future-plans-)
- [Do you want help me? đĨ](#do-you-want-help-me-)
- [License đŗī¸](#license-ī¸)
## How does it work? đĄ
SHA-256 is a hash function that works like a fingerprint for files. It converts any text into a 256-bit code. So if anything in the file changes, even a single character, the hash generated will be different. This is very useful (among other things) for checking whether a file has been modified by comparing the current hash with a previous one.
## Requirements đ
Supported OS:
- Linux
- Windows
- macOS (nÊe OS X, aka Darwin)
- OpenBSD
- DragonFly BSD
- FreeBSD
- NetBSD
- Solaris
To build:
- Go compiler
## Quick usage guide đ
#### Build:
```
go build -o hash-watcher cmd/main.go
```
> NOTE: Generate in the root directory of the project
---
#### Configuring targets:
Currently, you must create a JSON configuration file for each directory you wish to monitor. Put the file in a non-intrusive directory and name it as you wish. The JSON must follow the structure below:
```json
{
"directoryPath": "/full/path/to/directory/",
"fileNames": [],
"checkFrequencyInSeconds": 60
}
```
If you prefer not to monitor all files, you can filter specific files to include in the monitoring process:
```json
"fileNames": [
"file-1.txt",
"file-2.txt"
],
```
Optionally, you can also send notifications to Slack channels using an app. Endpoint refers to the identifier of the channel where the app is located. Token refers to the "Bot User OAuth Token" for your Workspace. To achieve this, configure the JSON as follows:
```json
{
"directoryPath": "/full/path/to/directory/",
"fileNames": [
"file-1.txt",
"file-2.txt"
],
"checkFrequencyInSeconds": 60,
"notification": {
"endpoint": "CXXXXXXXXXX",
"token": "xoxb-11111111111-2222222222222-abcdefghijklmnopqrstuvwx"
}
}
```
---
#### Usage example:
```
./hash-watcher /full/path/to/configuration/file/settings.json
```
The `file-1.txt` was initially empty. Upon adding the letter 'X', the change was detected (after 60 seconds), and the hash comparison triggered a notification:
```
2024/07/09 11:44:43 => Watching...
2024/07/09 11:45:43 => file-1.txt was modified!
- Before: e6de32585e70330a8de848b7b7859911e1e108e00dd6527391533853dd7c9409
- Now: ea6fcfe57703205da4d1b74ec99a8c67f721b2ab2e9c31d2222da066606d5d44
```
## Slack app đŦ
Quick guide to create an app using a manifest. For more information, see https://api.slack.com/reference/manifests
#### Main steps:
1- Go to https://api.slack.com/apps, and click on "Create New App".
2- Select "From an app manifest":

3- Choose a workspace:

4- Copy the YAML from `hash-watcher/doc/slack/slack_app_manifest.yml` and paste it in:

5- Check that the settings are correct and proceed:

6- Once the app has been created, go to `Settings -> Basic Information` and set up an icon (e.g. the official one in `hash-watcher/doc/slack/logo.png`):

7- Go to `Features -> OAuth & Permissions -> OAuth Tokens for Your Workspace` and copy the token generated when creating:

8- Finally, choose or create a new channel and add the HashWatcher app to the channel: `Channel details -> Integrations -> Add apps`
## Future plans đ
- Check sub-directories
- Create customized schedules
- Write unit and functional tests
## Do you want help me? đĨ
If you have any ideas or wish to contribute to the project, contact me on X (@ohtoaki) or send me a pull request :)
## License đ
Distributed under the MIT License. See [`LICENSE`](LICENSE) for more information.