App::PerlWatcher::Engine - Creates Watchers and lets them notify Frontend with their's Statuses
version 0.16
# define own frontend in separate package package My::FrontEnd; use Moo; with 'App::PerlWatcher::Frontend'; sub update { my ( $self, $status ) = @_; say $status->level; } # define engine config with reqired watchers $config = { watchers => [ { class => 'App::PerlWatcher::Watcher::Ping', config => { host => 'google.com', port => 80, frequency => 10, timeout => 1, on => { fail => { 3 => 'info', 5 => 'warn', 8 => 'alert', } ok => { 1 => 'notice'}, }, }, }, { class => 'App::PerlWatcher::Watcher::GenericExecutor', config => { command => "/bin/ls", arguments => ["-1a", "/tmp/"], frequency => 60, timeout => 5, # filtering "." and ".." files filter => sub { ($_ !~ /^\.{1,2}$/) && (/\S+/) }, rules => [ warn => sub { any { /strange_file.txt/ } @_ }, ], } }, ], }; # initialization: bring all pieces together my $frontend = My::FrontEnd->new(engine => $engine); my $backend = My::BackEnd->new; $engine = Engine->new(config => $config, backend => $backend) $engine->frontend( $app ); $engine->start; # now if google is down, it says ping status with interpetation # notice # notice # notice # info # info # warn # ... # or you'll get warn if strange_file.txt suddendly appears # in /tmp
The more detailed description of PerlWatcher application can be found here: https://github.com/basiliscos/perl-watcher.
Required config, which defines watchers behaviour. See engine.conf.example
AnyEvent supported backed (loop engine), generally defined by using frontend, i.e. for Gtk2-frontend it should call Gtk2->main
Defines, where the Engine state is to be serialized. Default value: $HOME/.perl-watcher/statuses-shelf.data
An array_ref of Watcher instances. Watchers order is the same as it was defined in config
Return an map "watcher to watcher order".
Defines statuses shelf, where remembered watcher statuses are stored. It is needed because, where could be statuses, to which user does not payed attention, and they should not be stored.
Starts all watchers and backend.
Stops backend, all watchers and persists current state (watchers memories and shelf)
Helper method which sorts statuses in accordance with theirs watchers order
Ivan Baidakou <dmol@gmx.com>
This software is copyright (c) 2013 by Ivan Baidakou.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install App::PerlWatcher::Engine, copy and paste the appropriate command in to your terminal.
cpanm
cpanm App::PerlWatcher::Engine
CPAN shell
perl -MCPAN -e shell install App::PerlWatcher::Engine
For more information on module installation, please visit the detailed CPAN module installation guide.