NAME

POE::Component::RemoteTail - tail to remote server's access_log on ssh connection.

SYNOPSIS

use POE::Component::RemoteTail;

my ( $host, $path, $user, $password ) = @target_host_info;
my $alias = 'Remote_Tail';

# spawn component
my $tailer = POE::Component::RemoteTail->spawn( alias => $alias );

# create job
my $job = $tailer->job(
    host          => $host,
    path          => $path,
    user          => $user,
);

# prepare the postback subroutine at main POE session
POE::Session->create(
    inline_states => {
        _start => sub {
            my ( $kernel, $session ) = @_[ KERNEL, SESSION ];
            # create postback
            my $postback = $session->postback("MyPostback");

            # post to execute
            $kernel->post( $alias,
                "start_tail" => { job => $job, postback => $postback } );
        },

        # return to here
        MyPostback => sub {
            my ( $kernel, $session, $data ) = @_[ KERNEL, SESSION, ARG1 ];
            my $log  = $data->[0];
            my $host = $data->[1];
            ... do something ...;
        },
    },
);

POE::Kernel->run();

DESCRIPTION

POE::Component::RemoteTail provides some loop events that tailing access_log on remote host. It replaces "ssh -A user@host tail -f access_log" by the same function.

This moduel does not allow 'PasswordAuthentication'. Use RSA or DSA keys, or you must write your Custom Engine with this module. ( ex. POE::Component::RemoteTail::CustomEngine::NetSSHPerl.pm )

EXAMPLE

If you don't prepare 'postback', PoCo::RemoteTail outputs log data to child process's STDOUT.

use POE::Component::RemoteTail;

my $tailer = POE::Component::RemoteTail();
my $job = $tailer->job( host => $host, path => $path, user => $user );
POE::Session->create(
    inlines_states => {
        _start => sub {
            $kernel->post($tailer->session_id, "start_tail" => {job => $job}); 
        },
    }
);
POE::Kernel->run();

It can tail several servers at the same time.

use POE::Component::RemoteTail;

my $tailer = POE::Component::RemoteTail(alias => $alias);

my $job_1 = $tailer->job( host => $host1, path => $path, user => $user );
my $job_2 = $tailer->job( host => $host2, path => $path, user => $user );

POE::Session->create(
    inlines_states => {
        _start => sub {
            my $postback = $session->postback("MyPostback");
            $kernel->post($alias, "start_tail" => {job => $job_1, postback => $postback}); 
            $kernel->post($alias, "start_tail" => {job => $job_2, postback => $postback}); 
            $kernel->delay_add("stop_tail", 10, [ $job_1 ]);
            $kernel->delay_add("stop_tail", 20, [ $job_1 ]);
        },
        MyPostback => sub {
            my ( $kernel, $session, $data ) = @_[ KERNEL, SESSION, ARG1 ];
            my $log  = $data->[0];
            my $host = $data->[1];
            ... do something ...;
        },
        stop_tail => sub {
            my ( $kernel, $session, $arg ) = @_[ KERNEL, SESSION, ARG0 ];
            my $target_job = $arg->[0];
            $kernel->post( $alias, "stop_tail" => {job => $target_job});
        },
    },
);
POE::Kernel->run();

METHOD

spawn()

job()

start_tail()

stop_tail()

session_id()

debug()

new()

AUTHOR

Takeshi Miki <miki@cpan.org>

LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO