Skip to content

Commit 65a54f2

Browse files
author
Marius Burkard
committed
Merge branch 'journalctl' into 'develop'
Add journalctl support for logs See merge request ispconfig/ispconfig3!1342
2 parents cd59fa5 + 8eb7fe5 commit 65a54f2

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

server/lib/classes/monitor_tools.inc.php

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ public function _getLogData($log, $max_lines = 100) {
503503

504504
$dist = '';
505505
$logfile = '';
506+
$journalmatch = '';
506507

507508
if (@is_file('/etc/debian_version')) {
508509
$dist = 'debian';
@@ -552,7 +553,7 @@ public function _getLogData($log, $max_lines = 100) {
552553
if ($dist == 'debian') {
553554
$logfile = '/var/log/syslog';
554555
} elseif ($dist == 'redhat') {
555-
$logfile = '/var/log/messages';
556+
$journalmatch = ' ';
556557
} elseif ($dist == 'suse') {
557558
$logfile = '/var/log/messages';
558559
} elseif ($dist == 'gentoo') {
@@ -653,27 +654,40 @@ public function _getLogData($log, $max_lines = 100) {
653654
if (stristr($logfile, ';') or substr($logfile, 0, 9) != '/var/log/' or stristr($logfile, '..')) {
654655
$log = 'Logfile path error.';
655656
} else {
656-
$log = '';
657657
if (is_readable($logfile)) {
658-
$fd = popen('tail -n '.intval($max_lines).' ' . escapeshellarg($logfile), 'r');
659-
if ($fd) {
660-
while (!feof($fd)) {
661-
$log .= fgets($fd, 4096);
662-
$n++;
663-
if ($n > 1000)
664-
break;
665-
}
666-
fclose($fd);
667-
}
658+
$log = $this->_getOutputFromExecCommand('tail -n '.intval($max_lines).' ' . escapeshellarg($logfile));
668659
} else {
669660
$log = 'Unable to read ' . $logfile;
670661
}
671662
}
663+
} else {
664+
if($journalmatch != ''){
665+
$log = $this->_getOutputFromExecCommand('journalctl -n '.intval($max_lines).' --no-pager ' . escapeshellcmd($journalmatch));
666+
}else{
667+
$log = 'Unable to read logfile';
668+
}
669+
672670
}
673671

674672
return $log;
675673
}
676674

675+
private function _getOutputFromExecCommand ($command) {
676+
$log = '';
677+
$fd = popen($command, 'r');
678+
if ($fd) {
679+
$n = 0;
680+
while (!feof($fd)) {
681+
$log .= fgets($fd, 4096);
682+
$n++;
683+
if ($n > 1000)
684+
break;
685+
}
686+
fclose($fd);
687+
}
688+
return $log;
689+
}
690+
677691
private function _checkTcp($host, $port) {
678692
/* Try to open a connection */
679693
$fp = @fsockopen($host, $port, $errno, $errstr, 2);

0 commit comments

Comments
 (0)