Agent-TCLI

 view release on metacpan or  search on metacpan

lib/Agent/TCLI/Package/Tail.pm  view on Meta::CPAN


This POE event handler executes the show commands. It is called by the
Control and takes a Request as an argument.

=cut
#
# Now handled in base class

=item log

This POE event handler executes the log commands. It is called by the
Control and takes a Request as an argument.

=cut

sub log {
    my ($kernel,  $self, $sender, $request, ) =
      @_[KERNEL, OBJECT,  SENDER,     ARG0, ];
	$self->Verbose("log: request ".$request->id." input(".$request->input.") ");

	my $txt = '';
	my $opt;
	my $command = $request->command->[0];

	my $num = $self->depth_test_queue + 1;

	if ($command eq 'log')
	{
		$self->Verbose("log: args dump \n 'name'		=> $request->input,\n	'num'		=> $num,\n'handler'	=> 'Log',\n'log_name'	=> 'Append',\n ",2);
		$self->Verbose("log: self dump (".$self->dump(1).") ",4);


		my $test = Agent::TCLI::Package::Tail::Test->new(
#			'code'		=> $testsub,
			'name'		=> $request->input,
			'num'		=> $num,
#			'max_lines'	=> $max_lines,
#			'match_times'=> $match_times,
			'ttl'		=> 30,
#			'verbose'	=> $verbose,
			'handler'	=> 'Log',
			'log_name'	=> 'Append',
			'ordered'	=> 0,
			'request'	=> $request,
		);
		$self->Verbose("log: new test dump (".$test->dump(1).") ",3);

		$self->push_test_queue($test);
	}
	return (1);
}

sub _preinit :Preinit {
	my ($self,$args) = @_;

	$args->{'name'} = 'tcli_tail';

  	$args->{'session'} = POE::Session->create(
      object_states => [
          $self => [qw(
          	_start
          	_stop
          	_shutdown
          	_default
          	_child

			clear
			establish_context
			file
			log
			show
			test
			settings

			Activate
			Append
			Check
			Complete
			FileReset
			PruneLineCache
			SetFollowTailWheel
			Wally

			)],
      ],
  	);
}

