view release on metacpan or search on metacpan
users, packages and other pertinent information. The agent will log in, join
chatrooms if in the user list, and wait for further commands from authorized
users or in a chatroom.
Test script:
A test script is written, see ex/probe.pl, that loads up a Test Transport,
other necessary transports, necessary local packages, and testees.
Using testees, one creates tests ala Test::More with the $testee->ok or
$testee->like_body and other Testee tests. These will run asynchronously
after the testing starts.
It is necessary to call the test_master->run at the end of the test script
to ensure that all tests have completed.
COPYRIGHT AND LICENCE
Copyright (C) 2007, Alcatel-Lucent
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
bin/agent_net.pl view on Meta::CPAN
Print a brief help message and exit.
=item B<man>
Print this command's manual page and exit.
=back
=head1 DESCRIPTION
B<agent_net> will start a TCLI Agent running on the XMPP Transport
with the Net, Tail and XMPP packages loaded.
Use B<agent_net> as is or as the basis for creating Agents with different
functionaity.
=head1 SEE ALSO
L<Agent::TCLI>
L<Agent::TCLI::Package::Net>
bin/agent_net.pl view on Meta::CPAN
'verbose' => \$verbose, # Verbose sets level or warnings
'control_options' => {
'packages' => \@packages,
},
);
print "Starting ".$alias unless $verbose;
# Required to start the Agent
POE::Kernel->run();
print" FINISHED\n";
exit;
ex/target.t view on Meta::CPAN
# Remote up?
$remote->ok('status');
# get remotes IP address
$remote->ok('Control show local_address');
my $target = $remote->get_param('local_address','',30);
#add a new response to the webserver
$remote->ok('httpd uri add regex=/test2.* response=OK200');
# start remote web server with logging
$remote->ok('httpd set logging');
$remote->ok('httpd spawn port=8080');
# make sure those completed before proceeding
$test_master->done;
# have local query target webserver.
$local->ok('http tget url=http://'.$target.':8080/test1.htm resp=404');
$local->ok('http tget url=http://'.$target.':8080/test2.htm resp=200');
# check to see if it's in the logs
$remote->ok('tail test add like=test1', 'passed test test1');
$remote->ok('tail test add like=test2', 'passed test test2');
# shut down httpd
$remote->ok('httpd stop port=8080');
# make sure to shut down the transport or else the script will not stop.
$local->ok('xmpp shutdown');
# Though tests will start during building of the tests, POE isn't fully running
# and all tests will not complete until the master run is called.
$test_master->run;
lib/Agent/TCLI/Package/Net/HTTP.pm view on Meta::CPAN
=cut
sub _preinit :PreInit {
my ($self,$args) = @_;
$args->{'name'} = 'tcli_http';
$args->{'session'} = POE::Session->create(
object_states => [
$self => [qw(
_start
_stop
_shutdown
_default
_child
establish_context
get
ProcessResponse
ResponseProgress
retry
lib/Agent/TCLI/Package/Net/HTTP.pm view on Meta::CPAN
retry_interval:
retry_count:
required:
url:
topic: net
usage: http cget url=http:\example.com\request
...
}
sub _start {
my ($kernel, $self, $session) =
@_[KERNEL, OBJECT, SESSION];
$self->Verbose("_start: tcli http starting");
# 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);
# Keep the cm session so we can shut it down
$self->set(\@poco_cm , POE::Component::Client::Keepalive->new(
max_per_host => 4, # defaults to 4
max_open => 128, # defaults to 128
lib/Agent/TCLI/Package/Net/HTTP.pm view on Meta::CPAN
my $command = $request->command->[0];
my $cmd = $self->commands->{$command};
return unless ( $param = $cmd->Validate($kernel, $request, $self) );
$self->Verbose("get: url(".$param->{'url'}.") ");
$self->Verbose("get: $command params",3,$param);
$param->{'try_count'} = 1;
$param->{'completed'} = 0;
$param->{'start_time'} = time();
$self->requests->{$request->id}{'request'} = $request;
$self->requests->{$request->id}{'param'} = $param;
# execution
$kernel->post( 'http-client' => 'request' => 'ProcessResponse' =>
GET($param->{'url'},
Connection => "Keep-Alive",
),
$request->id, #tag
lib/Agent/TCLI/Package/Net/HTTPD.pm view on Meta::CPAN
From within a TCLI Agent session:
httpd uri add regex=^/good/.* response=OK200
=head1 DESCRIPTION
This module provides a package of commands for the TCLI environment. Currently
one must use the TCLI environment (or browse the source) to see documentation
for the commands it supports within the TCLI Agent.
This package starts a specialized HTTPD on the local system. It does not
return files but does return 404 or 200 values for user defined URLs. It can
also be set to completely ignore a request. URLs may be defined with
regular expressions.
It can also log directly to the log being monitored by the Tail command
in memory with no disk writes.
=head1 INTERFACE
This module must be loaded into a Agent::TCLI::Control by an
lib/Agent/TCLI/Package/Net/HTTPD.pm view on Meta::CPAN
=cut
sub _preinit :PreInit {
my ($self,$args) = @_;
$args->{'name'} = 'tcli_httpd';
$args->{'session'} = POE::Session->create(
object_states => [
$self => [qw(
_start
_stop
_shutdown
_default
_child
establish_context
settings
show
spawn
stop
lib/Agent/TCLI/Package/Net/HTTPD.pm view on Meta::CPAN
-
- BETWEEN
- 1
- 65535
default: 8080
help: A port to listen on
manual: >
Port sets the port used for the HTTPD to receive requests on.
It must not already be in use by another process. If is is less
than 1024, then the script must already be running as root or
the HTTPD will fail to start. Port defaults to 8080.
type: Param
class: numeric
---
Agent::TCLI::Parameter:
name: hostname
constraints:
- ASCII
help: A hostname that the server will respond back with.
manual: >
The host nmae is the name the server will respond back with. It
lib/Agent/TCLI/Package/Net/HTTPD.pm view on Meta::CPAN
topic: net
usage: httpd spawn port=8080
---
Agent::TCLI::Command:
name: spawn
call_style: session
command: tcli_httpd
contexts:
httpd: spawn
handler: spawn
help: starts an http server on a particular port
manual: >
The spawn command starts an httpd listener on a particular port. One
may enable more than one httpd listener so long as they are
using different ports.
The script must have root priviledges if the port is less than 1024.
parameters:
port:
address:
hostname:
required:
port:
topic: net
lib/Agent/TCLI/Package/Net/HTTPD.pm view on Meta::CPAN
regex:
response:
handlers:
ports:
topic: testing
usage: httpd show settings
...
}
sub _start {
my ($kernel, $self, $session) =
@_[KERNEL, OBJECT, SESSION];
$self->Verbose("_start: tcli httpd starting");
# 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);
$self->handlers( [
{
'DIR' => '.*',
'SESSION' => $self->name,
'EVENT' => 'NA404',
},
] ) unless defined($self->handlers);
$self->Verbose("_start Dump ".$self->dump(1),3);
}
sub _shutdown :Cumulative {
my ($kernel, $self, $session) =
@_[KERNEL, OBJECT, SESSION];
$self->Verbose($self->name.':_shutdown:');
foreach my $port ( keys %{ $self->ports } )
{
lib/Agent/TCLI/Package/Net/HTTPD.pm view on Meta::CPAN
}
sub _stop {
my ($kernel, $self,) =
@_[KERNEL, OBJECT,];
$self->Verbose("_stop: ".$self->name." stopping",2);
}
=item spawn
This POE event handler executes the spawn command to start a new HTTPD listener.
=cut
sub spawn {
my ($kernel, $self, $sender, $request, ) =
@_[KERNEL, OBJECT, SENDER, ARG0, ];
my $txt = '';
my $param;
my $command = $request->command->[0];
lib/Agent/TCLI/Package/Net/Ping.pm view on Meta::CPAN
=over
=item new ( hash of attributes )
Usually the only attributes that are useful on creation are the
verbose and do_verbose attrbiutes that are inherited from Agent::TCLI::Base.
=cut
sub _start {
my ($kernel, $self, $session) =
@_[KERNEL, OBJECT, SESSION];
$self->Verbose("_start: tcli ping starting");
# 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);
# Keep the pinger session so we can shut it down
# Create a pinger component.
# $self->set(\@poco_pinger,
POE::Component::Client::Ping->spawn(
Alias => 'pinger', # This is the name it'll be known by.
Timeout => 10, # This is how long it waits for echo replies.
OneReply => 1, # Only tell us when success or timeout
);
return($self->name.":_start complete ");
} #end start
sub _stop {
my ($kernel, $self,) =
@_[KERNEL, OBJECT,];
$self->Verbose("_stop: ".$self->name." stopping",2);
return($self->name.":_stop complete ");
}
=item ping
lib/Agent/TCLI/Package/Net/Ping.pm view on Meta::CPAN
sub _preinit :PreInit {
my ($self,$args) = @_;
$args->{'name'} = 'tcli_ping';
$args->{'session'} = POE::Session->create(
object_states => [
$self => [qw(
_start
_stop
_shutdown
_default
_child
establish_context
ping
Pong
settings
show
)],
lib/Agent/TCLI/Package/Net/SMTP.pm view on Meta::CPAN
=cut
sub _preinit :PreInit {
my ($self,$args) = @_;
$args->{'name'} = 'tcli_smtp';
$args->{'session'} = POE::Session->create(
object_states => [
$self => [qw(
_start
_stop
_shutdown
_default
_child
establish_context
send
SendMailSuccess
SendMailFailure
settings
lib/Agent/TCLI/Package/Net/SMTP.pm view on Meta::CPAN
subject:
server:
port:
topic: network
usage: smtp show timeout
...
}
sub _start {
my ($kernel, $self, $session) =
@_[KERNEL, OBJECT, SESSION];
$self->Verbose("_start: tcli http starting");
# 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);
$self->Verbose(" Dump ".$self->dump(1),3 );
}
lib/Agent/TCLI/Package/Net/Traceroute.pm view on Meta::CPAN
=over
=item new ( hash of attributes )
Usually the only attributes that are useful on creation are the
verbose and do_verbose attrbiutes that are inherited from Agent::TCLI::Base.
=cut
sub _start {
my ($kernel, $self, $session) =
@_[KERNEL, OBJECT, SESSION];
$self->Verbose("_start: tcli traceroute starting");
# 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);
# Keep the pinger session so we can shut it down
# Create a pinger component.
POE::Component::Client::Traceroute->spawn(
lib/Agent/TCLI/Package/Net/Traceroute.pm view on Meta::CPAN
BasePort => 33434, # Defaults to 33434
PacketLen => 128, # Defaults to 68
SourceAddress => '0.0.0.0', # Defaults to '0.0.0.0'
PerHopPostback => 0, # Defaults to no PerHopPostback
Device => undef, # Defaults to undef
UseICMP => 0, # Defaults to 0
Debug => 0, # Defaults to 0
DebugSocket => 0, # Defaults to 0
);
return($self->name.":_start complete ");
} #end start
sub _shutdown {
my ($kernel, $self,) =
@_[KERNEL, OBJECT,];
$self->Verbose("_shutdown: ".$self->name." shutting down",2);
$kernel->post('tracer' => 'shutdown');
$kernel->alarm_remove_all();
return($self->name.":_shutdown complete ");
lib/Agent/TCLI/Package/Net/Traceroute.pm view on Meta::CPAN
}
sub _preinit :PreInit {
my ($self,$args) = @_;
$args->{'name'} = 'tcli_trace';
$args->{'session'} = POE::Session->create(
object_states => [
$self => [qw(
_start
_stop
_shutdown
_default
_child
establish_context
trace
TraceResponse
TraceHopResponse
settings
show
lib/Agent/TCLI/Package/Net/Traceroute.pm view on Meta::CPAN
$self->LoadYaml(<<'...');
---
Agent::TCLI::Parameter:
name: firsthop
constraints:
- UINT
default: 1
help: Set the first hop.
manual: >
Firsthop sets the starting TTL value for the traceroute. firsthop
defaults to 1 and can not be set higher than 255 or greater than max_ttl.
type: Param
class: numeric
---
Agent::TCLI::Parameter:
name: max_ttl
constraints:
- UINT
default: 30
help: Set the maximum TTL.
lib/Agent/TCLI/Package/Net/Traceroute.pm view on Meta::CPAN
---
Agent::TCLI::Parameter:
name: baseport
constraints:
- UINT
-
- BETWEEN
- 1
- 65279
default: 33434
help: The starting port for udp traces.
manual: >
Baseport sets the first port used for traceroute when not using ICMP.
The baseport is incremented by one for each hop, by traceroute
convention. BasePort defaults to 33434 and can not be higher than 65279.
type: Param
class: numeric
---
Agent::TCLI::Parameter:
name: useicmp
constraints:
t/TCLI.Package.Net.HTTPD.t view on Meta::CPAN
$t->ok('/http cget url=http://127.0.0.1:8080/bar.htm');
$t->ok('/tail test add like 404.*?foo');
$t->ok('/http cget url=http://127.0.0.1:8080/foo.htm');
$t->ok('/tail test add like 200.*?foobar');
$t->ok('/http cget url=http://127.0.0.1:8080/foobar.htm');
$t->ok('stop' );
$t->ok('uri delete regex=bar.*');
$t->unlike_body('show handlers',qr(bar),'bar gone');
# test for error on restarting on same port
$t->ok('spawn port 8000' );
$t->ok('/http cget url=http://127.0.0.1:8000/foo.htm','HTTPD up');
$t->not_ok('spawn port 8000' );
$t->not_ok('stop' );
$t->ok('stop port 8000' );
# Can't add handler after server up yet. Need to fix SimpleHTTP
# 13 tests
#$t->ok('spawn' );
#$t->ok('uri add regex=bar.*');
t/dev/target.t view on Meta::CPAN
# Remote up?
$remote->ok('status');
# get remotes IP address
$remote->ok('Control show local_address');
my $target = $remote->get_param('local_address','',30);
#add a new response to the webserver
$remote->ok('httpd uri add regex=/test2.* response=OK200');
# start remote web server with logging
$remote->ok('httpd set logging');
$remote->ok('httpd spawn port=8080');
# make sure those completed before proceeding
$test_master->done;
# have local query target webserver.
$local->ok('http tget url=http://'.$target.':8080/test1.htm resp=404');
$local->ok('http tget url=http://'.$target.':8080/test2.htm resp=200');
# check to see if it's in the logs
$remote->ok('tail test add like=test1', 'passed test test1');
$remote->ok('tail test add like=test2', 'passed test test2');
# shut down httpd
$remote->ok('httpd stop port=8080');
# make sure to shut down the transport or else the script will not stop.
$local->ok('xmpp shutdown');
# Though tests will start during building of the tests, POE isn't fully running
# and all tests will not complete until the master run is called.
$test_master->run;