<commit_before>#
# Copyright 2019 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

package apps::protocols::snmp::mode::responsetime;

use base qw(centreon::plugins::templates::counter);

use strict;
use warnings;
use Time::HiRes qw(gettimeofday tv_interval);

sub set_counters {
    my ($self, %options) = @_;
    
    $self->{maps_counters_type} = [
        { name => 'global', type => 0, cb_prefix_output => 'prefix_output' },
    ];

    $self->{maps_counters}->{global} = [
        { label => 'rta', set => {
                key_values => [ { name => 'rta' } ],
                output_template => 'rta %.3fms',
                perfdatas => [
                    { label => 'rta', value => 'rta_absolute', template => '%.3f', min => 0, unit => 'ms' },
                ],
            }
        },
        { label => 'rtmax', display_ok => 0, set => {
                key_values => [ { name => 'rtmax' } ],
                perfdatas => [
                    { label => 'rtmax', value => 'rtmax_absolute', template => '%.3f', min => 0, unit => 'ms' },
                ],
            }
        },
        { label => 'rtmin', display_ok => 0, set => {
                key_values => [ { name => 'rtmin' } ],
                perfdatas => [
                    { label => 'rtmin', value => 'rtmin_absolute', template => '%.3f', min => 0, unit => 'ms' },
                ],
            }
        },
        { label => 'pl', set => {
                key_values => [ { name => 'pl' } ],
                output_template => 'lost %s%%',
                perfdatas => [
                    { label => 'pl', value => 'pl_absolute', template => '%s', min => 0, max => 100, unit => '%' },
                ],
            }
        },
    ];
}

sub prefix_output {
    my ($self, %options) = @_;

    return "SNMP Agent ";
}

sub new {
    my ($class, %options) = @_;
    my $self = $class->SUPER::new(package => __PACKAGE__, %options);
    bless $self, $class;
    
    $self->{version} = '1.0';
    $options{options}->add_options(arguments => {
        "timeout:s" => { name => 'timeout' },
        "packets:s" => { name => 'packets' },
    });
                                
    return $self;
}

sub check_options {
    my ($self, %options) = @_;
    $self->SUPER::check_options(%options);

    $self->{option_timeout} = 5;
    $self->{option_packets} = 5;
    if (defined($self->{option_results}->{timeout}) && $self->{option_results}->{timeout} =~ /(\d+)/) {
        $self->{option_timeout} = $1;
    }
    if (defined($self->{option_results}->{packets}) && $self->{option_results}->{packets} =~ /(\d+)/) {
        $self->{option_packets} = $1;
    }
    
    $options{snmp}->set_snmp_connect_params(Timeout => $self->{option_timeout} * (10**6));
    $options{snmp}->set_snmp_connect_params(Retries => 0);
}

sub manage_selection {
    my ($self, %options) = @_;<commit_msg>better management response-time snmp mode<commit_after>#
# Copyright 2019 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

package apps::protocols::snmp::mode::responsetime;

use base qw(centreon::plugins::templates::counter);

use strict;
use warnings;
use Time::HiRes qw(gettimeofday tv_interval);

sub set_counters {
    my ($self, %options) = @_;
    
    $self->{maps_counters_type} = [
        { name => 'global', type => 0, cb_prefix_output => 'prefix_output' },
    ];

    $self->{maps_counters}->{global} = [
        { label => 'rta', set => {
                key_values => [ { name => 'rta' } ],
                output_template => 'rta %.3fms',
                perfdatas => [
                    { label => 'rta', value => 'rta_absolute', template => '%.3f', min => 0, unit => 'ms' },
                ],
            }
        },
        { label => 'rtmax', display_ok => 0, set => {
                key_values => [ { name => 'rtmax' } ],
                perfdatas => [
                    { label => 'rtmax', value => 'rtmax_absolute', template => '%.3f', min => 0, unit => 'ms' },
                ],
            }
        },
        { label => 'rtmin', display_ok => 0, set => {
                key_values => [ { name => 'rtmin' } ],
                perfdatas => [
                    { label => 'rtmin', value => 'rtmin_absolute', template => '%.3f', min => 0, unit => 'ms' },
                ],
            }
        },
        { label => 'pl', set => {
                key_values => [ { name => 'pl' } ],
                output_template => 'lost %s%%',
                perfdatas => [
                    { label => 'pl', value => 'pl_absolute', template => '%s', min => 0, max => 100, unit => '%' },
                ],
            }
        },
    ];
}

sub prefix_output {
    my ($self, %options) = @_;

    return "SNMP Agent ";
}

sub new {
    my ($class, %options) = @_;
    my $self = $class->SUPER::new(package => __PACKAGE__, %options);
    bless $self, $class;
    
    $self->{version} = '1.0';
    $options{options}->add_options(arguments => {
        "timeout:s" => { name => 'timeout' },
        "packets:s" => { name => 'packets' },
    });
                                
    return $self;
}

sub check_options {
    my ($self, %options) = @_;
    $self->SUPER::check_options(%options);

    $self->{option_timeout} = 5;
    $self->{option_packets} = 5;
    if (defined($self->{option_results}->{timeout}) && $self->{option_results}->{timeout} =~ /(\d+)/) {
        $self->{option_timeout} = $1;
    }
    if (defined($self->{option_results}->{packets}) && $self->{option_results}->{packets} =~ /(\d+)/) {
        $self->{option_packets} = $1;
    }
    
    $options{snmp}->set_snmp_connect_params(Timeout => $self->{option_timeout} * (10**6));
    $options{snmp}->set_snmp_connect_params(Retries => 0);
    $options{snmp}->set_snmp_params(subsetleef => 1);
}

sub manage_selection {
    my ($self, %options) = @_;
{'fraction_non_alphanumeric': 0.17329071706503613, 'fraction_numerical': 0.009032795997776542, 'mean_word_length': 2.2100802854594113, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 161, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '398622', 'n_tokens_mistral': 2310, 'n_tokens_neox': 2211, 'n_words': 548}