Skip to content

Commit 5489333

Browse files
committed
Add journalctl support for log_messages
1 parent 333d13a commit 5489333

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

server/lib/classes/monitor_tools.inc.php

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ public function _getLogData($log) {
493493

494494
$dist = '';
495495
$logfile = '';
496+
$journalmatch = '';
496497

497498
if (@is_file('/etc/debian_version')) {
498499
$dist = 'debian';
@@ -542,7 +543,7 @@ public function _getLogData($log) {
542543
if ($dist == 'debian') {
543544
$logfile = '/var/log/syslog';
544545
} elseif ($dist == 'redhat') {
545-
$logfile = '/var/log/messages';
546+
$journalmatch = ' ';
546547
} elseif ($dist == 'suse') {
547548
$logfile = '/var/log/messages';
548549
} elseif ($dist == 'gentoo') {
@@ -643,27 +644,41 @@ public function _getLogData($log) {
643644
if (stristr($logfile, ';') or substr($logfile, 0, 9) != '/var/log/' or stristr($logfile, '..')) {
644645
$log = 'Logfile path error.';
645646
} else {
646-
$log = '';
647647
if (is_readable($logfile)) {
648-
$fd = popen('tail -n 100 ' . escapeshellarg($logfile), 'r');
649-
if ($fd) {
650-
while (!feof($fd)) {
651-
$log .= fgets($fd, 4096);
652-
$n++;
653-
if ($n > 1000)
654-
break;
655-
}
656-
fclose($fd);
657-
}
648+
$log = $this->_getOutputFromExecCommand('tail -n 100 ' . escapeshellarg($logfile));
658649
} else {
659650
$log = 'Unable to read ' . $logfile;
660651
}
661652
}
653+
}else{
654+
if($journalmatch != ''){
655+
$log = $this->_getOutputFromExecCommand('journalctl -n 100 --no-pager ' . escapeshellcmd($journalmatch));
656+
}else{
657+
$log = 'Unable to read ' . $logfile;
658+
}
659+
662660
}
663661

664662
return $log;
665663
}
666664

665+
private function _getOutputFromExecCommand ($command) {
666+
$log = '';
667+
echo $command;
668+
$fd = popen($command, 'r');
669+
if ($fd) {
670+
$n = 0;
671+
while (!feof($fd)) {
672+
$log .= fgets($fd, 4096);
673+
$n++;
674+
if ($n > 1000)
675+
break;
676+
}
677+
fclose($fd);
678+
}
679+
return $log;
680+
}
681+
667682
private function _checkTcp($host, $port) {
668683
/* Try to open a connection */
669684
$fp = @fsockopen($host, $port, $errno, $errstr, 2);

0 commit comments

Comments
 (0)