This commit is contained in:
garnier-quentin 2016-10-17 23:06:44 +02:00
commit c03dcf1d2b
14 changed files with 1170 additions and 8 deletions

View File

@ -55,6 +55,9 @@ sub custom_status_threshold {
sub custom_status_output {
my ($self, %options) = @_;
my $msg = 'status : ' . $self->{result_values}->{status};
if ($self->{result_values}->{information} ne '') {
$msg .= ' [information: ' . $self->{result_values}->{information} . ']';
}
return $msg;
}
@ -66,6 +69,7 @@ sub custom_status_calc {
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
$self->{result_values}->{exit_code} = $options{new_datas}->{$self->{instance} . '_exit_code'};
$self->{result_values}->{family} = $options{new_datas}->{$self->{instance} . '_family'};
$self->{result_values}->{information} = $options{new_datas}->{$self->{instance} . '_information'};
return 0;
}
@ -124,7 +128,7 @@ sub set_counters {
$self->{maps_counters}->{job} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'status' }, { name => 'display' }, { name => 'exit_code' }, { name => 'family' } ],
key_values => [ { name => 'status' }, { name => 'display' }, { name => 'exit_code' }, { name => 'family' }, { name => 'information' } ],
closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
@ -199,6 +203,7 @@ sub new {
$options{options}->add_options(arguments =>
{
"filter-name:s" => { name => 'filter_name' },
"filter-family:s" => { name => 'filter_family' },
"warning-status:s" => { name => 'warning_status' },
"critical-status:s" => { name => 'critical_status', default => '%{status} =~ /Error/i' },
"warning-long:s" => { name => 'warning_long' },
@ -261,16 +266,24 @@ sub manage_selection {
$self->{output}->output_add(long_msg => "skipping '" . $entry->{name} . "': no matching filter.", debug => 1);
next;
}
my $family = defined($entry->{family}) ? $entry->{family} : '-';
if (defined($self->{option_results}->{filter_family}) && $self->{option_results}->{filter_family} ne '' &&
$family !~ /$self->{option_results}->{filter_family}/) {
$self->{output}->output_add(long_msg => "skipping '" . $family . "': no matching filter.", debug => 1);
next;
}
my $information = defined($entry->{information}) ? $entry->{information} : '';
$information =~ s/\|/-/msg;
my $elapsed_time = $current_time - $entry->{timeBegin};
$self->{global}->{total} += 1;
$self->{global}->{lc($mapping_job_status{$entry->{status}})} += 1;
$self->{job}->{$entry->{id}} = {
display => $entry->{name},
status => $mapping_job_status{$entry->{status}},
status => $mapping_job_status{$entry->{status}}, information => $information,
exit_code => $entry->{retcode},
family => defined($entry->{family}) ? $entry->{family} : '-',
family => $family,
elapsed => $elapsed_time
};
}
@ -296,6 +309,10 @@ Check job status.
Filter name (can be a regexp).
=item B<--filter-family>
Filter family (can be a regexp).
=item B<--filter-counters>
Only display some counters (regexp can be used).
@ -316,12 +333,14 @@ Can be: 'total-error', 'total-running', 'total-unplanned',
=item B<--warning-status>
Set warning threshold for status (Default: -)
Can used special variables like: %{display}, %{status}, %{exit_code}, %{family}
Can used special variables like: %{display}, %{status},
%{exit_code}, %{family}, %{information}
=item B<--critical-status>
Set critical threshold for status (Default: '%{exit_code} =~ /Error/i').
Can used special variables like: %{display}, %{status}, %{exit_code}, %{family}
Can used special variables like: %{display}, %{status},
%{exit_code}, %{family}, %{information}
=item B<--warning-long>

View File

@ -30,7 +30,7 @@ use Pod::Find qw(pod_where);
my %handlers = (DIE => {});
my $global_version = 20160902;
my $global_version = 20161014;
my $alternative_fatpacker = 0;
sub new {

View File

@ -1,3 +1,13 @@
2016-10-14 Quentin Garnier <qgarnier@centreon.com>
* Plugin added: to check StorageTek SLxxx
* Plugin added: to check HP Storeonce Rest API
* Plugin added: to check Gorgy ntpserver SNMP
* Plugin added: to check Nortel/Avaya SNMP
* Plugin added: to check Vtom Rest API
* Plugin added: to check Sybase
* Plugin added: to check Cyberoam SNMP (#517)
* Minor fixes and enhancement
2016-09-02 Quentin Garnier <qgarnier@centreon.com>
* Plugin added: to check HP-UX SNMP (#13)
* Plugin added: to check Hitachi HNAS

View File

@ -47,6 +47,7 @@ $Param[1] = {
'NameSpace' => 'AWS/EC2',
'MetricName' => 'NetworkOut',
'ObjectName' => 'InstanceId',
'Unit' => 'Bytes',
'Labels' => {
'ShortOutput' => "Traffic Out %s Bytes",
'LongOutput' => "Traffic Out %s Bytes",

View File

@ -105,8 +105,8 @@ WHERE d.oid=sd.datid
my %prcts = ();
my $total_read_requests = $new_datas->{$$row[2] . '_blks_hit'} - $old_blks_hit;
my $total_read_disk = $new_datas->{$$row[2] . '_blks_read'} - $old_blks_read;
$prcts{hitratio_now} = ($total_read_requests == 0) ? 100 : ($total_read_requests - $total_read_disk) * 100 / $total_read_requests;
$prcts{hitratio} = ($new_datas->{$$row[2] . '_blks_hit'} == 0) ? 100 : ($new_datas->{$$row[2] . '_blks_hit'} - $new_datas->{$$row[2] . '_blks_read'}) * 100 / $new_datas->{$$row[2] . '_blks_hit'};
$prcts{hitratio_now} = (($total_read_requests + $total_read_disk) == 0) ? 100 : $total_read_requests * 100 / ($total_read_requests + $total_read_disk);
$prcts{hitratio} = (($new_datas->{$$row[2] . '_blks_hit'} + + $new_datas->{$$row[2] . '_blks_read'}) == 0) ? 100 : $new_datas->{$$row[2] . '_blks_hit'} * 100 / ($new_datas->{$$row[2] . '_blks_hit'} + $new_datas->{$$row[2] . '_blks_read'});
my $exit_code = $self->{perfdata}->threshold_check(value => $prcts{'hitratio' . ((defined($self->{option_results}->{lookback})) ? '' : '_now' )}, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
$self->{output}->output_add(long_msg => sprintf("Database '%s' hitratio at %.2f%%",

View File

@ -0,0 +1,99 @@
#
# Copyright 2016 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 database::sybase::mode::blockedprocesses;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
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 =>
{
"warning:s" => { name => 'warning', },
"critical:s" => { name => 'critical', },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
$self->{output}->option_exit();
}
}
sub run {
my ($self, %options) = @_;
# $options{sql} = sqlmode object
$self->{sql} = $options{sql};
$self->{sql}->connect();
$self->{sql}->query(query => q{SELECT count(*) FROM master.dbo.sysprocesses WHERE blocked <> 0});
my $blocked = $self->{sql}->fetchrow_array();
my $exit_code = $self->{perfdata}->threshold_check(value => $blocked, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
$self->{output}->output_add(severity => $exit_code,
short_msg => sprintf("%i blocked process(es).", $blocked));
$self->{output}->perfdata_add(label => 'blocked_processes',
value => $blocked,
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
min => 0);
$self->{output}->display();
$self->{output}->exit();
}
1;
__END__
=head1 MODE
Check MSSQL blocked processes.
=over 8
=item B<--warning>
Threshold warning.
=item B<--critical>
Threshold critical.
=back
=cut

View File

@ -0,0 +1,99 @@
#
# Copyright 2016 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 database::sybase::mode::connectedusers;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
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 =>
{
"warning:s" => { name => 'warning', },
"critical:s" => { name => 'critical', },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
$self->{output}->option_exit();
}
}
sub run {
my ($self, %options) = @_;
# $options{sql} = sqlmode object
$self->{sql} = $options{sql};
$self->{sql}->connect();
$self->{sql}->query(query => q{SELECT count(*) FROM master..sysprocesses WHERE spid >= 51});
my $users = $self->{sql}->fetchrow_array();
my $exit_code = $self->{perfdata}->threshold_check(value => $users, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
$self->{output}->output_add(severity => $exit_code,
short_msg => sprintf("%i Connected user(s).", $users));
$self->{output}->perfdata_add(label => 'connected_users',
value => $users,
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
min => 0);
$self->{output}->display();
$self->{output}->exit();
}
1;
__END__
=head1 MODE
Check MSSQL connected users.
=over 8
=item B<--warning>
Threshold warning.
=item B<--critical>
Threshold critical.
=back
=cut

View File

@ -0,0 +1,217 @@
#
# Copyright 2016 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 database::sybase::mode::databasessize;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
my $instance_mode;
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'database', type => 1, cb_prefix_output => 'prefix_database_output', message_multiple => 'All databases are OK', message_separator => ' - ' },
];
$self->{maps_counters}->{database} = [
{ label => 'data', set => {
key_values => [ { name => 'data_used' }, { name => 'data_size' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_calc_extra_options => { label_ref => 'data' },
closure_custom_output => $self->can('custom_usage_output'),
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
closure_custom_threshold_check => $self->can('custom_usage_threshold'),
}
},
{ label => 'log', set => {
key_values => [ { name => 'log_used' }, { name => 'log_size' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_calc_extra_options => { label_ref => 'log' },
closure_custom_output => $self->can('custom_usage_output'),
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
closure_custom_threshold_check => $self->can('custom_usage_threshold'),
}
},
];
}
sub custom_usage_perfdata {
my ($self, %options) = @_;
my $label = $self->{result_values}->{label} . '_used';
my $value_perf = $self->{result_values}->{used};
if (defined($instance_mode->{option_results}->{free})) {
$label = $self->{result_values}->{label} . '_free';
$value_perf = $self->{result_values}->{free};
}
my $extra_label = '';
$extra_label = '_' . $self->{result_values}->{display} if (!defined($options{extra_instance}) || $options{extra_instance} != 0);
my %total_options = ();
if ($instance_mode->{option_results}->{units} eq '%') {
$total_options{total} = $self->{result_values}->{total};
$total_options{cast_int} = 1;
}
$self->{output}->perfdata_add(label => $label . $extra_label, unit => 'B',
value => $value_perf,
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options),
min => 0, max => $self->{result_values}->{total});
}
sub custom_usage_threshold {
my ($self, %options) = @_;
my ($exit, $threshold_value);
$threshold_value = $self->{result_values}->{used};
$threshold_value = $self->{result_values}->{free} if (defined($instance_mode->{option_results}->{free}));
if ($instance_mode->{option_results}->{units} eq '%') {
$threshold_value = $self->{result_values}->{prct_used};
$threshold_value = $self->{result_values}->{prct_free} if (defined($instance_mode->{option_results}->{free}));
}
$exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]);
return $exit;
}
sub custom_usage_output {
my ($self, %options) = @_;
my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
my $msg = sprintf("Total %s: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
ucfirst($self->{result_values}->{label}),
$total_size_value . " " . $total_size_unit,
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free});
return $msg;
}
sub custom_usage_calc {
my ($self, %options) = @_;
my $label = $options{extra_options}->{label_ref};
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
$self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_' . $label . '_size'};
$self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_' . $label . '_used'};
$self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used};
$self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total};
$self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used};
$self->{result_values}->{label} = $label;
return 0;
}
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 =>
{
"filter-database:s" => { name => 'filter_database' },
"units:s" => { name => 'units', default => '%' },
"free" => { name => 'free' },
});
return $self;
}
sub prefix_database_output {
my ($self, %options) = @_;
return "Database '" . $options{instance_value}->{display} . "' ";
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$instance_mode = $self;
}
sub manage_selection {
my ($self, %options) = @_;
$options{sql}->connect();
$options{sql}->query(query => q{
select db_name(d.dbid) as db_name,
ceiling(sum(case when u.segmap != 4 then u.size/1.*@@maxpagesize end )) as data_size,
ceiling(sum(case when u.segmap != 4 then size - curunreservedpgs(u.dbid, u.lstart, u.unreservedpgs) end)/1.*@@maxpagesize) as data_used,
ceiling(sum(case when u.segmap = 4 then u.size/1.*@@maxpagesize end)) as log_size,
ceiling(sum(case when u.segmap = 4 then u.size/1.*@@maxpagesize end) - lct_admin("logsegment_freepages",d.dbid)/1.*@@maxpagesize) as log_used
from master..sysdatabases d, master..sysusages u
where u.dbid = d.dbid and d.status not in (256,4096)
group by d.dbid
order by db_name(d.dbid)
});
my $result = $options{sql}->fetchall_arrayref();
foreach my $row (@$result) {
if (defined($self->{option_results}->{filter_database}) && $self->{option_results}->{filter_database} ne '' &&
$$row[0] !~ /$self->{option_results}->{filter_database}/) {
$self->{output}->output_add(long_msg => "skipping '" . $$row[0] . "': no matching filter.", debug => 1);
next;
}
$self->{database}->{$$row[0]} = { data_size => $$row[1], data_used => $$row[2],
log_size => $$row[3], log_used => $$row[4],
display => lc($$row[0]) };
}
}
1;
__END__
=head1 MODE
Check MSSQL Database usage
=over 8
=item B<--warning-*>
Threshold warning.
Can be: 'data', 'log'.
=item B<--critical-*>
Threshold warning.
Can be: 'data', 'log'.
=item B<--filter-database>
Filter database by name. Can be a regex
=item B<--units>
Units of thresholds (Default: '%') ('%', 'B').
=item B<--free>
Thresholds are on free space left.
=back
=cut

104
database/sybase/plugin.pm Normal file
View File

@ -0,0 +1,104 @@
#
# Copyright 2016 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 database::sybase::plugin;
use strict;
use warnings;
use base qw(centreon::plugins::script_sql);
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '0.1';
%{$self->{modes}} = (
'blocked-processes' => 'database::sybase::mode::blockedprocesses',
'connected-users' => 'database::sybase::mode::connectedusers',
'connection-time' => 'centreon::common::protocols::sql::mode::connectiontime',
'databases-size' => 'database::sybase::mode::databasessize',
'sql' => 'centreon::common::protocols::sql::mode::sql',
);
return $self;
}
sub init {
my ($self, %options) = @_;
$self->{options}->add_options(
arguments => {
'hostname:s@' => { name => 'hostname' },
'port:s@' => { name => 'port' },
'tds-level:s@' => { name => 'tds_level' },
'database:s' => { name => 'database' },
}
);
$self->{options}->parse_options();
my $options_result = $self->{options}->get_options();
$self->{options}->clean();
if (defined($options_result->{hostname})) {
@{$self->{sqldefault}->{dbi}} = ();
for (my $i = 0; $i < scalar(@{$options_result->{hostname}}); $i++) {
$self->{sqldefault}->{dbi}[$i] = { data_source => 'Sybase:host=' . $options_result->{hostname}[$i] };
my $port = defined($options_result->{port}[$i]) && $options_result->{port}[$i] ne ''
? $options_result->{port}[$i] : 2638;
$self->{sqldefault}->{dbi}[$i]->{data_source} .= ';port=' . $port;
my $tds_level = defined($options_result->{tds_level}[$i]) && $options_result->{tds_level}[$i] ne ''
? $options_result->{tds_level}[$i] : 'CS_TDS_50';
$self->{sqldefault}->{dbi}[$i]->{data_source} .= ';tdsLevel=' . $tds_level;
if ((defined($options_result->{database})) && ($options_result->{database} ne '')) {
$self->{sqldefault}->{dbi}[$i]->{data_source} .= ';database=' . $options_result->{database};
}
}
}
$self->SUPER::init(%options);
}
1;
__END__
=head1 PLUGIN DESCRIPTION
Check Sybase Server.
=over 8
=item B<--hostname>
Hostname to query.
=item B<--port>
Database Server Port (Default: 2638).
=item B<--tds-level>
TDS protocol level to use (Default: 'CS_TDS_50')
=back
=cut

View File

@ -0,0 +1,99 @@
#
# Copyright 2016 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 network::cyberoam::snmp::mode::cpu;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
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 =>
{
"warning:s" => { name => 'warning' },
"critical:s" => { name => 'critical' },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
$self->{output}->option_exit();
}
}
sub run {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
my $oid_cpuPercentUsage = '.1.3.6.1.4.1.21067.2.1.2.2.1.0';
my $result = $self->{snmp}->get_leef(oids => [$oid_cpuPercentUsage], nothing_quit => 1);
my $exit = $self->{perfdata}->threshold_check(value => $result->{$oid_cpuPercentUsage},
threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("CPU Usage : %.2f %%", $result->{$oid_cpuPercentUsage}));
$self->{output}->perfdata_add(label => "cpu", unit => '%',
value => sprintf("%.2f", $result->{$oid_cpuPercentUsage}),
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
min => 0);
$self->{output}->display();
$self->{output}->exit();
}
1;
__END__
=head1 MODE
Check current processor usage.
=over 8
=item B<--warning>
Threshold warning.
=item B<--critical>
Threshold critical.
=back
=cut

