From f2133e98aa5457f99e4ab7e8f8ac48b9720fb777 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 22 Aug 2016 12:11:27 +0200 Subject: Modularize cron api Modules now can have a ./hooks/cron.inc.php to run every X minutes, according to how you set up the cron job for the global /inc/cron.inc.php --- modules-available/eventlog/hooks/cron.inc.php | 5 +++++ modules-available/statistics/hooks/cron.inc.php | 18 ++++++++++++++++++ modules-available/syslog/hooks/cron.inc.php | 5 +++++ 3 files changed, 28 insertions(+) create mode 100644 modules-available/eventlog/hooks/cron.inc.php create mode 100644 modules-available/statistics/hooks/cron.inc.php create mode 100644 modules-available/syslog/hooks/cron.inc.php (limited to 'modules-available') diff --git a/modules-available/eventlog/hooks/cron.inc.php b/modules-available/eventlog/hooks/cron.inc.php new file mode 100644 index 00000000..027acf87 --- /dev/null +++ b/modules-available/eventlog/hooks/cron.inc.php @@ -0,0 +1,5 @@ + 86400 * 190"); +} \ No newline at end of file diff --git a/modules-available/statistics/hooks/cron.inc.php b/modules-available/statistics/hooks/cron.inc.php new file mode 100644 index 00000000..94c65248 --- /dev/null +++ b/modules-available/statistics/hooks/cron.inc.php @@ -0,0 +1,18 @@ + 86400 * 190"); +Database::exec("DELETE FROM machine WHERE (UNIX_TIMESTAMP() - lastseen) > 86400 * 365"); + +function logstats() { + $NOW = time(); + $cutoff = $NOW - 86400 * 30; + $online = $NOW - 610; + $known = Database::queryFirst("SELECT Count(*) AS val FROM machine WHERE lastseen > $cutoff"); + $on = Database::queryFirst("SELECT Count(*) AS val FROM machine WHERE lastseen > $online"); + $used = Database::queryFirst("SELECT Count(*) AS val FROM machine WHERE lastseen > $online AND logintime <> 0"); + Database::exec("INSERT INTO statistic (dateline, typeid, clientip, username, data) VALUES (:now, '~stats', '', '', :vals)", array( + 'now' => $NOW, + 'vals' => $known['val'] . '#' . $on['val'] . '#' . $used['val'], + )); +} +logstats(); diff --git a/modules-available/syslog/hooks/cron.inc.php b/modules-available/syslog/hooks/cron.inc.php new file mode 100644 index 00000000..c796675f --- /dev/null +++ b/modules-available/syslog/hooks/cron.inc.php @@ -0,0 +1,5 @@ + 86400 * 190"); +} \ No newline at end of file -- cgit v1.2.3-55-g7522