-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvigilant.php
54 lines (46 loc) · 1.66 KB
/
vigilant.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
use Vigilant\Config;
use Vigilant\Feeds;
use Vigilant\Notify;
use Vigilant\Logger;
use Vigilant\Version;
use Vigilant\Exception\ConfigException;
use Vigilant\Exception\AppException;
require('vendor/autoload.php');
try {
$config = new Config();
$config->validate();
$logger = new Logger(
$config->getTimezone(),
$config->getLoggingLevel()
);
$logger->debug(sprintf('Vigilant v%s', Version::get()));
$feeds = new Feeds($config, $logger);
foreach ($feeds->get() as $feed) {
$notify = new Notify($feed->details, $config, $logger);
if ($feed->details->hasActiveHours() === false || $feed->activeHours->isEnabled() === true) {
if ($feed->check->isDue() === true) {
$feed->check->check();
$notify->send($feed->check->getMessages());
if (
$feed->details->hasActiveHours() === true &&
$feed->check->getNextCheckDate('U') >= $feed->activeHours->getEndTime('U')
) {
$logger->info(sprintf(
'Next check during active hours starting at %s',
$feed->details->getActiveHoursStartTime()
));
} else {
$logger->info(sprintf(
'Next check in %s seconds at %s',
$feed->details->getInterval(),
$feed->check->getNextCheckDate()
));
}
}
}
}
} catch (ConfigException | AppException $err) {
(new Logger(date_default_timezone_get()))->info($err->getMessage());
exit(1);
}