Routerconfigs plugin / how it works?

Discussions on developing plugins for the Cacti Plugin Architecture

Moderators: Developers, Moderators

Post Reply
dieselboy
Cacti User
Posts: 135
Joined: Wed May 27, 2009 5:10 pm

Post by dieselboy »

I would like this command to work but it doesnt follow.

Code: Select all

// If HP skip re-connecting to the device and causing a false positive
			if ($value !="HP") {
	        	$result = $telnet->Connect($device['ipaddress'], $info['username'], $info['password'], $info['enablepw'], $devicetype);
       	        	$debug = $telnet->debug;
			$telnet->DoCommand($devicetype['enable'], $result);
			$debug .= $result;
			//echo $result;
			$telnet->DoCommand($info['password'], $result);
			$debug .= $result;
			//echo $result;
			$telnet->DoCommand($devicetype['copytftp'], $result);
			$debug .= $result;
			echo $result;
			$telnet->DoCommand($tftpserver, $result);
			$debug .= $result;
			echo $result;
			$telnet->DoCommand($filename, $result);
			$debug .= $result;
			echo $result;
it gives up after logging in and will not enter the commands:

1) enable
2) user password

any ideas? :cry:
grady
Cacti User
Posts: 60
Joined: Wed Feb 20, 2008 5:02 pm

Post by grady »

What do you mean it doesnt follow?
dieselboy
Cacti User
Posts: 135
Joined: Wed May 27, 2009 5:10 pm

Post by dieselboy »

It doesn't follow that rule set. I put an enable command in there and it doesn't run it at all.
I've tried setting the device as auto detect and cisco ios without change.
grady
Cacti User
Posts: 60
Joined: Wed Feb 20, 2008 5:02 pm

Post by grady »

A little ways up you should see:

Code: Select all

        $telnet = new PHPTelnet();
Near the bottom of the file is that PHPTelnet class. Do you have the code after the

Code: Select all

                                        # Get > to show we are at the command prompt and ready to input the en command
comment in that class that looks for the different cisco prompts?
dieselboy
Cacti User
Posts: 135
Joined: Wed May 27, 2009 5:10 pm

Post by dieselboy »

It has that code. Not sure how to fix this :/
grady
Cacti User
Posts: 60
Joined: Wed Feb 20, 2008 5:02 pm

Post by grady »

Youre still running it from the command line? If so does it eventually error out or just hang forever or what? It ought to work fine. I have updated code if you'd like to try it. (I've now extended it to work with HP and Foundry devices)
dieselboy
Cacti User
Posts: 135
Joined: Wed May 27, 2009 5:10 pm

Post by dieselboy »

It gets to the enable prompt and doesn't go any further. The command you mentioned above where it looks for the enable prompt is there, but I couldn't say why it is not finding the enable prompt :/
Thanks for the update Ill give it a try when I'm near a computer next.
grady
Cacti User
Posts: 60
Joined: Wed Feb 20, 2008 5:02 pm

Post by grady »

Yeah, I'd run it from cli using php /cactipath/plugins/routerconfigs/router-download.php and watch it til it completes. Ive removed some of the echo stuff from the script (cause I didnt need it) and as such the debug information isnt always useful. When it finishes it'll either say failed or success and why. Post that.
dieselboy
Cacti User
Posts: 135
Joined: Wed May 27, 2009 5:10 pm

Post by dieselboy »

Code: Select all

[root@localhost ~]# php /var/www/html/plugins/routerconfigs/router-download.php
Processing asa
PHP Notice:  Undefined index:  enablepw in /var/www/html/plugins/routerconfigs/functions.php on line 337

Notice: Undefined index:  enablepw in /var/www/html/plugins/routerconfigs/functions.php on line 337
PHP Warning:  Invalid argument supplied for foreach() in /var/www/html/plugins/routerconfigs/functions.php on line 127

Warning: Invalid argument supplied for foreach() in /var/www/html/plugins/routerconfigs/functions.php on line 127
PHP Notice:  Undefined variable: result in /var/www/html/plugins/routerconfigs/functions.php on line 140

Notice: Undefined variable: result in /var/www/html/plugins/routerconfigs/functions.php on line 140
PHP Notice:  Undefined variable: value in /var/www/html/plugins/routerconfigs/functions.php on line 142

