Routerconfigs plugin / how it works?

Discussions on developing plugins for the Cacti Plugin Architecture

Moderators: Moderators, Developers

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

#46 Post by dieselboy » Thu Apr 08, 2010 3:40 am

When I run that from the command line, it doesnt seem to be pressing "any key" when it connects to the HP switch. Because of this it trys to log in and fails - because entering the username only takes it to the username prompt, and then it appears as if it puts the password into the username prompt and then times out.

How did you get it to press any key?

grady
Cacti User
Posts: 60
Joined: Wed Feb 20, 2008 5:02 pm

#47 Post by grady » Thu Apr 08, 2010 8:07 am

Anyway you can attach your current functions file?

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

#48 Post by dieselboy » Thu Apr 08, 2010 8:10 am

Sure,
Here you go
Attachments
functions_208.txt
(29.61 KiB) Downloaded 172 times

grady
Cacti User
Posts: 60
Joined: Wed Feb 20, 2008 5:02 pm

#49 Post by grady » Thu Apr 08, 2010 8:34 am

Your functions file looks right. I'd removed a couple of lines of redundant code to clean mine up and have attached what I'm using at present. When you telnet to this HP it asks for a username and password when logging in right? Post login the command you're using to backup to tftp is:

Code: Select all

copy running-config tftp x.x.x.x
correct? (of course using the credentials listed in routerconfigs / auth)
Attachments
functions.txt
(28.49 KiB) Downloaded 243 times

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

#50 Post by dieselboy » Fri Apr 09, 2010 11:20 am

Thanks that now backs up HP kit!

The only problem I now have is that when I replace my config for enabling onto switches it doesn't enable. I noticed you have some enable config on there, how does this work?

grady
Cacti User
Posts: 60
Joined: Wed Feb 20, 2008 5:02 pm

#51 Post by grady » Fri Apr 09, 2010 11:22 am

Can you clarify a bit? Mine is working on both platforms for enabled and no enable mode

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

#52 Post by dieselboy » Fri Apr 09, 2010 11:23 am

Ok I'll retry,
When I look at the debug and through CLI it doesnt seem to enable at all.
Where does it get the "enablepassword" from in the $info field?

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

#53 Post by dieselboy » Fri Apr 09, 2010 11:27 am

I copied over the functions file from above again so it was fresh but I still get this:

Code: Select all

��������

User Access Verification

Username: �� ������'��admin
Password: 

3750-1>exit
333

grady
Cacti User
Posts: 60
Joined: Wed Feb 20, 2008 5:02 pm

#54 Post by grady » Fri Apr 09, 2010 11:36 am

Yeah, I removed some of that debug crap for clarity. Does it just hang when run from cli against devs requiring enable mode or does it error out eventually or what? (when run from cli eventually it should echo back something along the lines of "the following failed to be backed up" or whatever)

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

#55 Post by dieselboy » Fri Apr 09, 2010 11:43 am

It logs in but when it gets to the enable prompt it doesnt do anything. after a while it says "login failed333"
Then it moves on to the next device - this is in the CLI.

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

#56 Post by dieselboy » Fri Apr 09, 2010 11:44 am

Does the script wait for the > before trying any further commands?

grady
Cacti User
Posts: 60
Joined: Wed Feb 20, 2008 5:02 pm

#57 Post by grady » Fri Apr 09, 2010 11:51 am

Yeah, so what should happen based on the below code is this. $devicetypeHP is a mysql select NAME from the plugin_routerconfigs_devicetypes table where blah isn't null. That returns a variable of type array, so we use php's foreach to evaluate what's returned and assign that string to $value. If $value is equal to HP then we use the telnetHP class to initiate a connection. (telnetHP can be found at the very bottom of the functions file. Its essentially the same as the phptelnet class, but passes extra stuff for username and copy commands) If $value is not HP and $result = 0 (result = 0 means successful connection to device) we continue down through unaltered functions (original) and use the original phptelnet class. I'm not really sure why it wouldnt work on devices that require enable. Can you try disabling that device in the routerconfigus gui and attempt to back up a device that does not require enable (cisco) to see if that works or not?

Code: Select all