View File

@ -0,0 +1,177 @@
#
# Copyright 2016 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 network::cyberoam::snmp::mode::memory;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
sub custom_usage_perfdata {
my ($self, %options) = @_;
$self->{output}->perfdata_add(label => $self->{result_values}->{label} . '_used', unit => 'B',
value => $self->{result_values}->{used},
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1),
min => 0, max => $self->{result_values}->{total});
}
sub custom_usage_threshold {
my ($self, %options) = @_;
my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{prct_used}, threshold => [ { label => 'critical-' . $self->{result_values}->{label} . '-usage', exit_litteral => 'critical' }, { label => 'warning-' . $self->{result_values}->{label} . '-usage', exit_litteral => 'warning' } ]);
return $exit;
}
sub custom_usage_output {
my ($self, %options) = @_;
my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
my $msg = sprintf("Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
$total_size_value . " " . $total_size_unit,
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free});
return $msg;
}
sub custom_usage_calc {
my ($self, %options) = @_;
$self->{result_values}->{label} = $options{extra_options}->{label_ref};
$self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_used'} + $options{new_datas}->{$self->{instance} . '_free'};
$self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_used'};
$self->{result_values}->{free} = $options{new_datas}->{$self->{instance} . '_free'};
$self->{result_values}->{prct_free} = $self->{result_values}->{free} * 100 / $self->{result_values}->{total};
$self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total};
return 0;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'memory', type => 0, cb_prefix_output => 'prefix_memory_output' },
{ name => 'swap', type => 0, cb_prefix_output => 'prefix_swap_output' }
];
$self->{maps_counters}->{memory} = [
{ label => 'physical-usage', set => {
key_values => [ { name => 'free' }, { name => 'used' } ],
closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_calc_extra_options => { label_ref => 'physical' },
closure_custom_output => $self->can('custom_usage_output'),
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
closure_custom_threshold_check => $self->can('custom_usage_threshold'),
}
},
];
$self->{maps_counters}->{swap} = [
{ label => 'swap-usage', set => {
key_values => [ { name => 'free' }, { name => 'used' } ],
closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_calc_extra_options => { label_ref => 'swap' },
closure_custom_output => $self->can('custom_usage_output'),
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
closure_custom_threshold_check => $self->can('custom_usage_threshold'),
}
},
];
}
sub prefix_memory_output {
my ($self, %options) = @_;
return "Physical memory ";
}
sub prefix_swap_output {
my ($self, %options) = @_;
return "Swap memory ";
}
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 =>
{
"filter-counters:s" => { name => 'filter_counters' },
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
my $oid_memoryCapacity = '.1.3.6.1.4.1.21067.2.1.2.4.1.0'; # in MB
my $oid_memoryPercentUsage = '.1.3.6.1.4.1.21067.2.1.2.4.2.0';
my $oid_swapCapacity = '.1.3.6.1.4.1.21067.2.1.2.4.3.0'; # in MB
my $oid_swapPercentUsage = '.1.3.6.1.4.1.21067.2.1.2.4.4.0';
my $result = $options{snmp}->get_leef(oids => [$oid_memoryCapacity, $oid_memoryPercentUsage,
$oid_swapCapacity, $oid_swapPercentUsage],
nothing_quit => 1);
my $memory_used = $result->{$oid_memoryPercentUsage} * $result->{$oid_memoryCapacity} * 1024 * 1024 / 100;
my $swap_used = $result->{$oid_swapPercentUsage} * $result->{$oid_swapCapacity} * 1024 * 1024 / 100;
$self->{memory} = {
free => $result->{$oid_memoryCapacity} * 1024 * 1024 - $memory_used,
used => $memory_used,
};
$self->{swap} = {
free => $result->{$oid_swapCapacity} * 1024 * 1024 - $swap_used,
used => $swap_used,
};
}
1;
__END__
=head1 MODE
Check memory usages.
=over 8
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example : --filter-counters='^physical-usage$'
=item B<--warning-*>
Threshold warning.
Can be: 'physical-usage' (%), 'swap-usage' (%).
=item B<--critical-*>
Threshold critical.
Can be: 'physical-usage' (%), 'swap-usage' (%).
=back
=cut

View File

@ -0,0 +1,151 @@
#
# Copyright 2016 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 network::cyberoam::snmp::mode::requests;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
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 => 'http-hits', set => {
key_values => [ { name => 'http_hits', diff => 1 } ],
output_template => 'http hits = %s',
perfdatas => [
{ label => 'http_hits', value => 'http_hits_absolute', template => '%s', min => 0 },
],
}
},
{ label => 'ftp-hits', set => {
key_values => [ { name => 'ftp_hits', diff => 1 } ],
output_template => 'ftp hits = %s',
perfdatas => [
{ label => 'ftp_hits', value => 'ftp_hits_absolute', template => '%s', min => 0 },
],
}
},
{ label => 'pop3-hits', set => {
key_values => [ { name => 'pop3_hits', diff => 1 } ],
output_template => 'pop3 hits = %s',
perfdatas => [
{ label => 'pop3_hits', value => 'pop3_hits_absolute', template => '%s', min => 0 },
],
}
},
{ label => 'imap-hits', set => {
key_values => [ { name => 'imap_hits', diff => 1 } ],
output_template => 'imap hits = %s',
perfdatas => [
{ label => 'imap_hits', value => 'imap_hits_absolute', template => '%s', min => 0 },
],
}
},
{ label => 'smtp-hits', set => {
key_values => [ { name => 'smtp_hits', diff => 1 } ],
output_template => 'smtp hits = %s',
perfdatas => [
{ label => 'smtp_hits', value => 'smtp_hits_absolute', template => '%s', min => 0 },
],
}
},
];
}
sub prefix_output {
my ($self, %options) = @_;
return "Requests: ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
if ($options{snmp}->is_snmpv1()) {
$self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3.");
$self->{output}->option_exit();
}
my $oid_httpHits = '.1.3.6.1.4.1.21067.2.1.2.7.0';
my $oid_ftpHits = '.1.3.6.1.4.1.21067.2.1.2.8.0';
my $oid_pop3Hits = '.1.3.6.1.4.1.21067.2.1.2.9.1.0';
my $oid_imapHits = '.1.3.6.1.4.1.21067.2.1.2.9.2.0';
my $oid_smtpHits = '.1.3.6.1.4.1.21067.2.1.2.9.3.0';
my $result = $options{snmp}->get_leef(oids => [$oid_httpHits, $oid_ftpHits, $oid_pop3Hits,
$oid_imapHits, $oid_smtpHits], nothing_quit => 1);
$self->{cache_name} = "cyberoam_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
$self->{global} = { http_hits => $result->{$oid_httpHits},
ftp_hits => $result->{$oid_ftpHits},
pop3_hits => $result->{$oid_pop3Hits},
imap_hits => $result->{$oid_imapHits},
smtp_hits => $result->{$oid_smtpHits} };
}
1;
__END__
=head1 MODE
Check request statistics.
=over 8
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example: --filter-counters='http-hits'
=item B<--warning-*>
Threshold warning.
Can be: http-hits, ftp-hits, pop3-hits, imap-hits, smtp-hits.
=item B<--critical-*>
Threshold critical.
Can be: http-hits, ftp-hits, pop3-hits, imap-hits, smtp-hits.
=back
=cut