Notice: Undefined variable: value in /var/www/html/plugins/routerconfigs/functions.php on line 142
ÿûÿûÿûÿû

User Access Verification

Username: admin
Password: **********
Type help or '?' for a list of available commands.
ASA-01> Login failed333PHP Notice:  Undefined variable: value in /var/www/html/plugins/routerconfigs/functions.php on line 207

Notice: Undefined variable: value in /var/www/html/plugins/routerconfigs/functions.php on line 207
Saving Debug
Processing switch
PHP Notice:  Undefined index:  enablepw in /var/www/html/plugins/routerconfigs/functions.php on line 337

Notice: Undefined index:  enablepw in /var/www/html/plugins/routerconfigs/functions.php on line 337
PHP Notice:  Undefined variable: result in /var/www/html/plugins/routerconfigs/functions.php on line 140

Notice: Undefined variable: result in /var/www/html/plugins/routerconfigs/functions.php on line 140
ÿûÿûÿýÿý

User Access Verification

Username: ÿþ ÿúÿðÿþ'ÿýadmin
Password:

3750-1>Login failed333Saving Debug
04/26/2010 10:58:39 AM - RouterConfigs: Poller[0] -1272279345 seconds
0 devices backed up successfully.
2 devices failed to backup.

These devices failed to backup
--------------------------------
asa - Login failed
switch - Login failed
[root@localhost ~]#
Here is the complete output under the command line. Thanks for helping.. I've tried to get it working myself but any changes I make to the functions.php either don't work or run or I get a blank page with a php syntax error when I load the page..
grady
Cacti User
Posts: 60
Joined: Wed Feb 20, 2008 5:02 pm

Post by grady »

It almost looks like theres a syntax error in functions that while not severe enough to cause it to not run, has made it unaware of the enablepw variable. Back that file up and try this one out of the box from the command line again and post the results if you would.
Attachments
functions.txt
(28.49 KiB) Downloaded 741 times
dieselboy
Cacti User
Posts: 135
Joined: Wed May 27, 2009 5:10 pm

Post by dieselboy »

Here is the CLI output with the new functions:

Code: Select all

[root@localhost ~]# php /var/www/html/plugins/routerconfigs/router-download.php
Processing asa
PHP Notice:  Undefined index:  enablepw in /var/www/html/plugins/routerconfigs/functions.php on line 337

Notice: Undefined index:  enablepw in /var/www/html/plugins/routerconfigs/functions.php on line 337
PHP Warning:  Invalid argument supplied for foreach() in /var/www/html/plugins/routerconfigs/functions.php on line 127

Warning: Invalid argument supplied for foreach() in /var/www/html/plugins/routerconfigs/functions.php on line 127
PHP Notice:  Undefined variable: result in /var/www/html/plugins/routerconfigs/functions.php on line 140

Notice: Undefined variable: result in /var/www/html/plugins/routerconfigs/functions.php on line 140
PHP Notice:  Undefined variable: value in /var/www/html/plugins/routerconfigs/functions.php on line 142

Notice: Undefined variable: value in /var/www/html/plugins/routerconfigs/functions.php on line 142
ÿûÿûÿûÿû

User Access Verification

Username: admin
Password: **********
Type help or '?' for a list of available commands.
ASA-01> Login failed333PHP Notice:  Undefined variable: value in /var/www/html/plugins/routerconfigs/functions.php on line 207

Notice: Undefined variable: value in /var/www/html/plugins/routerconfigs/functions.php on line 207
Saving Debug
Processing switch
PHP Notice:  Undefined index:  enablepw in /var/www/html/plugins/routerconfigs/functions.php on line 337

Notice: Undefined index:  enablepw in /var/www/html/plugins/routerconfigs/functions.php on line 337
PHP Notice:  Undefined variable: result in /var/www/html/plugins/routerconfigs/functions.php on line 140

Notice: Undefined variable: result in /var/www/html/plugins/routerconfigs/functions.php on line 140
ÿûÿûÿýÿý

User Access Verification

Username: ÿþ ÿúÿðÿþ'ÿýadmin
Password:

3750-1>Login failed333Saving Debug
04/26/2010 02:26:15 PM - RouterConfigs: Poller[0] -1272291801 seconds
0 devices backed up successfully.
2 devices failed to backup.

These devices failed to backup
--------------------------------
asa - Login failed
switch - Login failed
[root@localhost ~]#

