Skip to content

Commit a626774

Browse files
TheWitnessCopilot
andauthored
Fixing: #298 and #300 - Signal Handler, Table Truncation and CHANGLOG Updates (#316)
* Fixing: #298 and #300 - Signal Handler and Table Truncation * This should stop the table truncation after install, it will flip the table to use the 'upgrade' process over the truncate process. * Most of the issues around #298 have been corrected with the exception of signal handling in syslog_process which is now addressed. * Also doing CHANGELOG.md catchup commit * Update syslog_process.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update syslog_process.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update syslog_process.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update setup.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent bb45b9b commit a626774

3 files changed

Lines changed: 51 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@
22

33
--- develop ---
44

5+
* issue#199: Duplicate Partition name errors
56
* issue#250: Fix date filter persistence by validating before shift_span detection
7+
* issue#252: hardening: escape device hostname output in syslog view; parameterize alert API functions
8+
* issue#256: hardening: prevent CSV formula injection and malformed CSV output in exports
69
* issue#258: Execute CREATE TABLE SQL correctly during replication sync
10+
* issue#260: hardening: replace eval-based callback execution in syslog autocomplete JS
711
* issue#278: Extract duplicated alert command execution paths in syslog_process_alerts
812
* issue#278: Extract alert command execution into shared helper in functions.php; command tokenization now uses preg_split (handles tabs and consecutive spaces); /bin/sh fallback for non-executable command templates removed (use absolute paths with execute bit set)
13+
* issue#298: syslog poller: lock timeout, signal handler, and earlier partition rotation
14+
* issue#300: Syslog table drop with no apparent reason
915
* issue: Making changes to support Cacti 1.3
1016
* issue: Don't use MyISAM for non-analytical tables
1117
* issue: The install advisor for Syslog was broken in current Cacti releases

setup.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ function syslog_setup_table_new($options) {
633633
$present = syslog_db_fetch_row("SHOW TABLES FROM `$syslogdb_default` LIKE 'syslog_reports'");
634634

635635
if (cacti_sizeof($present)) {
636-
$newreport = sizeof(syslog_db_fetch_row("SHOW COLUMNS FROM `$syslogdb_default`.`syslog_reports` LIKE 'body'"));
636+
$newreport = syslog_db_column_exists('syslog_reports', 'body');
637637
} else {
638638
$newreport = true;
639639
}
@@ -784,6 +784,9 @@ function syslog_setup_table_new($options) {
784784
set_config_option($name, $values['default']);
785785
}
786786
}
787+
788+
// ensure that the setting if set previously to truncate is switched to upgrade
789+
set_config_option('syslog_install_upgrade_type', 'upgrade');
787790
}
788791

789792
function syslog_replicate_out($data) {

syslog_process.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
+-------------------------------------------------------------------------+
2323
*/
2424

25+
if (function_exists('pcntl_async_signals')) {
26+
pcntl_async_signals(true);
27+
} else {
28+
declare(ticks = 100);
29+
}
30+
2531
include(__DIR__ . '/../../include/cli_check.php');
2632
include_once(__DIR__ . '/functions.php');
2733
include_once(__DIR__ . '/database.php');
@@ -32,9 +38,13 @@
3238
* Let it run for an hour if it has to, to clear up any big
3339
* bursts of incoming syslog events
3440
*/
41+
ini_set('output_buffering', 'Off');
3542
ini_set('max_execution_time', 3600);
3643
ini_set('memory_limit', '-1');
3744

45+
set_time_limit(3600);
46+
ob_implicit_flush();
47+
3848
global $debug, $syslog_facilities, $syslog_levels;
3949

4050
$debug = false;
@@ -82,6 +92,12 @@
8292
}
8393
}
8494

95+
// install signal handlers for UNIX only
96+
if (function_exists('pcntl_signal')) {
97+
pcntl_signal(SIGTERM, 'sig_handler');
98+
pcntl_signal(SIGINT, 'sig_handler');
99+
}
100+
85101
// record the start time
86102
$start_time = microtime(true);
87103

@@ -242,6 +258,31 @@
242258

243259
exit(0);
244260

261+
/**
262+
* sig_handler - handles UNIX signals and logs shutdown events to the Cacti log.
263+
*
264+
* @param int $signo The signal received by the process.
265+
*
266+
* @return (void)
267+
*/
268+
function sig_handler($signo) {
269+
global $config;
270+
271+
switch ($signo) {
272+
case SIGTERM:
273+
case SIGINT:
274+
cacti_log("WARNING: Syslog 'master' is shutting down by signal!", false, 'SYSLOG');
275+
276+
unregister_process('syslog', 'master', $config['poller_id']);
277+
278+
exit(1);
279+
280+
break;
281+
default:
282+
// ignore all other signals
283+
}
284+
}
285+
245286
/**
246287
* display_version - displays version information
247288
*

0 commit comments

Comments
 (0)