mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-30 01:04:12 +02:00
parent
8ce4cf49c0
commit
72fbe80e7b
@ -3,58 +3,91 @@
|
|||||||
use Icinga\Util\Format;
|
use Icinga\Util\Format;
|
||||||
|
|
||||||
$view = $this;
|
$view = $this;
|
||||||
$logLink = function ($match) use ($view) {
|
$logLink = function ($match, $severity) use ($view) {
|
||||||
|
$stageDir = $match[1];
|
||||||
|
$filename = $match[2];
|
||||||
|
$suffix = $match[3];
|
||||||
|
if (preg_match('/(\d+).*/', $suffix, $m)) {
|
||||||
|
$lineNumber = $m[1];
|
||||||
|
} else {
|
||||||
|
$lineNumber = null;
|
||||||
|
}
|
||||||
|
|
||||||
$params = array(
|
$params = array(
|
||||||
'config_checksum' => $view->config_checksum,
|
'config_checksum' => $view->config_checksum,
|
||||||
'file_path' => $match[4],
|
'file_path' => $filename,
|
||||||
'deployment_id' => $view->deployment->id,
|
'deployment_id' => $view->deployment->id,
|
||||||
'fileOnly' => true,
|
'fileOnly' => true,
|
||||||
);
|
);
|
||||||
if (isset($match[5])) {
|
if ($lineNumber !== null) {
|
||||||
$params['highlight'] = $match[5];
|
$params['highlight'] = $lineNumber;
|
||||||
$params['highlightSeverity'] = $match[1];
|
$params['highlightSeverity'] = $severity;
|
||||||
$suffix = ': ' . $match[5];
|
|
||||||
} else {
|
|
||||||
$suffix = '';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return sprintf(
|
return $view->qlink(
|
||||||
'>%s%s',
|
'[stage]/' . $filename,
|
||||||
$match[1] . $match[2],
|
'director/config/file',
|
||||||
$view->qlink(
|
$params,
|
||||||
$match[3] . $match[4],
|
array(
|
||||||
'director/config/file',
|
'data-base-target' => '_next',
|
||||||
$params,
|
'title' => $stageDir . $filename
|
||||||
array('data-base-target' => '_next')
|
|
||||||
)
|
)
|
||||||
) . $suffix;
|
) . $suffix;
|
||||||
};
|
};
|
||||||
|
|
||||||
function colorize($log, $logLink) {
|
function colorize($log, $logLink) {
|
||||||
$log = preg_replace(
|
|
||||||
'/^(debug|notice|information|warning|critical)\/(\w+)/m',
|
|
||||||
'<span class="loglevel \1">\1</span>/<span class="application">\2</span>',
|
|
||||||
$log
|
|
||||||
);
|
|
||||||
|
|
||||||
$log = preg_replace('/([\^]{2,})/', '<span class="error-hint">\1</span>', $log);
|
$lines = array();
|
||||||
|
$severity = 'information';
|
||||||
|
$sevPattern = '/^(debug|notice|information|warning|critical)\/(\w+)/';
|
||||||
|
$filePatternHint = '~(/[\w/]+/api/packages/director/[^/]+/)([^:]+\.conf)(: (\d+))~';
|
||||||
|
$filePatternDetail = '~(/[\w/]+/api/packages/director/[^/]+/)([^:]+\.conf)(\((\d+)\))~';
|
||||||
|
$markPattern = null;
|
||||||
|
// len [stage] + 1
|
||||||
|
$markReplace = ' ^';
|
||||||
|
foreach (preg_split('/\n/', $log) as $line) {
|
||||||
|
if (preg_match($sevPattern, $line, $m)) {
|
||||||
|
$severity = $m[1];
|
||||||
|
$line = preg_replace(
|
||||||
|
$sevPattern,
|
||||||
|
'<span class="loglevel \1">\1</span>/<span class="application">\2</span>',
|
||||||
|
$line
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$log = preg_replace_callback(
|
if ($markPattern !== null) {
|
||||||
'~\>(information)(\<.+ )'
|
$line = preg_replace($markPattern, $markReplace, $line);
|
||||||
. '(/.+?/api/packages/director/[^/]+/)([^:]+\.conf)$~m',
|
}
|
||||||
$logLink,
|
$line = preg_replace('/([\^]{2,})/', '<span class="error-hint">\1</span>', $line);
|
||||||
$log
|
$markPattern = null;
|
||||||
);
|
|
||||||
|
|
||||||
$log = preg_replace_callback(
|
if (preg_match($filePatternHint, $line, $m)) {
|
||||||
'~\>(critical|warning)(\<[^\n]+?\n?[^\n]+?in )'
|
$line = preg_replace_callback(
|
||||||
. '(/.+?/api/packages/director/[^/]+/)([^:]+\.conf): (\d+)~m',
|
$filePatternHint,
|
||||||
$logLink,
|
function ($matches) use ($logLink, $severity) {
|
||||||
$log
|
return $logLink($matches, $severity);
|
||||||
);
|
},
|
||||||
|
$line
|
||||||
|
);
|
||||||
|
$line = preg_replace('/\(in/', "\n (in", $line);
|
||||||
|
$line = preg_replace('/\), new declaration/', "),\n new declaration", $line);
|
||||||
|
} elseif (preg_match($filePatternDetail, $line, $m)) {
|
||||||
|
$markIndent = strlen($m[1]);
|
||||||
|
$markPattern = '/\s{' . $markIndent . '}\^/';
|
||||||
|
|
||||||
return $log;
|
$line = preg_replace_callback(
|
||||||
|
$filePatternDetail,
|
||||||
|
function ($matches) use ($logLink, $severity) {
|
||||||
|
return $logLink($matches, $severity);
|
||||||
|
},
|
||||||
|
$line
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$lines[] .= $line;
|
||||||
|
}
|
||||||
|
return implode("\n", $lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
?><div class="controls">
|
?><div class="controls">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user