Where does it get the enablepw info from?
grady
Cacti User
Posts: 60
Joined: Wed Feb 20, 2008 5:02 pm

Post by grady »

Right below this comment (//If non-cisco use PHPTelnetHP class vs standard
) is a select statement that's then run through a foreach and if block. Let's add the following to it: (underneath the foreach and then its opening brace)

Code: Select all

echo "value is $value"; 
Then run it again and post the output. I just want to make sure that the select is functioning as expected. After that run well throw some additional echos in to see whats breaking and why.
dieselboy
Cacti User
Posts: 135
Joined: Wed May 27, 2009 5:10 pm

Post by dieselboy »

I do not have that line but there is one similar:

Code: Select all

//If HP use PHPTelnetHP class vs standard 
	echo "value is $value";
I put the echo as above and here is the output:

Code: Select all

[root@localhost ~]# php /var/www/html/plugins/routerconfigs/router-download.php
Processing asa
PHP Notice:  Undefined variable: value in /var/www/html/plugins/routerconfigs/functions.php on line 126

Notice: Undefined variable: value in /var/www/html/plugins/routerconfigs/functions.php on line 126
value is PHP Warning:  Invalid argument supplied for foreach() in /var/www/html/plugins/routerconfigs/functions.php on line 1

Warning: Invalid argument supplied for foreach() in /var/www/html/plugins/routerconfigs/functions.php on line 128
PHP Notice:  Undefined variable: result in /var/www/html/plugins/routerconfigs/functions.php on line 141

Notice: Undefined variable: result in /var/www/html/plugins/routerconfigs/functions.php on line 141
PHP Notice:  Undefined variable: value in /var/www/html/plugins/routerconfigs/functions.php on line 143

Notice: Undefined variable: value in /var/www/html/plugins/routerconfigs/functions.php on line 143
ÿûÿûÿûÿû

User Access Verification

Username: admin
Password:
Username: Login failed333PHP Notice:  Undefined variable: value in /var/www/html/plugins/routerconfigs/functions.php on line 208

Notice: Undefined variable: value in /var/www/html/plugins/routerconfigs/functions.php on line 208
Saving Debug
Processing switch
PHP Notice:  Undefined variable: value in /var/www/html/plugins/routerconfigs/functions.php on line 126

Notice: Undefined variable: value in /var/www/html/plugins/routerconfigs/functions.php on line 126
value is PHP Notice:  Undefined variable: result in /var/www/html/plugins/routerconfigs/functions.php on line 141

Notice: Undefined variable: result in /var/www/html/plugins/routerconfigs/functions.php on line 141
ÿûÿûÿýÿý

User Access Verification

Username: ÿþ ÿúÿðÿþ'ÿýadmin
Password:

% Authentication failed

Username:
% Username:  timeout expired!Login failed333Saving Debug
04/27/2010 11:26:48 AM - RouterConfigs: Poller[0] -1272367436 seconds
0 devices backed up successfully.
2 devices failed to backup.

These devices failed to backup
--------------------------------
asa - Login failed
switch - Login failed
[root@localhost ~]#
grady
Cacti User
Posts: 60
Joined: Wed Feb 20, 2008 5:02 pm

Post by grady »

Strange, I dont see that echo in your output. It looks like the select is what's breaking. (select being the if $value == "HP" line) For some reason it looks like it's not executing that if block. Underneath the if $value == HP line add in a

Code: Select all

echo "are we here?";
and rerun it. Let's see if that shows up in the output.
dieselboy
Cacti User
Posts: 135
Joined: Wed May 27, 2009 5:10 pm

Post by dieselboy »

Hmm. I cannot see that line but I can see these lines:

Code: Select all

//end class use 
		if ($result == 0) {
// If HP skip re-connecting to the device and causing a false positive
			if ($value !="HP") {
I'm wondering what PHP version you are using, sicne I'm not using the latest. I'm using the CactiEZ pre-built software. I have just started a fresh with your original final functions.php file and it doesnt work then so it isnt breaking because of any thing I have done, but I am wondering if it's because of the php version I am using.
I'll try upgrading, and if I don't break everything else in the process I'll re-try and see what happens.
In the meantime, since I have two servers I can pursue both simultaneously - I just cannot see the == HP line, unless you mean != HP

Thanks again
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests