Skip to content

Commit

Permalink
Version 0.9.2 : Fix two problems
Browse files Browse the repository at this point in the history
 * the log files are not analyzed (problems with variables in log functions
 * I have forgotten to include the JS function for the view/hide functionnality
  • Loading branch information
earendilfr committed Mar 24, 2017
1 parent a5c0313 commit 511c000
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 25 deletions.
2 changes: 1 addition & 1 deletion INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[info]
name = intropage
version = 0.9.1
version = 0.9.2
longname = Intropage
author = Petr Macek
email = petr.macek@kostax.cz
Expand Down
17 changes: 16 additions & 1 deletion display.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ function display_informations() {
printf("<td style=\"vertical-align: top;\"><strong>%s</strong></td>\n",$val['name']);
printf("<td>%s",$val['data']);
if (isset($val['detail']) && !(is_null($val['detail']) || $val['detail'] == '')) {
printf("<span style='float: right'><a href='#' onclick=\"hide_display(\"block_%s\");\">View/hide details</a></span></td></tr>\n",$id);
printf("<span style='float: right'><a href='#' onclick=\"hide_display('block_%s');\">View/hide details</a></span></td></tr>\n",$id);
form_alternate_row($count,true);
print("<td colspan='3'>\n");
printf("<div id=\"block_%s\" style=\"display: none\">",$id);
Expand Down Expand Up @@ -266,6 +266,21 @@ function display_informations() {
print "<br/>";
}

print <<<EOF
<script type="text/javascript">
function hide_display (id) {
var temp = document.getElementById(id);
if (temp.style.display=='block')
temp.style.display='none';
else
temp.style.display='block';
return false;
}
</script>
EOF;

return true;
}

Expand Down
58 changes: 35 additions & 23 deletions functions/log.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,45 +43,42 @@ function tail_log($log_file, $nbr_lines = 1000, $adaptive = true) {
return explode("\n",$output);
}

if (read_config_option('intropage_log_analyze_enable')) {
$log_file = read_config_option("path_cactilog");
$nbr_lines = read_config_option("intropage_log_analyze_rows");
$log_lines = tail_log($log_file,$nbr_lines);
$size = filesize($log_file);
} else {
$nbr_lines = 0;
$log_lines = false;
$size = false;
function human_filesize($bytes, $decimals = 2) {
$size = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
$factor = floor((strlen($bytes) - 1) / 3);
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$size[$factor];
}

function get_log_size() {
global $config, $log_file, $size;
global $config, $log;

$result = array(
'name' => 'Log size',
'alarm' => 'green',
);

error_log("DEBUG: ".print_r($log,true));

$result['data'] = "<a href=\"" . htmlspecialchars($config['url_path']) . "utilities.php?action=view_logfile\">";

if (!$size) {
if (!$log['size']) {
$result['alarm'] = "red";
$result['data'] .= "Log file not accessible</a>";
} elseif ($size < 0) {
} elseif ($log['size'] < 0) {
$result['alarm'] = "red";
$result['data'] .= "Log file is larger than 2GB</a>";
} elseif ($size < 255999999) {
$result['data'] .= humanFileSize($size) . "</a>";
} elseif ($log['size'] < 255999999) {
$result['data'] .= human_filesize($log['size']) . "</a>";
} else {
$result['alarm'] = "yellow";
$result['data'] .= humanFileSize($size) . " (Logfile is quite large)</a>";
$result['data'] .= human_filesize($log['size']) . " (Logfile is quite large)</a>";
}

return $result;
}

function get_poller_stats() {
global $config, $log_file, $size, $log_lines;
global $config, $log;

$poller_interval = read_config_option("poller_interval");
$result = array(
Expand Down Expand Up @@ -119,8 +116,8 @@ function get_poller_stats() {
$result['alarm'] = "red";
$result['data'] = ($pollers_access)?"<a href=\"".htmlspecialchars($config['url_path'])."pollers.php\">No poller servers is active</a>":"No poller servers is active";
}
} elseif ($log_lines && $size) {
$stats_lines = preg_grep('/STATS/',$log_lines);
} elseif ($log['size'] && isset($log['lines'])) {
$stats_lines = preg_grep('/STATS/',$log['lines']);
if ($stats_lines) {
$result['detail'] = '';
$max_time = 0;
Expand Down Expand Up @@ -157,20 +154,20 @@ function get_poller_stats() {
}

function get_log_msg() {
global $config, $log_lines, $nbr_lines, $size;
global $config, $log;

$result = array(
'name' => "Warning and error (in last $nbr_lines lines)",
'name' => "Warning and error (in last ".$log['nbr_lines']." lines)",
'alarm' => 'green',
);

if (!$size) {
if (!$log['size'] || !isset($log['lines'])) {
$result['alarm'] = "red";
$result['data'] = "Log file not accessible";
} else {
$result['detail'] = '';
$error = 0;
foreach($log_lines as $line) {
foreach($log['lines'] as $line) {
if (preg_match('/(WARN|ERROR|FATAL)/',$line,$matches)) {
$result['detail'] .= "$line<br/>";
if (strcmp($matches[1],"WARN") && $error < 1) {
Expand All @@ -190,9 +187,24 @@ function get_log_msg() {
}

function get_log() {
global $config;
global $config, $log;

$result = array();

if (read_config_option('intropage_log_analyze_enable')) {
$log = array(
'file' => read_config_option("path_cactilog"),
'nbr_lines' => read_config_option("intropage_log_analyze_rows"),
);
$log['size'] = filesize($log['file']);
$log['lines'] = tail_log($log['file'],$log['nbr_lines']);
} else {
$log = array(
'size' => false,
'file' => read_config_option("path_cactilog"),
'nbr_lines' => 0,
);
}

$result['log_size'] = get_log_size();
$result['poller'] = get_poller_stats();
Expand Down

0 comments on commit 511c000

Please sign in to comment.