diff --git a/centreon/common/cisco/standard/snmp/mode/ipsectunnel.pm b/centreon/common/cisco/standard/snmp/mode/ipsectunnel.pm index 8c06ac262..adc1dfde8 100644 --- a/centreon/common/cisco/standard/snmp/mode/ipsectunnel.pm +++ b/centreon/common/cisco/standard/snmp/mode/ipsectunnel.pm @@ -27,6 +27,130 @@ use warnings; use Digest::MD5 qw(md5_hex); use Socket; +sub custom_traffic_perfdata { + my ($self, %options) = @_; + + $self->{output}->perfdata_add( + label => 'traffic_' . lc($self->{result_values}->{label}), unit => 'b/s', + instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, + value => sprintf("%.2f", $self->{result_values}->{traffic_per_seconds}), + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), + min => 0 + ); +} + +sub custom_traffic_threshold { + my ($self, %options) = @_; + + return $self->{perfdata}->threshold_check(value => $self->{result_values}->{traffic_per_seconds}, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]); +} + +sub custom_traffic_output { + my ($self, %options) = @_; + + my ($traffic_value, $traffic_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{traffic_per_seconds}, network => 1); + return sprintf( + 'traffic %s: %s/s', + lc($self->{result_values}->{label}), + $traffic_value . $traffic_unit + ); +} + +sub custom_traffic_calc { + my ($self, %options) = @_; + + if (!defined($options{old_datas}->{$self->{instance} . '_display'})) { + $self->{error_msg} = "Buffer creation"; + return -1; + } + + my $total_bytes = 0; + foreach (keys %{$options{new_datas}}) { + if (/$self->{instance}_cipSecTunHc$options{extra_options}->{label_ref}Octets_(\d+)/) { + my $new_bytes = $options{new_datas}->{$_}; + next if (!defined($options{old_datas}->{$_})); + my $old_bytes = $options{old_datas}->{$_}; + + my $diff_bytes = $new_bytes - $old_bytes; + $total_bytes += (($diff_bytes < 0) ? $new_bytes : $diff_bytes); + } elsif (/$self->{instance}_cipSecTun$options{extra_options}->{label_ref}Octets_(\d+)/) { + my $new_bytes = $options{new_datas}->{$_}; + my $new_wraps = $options{new_datas}->{$self->{instance} . '_cipSecTun' . $options{extra_options}->{label_ref} . 'OctWraps_' . $1}; + next if (!defined($options{old_datas}->{$_})); + my ($old_bytes, $old_wraps) = ($options{old_datas}->{$_}, $options{old_datas}->{$self->{instance} . '_cipSecTun' . $options{extra_options}->{label_ref} . 'OctWraps_' . $1}); + + my $diff_bytes = $new_bytes - $old_bytes + (($new_wraps - $old_wraps) * (2**32)); + $total_bytes += (($diff_bytes < 0) ? $new_bytes : $diff_bytes); + } + } + + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + $self->{result_values}->{traffic_per_seconds} = ($total_bytes * 8) / $options{delta_time}; + $self->{result_values}->{label} = $options{extra_options}->{label_ref}; + + return 0; +} + +sub custom_drop_perfdata { + my ($self, %options) = @_; + + $self->{output}->perfdata_add( + label => 'drop_' . lc($self->{result_values}->{label}), unit => 'pkts/s', + instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, + value => sprintf("%.2f", $self->{result_values}->{pkts_per_seconds}), + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), + min => 0 + ); +} + +sub custom_drop_threshold { + my ($self, %options) = @_; + + return $self->{perfdata}->threshold_check(value => $self->{result_values}->{pkts_per_seconds}, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]); +} + +sub custom_drop_output { + my ($self, %options) = @_; + + return sprintf( + 'drop %s: %s pkts/s', + lc($self->{result_values}->{label}), $self->{result_values}->{pkts_per_seconds} + ); +} + +sub custom_drop_calc { + my ($self, %options) = @_; + + if (!defined($options{old_datas}->{$self->{instance} . '_display'})) { + $self->{error_msg} = "Buffer creation"; + return -1; + } + + my $total_pkts = 0; + foreach (keys %{$options{new_datas}}) { + if (/$self->{instance}_cipSecTun$options{extra_options}->{label_ref}DropPkts_(\d+)/) { + next if (!defined($options{old_datas}->{$_})); + + my $diff_pkts = $options{new_datas}->{$_} - $options{old_datas}->{$_}; + $total_pkts += (($diff_pkts < 0) ? $options{new_datas}->{$_} : $diff_pkts); + } + } + + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + $self->{result_values}->{pkts_per_seconds} = $total_pkts / $options{delta_time}; + $self->{result_values}->{label} = $options{extra_options}->{label_ref}; + + return 0; +} + +sub prefix_tunnel_output { + my ($self, %options) = @_; + + return "Tunnel '" . $options{instance_value}->{display} . "' "; +} + sub set_counters { my ($self, %options) = @_; @@ -38,7 +162,7 @@ sub set_counters { $self->{maps_counters}->{global} = [ { label => 'tunnels-total', set => { key_values => [ { name => 'total' } ], - output_template => 'Total Tunnels : %s', + output_template => 'Total tunnels: %s', perfdatas => [ { label => 'total_tunnels', template => '%s', min => 0 } ] @@ -85,7 +209,7 @@ sub set_counters { }, { label => 'sa-total', set => { key_values => [ { name => 'sa' }, { name => 'display' } ], - output_template => 'Total SA : %s', + output_template => 'total sa: %s', perfdatas => [ { label => 'total_sa', template => '%s', min => 0, label_extra_instance => 1, instance_use => 'display' } ] @@ -94,138 +218,6 @@ sub set_counters { ]; } -sub custom_traffic_perfdata { - my ($self, %options) = @_; - - my $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}); - my $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}); - - $self->{output}->perfdata_add( - label => 'traffic_' . lc($self->{result_values}->{label}), unit => 'b/s', - instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, - value => sprintf("%.2f", $self->{result_values}->{traffic_per_seconds}), - warning => $warning, - critical => $critical, - min => 0 - ); -} - -sub custom_traffic_threshold { - my ($self, %options) = @_; - - return $self->{perfdata}->threshold_check(value => $self->{result_values}->{traffic_per_seconds}, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]); -} - -sub custom_traffic_output { - my ($self, %options) = @_; - - my ($traffic_value, $traffic_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{traffic_per_seconds}, network => 1); - return sprintf( - 'Traffic %s : %s/s', - $self->{result_values}->{label}, - $traffic_value . $traffic_unit - ); -} - -sub custom_traffic_calc { - my ($self, %options) = @_; - - if (!defined($options{old_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref}})) { - $self->{error_msg} = "Buffer creation"; - return -1; - } - - my $total_bytes = 0; - foreach (keys %{$options{new_datas}}) { - if (/$self->{instance}_cipSecTunHc$options{extra_options}->{label_ref}Octets_(\d+)/) { - my $new_bytes = $options{new_datas}->{$_}; - next if (!defined($options{old_datas}->{$_})); - my $old_bytes = $options{old_datas}->{$_}; - - $total_bytes += $new_bytes - $old_bytes; - $total_bytes += $new_bytes if ($total_bytes <= 0); - } elsif (/$self->{instance}_cipSecTun$options{extra_options}->{label_ref}Octets_(\d+)/) { - my $new_bytes = $options{new_datas}->{$_}; - my $new_wraps = $options{new_datas}->{$self->{instance} . '_cipSecTun' . $options{extra_options}->{label_ref} . 'OctWraps_' . $1}; - next if (!defined($options{old_datas}->{$_})); - my ($old_bytes, $old_wraps) = ($options{old_datas}->{$_}, $options{old_datas}->{$self->{instance} . '_cipSecTun' . $options{extra_options}->{label_ref} . 'OctWraps_' . $1}); - - $total_bytes += $new_bytes - $old_bytes + (($new_wraps - $old_wraps) * (2**32)); - $total_bytes += $new_bytes if ($total_bytes <= 0); - } - } - - $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; - $self->{result_values}->{traffic_per_seconds} = ($total_bytes * 8) / $options{delta_time}; - $self->{result_values}->{label} = $options{extra_options}->{label_ref}; - - return 0; -} - -sub custom_drop_perfdata { - my ($self, %options) = @_; - - my $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}); - my $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}); - - $self->{output}->perfdata_add( - label => 'drop_' . lc($self->{result_values}->{label}), unit => 'pkts/s', - instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, - value => sprintf("%.2f", $self->{result_values}->{pkts_per_seconds}), - warning => $warning, - critical => $critical, - min => 0 - ); -} - -sub custom_drop_threshold { - my ($self, %options) = @_; - - return $self->{perfdata}->threshold_check(value => $self->{result_values}->{pkts_per_seconds}, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]); -} - -sub custom_drop_output { - my ($self, %options) = @_; - - return sprintf( - 'Drop %s : %s pkts/s', - $self->{result_values}->{label}, $self->{result_values}->{pkts_per_seconds} - ); -} - -sub custom_drop_calc { - my ($self, %options) = @_; - - if (!defined($options{old_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref}})) { - $self->{error_msg} = "Buffer creation"; - return -1; - } - - my $total_pkts = 0; - foreach (keys %{$options{new_datas}}) { - if (/$self->{instance}_cipSecTun$options{extra_options}->{label_ref}DropPkts_(\d+)/) { - my $new_pkts = $options{new_datas}->{$_}; - next if (!defined($options{old_datas}->{$_})); - my $old_pkts = $options{old_datas}->{$_}; - - $old_pkts = 0 if ($old_pkts > $new_pkts); - $total_pkts += $new_pkts - $old_pkts; - } - } - - $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; - $self->{result_values}->{pkts_per_seconds} = $total_pkts / $options{delta_time}; - $self->{result_values}->{label} = $options{extra_options}->{label_ref}; - - return 0; -} - -sub prefix_tunnel_output { - my ($self, %options) = @_; - - return "Tunnel '" . $options{instance_value}->{display} . "' "; -} - sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); @@ -252,13 +244,13 @@ my $mapping2 = { cipSecTunOutOctets => { oid => '.1.3.6.1.4.1.9.9.171.1.3.2.1.39' }, cipSecTunHcOutOctets => { oid => '.1.3.6.1.4.1.9.9.171.1.3.2.1.40' }, # seems buggy cipSecTunOutOctWraps => { oid => '.1.3.6.1.4.1.9.9.171.1.3.2.1.41' }, - cipSecTunOutDropPkts => { oid => '.1.3.6.1.4.1.9.9.171.1.3.2.1.46' }, + cipSecTunOutDropPkts => { oid => '.1.3.6.1.4.1.9.9.171.1.3.2.1.46' } }; my $mapping3 = { cipSecEndPtLocalAddr1 => { oid => '.1.3.6.1.4.1.9.9.171.1.3.3.1.4' }, cipSecEndPtLocalAddr2 => { oid => '.1.3.6.1.4.1.9.9.171.1.3.3.1.5' }, cipSecEndPtRemoteAddr1 => { oid => '.1.3.6.1.4.1.9.9.171.1.3.3.1.10' }, - cipSecEndPtRemoteAddr2 => { oid => '.1.3.6.1.4.1.9.9.171.1.3.3.1.11' }, + cipSecEndPtRemoteAddr2 => { oid => '.1.3.6.1.4.1.9.9.171.1.3.3.1.11' } }; my $oid_cikeTunnelEntry = '.1.3.6.1.4.1.9.9.171.1.2.3.1'; @@ -268,7 +260,7 @@ my $oid_cipSecTunIkeTunnelIndex = '.1.3.6.1.4.1.9.9.171.1.3.2.1.2'; sub manage_selection { my ($self, %options) = @_; - + $self->{tunnel} = {}; my $request_oids = [ { oid => $oid_cikeTunnelEntry, start => $mapping->{cikeTunLocalValue}->{oid}, end => $mapping->{cikeTunActiveTime}->{oid} }, @@ -292,12 +284,12 @@ sub manage_selection { $self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter name.", debug => 1); next; } - + foreach my $key (keys %{$results->{$oid_cipSecTunIkeTunnelIndex}}) { next if ($results->{$oid_cipSecTunIkeTunnelIndex}->{$key} != $cike_tun_index); $key =~ /^$oid_cipSecTunIkeTunnelIndex\.(\d+)/; my $cip_tun_index = $1; - + my $result2 = $options{snmp}->map_instance(mapping => $mapping2, results => $results->{$oid_cipSecTunnelEntry}, instance => $cip_tun_index); my $sa_name = ''; foreach my $key2 (keys %{$results->{$oid_cipSecEndPtEntry}}) { @@ -307,13 +299,13 @@ sub manage_selection { last; } } - + if (defined($self->{option_results}->{filter_sa}) && $self->{option_results}->{filter_sa} ne '' && $sa_name !~ /$self->{option_results}->{filter_sa}/) { $self->{output}->output_add(long_msg => "skipping '" . $sa_name . "': no matching filter sa.", debug => 1); next; } - + $self->{tunnel}->{$name} = { display => $name, sa => 0 } if (!defined($self->{tunnel}->{$name})); if (defined($result2->{cipSecTunHcInOctets}) && defined($result2->{cipSecTunHcOutOctets})) { @@ -329,12 +321,12 @@ sub manage_selection { $self->{tunnel}->{$name}->{sa}++; } } - + $self->{cache_name} = 'cisco_ipsectunnel_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')) . '_' . (defined($self->{option_results}->{filter_sa}) ? md5_hex($self->{option_results}->{filter_sa}) : md5_hex('all')) . '_' . (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); - + $self->{global} = { total => scalar(keys %{$self->{tunnel}}) }; }