Skip to content

Commit

Permalink
Resolving Issues #81, #84
Browse files Browse the repository at this point in the history
Two fixes, some i18n and format changes, and an easter egg
  • Loading branch information
cigamit committed Feb 17, 2019
1 parent 38cc4ed commit 8336774
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 93 deletions.
3 changes: 1 addition & 2 deletions index.php
@@ -1,5 +1,4 @@
<?php

header("Location:../index.php");
header('Location:../index.php');

?>
3 changes: 1 addition & 2 deletions locales/LC_MESSAGES/index.php
@@ -1,5 +1,4 @@
<?php

header("Location:../index.php");
header('Location:../index.php');

?>
Binary file added locales/LC_MESSAGES/zh-CN.mo
Binary file not shown.
6 changes: 6 additions & 0 deletions locales/build_mo.sh
@@ -0,0 +1,6 @@
#!/bin/sh
for file in `ls -1 po/*.po`;do
ofile=$(basename --suffix=.po ${file})
echo "Converting $file to LC_MESSAGES/${ofile}.mo"
msgfmt ${file} -o LC_MESSAGES/${ofile}.mo
done
3 changes: 1 addition & 2 deletions locales/index.php
@@ -1,5 +1,4 @@
<?php

header("Location:../index.php");
header('Location:../index.php');

