Cacti (home)ForumsRepositoryDocumentation
Cacti: offical forums and support
It is currently Sat Aug 23, 2014 4:26 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Unknown status: I'm stuck [Solved]
PostPosted: Mon Sep 19, 2011 5:44 pm 
Offline
Cacti User

Joined: Thu Jul 30, 2009 3:13 am
Posts: 85
Hello,

I open a new topic after this one
Cacti in a chrooted Apache

I've searched, searched, searched...it still doesn't work

I have one host 127.0.0.1 and it's showing unknown status
- I'm able to snmpwalk, snmpget, snmpbulkwalk and snmpgetnext from inside the jail
- At least one graph is created for my host
- The cron is running (checked /var/cron/log)

After some investigations in lib/database.php I notice that
Code:
echo "testA\n";
                if ($cnn->pconnect($hostport,$user,$pass,$db_name)) {
echo "testB\n";

testA is displayed, testB is never displayed

It's like the cron job that executes the poller.php or if i execute cmd.php, the scripts stop silently without any warnings.

I'm not sure where should I search

_________________
Some info about my system
- Cacti: 0.8.8b / OpenBSD 5.3
- Third Party: Apache 1.3.29 / PHP 5.3.21 / MySQLd 5.1.68 / NET-SNMP version 5.7.2 / RRDTool 1.2.30
- Plugins: Weathermap 0.97a / Settings 0.71 / Thold 0.4.9 / Flowview 1.1 / Realtime 0.42


Last edited by mikygee on Fri Oct 07, 2011 4:17 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Unknown status: I'm stuck
PostPosted: Sun Sep 25, 2011 9:10 pm 
Offline
Cacti Guru User

Joined: Thu Aug 05, 2010 2:04 am
Posts: 1573
Location: Japan
This code imitates PConnect() function in 'lib/adodb/adodb.inc.php'.
Code:
<?php

include("./include/global.php");
include_once($config["library_path"] . "/database.php");

$cnn = ADONewConnection($database_type);

$cnn->host = $database_hostname;
$cnn->user = $database_username;
$cnn->password = $database_password;
$cnn->database = $database_default;

$cnn->_isPersistentConnection = true;
$cnn->debug = true;

if ($cnn->_pconnect($cnn->host, $cnn->user, $cnn->password, $cnn->database)) {
        echo "Success: _pconnect()\n";
} else {
        $err = $cnn->ErrorMsg();
        if (empty($err)) {
                $err = "Connection error to server '$database_hostname' with user '$database_username'";
        }
        echo "$err\n";
}

$cnn->Close();

?>

Place the above code in Cacti install directory, and try to perform that as normal user and poller user in jail.
What error do you see?


Top
 Profile  
 
 Post subject: Re: Unknown status: I'm stuck
PostPosted: Fri Sep 30, 2011 4:32 am 
Offline
Cacti User

Joined: Thu Jul 30, 2009 3:13 am
Posts: 85
Hello Thank you for this code,

As an http user I have
Code:
Success: _pconnect()


As a poller I have
Code:
# /usr/sbin/chroot /var/www /bin/php /htdocs/metrologie/cacti/testadodb.php
PHP Warning:  include(./include/global.php): failed to open stream: No such file or directory in /htdocs/metrologie/cacti/testadodb.php on line 3

Warning: include(./include/global.php): failed to open stream: No such file or directory in /htdocs/metrologie/cacti/testadodb.php on line 3
PHP Warning:  include(): Failed opening './include/global.php' for inclusion (include_path='.:/pear/lib:/var/www/pear/lib') in /htdocs/metrologie/cacti/testadodb.php on line 3

Warning: include(): Failed opening './include/global.php' for inclusion (include_path='.:/pear/lib:/var/www/pear/lib') in /htdocs/metrologie/cacti/testadodb.php on line 3
PHP Notice:  Undefined variable: config in /htdocs/metrologie/cacti/testadodb.php on line 4

Notice: Undefined variable: config in /htdocs/metrologie/cacti/testadodb.php on line 4
PHP Warning:  include_once(/database.php): failed to open stream: No such file or directory in /htdocs/metrologie/cacti/testadodb.php on line 4

Warning: include_once(/database.php): failed to open stream: No such file or directory in /htdocs/metrologie/cacti/testadodb.php on line 4
PHP Warning:  include_once(): Failed opening '/database.php' for inclusion (include_path='.:/pear/lib:/var/www/pear/lib') in /htdocs/metrologie/cacti/testadodb.php on line 4

Warning: include_once(): Failed opening '/database.php' for inclusion (include_path='.:/pear/lib:/var/www/pear/lib') in /htdocs/metrologie/cacti/testadodb.php on line 4
PHP Fatal error:  Call to undefined function ADONewConnection() in /htdocs/metrologie/cacti/testadodb.php on line 6

Fatal error: Call to undefined function ADONewConnection() in /htdocs/metrologie/cacti/testadodb.php on line 6


So yes it seems there's a problem when the poller is trying to work. A path problem. Thank you for this test, I'm going to try to think more in this direction.

_________________
Some info about my system
- Cacti: 0.8.8b / OpenBSD 5.3
- Third Party: Apache 1.3.29 / PHP 5.3.21 / MySQLd 5.1.68 / NET-SNMP version 5.7.2 / RRDTool 1.2.30
- Plugins: Weathermap 0.97a / Settings 0.71 / Thold 0.4.9 / Flowview 1.1 / Realtime 0.42


Top
 Profile  
 
 Post subject: Re: Unknown status: I'm stuck
PostPosted: Fri Sep 30, 2011 5:16 am 
Offline
Cacti Guru User

Joined: Thu Aug 05, 2010 2:04 am
Posts: 1573
Location: Japan
Hmm, it seems to fail to include 'global.php'...
(But sorry, I'm not sure how chroot/jail works)

When you change the first line of 'testadodb.php' as follows, do you get errors?
Code:
include(dirname(__FILE__) . "/include/global.php");


If it didn't solved, then try to modify 'cacti/poller.php':
Quote:
/* start initialization section */
include(dirname(__FILE__) . "/include/global.php");
include_once($config["base_path"] . "/lib/poller.php");
...
to
Quote:
/* start initialization section */
include("/full-path-name-to-cacti/include/global.php");
include_once($config["base_path"] . "/lib/poller.php");
...


If still failed, maybe you should also modify following part in 'include/global.php'.. (not sure)
Quote:
/* used for includes */
$config["base_path"] = strtr(ereg_replace("(.*)[\\\/]include", "\\1", dirname(__FILE__)), "\\", "/");
$config["library_path"] = ereg_replace("(.*[\\\/])include", "\\1lib", dirname(__FILE__));
$config["include_path"] = dirname(__FILE__);
$config["rra_path"] = $config["base_path"] . '/rra';


Top
 Profile  
 
 Post subject: Re: Unknown status: I'm stuck
PostPosted: Fri Sep 30, 2011 5:25 am 
Offline
Cacti User

Joined: Thu Jul 30, 2009 3:13 am
Posts: 85
Thank you !

Changing the first line to
Code:
include(dirname(__FILE__) . "/include/global.php");

works with both http request and cli

So I suppose this workaround has to be implemented somewhere.

_________________
Some info about my system
- Cacti: 0.8.8b / OpenBSD 5.3
- Third Party: Apache 1.3.29 / PHP 5.3.21 / MySQLd 5.1.68 / NET-SNMP version 5.7.2 / RRDTool 1.2.30
- Plugins: Weathermap 0.97a / Settings 0.71 / Thold 0.4.9 / Flowview 1.1 / Realtime 0.42


Top
 Profile  
 
 Post subject: Re: Unknown status: I'm stuck
PostPosted: Sat Oct 01, 2011 4:54 am 
Offline
Cacti User

Joined: Thu Jul 30, 2009 3:13 am
Posts: 85
I've continued my debugging without any success.

In global.php, I have
Code:
echo "DEBUG: Global.php BEFORE DB_CONNECT_REAL -> $database_hostname, $database_username, $database_password, $database_default, $database_type, $database_port<br>\n";
db_connect_real($database_hostname, $database_username, $database_password, $database_default, $database_type, $database_port);
echo "DEBUG: Global.php DB_CONNECT_REAL passed<br>\n";


In lib/database.php, I have
Code:
        while ($i <= $retries) {
echo "DEBUG: Loop In<br>\n";
                if ($cnn->PConnect($hostport,$user,$pass,$db_name)) {
echo "DEBUG: PConnect OK<br>\n";
                        return($cnn);
                }
echo "DEBUG: After PConnect\n";
                $i++;

                usleep(40000);
        }


In lib/adodb/adodb.inc.php, I have within the function function PConnect
Code:
echo "DEBUG: lib/adodb/adodb.inc.php $this->host, $this->user, $this->password, $this->database<br>\n";
                $debug_pconnect = $this->_pconnect($this->host, $this->user, $this->password, $this->database);
echo "DEBUG: lib/adodb/adodb.inc.php >$debug_pconnect<";


To sum up: global.php calls lib/database.php which calls lib/adodb/adodb.inc.php

My results
1) In command line
Code:
# /usr/sbin/chroot /var/www /bin/php /htdocs/metrologie/cacti/poller.php
DEBUG: Global.php BEFORE DB_CONNECT_REAL -> 127.0.0.1, cacti, cactipw, cactidb, mysql, 3306<br>
DEBUG: Loop In<br>
DEBUG: lib/adodb/adodb.inc.php 127.0.0.1:3306, cacti, cactipw, cactidb<br>
#

2) In http
Code:
DEBUG: Global.php BEFORE DB_CONNECT_REAL -> 127.0.0.1, cacti, cactipw, cactidb, mysql, 3306
DEBUG: Loop In
DEBUG: lib/adodb/adodb.inc.php 127.0.0.1:3306, cacti, cactipw, cactidb
DEBUG: lib/adodb/adodb.inc.php >1<
DEBUG: PConnect OK
DEBUG: Global.php DB_CONNECT_REAL passed


