Cacti (home)ForumsRepositoryDocumentation
Cacti: offical forums and support  

 FAQFAQ   SearchSearch   MemberlistMemberlist    RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in    


Division by Zero

 
Post new topic   Reply to topic    Cacti Forum Index -> Help: Linux/Unix Specific
Author Message
ccogdill



Joined: 25 Apr 2007
Posts: 30
Location: Bismarck, ND

PostPosted: Fri May 30, 2008 10:43 am    Post subject: Division by Zero Reply with quote

I am having a problem with division by zero when I create new graphs for any host. I have traced the problem down to switching the poller interval from one minute to five minutes. When the poller interval is set to one minute everything is fine. However, when I set the poller interval to 5 minutes that is when I receive the following error. Can someone please help with this? Is it a bug in Cacti or am I doing something wrong? I have searched and searched the forums but no luck.

ERROR MESSAGE:
-----------------------------------
Warning: Division by zero in /opt/cacti/lib/api_poller.php on line 119

Warning: Cannot modify header information - headers already sent by (output started at /opt/cacti/lib/api_poller.php:119) in /opt/cacti/graphs_new.php on line 323

CRONTAB SETTINGS:
---------------------------------------
Crontab used with one minute poller:
* * * * * /opt/php/bin/php /opt/cacti/poller.php > /dev/null 2>&1

Crontab used with five minute poller setting:
0,5,10,15,20,25,30,35,40,45,50,55 * * * * /opt/php/bin/php /opt/cacti/poller.php > /dev/null 2>&1

I have also tried this one as well
5,10,15,20,25,30,35,40,45,50,55 * * * * /opt/php/bin/php /opt/cacti/poller.php > /dev/null 2>&1


ENVIRONMENT
---------------------------
OS: Solaris 10 update 5
Apache 2.2.8
PHP 5.2.5
libxml 2.6.31
MySQL 5.0.51a
rrdtool 1.2.x
Cacti 0.8.7b (with settings 0.5 and thold 0.3.9
Spine 0.8.7a
Perl 5.10.0



broken.png
 Description:
 Filesize:  22.54 KB
 Viewed:  1210 Time(s)

broken.png



works.png
 Description:
 Filesize:  20.71 KB
 Viewed:  1210 Time(s)

works.png


Back to top
TheWitness
Developer


Joined: 14 May 2002
Posts: 9671
Location: MI, USA

PostPosted: Sun Jun 01, 2008 7:48 am    Post subject: Reply with quote

It looks as though poller.php is not creating a session file to maintain variable state. The error message seems to indicate that the variable $poller_interval is uninitialized, which it should not be due to the fact that it is initialized in the following:

Code:
$poller_interval = read_config_option("poller_interval")


A few lines before. You should attempt to patch Cacti. Goto the web site and look at the current patches for 0.8.7b. I think there is one in there specific to this problem maybe. Not 100% sure. It's definitely configuration related though.

TheWitness
Back to top
nduda78
Cacti User


Joined: 01 Mar 2005
Posts: 106

PostPosted: Tue Jul 29, 2008 7:55 am    Post subject: Reply with quote

I am in the same boat here...
Back to top
TheWitness
Developer


Joined: 14 May 2002
Posts: 9671
Location: MI, USA

PostPosted: Tue Jul 29, 2008 8:33 pm    Post subject: Reply with quote

Make sure you are running 0.8.7b and not "a".

TheWitness
Back to top
nduda78
Cacti User


Joined: 01 Mar 2005
Posts: 106

PostPosted: Wed Jul 30, 2008 4:59 am    Post subject: Reply with quote

I am running 8.7b with all patches
Back to top
TheWitness
Developer


Joined: 14 May 2002
Posts: 9671
Location: MI, USA

PostPosted: Wed Jul 30, 2008 5:23 am    Post subject: Reply with quote

This may be PHP specific. Try the modified code below and see if the error goes away. Please post updates here.

Code:
      if ($modulus == 0) {
         $rrd_next_step = 0;
      }else{
         $rrd_next_step = $poller_interval * ($rrd_step_counter % $modulus);


TheWitness
Back to top
nduda78
Cacti User


Joined: 01 Mar 2005
Posts: 106

PostPosted: Wed Jul 30, 2008 5:41 am    Post subject: Reply with quote

TheWitness wrote:
This may be PHP specific. Try the modified code below and see if the error goes away. Please post updates here.

Code:
      if ($modulus == 0) {
         $rrd_next_step = 0;
      }else{
         $rrd_next_step = $poller_interval * ($rrd_step_counter % $modulus);


TheWitness


Thanks Witness, I'll try as soon as I get into work in 30min or so. What file is that, not that it matters I can grep for the text.
Back to top
nduda78
Cacti User


Joined: 01 Mar 2005
Posts: 106

PostPosted: Wed Jul 30, 2008 7:20 am    Post subject: Reply with quote

I get this when i try to reindex with your changes:
Parse error: syntax error, unexpected $end in /www/htdocs/cacti/lib/api_poller.php on line 145

Here is what api_poller.php looks like:

<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2008 The Cacti Group |
| |
| This program is free software; you can redistribute it and/or |
| modify it under the terms of the GNU General Public License |
| as published by the Free Software Foundation; either version 2 |
| of the License, or (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
+-------------------------------------------------------------------------+
| Cacti: The Complete RRDTool-based Graphing Solution |
+-------------------------------------------------------------------------+
| This code is designed, written, and maintained by the Cacti Group. See |
| about.php and/or the AUTHORS file for specific developer information. |
+-------------------------------------------------------------------------+
| http://www.cacti.net/ |
+-------------------------------------------------------------------------+
*/

function api_poller_cache_item_add($host_id, $host_field_override, $local_data_id, $rrd_step, $poller_action_id, $data_source_item_name, $num_rrd_items, $arg1 = "", $arg2 = "", $arg3 = "") {
$host = db_fetch_row("select
host.id,
host.hostname,
host.snmp_community,
host.snmp_version,
host.snmp_username,
host.snmp_password,
host.snmp_auth_protocol,
host.snmp_priv_passphrase,
host.snmp_priv_protocol,
host.snmp_context,
host.snmp_port,
host.snmp_timeout,
host.disabled
from host
where host.id=$host_id");

/* the $host_field_override array can be used to override certain host fields in the poller cache */
if (isset($host)) {
$host = array_merge($host, $host_field_override);
}

if (isset($host["id"]) || (isset($host_id))) {
if (isset($host)) {
if ($host["disabled"] == "on") {
return true;
}
} else {
if ($poller_action_id == 0) {
return true;
}

$host["id"] = 0;
$host["snmp_community"] = "";
$host["snmp_timeout"] = "";
$host["snmp_username"] = "";
$host["snmp_password"] = "";
$host["snmp_auth_protocol"] = "";
$host["snmp_priv_passphrase"] = "";
$host["snmp_priv_protocol"] = "";
$host["snmp_context"] = "";
$host["snmp_version"] = "";
$host["snmp_port"] = "";
$host["hostname"] = "None";
}

if ($poller_action_id == 0) {
if (($host["snmp_version"] < 1) || ($host["snmp_version"] > 3) ||
($host["snmp_community"] == "" && $host["snmp_version"] != 3)) {
return true;
}
}

$rrd_next_step = api_poller_get_rrd_next_step($rrd_step, $num_rrd_items);

return db_execute("INSERT INTO poller_item (local_data_id, host_id, action,hostname,
snmp_community, snmp_version, snmp_timeout, snmp_username, snmp_password,
snmp_auth_protocol, snmp_priv_passphrase, snmp_priv_protocol, snmp_context, snmp_port, rrd_name, rrd_path,
rrd_num, rrd_step, rrd_next_step, arg1, arg2, arg3)
VALUES
($local_data_id, " . $host["id"] . ", $poller_action_id,'" . $host["hostname"] . "',
'" . $host["snmp_community"] . "', '" . $host["snmp_version"] . "', '" . $host["snmp_timeout"] . "',
'" . $host["snmp_username"] . "', '" . $host["snmp_password"] . "', '" . $host["snmp_auth_protocol"] . "',
'" . $host["snmp_priv_passphrase"] . "', '" . $host["snmp_priv_protocol"] . "', '" . $host["snmp_context"] . "',
'" . $host["snmp_port"] . "', '$data_source_item_name', '" . addslashes(clean_up_path(get_data_source_path($local_data_id, true))) . "',
'$num_rrd_items', '$rrd_step', '$rrd_next_step', '$arg1', '$arg2', '$arg3')");
}
}

function api_poller_get_rrd_next_step($rrd_step=300, $num_rrd_items=1) {
global $config;

$poller_interval = read_config_option("poller_interval");
$rrd_next_step = 0;
if (($rrd_step != $poller_interval) && (isset($poller_interval))){
if (!isset($config["rrd_step_counter"])) {
$rrd_step_counter = read_config_option("rrd_step_counter");
}else{
$rrd_step_counter = $config["rrd_step_counter"];
}

if ($num_rrd_items == 1) {
$config["rrd_num_counter"] = 0;
}else{
if (!isset($config["rrd_num_counter"])) {
$config["rrd_num_counter"] = 1;
}else{
$config["rrd_num_counter"]++;
}
}

$modulus = $rrd_step / $poller_interval;

if ($modulus == 0) {
$rrd_next_step = 0;
}else{
$rrd_next_step = $poller_interval * ($rrd_step_counter % $modulus);

if ($num_rrd_items == 1) {
$rrd_step_counter++;
}else{
if ($num_rrd_items == $config["rrd_num_counter"]) {
$rrd_step_counter++;
$config["rrd_num_counter"] = 0;
}
}

if ($rrd_step_counter >= $modulus) {
$rrd_step_counter = 0;
}

/* save rrd_step_counter */
$config["rrd_step_counter"] = $rrd_step_counter;
db_execute("replace into settings (name, value) values ('rrd_step_counter','$rrd_step_counter')");
}

return $rrd_next_step;
}
?>
Back to top
TheWitness
Developer


Joined: 14 May 2002
Posts: 9671
Location: MI, USA

PostPosted: Wed Jul 30, 2008 9:45 pm    Post subject: Reply with quote

Sorry missed
Code:
}
at the end.

TheWitness
Back to top
nduda78
Cacti User


Joined: 01 Mar 2005
Posts: 106

PostPosted: Thu Jul 31, 2008 7:35 am    Post subject: Reply with quote

No go...re-indexing works, but rebuilding poller cache spits out:
Warning: Division by zero in /www/htdocs/cacti/lib/api_poller.php on line 122
Back to top
igorx



Joined: 14 Sep 2008
Posts: 4
Location: Russia

PostPosted: Sun Sep 14, 2008 4:21 am    Post subject: Reply with quote

Try php code
Code:

<?php print 3 % 0.5;?>

You get the error "div by zero". Only integer divider must be used with operator '%'

Code:

if ($modulus<1) {
         $rrd_next_step = 0;
      }else{
         $rrd_next_step = $poller_interval * ($rrd_step_counter % $modulus);
}
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Cacti Forum Index -> Help: Linux/Unix Specific All times are GMT - 5 Hours
Page 1 of 1

 



Powered by phpBB © 2001, 2005 phpBB Group