Apache-TS-AdminClient

 view release on metacpan or  search on metacpan

lib/Apache/TS/AdminClient.pm  view on Meta::CPAN

sub get_stat {
    my ( $self, $stat ) = @_;
    my $res               = "";
    my $max_read_attempts = 25;

    return undef unless defined( $self->{_socket} );
    return undef unless $self->{_select}->can_write(10);

# This is a total hack for now, we need to wrap this into the proper mgmt API library.
    $self->{_socket}
        ->print( pack( "sla*", TS_RECORD_GET, length($stat) ), $stat );

    while ( $res eq "" ) {
        return undef if ( $max_read_attempts-- < 0 );
        return undef unless $self->{_select}->can_read(10);

        my $status = $self->{_socket}->sysread( $res, 1024 );
        return undef unless defined($status) || ( $status == 0 );

    }
    my @resp = unpack( "sls", $res );
    return undef unless ( scalar(@resp) == 3 );

    if ( $resp[0] == TS_ERR_OKAY ) {
        if ( $resp[2] < TS_REC_FLOAT ) {
            @resp = unpack( "slsl", $res );
            return undef unless ( scalar(@resp) == 4 );
            return int( $resp[3] );
        }
        elsif ( $resp[2] == TS_REC_FLOAT ) {
            @resp = unpack( "slsf", $res );
            return undef unless ( scalar(@resp) == 4 );
            return $resp[3];
        }
        elsif ( $resp[2] == TS_REC_STRING ) {
            @resp = unpack( "slsa*", $res );
            return undef unless ( scalar(@resp) == 4 );
            return $resp[3];
        }
    }

    return undef;
}

1;

__END__

#-=-=-=-=-=-=-=-= Give us some POD please =-=-=-=-=-=-=-=- 

=head1 NAME:

Apache::TS::AdminClient - a perl interface to the statistics and configuration settings stored within Apache Traffic Server.

=head1 SYNOPSIS

  #!/usr/bin/perl
  use Apache::TS::AdminClient;

  my $cli = Apache::TS::AdminClient->new(%input);
  my $string = $cli->get_stat("proxy.config.product_company");
  print "$string\n";


=head1 DESCRIPTION:

AdminClient opens a TCP connection to a unix domain socket on local disk.  When the connection is established, 
AdminClient will write requests to the socket and wait for Apache Traffic Server to return a response.  Valid 
request strings can be found in RecordsConfig.cc which is included with Apache Traffic Server source.  
A list of valid request strings are included with this documentation, but this included list may not be complete
as future releases of Apache Traffic Server may include new request strings or remove existing ones.  

=head1 OPTIONS

=head2 socket_path

When the object is created for this module, it assumes the 'Unix Domain Socket' is at the default location of 
B<'/usr/local/var/trafficserver/cli'>  This can be changed when creating the object by setting B<'socket_path'>. For example: 

  my $cli = AdminClient->new(socket_path=> "/dev/null");

would make the module look for the 'Unix Domain Socket' at /dev/null.  Of course this isn't a realistic example, but can be used when
modified appropiately.  

=head2 traffic_line

There is a command line tool included with Apache Traffic Server called traffic_line which overlaps with this module.  traffic_line 
can be used to read and write statistics or config settings that this module can.  Hence if you don't want to write a perl one-liner to 
get to this information, traffic_line is your tool.

=head1 List of Request Strings

The Apache Traffic Server Administration Manual will explain what these strings represent.  (http://trafficserver.apache.org/docs/)

 proxy.config.accept_threads
 proxy.config.task_threads
 proxy.config.admin.access_control_file
 proxy.config.admin.admin_password
 proxy.config.admin.admin_user
 proxy.config.admin.advanced_ui
 proxy.config.admin.autoconf.localhost_only
 proxy.config.admin.autoconf.pac_filename
 proxy.config.admin.autoconf_port
 proxy.config.admin.autoconf.wpad_filename
 proxy.config.admin.basic_auth
 proxy.config.admin.cli_path
 proxy.config.admin.cli_port
 proxy.config.admin.html_doc_root
 proxy.config.admin.ip_allow.filename
 proxy.config.admin.lang_dict
 proxy.config.admin.load_factor
 proxy.config.admin.log_mgmt_access
 proxy.config.admin.log_resolve_hostname
 proxy.config.admin.number_config_bak
 proxy.config.admin.session
 proxy.config.admin.session.timeout
 proxy.config.admin.ssl_cert_file
 proxy.config.admin.ui_refresh_rate
 proxy.config.admin.user_id
 proxy.config.admin.use_ssl
 proxy.config.admin.web_interface_port



( run in 0.801 second using v1.01-cache-2.11-cpan-39bf76dae61 )