Progammers/Developers - please help Ubuntu PHP7 and CaMM rules stopped working **SOLVED**

General discussion about Plugins for Cacti

Moderators: Developers, Moderators

Post Reply
Moegoe
Posts: 16
Joined: Sun Aug 04, 2019 7:13 am

Progammers/Developers - please help Ubuntu PHP7 and CaMM rules stopped working **SOLVED**

Post by Moegoe »

My Camm rules stoped working - suspect PHP updated. I get the following error for the code below in the camm/poller_camm.php:
PHP Warning: mysqli_affected_rows() expects parameter 1 to be mysqli, array given in poller_camm.php

Below is the code block. I have played around but have not found and answer yet
###################################################################################

function process_rules() {
global $cacti_camm_components;

if (read_config_option("camm_rule_order") == 2) {
$str_sql_order = ' ORDER BY `order` DESC; ';
}else{
$str_sql_order = ' ORDER BY `is_delete` DESC, `count_triggered` DESC; ';
}

$rules = db_fetch_assoc("SELECT * FROM `plugin_camm_rule` where `rule_enable`=1 " . $str_sql_order);
# $sql = "SELECT * FROM `plugin_camm_rule` where `rule_enable`=1";
# $result = $mysqli -> query($sql);
# $rules = $result -> fetch_assoc($str_sql_order);
//$use_syslog = (read_config_option("camm_use_syslog") == "1");
$camm_syslog_db_name = read_config_option("camm_syslog_db_name");

camm_debug("S1. Found " . sizeof($rules) . " camm rule" . (sizeof($rules) == 1 ? "" : "s" ) . " to process");

/* FLAG ALL THE CURRENT ITEMS TO WORK WITH */
if ($cacti_camm_components["snmptt"]) {
camm_debug("S1.1 Use SNMPTT component");
db_execute("UPDATE `plugin_camm_snmptt` set status=1 where status=0");
// ñîõðàíèì îáùùåå êîëè÷åñòâî ñîîáùåíèé äî íà÷àëà ðàáîòû ñ ïðàâèëàìè
$stat_allTraps=mysqli_affected_rows($cacti_camm_components);
}else{
$stat_ruleDeleTraps = 0;
}

if ($cacti_camm_components["syslog"]) {
camm_debug("S1.1 Use SYSLOG component");
if ((strlen(trim(read_config_option("camm_syslog_pretable_name"))) > 0) && (read_config_option("camm_syslog_pretable_name") != "plugin_camm_syslog")) {
$syslog_use_pretable = true;
$syslog_table = '`' . read_config_option("camm_syslog_db_name") . '`.`' . read_config_option("camm_syslog_pretable_name") . '`';
}else{
$syslog_use_pretable = false;
$syslog_table = '`' . read_config_option("camm_syslog_db_name") . '`.`plugin_camm_syslog`';
}
db_execute("UPDATE " . $syslog_table . " set status=1 where status=0");
// ñîõðàíèì îáùùåå êîëè÷åñòâî ñîîáùåíèé äî íà÷àëà ðàáîòû ñ ïðàâèëàìè
$stat_allSyslogs=mysqli_affected_rows ($cacti_camm_components);
}else{
$stat_allSyslogs = 0;
}
Last edited by Moegoe on Thu Mar 11, 2021 3:44 am, edited 1 time in total.
Moegoe
Posts: 16
Joined: Sun Aug 04, 2019 7:13 am

Re: Progammers/Developers - please help Ubuntu PHP7 and CaMM rules **SOLVED**

Post by Moegoe »

Turns out the syntax structure for the connection to your database has changed as well within PHP7 updates.

Fixed it by adding in poller_camm_php under "function process_rules()"

$link = mysqli_connect("localhost", "YourMysqlUsername", "YourMysqlPassword", "YourDatabaseName");

And then change a bit lower down:

comment out: #db_execute("UPDATE `plugin_camm_snmptt` set status=1 where status=0");
REPLACE WITH
mysqli_query($link, "UPDATE `plugin_camm_snmptt` set status=1 where status=0");

- and change to: $stat_allTraps=mysqli_affected_rows($link);

This only takes care of the SNMPTT entries in your syslog -

* Do the same procedure a bit lower down for the "syslog" entry as well.

Maybe this will help someone else - took me 2 weeks and weekends to figure out...lol
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests