Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor riverbed steelhead #971

Merged
merged 2 commits into from
Apr 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
200 changes: 109 additions & 91 deletions network/riverbed/steelhead/snmp/mode/bwoptimization.pm
Original file line number Diff line number Diff line change
Expand Up @@ -20,112 +20,117 @@

package network::riverbed::steelhead::snmp::mode::bwoptimization;

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

use strict;
use warnings;
use POSIX;
use centreon::plugins::statefile;
use Digest::MD5 qw(md5_hex);

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

$self->{maps_counters_type} = [
{ name => 'global', type => 0, cb_prefix_output => 'prefix_output' }
];

$self->{maps_counters}->{global} = [
{ label => 'wan2lan-lan', set => {
key_values => [ { name => 'bwHCAggInLan', diff => 1 } ],
output_template => 'Wan2Lan on Lan: %s %s/s',
output_change_bytes => 1,
perfdatas => [
{ label => 'wan2lan_lan', value => 'bwHCAggInLan_absolute',
template => '%s', min => 0, unit => 'B/s' },
],
}
},
{ label => 'wan2lan-wan', set => {
key_values => [ { name => 'bwHCAggInWan', diff => 1 } ],
output_template => 'Wan2Lan on Wan: %s %s/s',
output_change_bytes => 1,
perfdatas => [
{ label => 'wan2lan_wan', value => 'bwHCAggInWan_absolute',
template => '%s', min => 0, unit => 'B/s' },
],
}
},
{ label => 'lan2wan-lan', set => {
key_values => [ { name => 'bwHCAggOutLan', diff => 1 } ],
output_template => 'Lan2Wan on Lan: %s %s/s',
output_change_bytes => 1,
perfdatas => [
{ label => 'lan2wan_lan', value => 'bwHCAggOutLan_absolute',
template => '%s', min => 0, unit => 'B/s' },
],
}
},
{ label => 'wan2lan-lan', set => {
key_values => [ { name => 'bwHCAggOutWan', diff => 1 } ],
output_template => 'Lan2Wan on Wan: %s %s/s',
output_change_bytes => 1,
perfdatas => [
{ label => 'wan2lan_lan', value => 'bwHCAggOutWan_absolute',
template => '%s', min => 0, unit => 'B/s' },
],
}
},
];
}

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

return "Optimized: ";
}

sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
bless $self, $class;

$self->{version} = '0.1';
$options{options}->add_options(arguments =>
{
});

$self->{statefile_value} = centreon::plugins::statefile->new(%options);
return $self;
}

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

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

$self->{snmp} = $options{snmp};
$self->{hostname} = $self->{snmp}->get_hostname();
$self->{snmp_port} = $self->{snmp}->get_port();

my $oid_bwHCAggInLan = '.1.3.6.1.4.1.17163.1.1.5.6.1.1.0'; # in bytes, 64 bits
my $oid_bwHCAggInWan = '.1.3.6.1.4.1.17163.1.1.5.6.1.2.0'; # in bytes, 64 bits
my $oid_bwHCAggOutLan = '.1.3.6.1.4.1.17163.1.1.5.6.1.3.0'; # in bytes, 64 bits
my $oid_bwHCAggOutWan = '.1.3.6.1.4.1.17163.1.1.5.6.1.4.0'; # in bytes, 64 bits
my ($result, $bw_in_lan, $bw_out_lan, $bw_in_wan, $bw_out_wan);

$result = $self->{snmp}->get_leef(oids => [ $oid_bwHCAggInLan, $oid_bwHCAggInWan, $oid_bwHCAggOutLan, $oid_bwHCAggOutWan ], nothing_quit => 1);
$bw_in_lan = $result->{$oid_bwHCAggInLan};
$bw_in_wan = $result->{$oid_bwHCAggInWan};
$bw_out_lan = $result->{$oid_bwHCAggOutLan};
$bw_out_wan = $result->{$oid_bwHCAggOutWan};

$self->{statefile_value}->read(statefile => 'steelhead_' . $self->{hostname} . '_' . $self->{snmp_port} . '_' . $self->{mode});
my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
my $old_bwHCAggInLan = $self->{statefile_value}->get(name => 'bwHCAggInLan');
my $old_bwHCAggInWan = $self->{statefile_value}->get(name => 'bwHCAggInWan');
my $old_bwHCAggOutLan = $self->{statefile_value}->get(name => 'bwHCAggOutLan');
my $old_bwHCAggOutWan = $self->{statefile_value}->get(name => 'bwHCAggOutWan');

my $new_datas = {};
$new_datas->{last_timestamp} = time();
$new_datas->{bwHCAggInLan} = $bw_in_lan;
$new_datas->{bwHCAggInWan} = $bw_in_wan;
$new_datas->{bwHCAggOutLan} = $bw_out_lan;
$new_datas->{bwHCAggOutWan} = $bw_out_wan;

$self->{statefile_value}->write(data => $new_datas);

if (!defined($old_timestamp) || !defined($old_bwHCAggInLan) || !defined($old_bwHCAggInWan) || !defined($old_bwHCAggOutLan) || !defined($old_bwHCAggOutWan)) {
$self->{output}->output_add(severity => 'OK',
short_msg => "Buffer creation...");
$self->{output}->display();
$self->{output}->exit();
# STEELHEAD-MIB
my $oids = {
bwHCAggInLan => '.1.3.6.1.4.1.17163.1.1.5.6.1.1.0',
bwHCAggInWan => '.1.3.6.1.4.1.17163.1.1.5.6.1.2.0',
bwHCAggOutLan => '.1.3.6.1.4.1.17163.1.1.5.6.1.3.0',
bwHCAggOutWan => '.1.3.6.1.4.1.17163.1.1.5.6.1.4.0',
};

# STEELHEAD-EX-MIB
my $oids_ex = {
bwHCAggInLan => '.1.3.6.1.4.1.17163.1.51.5.6.1.1.0',
bwHCAggInWan => '.1.3.6.1.4.1.17163.1.51.5.6.1.2.0',
bwHCAggOutLan => '.1.3.6.1.4.1.17163.1.51.5.6.1.3.0',
bwHCAggOutWan => '.1.3.6.1.4.1.17163.1.51.5.6.1.4.0',
};

my $result = $options{snmp}->get_leef(oids => [ values %{$oids}, values %{$oids_ex} ], nothing_quit => 1);

$self->{cache_name} = "riverbed_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() .
'_' . $self->{mode} . '_' . md5_hex('all');

$self->{global} = {};

if (defined($result->{$oids->{bwHCAggInLan}})) {
foreach (keys %{$oids}) {
$self->{global}->{$_} = $result->{$oids->{$_}};
}
} else {
foreach (keys %{$oids_ex}) {
$self->{global}->{$_} = $result->{$oids_ex->{$_}};
}
}

$old_bwHCAggInLan = 0 if ($old_bwHCAggInLan > $new_datas->{bwHCAggInLan});
$old_bwHCAggInWan = 0 if ($old_bwHCAggInWan > $new_datas->{bwHCAggInWan});
$old_bwHCAggOutLan = 0 if ($old_bwHCAggOutLan > $new_datas->{bwHCAggOutLan});
$old_bwHCAggOutWan = 0 if ($old_bwHCAggOutWan > $new_datas->{bwHCAggOutWan});

my $delta_time = $new_datas->{last_timestamp} - $old_timestamp;
$delta_time = 1 if ($delta_time == 0);

my $bwHCAggInLanPerSec = int(($new_datas->{bwHCAggInLan} - $old_bwHCAggInLan) / $delta_time);
my $bwHCAggInWanPerSec = int(($new_datas->{bwHCAggInWan} - $old_bwHCAggInWan) / $delta_time);
my $bwHCAggOutLanPerSec = int(($new_datas->{bwHCAggOutLan} - $old_bwHCAggOutLan) / $delta_time);
my $bwHCAggOutWanPerSec = int(($new_datas->{bwHCAggOutWan} - $old_bwHCAggOutWan) / $delta_time);

$self->{output}->perfdata_add(label => 'wan2lan_lan', unit => 'B/s',
value => $bwHCAggInLanPerSec,
min => 0);
$self->{output}->perfdata_add(label => 'wan2lan_wan', unit => 'B/s',
value => $bwHCAggInWanPerSec,
min => 0);
$self->{output}->perfdata_add(label => 'lan2wan_lan', unit => 'B/s',
value => $bwHCAggOutLanPerSec,
min => 0);
$self->{output}->perfdata_add(label => 'lan2wan_wan', unit => 'B/s',
value => $bwHCAggOutWanPerSec,
min => 0);

my ($bwHCAggInLanPerSec_value, $bwHCAggInLanPerSec_unit) = $self->{perfdata}->change_bytes(value => $bwHCAggInLanPerSec);
my ($bwHCAggInWanPerSec_value, $bwHCAggInWanPerSec_unit) = $self->{perfdata}->change_bytes(value => $bwHCAggInWanPerSec);
my ($bwHCAggOutLanPerSec_value, $bwHCAggOutLanPerSec_unit) = $self->{perfdata}->change_bytes(value => $bwHCAggOutLanPerSec);
my ($bwHCAggOutWanPerSec_value, $bwHCAggOutWanPerSec_unit) = $self->{perfdata}->change_bytes(value => $bwHCAggOutWanPerSec);
$self->{output}->output_add(severity => 'OK',
short_msg => sprintf("Optimized: Wan2Lan on Lan %s/s, Wan2Lan on Wan %s/s, Lan2Wan on Lan %s/s, Lan2Wan on Wan %s/s",
$bwHCAggInLanPerSec_value . " " . $bwHCAggInLanPerSec_unit,
$bwHCAggInWanPerSec_value . " " . $bwHCAggInWanPerSec_unit,
$bwHCAggOutLanPerSec_value . " " . $bwHCAggOutLanPerSec_unit,
$bwHCAggOutWanPerSec_value . " " . $bwHCAggOutWanPerSec_unit
));

$self->{output}->display();
$self->{output}->exit();
}

1;
Expand All @@ -134,7 +139,20 @@ __END__

=head1 MODE

Total optimized bytes across all application ports in both directions and on both sides, in bytes per second (STEELHEAD-MIB).
Total optimized bytes across all application ports in both directions and on both sides,
in bytes per second (STEELHEAD-MIB and STEELHEAD-EX-MIB).

=over 8

=item B<--warning-*>

Threshold warning (Can be: 'wan2lan-lan', 'wan2lan-wan',
'lan2wan-lan', 'lan2wan-wan')

=item B<--critical-*>

Threshold critical (Can be: 'wan2lan-lan', 'wan2lan-wan',
'lan2wan-lan', 'lan2wan-wan')

=over 8

Expand Down
Loading