zebra bars on table from MongoDB store
[pxelator] / bin / smclp.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 # Dell's DRAC SM-CLP
7
8 use Data::Dump qw/dump/;
9
10 use Net::OpenSSH;
11 use Expect;
12 use Getopt::Long;
13
14 my $debug = 0;
15 my $timeout = 5;
16
17 GetOptions(
18         'debug!' => \$debug,
19         'timeout=i' => \$timeout,
20 ) or die $!;
21
22 my ( $uri, $command, $path ) = @ARGV;
23 die "usage: $0 login:passwd\@host show /system1\n" unless $uri && $command;
24
25 my $ssh = Net::OpenSSH->new( $uri );
26 my ( $pty, $pid ) = $ssh->open2pty;
27 my $expect = Expect->init($pty);
28 $expect->raw_pty(1);
29 $expect->log_user(1) if $debug;
30
31 $expect->expect( $timeout, '$' );
32 $expect->send( "smclp\n" );
33
34 $expect->expect( $timeout, '>' );
35
36 my $data;
37
38 sub smclp {
39         my ( $command, $path ) = @_;
40
41         warn "smclp $command $path\n" if $debug;
42
43         $expect->send( "$command $path\n" );
44
45         $expect->expect( $timeout, '>' );
46
47         my $got = $expect->before;
48
49         my $section;
50
51         foreach ( split(/\r\n/, $got ) ) {
52                 if ( m{(/.*):} ) {
53                         $path = $1;
54                 } elsif ( m{^\s{2}(\w+):} ) {
55                         $section = $1;
56                 } elsif ( m{^\s{4}(.+)} ) {
57                         if ( $section eq 'Properties' ) {
58                                 my ( $k, $v ) = split(/\s+=\s+/,$1,2);
59                                 $data->{$path}->{$section}->{$k} = $v;
60                         } else {
61                                 push @{ $data->{$path}->{$section} }, $1;
62                         }
63                 } else {
64                         print "# IGNORE [$_]\n" if $debug;
65                 }
66         }
67
68         warn "# data = ",dump $data;
69 }
70
71 smclp $command => $path;
72