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 »

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

Post by grady »

Anyway you can attach your current functions file?
dieselboy
Cacti User
Posts: 135
Joined: Wed May 27, 2009 5:10 pm

Post by dieselboy »

Sure,
Here you go
Attachments
functions_208.txt
(29.61 KiB) Downloaded 365 times
grady
Cacti User
Posts: 60
Joined: Wed Feb 20, 2008 5:02 pm

Post by grady »

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 561 times
dieselboy
Cacti User
Posts: 135
Joined: Wed May 27, 2009 5:10 pm

Post by dieselboy »

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

Post by grady »

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

Post by dieselboy »

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

Post by dieselboy »

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

Post by grady »

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

Post by dieselboy »

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

Post by dieselboy »

Does the script wait for the > before trying any further commands?
grady
Cacti User
Posts: 60
Joined: Wed Feb 20, 2008 5:02 pm

Post by grady »

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

Post by dieselboy »

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

Post by grady »

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

Post by dieselboy »

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

Who is online

Users browsing this forum: No registered users and 0 guests