Skip to content

Commit 6715384

Browse files
committed
Fixing Issue #117
Export of rules does not work when using db other than Cacti
1 parent 6c00d0d commit 6715384

4 files changed

Lines changed: 40 additions & 11 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ that.
159159

160160
* issue#115: Some field where not corrected following the version change
161161

162-
* issue#116: Background process fail to operate syslog_coming table; syslog_process.php fail if current workdir is not CACTI_TOP
162+
* issue#116: Background process fail to operate syslog_coming table; syslog_process.php fail if current workdir is not CACTI_TOP
163+
164+
* issue#1117: Export of rules does not work when using db other than Cacti
163165

164166
--- 2.7 ---
165167

database.php

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,10 @@ function syslog_db_fetch_cell($sql, $col_name = '', $log = TRUE) {
7979

8080
/* syslog_db_fetch_cell_prepared - run a 'select' sql query and return the first column of the
8181
first row found
82-
@param $sql - the sql query to execute
83-
@param $col_name - use this column name instead of the first one
84-
@param $log - whether to log error messages, defaults to true
82+
@arg $sql - the sql query to execute
83+
@arg $params - an array of parameters
84+
@arg $col_name - use this column name instead of the first one
85+
@arg $log - whether to log error messages, defaults to true
8586
@returns - (bool) the output of the sql query as a single variable */
8687
function syslog_db_fetch_cell_prepared($sql, $params = array(), $col_name = '', $log = TRUE) {
8788
global $syslog_cnn;
@@ -97,6 +98,16 @@ function syslog_db_fetch_row($sql, $log = TRUE) {
9798
return db_fetch_row($sql, $log, $syslog_cnn);
9899
}
99100

101+
/* syslog_db_fetch_row_prepared - run a 'select' sql query and return the first row found
102+
@arg $sql - the sql query to execute
103+
@arg $params - an array of parameters
104+
@arg $log - whether to log error messages, defaults to true
105+
@returns - the first row of the result as a hash */
106+
function syslog_db_fetch_row_prepared($sql, $params = array(), $log = TRUE) {
107+
global $syslog_cnn;
108+
return db_fetch_row_prepared($sql, $params, $log, $syslog_cnn);
109+
}
110+
100111
/* syslog_db_fetch_assoc - run a 'select' sql query and return all rows found
101112
@arg $sql - the sql query to execute
102113
@arg $log - whether to log error messages, defaults to true
@@ -106,6 +117,16 @@ function syslog_db_fetch_assoc($sql, $log = TRUE) {
106117
return db_fetch_assoc($sql, $log, $syslog_cnn);
107118
}
108119

120+
/* syslog_db_fetch_assoc_prepared - run a 'select' sql query and return all rows found
121+
@arg $sql - the sql query to execute
122+
@arg $params - an array of parameters
123+
@arg $log - whether to log error messages, defaults to true
124+
@returns - the entire result set as a multi-dimensional hash */
125+
function syslog_db_fetch_assoc_prepared($sql, $params = array(), $log = TRUE) {
126+
global $syslog_cnn;
127+
return db_fetch_assoc($sql, $params, $log, $syslog_cnn);
128+
}
129+
109130
/* syslog_db_fetch_insert_id - get the last insert_id or auto incriment
110131
@arg $syslog_cnn - the connection object to connect to
111132
@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 =
135156
}
136157

137158
/* syslog_db_table_exists - checks whether a table exists
138-
@param $table - the name of the table
139-
@param $log - whether to log error messages, defaults to true
159+
@arg $table - the name of the table
160+
@arg $log - whether to log error messages, defaults to true
140161
@returns - (bool) the output of the sql query as a single variable */
141162
function syslog_db_table_exists($table, $log = true) {
142163
global $syslog_cnn;

syslog_alerts.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ function form_actions() {
224224
}
225225

226226
function alert_export() {
227+
include(dirname(__FILE__) . '/config.php');
228+
227229
/* if we are to save this form, instead of display it */
228230
if (isset_request_var('selected_items')) {
229231
$selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
@@ -232,8 +234,8 @@ function alert_export() {
232234
$output = '<templates>' . PHP_EOL;
233235
foreach ($selected_items as $id) {
234236
if ($id > 0) {
235-
$data = db_fetch_row_prepared('SELECT *
236-
FROM syslog_alert
237+
$data = syslog_db_fetch_row_prepared('SELECT *
238+
FROM `' . $syslogdb_default . '`.`syslog_alert`
237239
WHERE id = ?',
238240
array($id));
239241

@@ -422,7 +424,9 @@ function syslog_action_edit() {
422424
$header_label = __('Alert Edit [new]', 'syslog');
423425
}
424426
} elseif (isset_request_var('id') && get_nfilter_request_var('action') == 'newedit') {
425-
$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") . "'":""));
427+
$syslog_rec = syslog_db_fetch_row("SELECT *
428+
FROM `" . $syslogdb_default . "`.`syslog`
429+
WHERE seq=" . get_request_var("id") . (isset_request_var('date') ? " AND logtime='" . get_request_var("date") . "'":""));
426430

427431
$header_label = __('Alert Edit [new]', 'syslog');
428432
if (cacti_sizeof($syslog_rec)) {

syslog_removal.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ function form_actions() {
247247
}
248248

249249
function removal_export() {
250+
include(dirname(__FILE__) . '/config.php');
251+
250252
/* if we are to save this form, instead of display it */
251253
if (isset_request_var('selected_items')) {
252254
$selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
@@ -255,8 +257,8 @@ function removal_export() {
255257
$output = '<templates>' . PHP_EOL;
256258
foreach ($selected_items as $id) {
257259
if ($id > 0) {
258-
$data = db_fetch_row_prepared('SELECT *
259-
FROM syslog_remove
260+
$data = syslog_db_fetch_row_prepared('SELECT *
261+
FROM `' . $syslogdb_default . '`.`syslog_remove`
260262
WHERE id = ?',
261263
array($id));
262264

0 commit comments

Comments
 (0)