View File

@ -0,0 +1,133 @@
#
# Copyright 2016 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 network::cyberoam::snmp::mode::storage;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
sub custom_usage_perfdata {
my ($self, %options) = @_;
$self->{output}->perfdata_add(label => 'used', unit => 'B',
value => $self->{result_values}->{used},
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1),
min => 0, max => $self->{result_values}->{total});
}
sub custom_usage_threshold {
my ($self, %options) = @_;
my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{prct_used}, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]);
return $exit;
}
sub custom_usage_output {
my ($self, %options) = @_;
my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
my $msg = sprintf("Storage Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
$total_size_value . " " . $total_size_unit,
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free});
return $msg;
}
sub custom_usage_calc {
my ($self, %options) = @_;
$self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'};
$self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_used'};
$self->{result_values}->{free} = $options{new_datas}->{$self->{instance} . '_total'} - $options{new_datas}->{$self->{instance} . '_used'};
$self->{result_values}->{prct_free} = $self->{result_values}->{free} * 100 / $self->{result_values}->{total};
$self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total};
return 0;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'storage', type => 0 }
];
$self->{maps_counters}->{storage} = [
{ label => 'usage', set => {
key_values => [ { name => 'used' }, { name => 'total' } ],
closure_custom_calc => $self->can('custom_usage_calc'),
closure_custom_output => $self->can('custom_usage_output'),
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
closure_custom_threshold_check => $self->can('custom_usage_threshold'),
}
},
];
}
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 =>
{
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
my $oid_diskCapacity = '.1.3.6.1.4.1.21067.2.1.2.3.1.0'; # in MB
my $oid_diskPercentUsage = '.1.3.6.1.4.1.21067.2.1.2.3.2.0';
my $result = $options{snmp}->get_leef(oids => [$oid_diskCapacity, $oid_diskPercentUsage],
nothing_quit => 1);
$self->{storage} = { used => $result->{$oid_diskPercentUsage} * $result->{$oid_diskCapacity} * 1024 * 1024 / 100,
total => $result->{$oid_diskCapacity} * 1024 * 1024 };
}
1;
__END__
=head1 MODE
Check storage usage.
=over 8
=item B<--warning-usage>
Threshold warning (in percent).
=item B<--critical-usage>
Threshold critical (in percent).
=back
=cut

View File

@ -0,0 +1,53 @@
#
# Copyright 2016 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 network::cyberoam::snmp::plugin;
use strict;
use warnings;
use base qw(centreon::plugins::script_snmp);
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '0.1';
%{$self->{modes}} = (
'cpu' => 'network::cyberoam::snmp::mode::cpu',
'interfaces' => 'snmp_standard::mode::interfaces',
'list-interfaces' => 'snmp_standard::mode::listinterfaces',
'memory' => 'network::cyberoam::snmp::mode::memory',
'requests' => 'network::cyberoam::snmp::mode::requests',
'storage' => 'network::cyberoam::snmp::mode::storage',
);
return $self;
}
1;
__END__
=head1 PLUGIN DESCRIPTION
Check Cyberoam equipments in SNMP.
=cut