Skip to content

Commit 25120e2

Browse files
committed
Resolving Issue #88 and QA
* Provide text color to indicate device status in Cacti * QA some SQL errors on statistics page
1 parent 4f3a022 commit 25120e2

2 files changed

Lines changed: 59 additions & 24 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ The sylog plugin has been in development for well over a decade with increasing
8484
* issue#100: Fix odd/even classes generation in report
8585
* issue#99: Re-Alert Cycle (Alert Rules) is wrong in case of 1 minute poller interval
8686
* issue#96: Syslog filtering does not work with some international characters
87+
* issue#88: Provide text color to indicate device status in Cacti
8788
* issue#87: Program data is not sync with syslog_incoming under PHP 7.2
8889

8990
--- 2.4 ---

syslog.php

Lines changed: 58 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
/* initialize cacti environment */
3232
chdir('../../');
3333
include('./include/auth.php');
34+
include('./lib/html_tree.php');
3435

3536
/* syslog specific database setup and functions */
3637
include('./plugins/syslog/config.php');
@@ -337,54 +338,51 @@ function syslog_statistics() {
337338
function get_stats_records(&$sql_where, &$sql_groupby, $rows) {
338339
include(dirname(__FILE__) . '/config.php');
339340

340-
$sql_where = '';
341-
$sql_groupby = 'GROUP BY sh.host';
342-
343341
/* form the 'where' clause for our main sql query */
344342
if (!isempty_request_var('filter')) {
345-
$sql_where .= (!strlen($sql_where) ? 'WHERE ' : ' AND ') .
343+
$sql_where .= ($sql_where == '' ? 'WHERE ' : ' AND ') .
346344
'sh.host LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . '
347345
OR spr.program LIKE ' . db_qstr('%' . get_request_var('filter') . '%');
348346
}
349347

350348
if (get_request_var('host') == '-2') {
351349
// Do nothing
352350
} elseif (get_request_var('host') != '-1' && get_request_var('host') != '') {
353-
$sql_where .= (!strlen($sql_where) ? 'WHERE ' : ' AND ') . 'ss.host_id=' . get_request_var('host');
354-
$sql_groupby .= ', sh.host';
351+
$sql_where .= ($sql_where == '' ? 'WHERE ' : ' AND ') . 'ss.host_id=' . get_request_var('host');
352+
$sql_groupby .= ($sql_groupby != '' ? ', ':'') . 'sh.host';
355353
} else {
356-
$sql_groupby .= ', sh.host';
354+
$sql_groupby .= ($sql_groupby != '' ? ', ':'') . 'sh.host';
357355
}
358356

359357
if (get_request_var('facility') == '-2') {
360358
// Do nothing
361359
} elseif (get_request_var('facility') != '-1' && get_request_var('facility') != '') {
362-
$sql_where .= (!strlen($sql_where) ? 'WHERE ' : ' AND ') . 'ss.facility_id=' . get_request_var('facility');
363-
$sql_groupby .= ', sf.facility';
360+
$sql_where .= ($sql_where == '' ? 'WHERE ' : ' AND ') . 'ss.facility_id=' . get_request_var('facility');
361+
$sql_groupby .= ($sql_groupby != '' ? ', ':'') . 'sf.facility';
364362
} else {
365-
$sql_groupby .= ', sf.facility';
363+
$sql_groupby .= ($sql_groupby != '' ? ', ':'') . 'sf.facility';
366364
}
367365

368366
if (get_request_var('priority') == '-2') {
369367
// Do nothing
370368
} elseif (get_request_var('priority') != '-1' && get_request_var('priority') != '') {
371-
$sql_where .= (!strlen($sql_where) ? 'WHERE ': ' AND ') . 'ss.priority_id=' . get_request_var('priority');
372-
$sql_groupby .= ', sp.priority';
369+
$sql_where .= ($sql_where == '' ? 'WHERE ': ' AND ') . 'ss.priority_id=' . get_request_var('priority');
370+
$sql_groupby .= ($sql_groupby != '' ? ', ':'') . 'sp.priority';
373371
} else {
374-
$sql_groupby .= ', sp.priority';
372+
$sql_groupby .= ($sql_groupby != '' ? ', ':'') . 'sp.priority';
375373
}
376374

377375
if (get_request_var('program') == '-2') {
378376
// Do nothing
379377
} elseif (get_request_var('program') != '-1' && get_request_var('program') != '') {
380-
$sql_where .= (!strlen($sql_where) ? 'WHERE ': ' AND ') . 'ss.program_id=' . get_request_var('program');
381-
$sql_groupby .= ', spr.program';
378+
$sql_where .= ($sql_where == '' ? 'WHERE ': ' AND ') . 'ss.program_id=' . get_request_var('program');
379+
$sql_groupby .= ($sql_groupby != '' ? ', ':'') . 'spr.program';
382380
} else {
383-
$sql_groupby .= ', spr.program';
381+
$sql_groupby .= ($sql_groupby != '' ? ', ':'') . 'spr.program';
384382
}
385383

386384
if (get_request_var('timespan') != '-1') {
387-
$sql_groupby .= ', UNIX_TIMESTAMP(insert_time) DIV ' . get_request_var('timespan');
385+
$sql_groupby .= ($sql_groupby != '' ? ', ':'') . ' UNIX_TIMESTAMP(insert_time) DIV ' . get_request_var('timespan');
388386
}
389387

390388
$sql_order = get_order_string();
@@ -394,6 +392,10 @@ function get_stats_records(&$sql_where, &$sql_groupby, $rows) {
394392
$sql_limit = ' LIMIT 10000';
395393
}
396394

395+
if ($sql_groupby != '') {
396+
$sql_groupby = 'GROUP BY ' . $sql_groupby;
397+
}
398+
397399
$time = 'FROM_UNIXTIME(TRUNCATE(UNIX_TIMESTAMP(insert_time)/' . get_request_var('timespan') . ',0)*' . get_request_var('timespan') . ') AS insert_time';
398400

399401
$query_sql = "SELECT sh.host, sf.facility, sp.priority, spr.program, sum(ss.records) AS records, $time
@@ -411,6 +413,8 @@ function get_stats_records(&$sql_where, &$sql_groupby, $rows) {
411413
$sql_order
412414
$sql_limit";
413415

416+
//cacti_log(str_replace("\n", "", $query_sql));
417+
414418
return syslog_db_fetch_assoc($query_sql);
415419
}
416420

@@ -430,13 +434,24 @@ function syslog_stats_filter() {
430434
<option value='-1'<?php if (get_request_var('host') == '-1') { ?> selected<?php } ?>><?php print __('All', 'syslog');?></option>
431435
<option value='-2'<?php if (get_request_var('host') == '-2') { ?> selected<?php } ?>><?php print __('None', 'syslog');?></option>
432436
<?php
433-
$facilities = syslog_db_fetch_assoc('SELECT DISTINCT host_id, host
437+
$hosts = syslog_db_fetch_assoc('SELECT DISTINCT sh.host_id, sh.host, h.id
434438
FROM syslog_hosts AS sh
439+
LEFT JOIN host AS h
440+
ON sh.host = h.hostname
441+
OR sh.host = h.description
442+
OR sh.host LIKE substring_index(h.hostname, ".", 1)
443+
OR sh.host LIKE substring_index(h.description, ".", 1)
435444
ORDER BY host');
436445

437-
if (cacti_sizeof($facilities)) {
438-
foreach ($facilities as $r) {
439-
print '<option value="' . $r['host_id'] . '"'; if (get_request_var('host') == $r['host_id']) { print ' selected'; } print '>' . $r['host'] . "</option>\n";
446+
if (cacti_sizeof($hosts)) {
447+
foreach ($hosts as $host) {
448+
if (!empty($host['id'])) {
449+
$class = get_device_leaf_class($host['id']);
450+
} else {
451+
$class = 'deviceUnknown';
452+
}
453+
454+
print '<option class="' . $class . '" value="' . $host['host_id'] . '"'; if (get_request_var('host') == $host['host_id']) { print ' selected'; } print '>' . $host['host'] . '</option>';
440455
}
441456
}
442457
?>
@@ -559,6 +574,14 @@ function clearFilter() {
559574
$('#clear').click(function() {
560575
clearFilter();
561576
});
577+
578+
$('#host').selectmenu({
579+
open: function() {
580+
$('div.ui-selectmenu-menu li.ui-menu-item').each(function(idx){
581+
$(this).addClass( $('#host option').eq(idx).attr('class') )
582+
})
583+
}
584+
});
562585
});
563586

564587
function applyFilter() {
@@ -1294,8 +1317,13 @@ function timeshiftFilterRight() {
12941317
$hosts_where = '';
12951318
$hosts_where = api_plugin_hook_function('syslog_hosts_where', $hosts_where);
12961319

1297-
$hosts = syslog_db_fetch_assoc("SELECT host_id, host
1298-
FROM `" . $syslogdb_default . "`.`syslog_hosts`
1320+
$hosts = syslog_db_fetch_assoc("SELECT sh.host_id, sh.host, h.id
1321+
FROM `" . $syslogdb_default . "`.`syslog_hosts` AS sh
1322+
LEFT JOIN host AS h
1323+
ON sh.host = h.hostname
1324+
OR sh.host = h.description
1325+
OR sh.host LIKE substring_index(h.hostname, '.', 1)
1326+
OR sh.host LIKE substring_index(h.description, '.', 1)
12991327
$hosts_where
13001328
ORDER BY host");
13011329

@@ -1308,7 +1336,13 @@ function timeshiftFilterRight() {
13081336
$host['host'] = $parts[0];
13091337
}
13101338

1311-
print "<option value='" . $host['host_id'] . "'";
1339+
if (!empty($host['id'])) {
1340+
$class = get_device_leaf_class($host['id']);
1341+
} else {
1342+
$class = 'deviceUnknown';
1343+
}
1344+
1345+
print "<option class='$class' value='" . $host['host_id'] . "'";
13121346
if (cacti_sizeof($selected)) {
13131347
if (in_array($host['host_id'], $selected)) {
13141348
print ' selected';

0 commit comments

Comments
 (0)