Skip to content

Commit

Permalink
Fixing Issue #117
Browse files Browse the repository at this point in the history
Export of rules does not work when using db other than Cacti
  • Loading branch information
TheWitness committed Mar 10, 2020
1 parent 6c00d0d commit 6715384
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 11 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ---

Expand Down
31 changes: 26 additions & 5 deletions database.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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 */
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 7 additions & 3 deletions syslog_alerts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand All @@ -232,8 +234,8 @@ function alert_export() {
$output = '<templates>' . 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));

Expand Down Expand Up @@ -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)) {
Expand Down
6 changes: 4 additions & 2 deletions syslog_removal.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand All @@ -255,8 +257,8 @@ function removal_export() {
$output = '<templates>' . 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));

Expand Down

0 comments on commit 6715384

Please sign in to comment.