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 »

Doesnt this part of routerconfigs work for you any more? When I disable the checking of the configs, I still have the diff functionality. The only thing I disabled was to delete the config if it doesnt meet the criteria. Everything else seems to work fine.
grady
Cacti User
Posts: 60
Joined: Wed Feb 20, 2008 5:02 pm

Post by grady »

Nope, I seem to have busted it totally. It works for all other devices but not the HP stuff. The script thinks that it errors out, thus it isnt aware that its actually written a file to tftp. lol
dieselboy
Cacti User
Posts: 135
Joined: Wed May 27, 2009 5:10 pm

Post by dieselboy »

Oh, so the config file count still remains at zero even though there are files there?
Does it make a difference if you specify a new folder? As the functions file will check and create a new folder with propper permissions if there isnt - not sure if this will have any different outcome
grady
Cacti User
Posts: 60
Joined: Wed Feb 20, 2008 5:02 pm

Post by grady »

Attached is the updated functions file. RouterConfigs is now working for both Cisco & HP devices. (I've tested using a few of each) In order for this to work your HP devices need a username and a password. To configure them in that manner do the following and it'll prompt you for a password.

Code: Select all

#password manager <username>
You'll also need to update the plugin_routerconfigs_devicetypes table. Make sure that you replace x.x.x.x in the below insert with the IP address of your tftp server.

Code: Select all

mysql> insert into plugin_routerconfigs_devicetypes (id, name, username, password, copytftp, version, confirm, forceconfirm) values ('', 'HP', 'sername', 'assword', 'copy running-config tftp x.x.x.x', 'sh ver', '', '');
I'm sure that there are better / cleaner approaches to take here. But, this works and all functionality in the RouterConfig UI has been maintained.

Let me know if you run into problems.
Attachments
functions.txt
(30.68 KiB) Downloaded 577 times
dieselboy
Cacti User
Posts: 135
Joined: Wed May 27, 2009 5:10 pm

Post by dieselboy »

Thanks for posting this, I ran the SQL database command and I also copied your functions.php over. The problem I have is whenever I try to back up the HP device the page displays a load of php errors and no device is backed up.

Not quite sure of what is wrong. The debug just shows the initial telnet screen of the HP device "press any key to continue"
Any ideas?
grady
Cacti User
Posts: 60
Joined: Wed Feb 20, 2008 5:02 pm

Post by grady »

Very strange. It's failing now for me as well. I'm looking into root cause.
grady
Cacti User
Posts: 60
Joined: Wed Feb 20, 2008 5:02 pm

Post by grady »

What a wonky issue this turned out to be. On initial run it should have worked, and did for me last Friday. However, on 2nd run it would connect, upload the config to tftp and error out. The problem was caused by the following code:

Code: Select all

                        if (substr($d, 0, 9) == 'hostname ') {
                                $filename = trim(substr($d, 9));
                                if ($device['hostname'] != $filename) {
                                        db_execute("UPDATE plugin_routerconfigs_devices SET hostname = '$filename' WHERE id = " . $device['id']);
                                }
                        }
                        if (substr($d, 0, 17) == 'set system name ') {
                                $filename = trim(substr($d, 17));
                                if ($device['hostname'] != $filename) {
                                        db_execute("UPDATE plugin_routerconfigs_devices SET hostname = '$filename' WHERE id = " . $device['id']);
                                }
                        }
When HP devices were thrown through the above if statements the substr function tripped on itself and triggered a false positive. It'd look at $hostname and compare that to $filename. $filename is defined above and is $hostname in quotes. ($filename vs "$hostname") Thus it evaluated it to false, and appended the device name in the plugin_routerconfigs_devices table using db_execute. Since it'd modify the table it'd then break on each subsequent run b/c "hostname" will never equal hostname. I've fixed this as well as cleaned up the functions file. (added some comments and removed redundant code that I'd added)


I've been able to successfully complete backups for a mixed bag of devices. (IOS, IOS without needing enable, HP)

Give it a go using the attached functions.php and let me know how it goes. -Naturally make sure to back your original working one up prior.
Attachments
functions.txt
(29.61 KiB) Downloaded 401 times
dieselboy
Cacti User
Posts: 135
Joined: Wed May 27, 2009 5:10 pm

Post by dieselboy »

Nice work, I will give it a try now. Thanks for the update
dieselboy
Cacti User
Posts: 135
Joined: Wed May 27, 2009 5:10 pm

Post by dieselboy »

I can't seem to get that working either. I setup a packet capture and cacti only initiates a telnet session. The session closes and about a minute later the cacti screen refreshes with php errors. The HP device never tries to upload a config
I'm not sure what the problem is :/
grady
Cacti User
Posts: 60
Joined: Wed Feb 20, 2008 5:02 pm

Post by grady »

The stuff that's echoed out and saved as debug likely is worthless in figuring out what the problem is. Can you do a select * from plugin_routerconfigs_devicetypes; and post that output here? Also, on your HP switch you've configured it such that it requires a username and password? Did you replace your existing functions file with the one I posted or did you add stuff from mine to yours? Finally, from a command line run php /path/to/cacti/plugins/routerconfigs/router-download.php and watch the output there. That'll give you a better idea of why it isn't working.
dieselboy
Cacti User
Posts: 135
Joined: Wed May 27, 2009 5:10 pm

Post by dieselboy »

I'm not sure how to do a select from plugin command?

Here is the output when I run the routerconfigs php from the command line as you describe:

Code: Select all


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

Notice: Undefined index:  enablepw in /var/www/html/plugins/routerconfigs/functions.php on line 340
PHP Warning:  Missing argument 5 for PHPTelnetHP::Connect(), called in /var/www/html/plugins/routerconfigs/functions.php on line 131 and define2

Warning: Missing argument 5 for PHPTelnetHP::Connect(), called in /var/www/html/plugins/routerconfigs/functions.php on line 131 and defined in 2
PHP Notice:  Undefined variable: devicetype in /var/www/html/plugins/routerconfigs/functions.php on line 678

Notice: Undefined variable: devicetype in /var/www/html/plugins/routerconfigs/functions.php on line 678

          ÿýÿû
ProCurve J9087A Switch 2610-24-PWR
Software revision R.11.30

Copyright (C) 1991-2009 Hewlett-Packard Co.  All Rights Reserved.

                           RESTRICTED RIGHTS LEGEND

 Use, duplication, or disclosure by the Government is subject to restrictions
 as set forth in subdivision (b) (3) (ii) of the Rights in Technical Data and
 Computer Software clause at 52.227-7013.

         HEWLETT-PACKARD COMPANY, 3000 Hanover St., Palo Alto, CA 94303

We'd like to keep you up to date about:
  * Software feature updates
  * New product announcements
  * Special events

Please register your products now at:  www.ProCurve.com




Press any key to continue PHP Notice:  Undefined variable: devicetype in /var/www/html/plugins/routerconfigs/functions.php on line 695

Notice: Undefined variable: devicetype in /var/www/html/plugins/routerconfigs/functions.php on line 695























Username: admin
Password: PHP Notice:  Undefined variable: devicetype in /var/www/html/plugins/routerconfigs/functions.php on line 713

Notice: Undefined variable: devicetype in /var/www/html/plugins/routerconfigs/functions.php on line 713

Invalid password
Username: Login failedPHP Warning:  fputs(): 96 is not a valid stream resource in /var/www/html/plugins/routerconfigs/functions.php on line 770

Warning: fputs(): 96 is not a valid stream resource in /var/www/html/plugins/routerconfigs/functions.php on line 770
PHP Warning:  stream_set_timeout(): 96 is not a valid stream resource in /var/www/html/plugins/routerconfigs/functions.php on line 792

Warning: stream_set_timeout(): 96 is not a valid stream resource in /var/www/html/plugins/routerconfigs/functions.php on line 792
PHP Warning:  fread(): 96 is not a valid stream resource in /var/www/html/plugins/routerconfigs/functions.php on line 794

Warning: fread(): 96 is not a valid stream resource in /var/www/html/plugins/routerconfigs/functions.php on line 794
PHP Warning:  socket_get_status(): 96 is not a valid stream resource in /var/www/html/plugins/routerconfigs/functions.php on line 796

Warning: socket_get_status(): 96 is not a valid stream resource in /var/www/html/plugins/routerconfigs/functions.php on line 796
PHP Warning:  fputs(): 96 is not a valid stream resource in /var/www/html/plugins/routerconfigs/functions.php on line 780

Warning: fputs(): 96 is not a valid stream resource in /var/www/html/plugins/routerconfigs/functions.php on line 780
PHP Warning:  stream_set_timeout(): 96 is not a valid stream resource in /var/www/html/plugins/routerconfigs/functions.php on line 792

Warning: stream_set_timeout(): 96 is not a valid stream resource in /var/www/html/plugins/routerconfigs/functions.php on line 792
PHP Warning:  fread(): 96 is not a valid stream resource in /var/www/html/plugins/routerconfigs/functions.php on line 794

Warning: fread(): 96 is not a valid stream resource in /var/www/html/plugins/routerconfigs/functions.php on line 794
PHP Warning:  socket_get_status(): 96 is not a valid stream resource in /var/www/html/plugins/routerconfigs/functions.php on line 796

Warning: socket_get_status(): 96 is not a valid stream resource in /var/www/html/plugins/routerconfigs/functions.php on line 796
PHP Warning:  fputs(): 96 is not a valid stream resource in /var/www/html/plugins/routerconfigs/functions.php on line 759

Warning: fputs(): 96 is not a valid stream resource in /var/www/html/plugins/routerconfigs/functions.php on line 759
PHP Warning:  stream_set_timeout(): 96 is not a valid stream resource in /var/www/html/plugins/routerconfigs/functions.php on line 792

Warning: stream_set_timeout(): 96 is not a valid stream resource in /var/www/html/plugins/routerconfigs/functions.php on line 792
PHP Warning:  fread(): 96 is not a valid stream resource in /var/www/html/plugins/routerconfigs/functions.php on line 794

Warning: fread(): 96 is not a valid stream resource in /var/www/html/plugins/routerconfigs/functions.php on line 794
PHP Warning:  socket_get_status(): 96 is not a valid stream resource in /var/www/html/plugins/routerconfigs/functions.php on line 796

Warning: socket_get_status(): 96 is not a valid stream resource in /var/www/html/plugins/routerconfigs/functions.php on line 796
PHP Warning:  fputs(): 96 is not a valid stream resource in /var/www/html/plugins/routerconfigs/functions.php on line 759

Warning: fputs(): 96 is not a valid stream resource in /var/www/html/plugins/routerconfigs/functions.php on line 759
PHP Warning:  stream_set_timeout(): 96 is not a valid stream resource in /var/www/html/plugins/routerconfigs/functions.php on line 792

Warning: stream_set_timeout(): 96 is not a valid stream resource in /var/www/html/plugins/routerconfigs/functions.php on line 792
PHP Warning:  fread(): 96 is not a valid stream resource in /var/www/html/plugins/routerconfigs/functions.php on line 794

Warning: fread(): 96 is not a valid stream resource in /var/www/html/plugins/routerconfigs/functions.php on line 794
PHP Warning:  socket_get_status(): 96 is not a valid stream resource in /var/www/html/plugins/routerconfigs/functions.php on line 796

Warning: socket_get_status(): 96 is not a valid stream resource in /var/www/html/plugins/routerconfigs/functions.php on line 796
PHP Warning:  fclose(): 96 is not a valid stream resource in /var/www/html/plugins/routerconfigs/functions.php on line 753

Warning: fclose(): 96 is not a valid stream resource in /var/www/html/plugins/routerconfigs/functions.php on line 753
Saving Debug
04/07/2010 09:56:09 AM - RouterConfigs: Poller[0] -1270634077 seconds
0 devices backed up successfully.
1 devices failed to backup.

These devices failed to backup
--------------------------------
172.23.3.250 - Login failed
[root@localhost ~]#
I used your complete functions.php as I wanted to ensure that was working before I played with the config.
grady
Cacti User
Posts: 60
Joined: Wed Feb 20, 2008 5:02 pm

Post by grady »

It almost looks like an error with the plugin_routerconfigs_devicetypes table. All you need to do to get that output (assuming your mysql instance for cacti is on the same host, and when you installed you used cactiuser / cactiuser for mysql login)

1. mysql -u cactiuser -p
2. use cacti;
3. select * from plugin_routerconfigs_devicetypes;
dieselboy
Cacti User
Posts: 135
Joined: Wed May 27, 2009 5:10 pm

Post by dieselboy »

Thanks for explaining that! I have never really used mysql from the command line. I installed phpmyadmin to use the mysql database.
Here is the output:

Code: Select all

mysql> select * from plugin_routerconfigs_devicetypes;
+----+-----------+----------+----------+--------------------------------+--------------+---------+--------------+
| id | name      | username | password | copytftp                       | version      | confirm | forceconfirm |
+----+-----------+----------+----------+--------------------------------+--------------+---------+--------------+
|  1 | Cisco IOS | sername: | assword: | copy start tftp:               | show version | y       | 0            |
|  2 | CatOS     | sername: | assword: | copy start tftp                |              | y       | 1            |
|  3 | HP        | sername  | assword  | copy start tftp 192.168.250.39 | sh ver       |         |              |
+----+-----------+----------+----------+--------------------------------+--------------+---------+--------------+
3 rows in set (0.00 sec)
grady
Cacti User
Posts: 60
Joined: Wed Feb 20, 2008 5:02 pm

Post by grady »

Strange, line 713 in my functions file is 713 $r=explode("\n", $r);


whats line 713 in yours?
dieselboy
Cacti User
Posts: 135
Joined: Wed May 27, 2009 5:10 pm

Post by dieselboy »

My line 713 is
if (strpos($res, $devicetype['password']) == FALSE) {
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest