以下の機能はルータにログインし、コマンドを実行してIPsecセッションのステータスを取得し、インターフェイス名とIPアドレスを文字列として返します。文字列を返す代わりに、関数がハッシュの配列を返すようにしたい。誰かがそれで私を助けることができますか?perlのハッシュ配列を返します
sub cryptoSessionStatus {
my ($self,$interface) = @_;
my $status = 0;
my $peer_ip = 0;
#command to check the tunnel status
my $cmd = 'command goes here ' . $interface;
#$self->_login();
my $tunnel_status = $self->_login->exec($cmd);
#Regex to match the 'tunnel status' and 'peer ip' string in the cmd output
#Session status: DOWN/UP
#Peer: x.x.x.x
foreach my $line ( $tunnel_status) {
if ($line =~ m/Session\s+status:\s+(.*)/) {
$status = $1;
}
if ($line =~ m/Peer:\s+(\d+.\d+.\d+.\d+)/) {
$peer_ip = $1;
}
}
return ($status,$peer_ip);
}
ファンクションコール:
my $tunnel_obj = test::Cryptotunnels->new('host'=> 'ip');
my $crypto_sessions = $tunnel_obj->cryptoSessionStatus("tunnel1");
Status => Ipのハッシュが存在することを意味しますか?そしてあなたはそれが返ってきたいと思いますか? –
@Edダン私はIPおよびステータス({=> "アップ" IP => "x.x.x.x"、 ステータス} )ハッシュアレイのアレイ=として返されたいです。 – virat
出力はどのように見えますか?サンプルを入手できますか? –