Watcher for watches the changes in the file system.
Watcher is an open source system to automate the detection of changes in the system, facilitating the integration of processes, workflows and the development of monitoring applications.
Detecting changes to the file system or data structures in memory is useful for developers of security applications, resource monitoring or process integration.
Watcher runs on Tarantool. Before you begin, ensure you have met the following requirements:
There are several ways to install watcher on your server. Choose the option that suits you best and ... go ahead! :blush:
docker pull racherb/watcher:latest
docker run -i -t racherb/watcher
If you want to look at the host or remote machine's file system then start a container with a volume.
The following example enables a volume on the temporary folder /tmp of the host at path /opt/watcher/host/ of the container.
docker run -i -t -v /tmp/:/opt/watcher/host/tmp racherb/watcher
:sparkles: https://hub.docker.com/r/racherb/watcher
Install the repository and package:
curl -s https://packagecloud.io/install/repositories/iamio/watcher/script.deb.sh | sudo bash
sudo apt-get install watcher=0.2.1-1
Available for the following distributions:
Available for the following distributions:
First install the repository:
curl -s https://packagecloud.io/install/repositories/iamio/watcher/script.rpm.sh | sudo bash
Install the package:
sudo yum install watcher-0.2.1-1.noarchsudo zypper install watcher-0.2.1-1.noarchInstall watcher through Tarantool's tarantoolctl command:
tarantoolctl rocks install https://raw.githubusercontent.com/racherb/watcher/master/watcher-scm-1.rockspec
Make sure you have Luarocks installed first, if you need to install it follow the instructions in the following link: luarocks/wiki
From the terminal run the following command:
luarocks install https://raw.githubusercontent.com/racherb/watcher/master/watcher-scm-1.rockspec
The execution of the tests will take between 2 and 10 minutes approximately. This time is required in the simulation of file generation, modification and deletion.
./test/watcher.test.lua
Create a watcher to detect file deletion:
tarantool> fw = require('watcher').file
tarantool> fw.deletion({'/path/to/file'})
Create a watcher to detect file creation:
tarantool> fw = require('watcher').file
tarantool> fw.creation({'/path/to/file'})
Create a watcher to detect file alteration:
tarantool> fw = require('watcher').file
tarantool> fw.alteration({'/path/to/file'})
Watcher for all files with extension txt in the temporary folder /tmp. But (there is always a but) you only want to detect the deletion of the first 2 of those 5 files that were recently modified.
Note: The /tmp directory may contain hundreds of files with .txt extension.
tarantool> fw = require('watcher').file
tarantool> pattern = {'/tmp/*.txt'}
tarantool> MAXWAIT = 120 --Maximum waiting time for the file [seconds}
tarantool> INTERVAL = 1 --File check frequency [seconds]
tarantool> ORDBY = 'MA' --Sorted in ascending order by date of modification
tarantool> ITEMS = 5 --Observe the first 5 cases in the ordered list
tarantool> MATCH = 2 --Detects the first 2 files to be deleted
tarantool> fw.deletion(pattern, MAXWAIT, INTERVAL, {ORDBY, ITEMS, MATCH})
Use monit to know the result of the watcher execution.
The following case is a file watcher for the detection of the creation of two files ('/tmp/fileA' and '/tmp/fileB'). One of them exists and the other has not been created yet.
The use of monit allows you to know the status of the watcher.
tarantool> fw = require('watcher').file
tarantool> mon = require('watcher').monit
tarantool> os.execute('touch /tmp/fileA') --Create fileA for demo
tarantool> fw.creation({'/tmp/fileA', '/tmp/fileB'}) --Create file watcher for fileA and fileB
---
- wid: 1618857178550065
fid: 123
...
tarantool> mon.info(1618857178550065) --wid as param for monitoring result
---
- ans: waiting --'waiting' means that it has not yet been completed
match: 1 --A file has been found
what: '{"/tmp/fileA","/tmp/fileB"}' --List of observable objects on request
wid: 1618857178550065 --The watcher id
type: FWC --Type of watcher, 'FWC' for file watcher creation
nomatch: 1 --A file was not found
status: started --File watcher started
...
Once the watcher has finished we can know the final status. For example, for the same watcher id (wid) we get:
tarantool> mon.info(1618857178550065)
---
- ans: false --The watcher has finished but the conditions were not met
match: 1
what: '{"/tmp/fileA","/tmp/fileB"}'
wid: 1618857178550065
type: FWC
nomatch: 1
status: completed
...
To know the cases that satisfy the watcher criteria use the function 'match' and for those that do not, use the function 'nomatch'.
tarantool> mon.match(1618857178550065)
---
- - [1618857178550065, '/tmp/fileA', 1618857178550662653, true, 'C', 1618857178651989852]
...
tarantool> mon.nomatch(1618857178550065)
---
- - [1618857178550065, '/tmp/fileB', 1618857178551146982, false, '_', 0]
...
This is a simple example of automatic processing of a file once the file is created in a given path. This particular case works in blocking mode using "waitfor" function.
#!/usr/bin/env tarantool
local filewatcher = require('watcher').file
local waitfor = require('watcher').waitfor
--Function that processes a file after it arrives
local function process_file(the_file)
print('Waiting for the file ...')
local res = waitfor(
filewatcher.creation(the_file).wid
)
if res.ans then
print('Orale! The file ' .. the_file[1] .. ' is ready')
--Write your code here!
--...
--...
else
print("'D'OH.! The file has not arrived")
end
end
process_file({'/tmp/abc.x'})
os.exit()
By default watcher runs in non-blocking mode through tarantool fibers.
:soon: Comming soon
There are many ways to contribute to Watcher:
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
For style guide in Lua coding follow the suggestions at Lua Style Guide.
Support is required for the construction of connectors that allow the use of watcher from different programming languages, for example:
Plugins allow you to extend watcher applications. If you want to write your own plugins based on watcher, follow the steps below:
...
We use SemVer for versioning. For the versions available, see the tags on this repository.
We’re using Discussions as a place to connect with other members of our community. We hope that you:
Raciel Hernández
See also the list of contributors who participated in this project.
This project is licensed under the MIT License - see the LICENSE file for details
Content type
Image
Digest
Size
87.4 MB
Last updated
over 5 years ago
docker pull racherb/watcher