summaryrefslogtreecommitdiffstats
path: root/library/Audit/ProvidedHook/AuditStream.php
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:41:27 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:41:27 +0000
commitadc6ca9ee76d4b765c0e892fd452bc7e7ff28f4c (patch)
tree48747500fe157b459d74fac87e7114e6c846d215 /library/Audit/ProvidedHook/AuditStream.php
parentInitial commit. (diff)
downloadicingaweb2-module-audit-upstream.tar.xz
icingaweb2-module-audit-upstream.zip
Adding upstream version 1.0.2.upstream/1.0.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/Audit/ProvidedHook/AuditStream.php')
-rw-r--r--library/Audit/ProvidedHook/AuditStream.php38
1 files changed, 38 insertions, 0 deletions
diff --git a/library/Audit/ProvidedHook/AuditStream.php b/library/Audit/ProvidedHook/AuditStream.php
new file mode 100644
index 0000000..b47968d
--- /dev/null
+++ b/library/Audit/ProvidedHook/AuditStream.php
@@ -0,0 +1,38 @@
+<?php
+
+/* Icinga Web 2 | (c) 2018 Icinga Development Team | GPLv2+ */
+
+namespace Icinga\Module\Audit\ProvidedHook;
+
+use InvalidArgumentException;
+use Icinga\Application\Config;
+use Icinga\Application\Hook\AuditHook;
+use Icinga\Util\File;
+
+class AuditStream extends AuditHook
+{
+ public function logMessage($time, $identity, $type, $message, array $data = null)
+ {
+ $activityData = [
+ 'activity_time' => $time,
+ 'activity' => $type,
+ 'message' => $message,
+ 'identity' => $identity
+ ];
+ if (! empty($data)) {
+ $activityData['data'] = $data;
+ }
+
+ $logConfig = Config::module('audit')->getSection('stream');
+ if ($logConfig->format === 'json') {
+ $json = json_encode($activityData, JSON_FORCE_OBJECT);
+ if ($json === false) {
+ throw new InvalidArgumentException('Failed to encode message data to JSON: ' . json_last_error_msg());
+ }
+
+ $file = new File($logConfig->get('path', '/var/log/icingaweb2/audit.json'), 'a');
+ $file->fwrite($json . PHP_EOL);
+ $file->fflush();
+ }
+ }
+}