//If HP use PHPTelnetHP class vs standard 
        $devicetypeHP = db_fetch_row("SELECT name FROM plugin_routerconfigs_devicetypes WHERE id = " . $device['devicetype']);
                 foreach ($devicetypeHP as $value)
                 {
                        if ($value == "HP"){
                        $result1 = $telnetHP->Connect($device['ipaddress'],  $info['username'], $info['password'], $devicetype);
                        $debug = $telnetHP->debug;
                        $result=$result1;
                        $telnetHP->DoCommandHP($devicetype['copytftp'], $result);
                        echo $result;
                        $telnetHP->DoCommandHP2($filename, $result);
                        echo $result;
                        }
                }
//end class use 
                if ($result == 0) {
// 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['copytftp'], $result);
                        $debug .= $result;
                        echo $result;
                        $telnet->DoCommand($tftpserver, $result);
                        $debug .= $result;
                        echo $result;
                        $telnet->DoCommand($filename, $result);
                        $debug .= $result;
                        echo $result;

                                if (strpos($result, 'confirm') !== FALSE || strpos($result, 'to tftp:') !== FALSE || $devicetype['forceconfirm']) {
                                $telnet->DoCommand('y', $result);
                                $debug .= $result;
                                echo $result;
                                }

                        }
//end false positive skip

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

#58 Post by dieselboy » Tue Apr 13, 2010 5:09 am

Without an enable prompt it works. It logs in and backs up the config. What does this mean?

grady
Cacti User
Posts: 60
Joined: Wed Feb 20, 2008 5:02 pm

#59 Post by grady » Tue Apr 13, 2010 8:11 am

That's very strange. It ought to work with enable as well. When the device type is pulled from that table there's an if statement that says if name = HP use telnetHP. -- If you page down near the bottom of the functions file you'll see both of those classes defined. Note that the telnethp class does not have the check for enable mode prompt stuff that the telnet class does.

Code: Select all

($telnetHP = new PHPTelnetHP();)
Here's that if:

Code: Select all

        $devicetypeHP = db_fetch_row("SELECT name FROM plugin_routerconfigs_devicetypes WHERE id = " . $device['devicetype']);
                 foreach ($devicetypeHP as $value)
                 {
                        if ($value == "HP"){
                        $result1 = $telnetHP->Connect($device['ipaddress'],  $info['username'], $info['password'], $devicetype);
                        $debug = $telnetHP->debug;
                        $result=$result1;
                        $telnetHP->DoCommandHP($devicetype['copytftp'], $result);
                        echo $result;
                        $telnetHP->DoCommandHP2($filename, $result);
                        echo $result;
                        }
                }
As a test try this, go into router configs and disable all non cisco, non enable mode devices. Then add an echo to the above code like this:

Code: Select all

   $devicetypeHP = db_fetch_row("SELECT name FROM plugin_routerconfigs_devicetypes WHERE id = " . $device['devicetype']);
                 foreach ($devicetypeHP as $value)
                 {
                        if ($value == "HP"){
                                                echo "Are we ending up here?"; 
                        $result1 = $telnetHP->Connect($device['ipaddress'],  $info['username'], $info['password'], $devicetype);
                        $debug = $telnetHP->debug;
                        $result=$result1;
                        $telnetHP->DoCommandHP($devicetype['copytftp'], $result);
                        echo $result;
                        $telnetHP->DoCommandHP2($filename, $result);
                        echo $result;
                        }
                }
Then run php /var/www/html/cacti/plugins/routerconfigs/router-download.php (assuming thats the path to your plugins directory) and see if you see that echo during execution. If so all that's happening is that for some reason you're hitting that code block when you shouldn't be and we'll need to figure out why.

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

#60 Post by dieselboy » Wed Apr 14, 2010 10:06 am

It doesn't echo that line back so I guess it's not matching that.

I've selected both cisco IOS and auto detect and neither of them work. What determines what rule set the functions.php follows?
When I had enable working on my setup I had to leave it as autodetect so that functions.php followed the ifresult=empty path. I then put the enable command and password part in there. I see you have put these in the log in path above this. I tried moving this but it still didn't have any effect :/

Post Reply