Conclusion:
In the file lib/adodb/adodb.inc.php, the line
Code:
$debug_pconnect = $this->_pconnect($this->host, $this->user, $this->password, $this->database);


1) Seems to crash when I run poller.php with the command line
Code:
# /usr/sbin/chroot /var/www /bin/php /htdocs/metrologie/cacti/poller.php


2) Returns 1 when I run in GUI

Now I have no idea why it crashes silently

_________________
Some info about my system
- Cacti: 0.8.8b / OpenBSD 5.3
- Third Party: Apache 1.3.29 / PHP 5.3.21 / MySQLd 5.1.68 / NET-SNMP version 5.7.2 / RRDTool 1.2.30
- Plugins: Weathermap 0.97a / Settings 0.71 / Thold 0.4.9 / Flowview 1.1 / Realtime 0.42


Top
 Profile  
 
 Post subject: Re: Unknown status: I'm stuck
PostPosted: Mon Oct 03, 2011 4:23 am 
Offline
Cacti Guru User

Joined: Thu Aug 05, 2010 2:04 am
Posts: 1573
Location: Japan
mikygee wrote:
Conclusion:
In the file lib/adodb/adodb.inc.php, the line
Code:
$debug_pconnect = $this->_pconnect($this->host, $this->user, $this->password, $this->database);


1) Seems to crash when I run poller.php with the command line
Code:
# /usr/sbin/chroot /var/www /bin/php /htdocs/metrologie/cacti/poller.php


2) Returns 1 when I run in GUI

Mmm...

(Just googling) Does this issue relate?
- https://forums.snort.org/forums/third-party-tools/topics/base#post_53628

What about "socket=" in your my.cnf?


Top
 Profile  
 
 Post subject: Re: Unknown status: I'm stuck
PostPosted: Tue Oct 04, 2011 4:41 pm 
Offline
Cacti User

Joined: Thu Jul 30, 2009 3:13 am
Posts: 85
Hello I'm still searching for the correct solution.

From the begining mysqld is started like this
Code:
# /usr/local/bin/mysqld_safe --user=_mysql --pid-file=/var/mysql/mysql.pid &


I have configured /etc/my.cnf in my base system like this
Code:
[mysqld]
socket          = /var/www/var/run/mysql/mysql.sock


Once mysqld is started I have the mysql.sock created in /var/www/var/run/mysql
Code:
# ls /var/www/var/run/mysql/
mysql.sock


I hard linked it to /var/run/mysql/
Code:
# ln -s /var/www/var/run/mysql/mysql.sock /var/run/mysql/mysql.sock


I have downloaded adodb5 and placed it in /var/www, then adapted this code for test purpose
Code:
<?php
include('../adodb5/adodb.inc.php');
$conn = &ADONewConnection('mysql');
$conn->PConnect('localhost','cacti','cactipw','cactidb');
$sql = 'select hostname,description from host;';
$recordSet = &$conn->Execute($sql);
if (!$recordSet)
        print $conn->ErrorMsg();
else
while (!$recordSet->EOF) {
        print $recordSet->fields[0].' '.$recordSet->fields[1].'<BR>';
        $recordSet->MoveNext();
}
$recordSet->Close();
$conn->Close();
?>



Case 1: The script is ran without any chroot consideration => Works
Code:
# /usr/local/bin/php /var/www/htdocs/adotest.php
127.0.0.1 System1<BR>1.1.1.1 System2<BR>


Case 2: The script is ran through the apache chrooted server using the url http://localhost/adotest.php => Works
Code:
127.0.0.1 System1
1.1.1.1 System2


Case 3: The script is ran in command line and simulates a user running it in the chroot (/var/www) => Fails
Code:
# /usr/sbin/chroot /var/www /bin/php /htdocs/adotest.php
PHP Fatal error:  Call to undefined function mysql_pconnect() in /adodb5/drivers/adodb-mysql.inc.php on line 383
Fatal error: Call to undefined function mysql_pconnect() in /adodb5/drivers/adodb-mysql.inc.php on line 383

Note that: the adotest.php script was able to include /adodb5/drivers/adodb-mysql.inc.php

I also copied /etc/my.cnf in /var/www/etc but changed the path for the client
Code:
[client]
socket         = /var/run/mysql/mysql.sock


I thought that maybe there is something wrong with connecting to mysql inside the chroot so I copied the mysql client inside the chroot (/var/www) and the associated dynamic libraries.
But everything worked when I tried to connect to the database
Code:
# /bin/mysql -u cacti -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6


So one thing seems to be clear now. Cacti is not woking inside the chroot because of adodb. It doesn't seem to be a problem with cacti at all. The only thing that I can say is that when the poller seems to mute when it fails to connect to the database, probably the cacti guys didn't activate error messages with adodb.

noname, I would like to thank you for helping me with this, I know it's not easy to follow a problem like this one.

_________________
Some info about my system
- Cacti: 0.8.8b / OpenBSD 5.3
- Third Party: Apache 1.3.29 / PHP 5.3.21 / MySQLd 5.1.68 / NET-SNMP version 5.7.2 / RRDTool 1.2.30
- Plugins: Weathermap 0.97a / Settings 0.71 / Thold 0.4.9 / Flowview 1.1 / Realtime 0.42


Top
 Profile  
 
 Post subject: Re: Unknown status: I'm stuck
PostPosted: Fri Oct 07, 2011 4:16 pm 
Offline
Cacti User

Joined: Thu Jul 30, 2009 3:13 am
Posts: 85
Hello noname,

I just wanted to say that this problem is now solved, and I thank you for your support.
The solution is that php was not loading mysql.so when executed in command line inside the chroot. It needs to be configured with the proper path in the php.ini
Outside the chroot there was the standard php.ini (Case 1) and Apache was loading properly the mysql.so inside the chroot (Case 2) that's why it worked in these cases.

I have other problems now but I have not searched enough yet to ask the question.

:roll: 3 weeks to solve this topic and that will probably need 2 months of intense debugging to make Cacti work inside the openbsd apache chroot. Glooops

This specific topic is now considered closed and solved

_________________
Some info about my system
- Cacti: 0.8.8b / OpenBSD 5.3
- Third Party: Apache 1.3.29 / PHP 5.3.21 / MySQLd 5.1.68 / NET-SNMP version 5.7.2 / RRDTool 1.2.30
- Plugins: Weathermap 0.97a / Settings 0.71 / Thold 0.4.9 / Flowview 1.1 / Realtime 0.42


Top
 Profile  
 
 Post subject: Re: Unknown status: I'm stuck
PostPosted: Mon Oct 10, 2011 7:45 pm 
Offline
Cacti Guru User

Joined: Thu Aug 05, 2010 2:04 am
Posts: 1573
Location: Japan
mikygee wrote:
The solution is that php was not loading mysql.so when executed in command line inside the chroot. It needs to be configured with the proper path in the php.ini
Outside the chroot there was the standard php.ini (Case 1) and Apache was loading properly the mysql.so inside the chroot (Case 2) that's why it worked in these cases.

Thanks for detailed investigation.
That surely provides others which faced to similar situations with a clue..


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Yahoo [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Protected by Anti-Spam ACP Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group