I just got back into ZipTie in the last few days after a couple years of not dealing with it at all. I wrote my first adapter last night (well, customized the output of AdapterTool that is). I was at home and wanted to learn how to write adapters so I figured I would start by backing up my WRT54G and WRT54GSs running OpenWrt. I found the video tutorial on using AdapterTool to be very straightforward and was able to hack something out very quickly.
Today I created an adapter for the HP Proliant GbE2 blade switches and then imported it into NetworkAuthority and backed up about 100 blade switches with it. It worked great. So in hopes to get ideas and help on improving these adapters I uploaded them to the zipforge repository:
HP Proliant Adapter:
http://forge.ziptie.org/node/911
OpenWrt Adapter:
http://forge.ziptie.org/node/912
As you can imagine these are very raw at the moment and I did enough to make them do what I want even though I know there are better ways to do what they do. That's the reason for this post.
In the OpenWrt adapter I am capturing the nvram and several config files from /etc and /etc/shorewall by doing a "cat filename" and capturing the output in a variable. I believe it would be much better to "scp" these files but I don't know exactly how that should be done. Also, I have hard coded a specific list of files to backup and it doesn't do any checking as to whether those files actually exist. If they do not exist you get a file in ZipTie with the "file not found" error from the cat. So, I also need to add some logic there. I would also like to get a nice list of common customized files to back up, maybe tar them up into a single package rather than downloading them individually, etc. In fact it might be good to back up the entire OS image since we're only talking a couple of meg.
The HP Proliant adapter works pretty well but I noticed 1 out of around 100 of our HP Proliant switches did not back up because it runs an older version of the OS and doesn't present a "more" type prompt where the newer OS does, so that should be an easy fix that I can get done tomorrow.
Anyone else out there developing adapters? I don't see a lot of talk about it here and have to assume it's happening on the mailing list. Would be nice to get some discussion going on these forums so other people interested in creating these adapters can have more info on the what to do and what not to do (as probably is the case with me). Thanks for any help and suggestions you can provide!
For the "more" prompt we
For the "more" prompt we have a method on the ZipTie::CLIProtocol module to help with this. I would call this method in your adapter's AutoLogin module and then you don't have to worry about it from then on out. The 2nd arg that you pass to the method is the ascii code for the action. The example below is '20', which is a space bar.
$cliProtocol->set_more_prompt( '--More--\s*$', '20' );
For the SCP question, we have a ZipTie::SCP module that uses the PuTTy pscp program. Look at how the BIG-IP adapter (ziptie.adapters.f5.bigip) uses this module to SCP its backup.ucs file over. You have a couple choices here, you could scp each file back individually or tar them up on the network device, scp the single file back and then unzip them in your adapter. The BIG-IP unzips as well so that could give you some pointers if you want to go that route.
Also, if you haven't found it yet, here is the POD for all of our Perl modules: http://dev.ziptie.org/docs/perldoc/index.htm
Thanks for the info on the
Thanks for the info on the more prompt. I had solved it another way but will go back and change it to use this method. Regarding putty, you even use that on the Linux version (no Windows in these parts)? I'll take a look at the F5 adapter (which we also use). Thanks!
Putty
We use putty on all platforms: Windows, Linux, Mac OS X, (and Solaris shhhhhh don't tell anyone), we compile and ship the binaries with ZipTie.
-Brett
Not having much luck
Ok, so I created another adapter for a Cisco GSS appliance and it is working but not the way it needs to. I have two issues that are probably both easily solved. Mind you that I used the adapterTool to create a basic adapter and am working from there:
1) I need to go into "enable" mode to show start/run configs, etc. There is no enable password on these devices. Interactively you would just type "enable" with no password and you get the enable prompt. In the adapter since you don't supply an enable password it doesn't take you all the way to the enable prompt and I would like it to. For now I just send the enable command in the adapter right after the _connect():
$responses->{version} = $cliProtocol->send_and_wait_for( 'enable', $promptRegex );
This poses another problem in that the $promptRegex is now no longer correct ('>' vs '#') that was returned from the _connect(). So, right after the connect I set the $prompRegex to '/[\>\#]\s*$/'. Ugly, ugly, ugly, and I know there must be a better way and would like to know what the experts would do.
2) I was not able to get the "set_more_prompt" to work as you suggested. The exact example you gave should work in my case as the prompt is exactly "--More--" and a spacebar will cause the continuation. I added the set_more_prompt right after the set_prompt_by_name in the _connect() subroutine like so:
$cliProtocol->set_prompt_by_name( 'prompt', $devicePromptRegex );
$cliProtocol->set_more_prompt( '--More--\s*$', '20' );
When the --More-- prompt appears on the "show running-config" it just hangs until timeout. Unfortunately you cant just "set terminal length 0" in straight enable mode on this device but you can go into configure mode and change it there which I assume is a no-no. That's the way I am currently doing it in the adapter but I don't like that and would like to get the set_more_prompt method working.
Thanks for any suggestions! I feel like I am almost over the hump. I'll also upload this adapter to ZipForge as soon as it's presentable.
P.S. I did verify in a network capture that there are no extra characters in the prompt that would cause a problem. This is the prompt in hex:
- - M o r e - -
2d 2d 4d 6f 72 65 2d 2d
1) send the 'enable' command
1) send the 'enable' command in your AutoLogin module before the prompt is captured rather than sending it from your main adapter module. The last method in AutoLogin will then capture the prompt based on the enable prompt and all should be good.
2) Can you paste the UNEXPECTED_RESPONSE error in this topic? It should show the issue pretty clearly.
Thanks, I'll give that a
Thanks, I'll give that a shot. When the --More-- prompt times out I get this:
--More-- at scripts/ZipTie/Telnet.pm line 338
at org.ziptie.perl.PerlServer.readResponse(PerlServer.java:452)
at org.ziptie.perl.PerlServer.eval(PerlServer.java:275)
at org.ziptie.adapters.AdapterInvokerElf.invoke(AdapterInvokerElf.java:129)
... 2 more
Is that what you were looking for?
There is more to that error
There is more to that error above what you pasted.
Solved
By taking care of the enable mode in AutoLogin.pm and getting the proper prompt it solved my other problem. I added an _enable_mode() subroutine:
sub _enable_mode
{
my $cli_protocol = shift;
my $credentials = shift;
my @responses = ();
push(@responses, ZipTie::Response->new('(#|\$|>)\s*$', \&_get_prompt));
$LOGGER->debug("Going to enable mode ...");
$cli_protocol->send('enable');
my $response = $cli_protocol->wait_for_responses(\@responses);
if ($response)
{
my $next_interaction = $response->get_next_interaction();
return &$next_interaction($cli_protocol, $credentials);
}
else
{
$LOGGER->fatal("Invalid response from device encountered!");
}
}
And changed the responses in _initial_connection() to:
my @responses = ();
push(@responses, ZipTie::Response->new('sername:|(?new('[Pp]assword:', \&_send_password));
push(@responses, ZipTie::Response->new('(\$|>)\s*$', \&_enable_mode));
push(@responses, ZipTie::Response->new('(#|\$|>)\s*$', \&_get_prompt));
and changed responses in _send_password() to:
my @responses = ();
push(@responses, ZipTie::Response->new('incorrect|login invalid', undef, $INVALID_CREDENTIALS));
push(@responses, ZipTie::Response->new('(#)\s*$', \&_get_prompt));
push(@responses, ZipTie::Response->new('(\$|>)\s*$', \&_enable_mode));
Looks like the forums can't keep the formatting for some reason (even with the code tag). Anyway, doing that solved both of my problems.
Thanks!