sub _init :Init {
	my $self = shift;

	$self->LoadYaml(<<'...');
---
Agent::TCLI::Parameter:
  name: file
  help: The full Unix path of the file name.
  manual: >
    The full Unix path of the file that will be tailed.
  type: Param
---
Agent::TCLI::Parameter:
  name: filter
  help: Optional POE::Filter.
  manual: >
    A POE::Filter that will be applied by POE::Wheel::FollowTail on the file
    being tailed.
  type: Param
---
Agent::TCLI::Parameter:
  name: interval
  help: Seconds to wait between checks.
  manual: >
    Seconds to wait between checks.
  type: Param
---
Agent::TCLI::Parameter:
  name: seek
  help: Seek forward byte count.
  manual: >
    The Seek parameter tells Tail how far from the start of the file to start
    reading. Its value is specified in bytes, and values greater than the
    file's current size will quietly cause Tail to start from the file's end.
    A Seek parameter of 0 starts FollowTail at the beginning of the file.
    A negative Seek parameter emulates SeekBack: it seeks backwards from
    the end of the file.
    Seek and SeekBack are mutually exclusive. If Seek and SeekBack are not
    specified, Tail seeks 4096 bytes back from the end of the file
    and discards everything until the end of the file. This helps ensure
    that Tail returns only complete records.
  type: Param
---
Agent::TCLI::Parameter:
  name: seekback
  help: Seek backwards byte count.
  manual: >
    The SeekBack parameter tells Tail how far back from the end of the file
    to start reading. Its value is specified in bytes, and values greater
    than the file's current size will quietly cause Tail to start from
    the file's beginning.
    A SeekBack parameter of 0 starts Tail at the end of the file.
    It's recommended to omit Seek and SeekBack to start from the end of a file.
    A negative SeekBack parameter emulates Seek: it seeks forwards from
    the start of the file.
  type: Param
---
Agent::TCLI::Parameter:
  name: name
  help: The name of the test.
  manual: >
    The name is purely cosmetic and will be returned with the test results
    simliarly to the way Test::Simple operates. This might be useful
    when reporting results to a group chat or log.
  type: Param
---
Agent::TCLI::Parameter:
  name: like
  help: A regex to match.
  manual: >
    Like sets a regular expression for the test to match within a line.
    The regex should be either a string
  type: Param
---
Agent::TCLI::Parameter:
  name: line_max_cache
  alaises: max_cache
  constraints:
    - UINT
  help: The maximum number of lines to keep in the line_cache.
  manual: >
    The line_max_cache parameter sets how many lines to keep in the line cache.
    Since actions are asynchronous, it is a good idea to have at least some
    line cache so that a tail test will work when the action to generate the
    log ocurred before the test was in place.
  type: Param
---
Agent::TCLI::Parameter:
  name: line_hold_time
  alaises: hold_time
  constraints:
    - UINT
  help: The time, in seconds, to keep lines in the cache.
  manual: >
    The line_hold_time parameter sets how many seconds to keep lines in
    the line_cache. This is not an exact amount but rather the minimum,
    The purge_line_cache process does not run every second, but lines that
    exceeed the hold_time will be purged when it does run.
  type: Param
---
Agent::TCLI::Parameter:
  name: test_max_lines
  alaises: max_lines
  help: The maximum number of lines to check before failing.
  manual: >
    The max_lines parameter sets how many lines to check before giving up
    and failing. For tests, the default is ten, which is the default size
    of the line cache. This means that by default, a test will only check the
    most recent lines of what is being tailed.
    For watches, the default is zero, which means it does not ever give up.
  type: Param
---
Agent::TCLI::Parameter:
  name: test_match_times
  aliases: match_times

lib/Agent/TCLI/Package/Tail.pm  view on Meta::CPAN

    active:
  topic: testing
  usage: tail show settings
---
Agent::TCLI::Command:
  name: log
  call_style: session
  command: tcli_tail
  contexts:
    tail: log
  handler: log
  help: add text to the line queue
  manual: >
    The log command allows one to add a line of text to the queue. It helped
    to facilitate testing of the tail package, but might not be useful
    otherwise. Still, here it is. Any text following log appears in the line
    queue as if it was coming from a tailed file.
  topic: testing
  usage: tail log "some text"
---
Agent::TCLI::Command:
  call_style: session
  command: tcli_tail
  contexts:
    tail: clear
  handler: establish_context
  help: clears out a cache
  name: clear
  topic: testing
  usage: tail clear lines
---
Agent::TCLI::Command:
  call_style: session
  command: tcli_tail
  contexts:
    tail:
      clear: lines
  handler: clear
  help: clears out the line cache
  name: clear_lines
  topic: testing
  usage: tail clear lines
...

}

=item _shutdown

This POE event handler is used to initiate a shutdown of the Package.

=cut

sub _shutdown :Cumulative {
	my ($kernel,  $self,) =
      @_[KERNEL, OBJECT,];
	$self->Verbose("_shutdown:tail ".$self->name." shutting down");

    return;
}

=item _start

This POE event handler is called when POE starts up a Package.
The B<_start> method is :Cumulative within OIO.

=cut

sub _start {
	my ($kernel,  $self,  $session) =
      @_[KERNEL, OBJECT,   SESSION];
    $self->Verbose("_start: Starting test_tail ");

	# are we up before OIO has finished initializing object?
	if (!defined( $self->name ))
	{
		$kernel->yield('_start');
		return;
	}

	# There is only one command object per TCLI
    $kernel->alias_set($self->name);

	$kernel->delay('PruneLineCache',10);
	$kernel->delay('Activate', $self->interval , 0 );

	return("_start ".$self->name);
}

1;
#__END__

=back

=head3 INHERITED METHODS

This module is an Object::InsideOut object that inherits from
Agent::TCLI::Package::Base. It inherits methods from both.
Please refer to their documentation for more details.

=head1 AUTHOR

Eric Hacker	 E<lt>hacker at cpan.orgE<gt>

=head1 BUGS

Currently there is no separation between users running tests, which means it
could be very ugly to have multiple users try to run tests on one TCLI Agent.

Test scripts not thorough enough.

Probably many others.

=head1 LICENSE

Copyright (c) 2007, Alcatel Lucent, All rights resevred.

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

=cut



( run in 2.339 seconds using v1.01-cache-2.11-cpan-437f7b0c052 )