tired_baboon has asked for the wisdom of the Perl Monks concerning the following question:

Long-time lurker, first-time poster. Please forgive the following atrocity.

Basically, I'm using Net::Appliance::Session to login to a Cisco router, and it's functioning perfectly. The only problem is that I'm getting a ton of output that I can't figure out how to turn off.

I've tried adding $s->set_global_log_at('error'); in hopes that it would turn off all non-error output, but to no avail. Does anyone know how to turn down the output level?

My code, taken from here, followed by a sample of the output I'm seeing:

use strict; use warnings; use Net::Appliance::Session; my $host = 'host'; my $user = 'username'; my $pass = 'password'; my $s = Net::Appliance::Session->new({ personality => 'cisco', transport => 'SSH', host => $host, do_paging => 0 }); try { $s->connect({ username => $user, password => $pass }); $s->begin_privileged({ password => $pass }); print $s->cmd('show clock'); $s->end_privileged; } catch { warn "Failed to execute command: $_"; } finally { $s->close; };

Output:

Net::CLI::Interact::ActionSet { Parents Moo::Object public methods (11) : apply_params, BUILDARGS, clone, current_matc +h, default_continuation, DOES, execute, has_current_match, has_defaul +t_continuation, new, register_callback private methods (6) : _callbacks, _do_exec, _forward_continuation_ +to_match, _has_callbacks, _marshall_responses, _pad_send_with_match internals: { _callbacks [], current_match [ [0] [Pp]assword\s*:\s*$ ], _position -1, _sequence [ [0] Net::CLI::Interact::Action { Parents Moo::Object public methods (12) : BUILDARGS, clone, continuation, +new, no_ors, num_params, params, prompt_hit, response, response_stash +, type, value private methods (0) internals: { no_ors 0, params [], response "", response_stash "", type "send", value " " } }, [1] Net::CLI::Interact::Action { Parents Moo::Object public methods (12) : BUILDARGS, clone, continuation, +new, no_ors, num_params, params, prompt_hit, response, response_stash +, type, value private methods (0) internals: { no_ors 0, params [], prompt_hit var{current_match}[0], response "password: ", response_stash "", type "match", value var{current_match} } } ] } }

Replies are listed 'Best First'.
Re: Net::Appliance::Session is sending too much output to the screen
by Discipulus (Canon) on Mar 03, 2016 at 08:45 UTC
    hello tired_baboon and welcome to (active life in) the monaastery!

    i've zero experience with such things but if i read correctly the docs $s->set_global_log_at is to turn on debug.

    In the same paragraph it is stated that $s->nci->logger is coming from Net::CLI::Interact::Logger and i suppose it is on that logger that you have to work to leverage the output. The doces says: "This module implements a generic logging service, based on Log::Dispatch but with additional options and configuration." so for a full understand you need to read also what Log::Dispatch does.

    This is the default configuration of the logger:

    # log_config( \%config ) ... { dispatchers => ['screen'], screen => { class => 'Log::Dispatch::Screen', min_level => 'debug', }, };
    So it seems you need to try different values for the min_level key.

    HtH

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

      Okay, so I attempted to navigate Net::CLI::Interact::Logger, and tried a few things, but no luck. I think I'm doing this right, but it doesn't seem to make any difference, and I'm still getting the same output.

      I slipped this snippet in immediately after my session declaration.

      $s->nci->logger->log_config({ dispatchers => ['screen'], screen => { class => 'Log::Dispatch::Screen', min_level => 'error' } });

      I also attempted another route, thinking I was attacking it at a deeper level, but it didn't do any good either

      use Log::Dispatch::Screen; my $log = Log::Dispatch->new(); $log->add( Log::Dispatch::Screen->new( name => 'screen', min_level => 'error' ) );
        okay i for sure not the best help for you.. i cannot reproduce your code nor your errors.. i just told you what i saw in the docs.

        Anyway the output you posted seems to me a dump of the Net::CLI::Interact::ActionSet that are Moo::Object stuffs. It is this the only unwanted output you get? the rest of the output is what do you expect? if you leverage the logger the otput change somehow?

        L*

        There are no rules, there are no thumbs..
        Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.