?>
83 changes: 57 additions & 26 deletions monitor.php
@@ -1,7 +1,7 @@
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2008-2017 The Cacti Group |
| Copyright (C) 2008-2019 The Cacti Group |
| |
| This program is free software; you can redistribute it and/or |
| modify it under the terms of the GNU General Public License |
Expand Down Expand Up @@ -104,17 +104,21 @@
switch(get_nfilter_request_var('action')) {
case 'ajax_status':
ajax_status();

break;
case 'ajax_mute_all':
mute_all_hosts();
draw_page();

break;
case 'ajax_unmute_all':
unmute_all_hosts();
draw_page();

break;
case 'save':
save_settings();

break;
default:
draw_page();
Expand Down Expand Up @@ -142,9 +146,11 @@ function draw_page() {

if (read_user_setting('monitor_legend', read_config_option('monitor_legend'))) {
print "<div class='center monitor_legend'><table class='center'><tr>\n";

foreach($iclasses as $index => $class) {
print "<td class='center $class" . "Bg' style='width:11%;'>" . $icolorsdisplay[$index] . "</td>\n";
}

print "</tr></table></div>\n";
}

Expand Down Expand Up @@ -331,10 +337,15 @@ function get_monitor_sound() {

function find_down_hosts() {
$dhosts = get_hosts_down_by_permission();

if (sizeof($dhosts)) {
set_request_var('downhosts', 'true');

if (isset($_SESSION['muted_hosts'])) {
unmute_up_hosts($dhosts);

$unmuted_hosts = array_diff($dhosts, $_SESSION['muted_hosts']);

if (sizeof($unmuted_hosts)) {
unmute_user();
}
Expand All @@ -347,6 +358,16 @@ function find_down_hosts() {
}
}

function unmute_up_hosts($dhosts) {
if (isset($_SESSION['muted_hosts'])) {
foreach($_SESSION['muted_hosts'] AS $index => $host_id) {
if (array_search($host_id, $dhosts) === false) {
unset($_SESSION['muted_hosts'][$index]);
}
}
}
}

function mute_all_hosts() {
$_SESSION['muted_hosts'] = get_hosts_down_by_permission();
mute_user();
Expand Down Expand Up @@ -457,6 +478,7 @@ function draw_filter_and_status() {
draw_filter_dropdown('grouping', __esc('Device Grouping', 'monitor'), $monitor_grouping);

print '</div><div class="monitorFilterRow">';

draw_filter_dropdown('crit', __esc('Select Minimum Criticality', 'monitor'), $criticalities);
draw_filter_dropdown('size', __esc('Device Icon Size', 'monitor'), $classes);

Expand Down Expand Up @@ -645,29 +667,27 @@ function render_where_join(&$sql_where, &$sql_join) {
$sql_where = 'WHERE h.disabled = ""
AND h.monitor = "on"
AND h.status < 3
AND (h.availability_method>0
OR h.snmp_version>0
OR (h.cur_time >= h.monitor_warn
AND monitor_warn > 0)
OR (h.cur_time >= h.monitor_alert
AND h.monitor_alert > 0)
AND (h.availability_method > 0
OR h.snmp_version > 0
OR (h.cur_time >= h.monitor_warn AND monitor_warn > 0)
OR (h.cur_time >= h.monitor_alert AND h.monitor_alert > 0)
)' . $crit;
} elseif (get_request_var('status') == '1') {
$sql_join = 'LEFT JOIN thold_data AS td ON td.host_id=h.id';
$sql_where = 'WHERE h.disabled = ""
AND h.monitor = "on"
AND (h.status < 3
OR (td.thold_enabled="on" AND td.thold_alert>0)
OR ((h.availability_method>0 OR h.snmp_version>0)
OR (td.thold_enabled = "on" AND td.thold_alert > 0)
OR ((h.availability_method > 0 OR h.snmp_version > 0)
AND ((h.cur_time > h.monitor_warn AND h.monitor_warn > 0)
OR (h.cur_time > h.monitor_alert AND h.monitor_alert > 0))
))' . $crit;
} else {
$sql_join = 'LEFT JOIN thold_data AS td ON td.host_id=h.id';
$sql_where = 'WHERE h.disabled = ""
AND h.monitor = "on"
AND (h.availability_method>0 OR h.snmp_version>0
OR (td.thold_enabled="on" AND td.thold_alert>0)
AND (h.availability_method > 0 OR h.snmp_version > 0
OR (td.thold_enabled="on" AND td.thold_alert > 0)
)' . $crit;
}
}
Expand Down Expand Up @@ -1035,11 +1055,11 @@ function render_branch($leafs, $title = '') {
}
}

function get_host_status($host,$real=false) {
function get_host_status($host, $real = false) {
global $thold_hosts, $iclasses;

/* If the host has been muted, show the muted Icon */
if (array_key_exists($host['id'], $thold_hosts)) {
if ($host['status'] != 1 && array_key_exists($host['id'], $thold_hosts)) {
$host['status'] = 4;
} elseif (in_array($host['id'], $_SESSION['muted_hosts']) && $host['status'] == 1) {
$host['status'] = 5;
Expand Down Expand Up @@ -1087,14 +1107,15 @@ function render_host($host, $float = true, $maxlen = 120) {

if ($host['status'] == 3 && array_key_exists($host['id'], $thold_hosts)) {
$host['status'] = 4;

if (file_exists($config['base_path'] . '/plugins/thold/thold_graph.php')) {
$host['anchor'] = $config['url_path'] . 'plugins/thold/thold_graph.php';
} else {
$host['anchor'] = $config['url_path'] . 'plugins/thold/graph_thold.php';
}
}

$host['real_status'] = get_host_status($host,true);
$host['real_status'] = get_host_status($host, true);
$host['status'] = get_host_status($host);
$host['iclass'] = $iclasses[$host['status']];

Expand All @@ -1113,9 +1134,9 @@ function render_host($host, $float = true, $maxlen = 120) {
$fclass = get_request_var('size');

if ($host['status'] <= 2 || $host['status'] == 5) {
$result = "<div class='$fclass flash monitor_device_frame' style='width:" . max(120, $maxlen*7) . 'px;' . ($float ? 'float:left;':'') . "'><a href='" . $host['anchor'] . "'><i id='" . $host['id'] . "' class='fa $iclass " . $host['iclass'] . "'></i><br><span class='center'>" . trim($host['description']) . "</span><br><span style='font-size:10px;padding:2px;' class='deviceDown'>$dt</span></a></div>\n";
$result = "<div class='$fclass flash monitor_device_frame' style='width:" . max(120, $maxlen*7) . 'px;' . ($float ? 'float:left;':'') . "'><a href='" . $host['anchor'] . "'><i id='" . $host['id'] . "' class='$iclass " . $host['iclass'] . "'></i><br><span class='center'>" . trim($host['description']) . "</span><br><span style='font-size:10px;padding:2px;' class='deviceDown'>$dt</span></a></div>\n";
} else {
$result = "<div class='monitor_device_frame $fclass' style='width:" . max(120, $maxlen*7) . 'px;' . ($float ? 'float:left;':'') . "'><a href='" . $host['anchor'] . "'><i id=" . $host['id'] . " class='fa $iclass " . $host['iclass'] . "'></i><br>" . trim($host['description']) . "</a></div>\n";
$result = "<div class='monitor_device_frame $fclass' style='width:" . max(120, $maxlen*7) . 'px;' . ($float ? 'float:left;':'') . "'><a href='" . $host['anchor'] . "'><i id=" . $host['id'] . " class='$iclass " . $host['iclass'] . "'></i><br>" . trim($host['description']) . "</a></div>\n";
}
}

Expand All @@ -1124,9 +1145,9 @@ function render_host($host, $float = true, $maxlen = 120) {

function get_status_icon($status) {
if ($status == 1 && read_user_setting('monitor_sound') == 'First Orders Suite.mp3') {
return 'fa-first-order fa-spin';
return 'fab fa-first-order fa-spin';
} else {
return 'fa-server';
return 'fa fa-server';
}
}

Expand Down Expand Up @@ -1164,9 +1185,13 @@ function ajax_status() {
if (isset_request_var('id') && get_filter_request_var('id')) {
$id = get_request_var('id');

$host = db_fetch_row_prepared('SELECT * FROM host WHERE id = ?', array($id));
if (empty($host)) {
cacti_log('Attempted to retrieve status for missing host id ' . $id, false, 'MONITOR', POLLER_VERBOSITY_HIGH);
$host = db_fetch_row_prepared('SELECT *
FROM host
WHERE id = ?',
array($id));

if (!cacti_sizeof($host)) {
cacti_log('Attempted to retrieve status for missing Device ' . $id, false, 'MONITOR', POLLER_VERBOSITY_HIGH);
return false;
}

Expand All @@ -1185,7 +1210,7 @@ function ajax_status() {
$host['status'] = 6;
}

$host['real_status'] = get_host_status($host,true);
$host['real_status'] = get_host_status($host, true);
$host['status'] = get_host_status($host);

if (sizeof($host)) {
Expand All @@ -1194,7 +1219,11 @@ function ajax_status() {
}

// Get the number of graphs
$graphs = db_fetch_cell_prepared('SELECT count(*) FROM graph_local WHERE host_id = ?', array($host['id']));
$graphs = db_fetch_cell_prepared('SELECT COUNT(*)
FROM graph_local
WHERE host_id = ?',
array($host['id']));

if ($graphs > 0) {
$graph_link = htmlspecialchars($config['url_path'] . 'graph_view.php?action=preview&reset=1&host_id=' . $host['id']);
}
Expand All @@ -1215,6 +1244,7 @@ function ajax_status() {
if (api_plugin_is_enabled('syslog') && api_plugin_user_realm_auth('syslog.php')) {
include($config['base_path'] . '/plugins/syslog/config.php');
include_once($config['base_path'] . '/plugins/syslog/functions.php');

$syslog_logs = syslog_db_fetch_cell_prepared('SELECT count(*)
FROM syslog_logs
WHERE host = ?',
Expand Down Expand Up @@ -1257,6 +1287,7 @@ function ajax_status() {

$iclass = $iclasses[$host['status']];
$sdisplay = get_host_status_description($host['real_status']);

print "<table class='monitorHover'>
<tr class='tableHeader'>
<th class='left' colspan='2'>Device Status Information</th>
Expand Down Expand Up @@ -1451,7 +1482,7 @@ function render_host_tiles($host) {
return;
}

$result = "<div class='monitor_device_frame $fclass ${fclass}_tiles'><a class='textSubHeaderDark' href='" . $host['anchor'] . "'><i id='" . $host['id'] . "' class='fa $class " . $host['iclass'] . "'></i></a></div>";
$result = "<div class='monitor_device_frame $fclass ${fclass}_tiles'><a class='textSubHeaderDark' href='" . $host['anchor'] . "'><i id='" . $host['id'] . "' class='$class " . $host['iclass'] . "'></i></a></div>";

return $result;
}
Expand All @@ -1469,7 +1500,7 @@ function render_host_tilesadt($host) {
if ($host['status'] < 2 || $host['status'] == 5) {
$dt = get_timeinstate($host);

$result = "<div class='monitor_device_frame $fclass ${fclass}_tilesadt'><a class='textSubHeaderDark' href='" . $host['anchor'] . "'><i id='" . $host['id'] . "' class='fa $class " . $host['iclass'] . "'></i><br><span class='monitor_device deviceDown'>$dt</span></a></div>\n";
$result = "<div class='monitor_device_frame $fclass ${fclass}_tilesadt'><a class='textSubHeaderDark' href='" . $host['anchor'] . "'><i id='" . $host['id'] . "' class='$class " . $host['iclass'] . "'></i><br><span class='monitor_device deviceDown'>$dt</span></a></div>\n";

return $result;
} else {
Expand All @@ -1479,7 +1510,7 @@ function render_host_tilesadt($host) {
$dt = __('Never', 'monitor');
}

$result = "<div class='monitor_device_frame $fclass ${fclass}_tilesadt'><a class='textSubHeaderDark' href='" . $host['anchor'] . "'><i id='" . $host['id'] . "' class='fa $class " . $host['iclass'] . "'></i><br><span class='monitor_device deviceUp'>$dt</span></a></div>\n";
$result = "<div class='monitor_device_frame $fclass ${fclass}_tilesadt'><a class='textSubHeaderDark' href='" . $host['anchor'] . "'><i id='" . $host['id'] . "' class='$class " . $host['iclass'] . "'></i><br><span class='monitor_device deviceUp'>$dt</span></a></div>\n";

return $result;
}
Expand Down

0 comments on commit 8336774

Please sign in to comment.