From 6715384e824481341afc405fa822edb883c7bee3 Mon Sep 17 00:00:00 2001 From: TheWitness Date: Tue, 10 Mar 2020 09:18:21 -0400 Subject: [PATCH] Fixing Issue #117 Export of rules does not work when using db other than Cacti --- README.md | 4 +++- database.php | 31 ++++++++++++++++++++++++++----- syslog_alerts.php | 10 +++++++--- syslog_removal.php | 6 ++++-- 4 files changed, 40 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 25b0ca1..8869156 100644 --- a/README.md +++ b/README.md @@ -159,7 +159,9 @@ that. * issue#115: Some field where not corrected following the version change -* issue#116: Background process fail to operate syslog_coming table; syslog_process.php fail if current workdir is not CACTI_TOP +* issue#116: Background process fail to operate syslog_coming table; syslog_process.php fail if current workdir is not CACTI_TOP + +* issue#1117: Export of rules does not work when using db other than Cacti --- 2.7 --- diff --git a/database.php b/database.php index 98325a0..26ca3d3 100644 --- a/database.php +++ b/database.php @@ -79,9 +79,10 @@ function syslog_db_fetch_cell($sql, $col_name = '', $log = TRUE) { /* syslog_db_fetch_cell_prepared - run a 'select' sql query and return the first column of the first row found - @param $sql - the sql query to execute - @param $col_name - use this column name instead of the first one - @param $log - whether to log error messages, defaults to true + @arg $sql - the sql query to execute + @arg $params - an array of parameters + @arg $col_name - use this column name instead of the first one + @arg $log - whether to log error messages, defaults to true @returns - (bool) the output of the sql query as a single variable */ function syslog_db_fetch_cell_prepared($sql, $params = array(), $col_name = '', $log = TRUE) { global $syslog_cnn; @@ -97,6 +98,16 @@ function syslog_db_fetch_row($sql, $log = TRUE) { return db_fetch_row($sql, $log, $syslog_cnn); } +/* syslog_db_fetch_row_prepared - run a 'select' sql query and return the first row found + @arg $sql - the sql query to execute + @arg $params - an array of parameters + @arg $log - whether to log error messages, defaults to true + @returns - the first row of the result as a hash */ +function syslog_db_fetch_row_prepared($sql, $params = array(), $log = TRUE) { + global $syslog_cnn; + return db_fetch_row_prepared($sql, $params, $log, $syslog_cnn); +} + /* syslog_db_fetch_assoc - run a 'select' sql query and return all rows found @arg $sql - the sql query to execute @arg $log - whether to log error messages, defaults to true @@ -106,6 +117,16 @@ function syslog_db_fetch_assoc($sql, $log = TRUE) { return db_fetch_assoc($sql, $log, $syslog_cnn); } +/* syslog_db_fetch_assoc_prepared - run a 'select' sql query and return all rows found + @arg $sql - the sql query to execute + @arg $params - an array of parameters + @arg $log - whether to log error messages, defaults to true + @returns - the entire result set as a multi-dimensional hash */ +function syslog_db_fetch_assoc_prepared($sql, $params = array(), $log = TRUE) { + global $syslog_cnn; + return db_fetch_assoc($sql, $params, $log, $syslog_cnn); +} + /* syslog_db_fetch_insert_id - get the last insert_id or auto incriment @arg $syslog_cnn - the connection object to connect to @returns - the id of the last auto incriment row that was created */ @@ -135,8 +156,8 @@ function syslog_sql_save($array_items, $table_name, $key_cols = 'id', $autoinc = } /* syslog_db_table_exists - checks whether a table exists - @param $table - the name of the table - @param $log - whether to log error messages, defaults to true + @arg $table - the name of the table + @arg $log - whether to log error messages, defaults to true @returns - (bool) the output of the sql query as a single variable */ function syslog_db_table_exists($table, $log = true) { global $syslog_cnn; diff --git a/syslog_alerts.php b/syslog_alerts.php index 32cd92c..b3acd50 100644 --- a/syslog_alerts.php +++ b/syslog_alerts.php @@ -224,6 +224,8 @@ function form_actions() { } function alert_export() { + include(dirname(__FILE__) . '/config.php'); + /* if we are to save this form, instead of display it */ if (isset_request_var('selected_items')) { $selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items')); @@ -232,8 +234,8 @@ function alert_export() { $output = '' . PHP_EOL; foreach ($selected_items as $id) { if ($id > 0) { - $data = db_fetch_row_prepared('SELECT * - FROM syslog_alert + $data = syslog_db_fetch_row_prepared('SELECT * + FROM `' . $syslogdb_default . '`.`syslog_alert` WHERE id = ?', array($id)); @@ -422,7 +424,9 @@ function syslog_action_edit() { $header_label = __('Alert Edit [new]', 'syslog'); } } elseif (isset_request_var('id') && get_nfilter_request_var('action') == 'newedit') { - $syslog_rec = syslog_db_fetch_row("SELECT * FROM `" . $syslogdb_default . "`.`syslog` WHERE seq=" . get_request_var("id") . (isset_request_var('date') ? " AND logtime='" . get_request_var("date") . "'":"")); + $syslog_rec = syslog_db_fetch_row("SELECT * + FROM `" . $syslogdb_default . "`.`syslog` + WHERE seq=" . get_request_var("id") . (isset_request_var('date') ? " AND logtime='" . get_request_var("date") . "'":"")); $header_label = __('Alert Edit [new]', 'syslog'); if (cacti_sizeof($syslog_rec)) { diff --git a/syslog_removal.php b/syslog_removal.php index 2240f5b..a84c103 100644 --- a/syslog_removal.php +++ b/syslog_removal.php @@ -247,6 +247,8 @@ function form_actions() { } function removal_export() { + include(dirname(__FILE__) . '/config.php'); + /* if we are to save this form, instead of display it */ if (isset_request_var('selected_items')) { $selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items')); @@ -255,8 +257,8 @@ function removal_export() { $output = '' . PHP_EOL; foreach ($selected_items as $id) { if ($id > 0) { - $data = db_fetch_row_prepared('SELECT * - FROM syslog_remove + $data = syslog_db_fetch_row_prepared('SELECT * + FROM `' . $syslogdb_default . '`.`syslog_remove` WHERE id = ?', array($id));