enhance indent

This commit is contained in:
garnier-quentin 2019-10-29 15:40:07 +01:00
parent 28b8e0eb73
commit b43132c75a
3 changed files with 61 additions and 47 deletions

View File

@ -32,10 +32,10 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ 'broker-config:s@' => { name => 'broker_config' },
"broker-config:s@" => { name => 'broker_config' },
}); });
return $self; return $self;
} }
@ -82,8 +82,10 @@ sub run {
$self->{output}->output_add(long_msg => "Checking config '$config'"); $self->{output}->output_add(long_msg => "Checking config '$config'");
if (! -f $config or ! -r $config) { if (! -f $config or ! -r $config) {
$self->{output}->output_add(severity => 'UNKNOWN', $self->{output}->output_add(
short_msg => "'$config': not a file or cannot be read"); severity => 'UNKNOWN',
short_msg => "'$config': not a file or cannot be read"
);
next; next;
} }
@ -93,8 +95,10 @@ sub run {
$xml = $parser->parse_file($config); $xml = $parser->parse_file($config);
}; };
if ($@) { if ($@) {
$self->{output}->output_add(severity => 'UNKNOWN', $self->{output}->output_add(
short_msg => "'$config': cannot parse xml"); severity => 'UNKNOWN',
short_msg => "'$config': cannot parse xml"
);
next; next;
} }
my %failover_found = (); my %failover_found = ();

View File

@ -31,14 +31,13 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ 'warning:s' => { name => 'warning' },
"warning:s" => { name => 'warning' }, 'critical:s' => { name => 'critical' },
"critical:s" => { name => 'critical' }, 'centreon-storage-database:s' => { name => 'centreon_storage_database', default => 'centreon_storage' },
"centreon-storage-database:s" => { name => 'centreon_storage_database', default => 'centreon_storage' },
}); });
$self->{statefile_cache} = centreon::plugins::statefile->new(%options);
$self->{statefile_cache} = centreon::plugins::statefile->new(%options);
return $self; return $self;
} }
@ -68,10 +67,12 @@ sub execute {
my $total_problems_by_poller = {}; my $total_problems_by_poller = {};
while ((my $row = $self->{sql}->fetchrow_hashref())) { while ((my $row = $self->{sql}->fetchrow_hashref())) {
if (!defined($total_problems_by_poller->{$row->{name}})) { if (!defined($total_problems_by_poller->{$row->{name}})) {
$total_problems_by_poller->{$row->{name}} = { '0_1' => { label_perf => 'host_down', label => 'host down', num => 0 }, $total_problems_by_poller->{$row->{name}} = {
'0_1' => { label_perf => 'host_down', label => 'host down', num => 0 },
'1_1' => { label_perf => 'service_warning', label => 'service warning', num => 0 }, '1_1' => { label_perf => 'service_warning', label => 'service warning', num => 0 },
'1_2' => { label_perf => 'service_critical', label => 'service critical', num => 0 }, '1_2' => { label_perf => 'service_critical', label => 'service critical', num => 0 },
'1_3' => { label_perf => 'service_unknown', label => 'service unknown', num => 0 }}; '1_3' => { label_perf => 'service_unknown', label => 'service unknown', num => 0 }
};
} }
if ($row->{num} != 0 && defined($total_problems_by_poller->{$row->{name}}->{$row->{msg_type} . '_' . $row->{status}})) { if ($row->{num} != 0 && defined($total_problems_by_poller->{$row->{name}}->{$row->{msg_type} . '_' . $row->{status}})) {
@ -89,35 +90,45 @@ sub execute {
$self->{output}->output_add(long_msg => sprintf("%d total services problems", $total_problems->{services})); $self->{output}->output_add(long_msg => sprintf("%d total services problems", $total_problems->{services}));
foreach my $poller (sort keys %{$total_problems_by_poller}) { foreach my $poller (sort keys %{$total_problems_by_poller}) {
foreach my $id (sort keys %{$total_problems_by_poller->{$poller}}) { foreach my $id (sort keys %{$total_problems_by_poller->{$poller}}) {
$self->{output}->output_add(long_msg => sprintf("%d %s problems on %s", $self->{output}->output_add(
long_msg => sprintf(
"%d %s problems on %s",
$total_problems_by_poller->{$poller}->{$id}->{num}, $total_problems_by_poller->{$poller}->{$id}->{num},
$total_problems_by_poller->{$poller}->{$id}->{label}, $total_problems_by_poller->{$poller}->{$id}->{label},
$poller)); $poller
$self->{output}->perfdata_add(label => $total_problems_by_poller->{$poller}->{$id}->{label_perf} . "_" . $poller, )
);
$self->{output}->perfdata_add(
label => $total_problems_by_poller->{$poller}->{$id}->{label_perf} . "_" . $poller,
value => $total_problems_by_poller->{$poller}->{$id}->{num}, value => $total_problems_by_poller->{$poller}->{$id}->{num},
min => 0); min => 0
);
} }
} }
my $exit_code = $self->{perfdata}->threshold_check(value => $total_problems->{total}, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); my $exit_code = $self->{perfdata}->threshold_check(value => $total_problems->{total}, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
$self->{output}->output_add(severity => $exit_code, $self->{output}->output_add(severity => $exit_code,
short_msg => sprintf("%d total problems", $total_problems->{total})); short_msg => sprintf("%d total problems", $total_problems->{total}));
$self->{output}->perfdata_add(label => 'total', $self->{output}->perfdata_add(
label => 'total',
value => $total_problems->{total}, value => $total_problems->{total},
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
min => 0); min => 0
$self->{output}->perfdata_add(label => 'total_hosts', );
$self->{output}->perfdata_add(
label => 'total_hosts',
value => $total_problems->{hosts}, value => $total_problems->{hosts},
min => 0); min => 0);
$self->{output}->perfdata_add(label => 'total_services', $self->{output}->perfdata_add(
label => 'total_services',
value => $total_problems->{services}, value => $total_problems->{services},
min => 0); min => 0
);
} }
sub run { sub run {
my ($self, %options) = @_; my ($self, %options) = @_;
# $options{sql} = sqlmode object
$self->{sql} = $options{sql}; $self->{sql} = $options{sql};
$self->{statefile_cache}->read(statefile => 'sql_' . $self->{mode} . '_' . $self->{sql}->get_unique_id4save()); $self->{statefile_cache}->read(statefile => 'sql_' . $self->{mode} . '_' . $self->{sql}->get_unique_id4save());

View File

@ -65,10 +65,9 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ 'filter-poller:s' => { name => 'filter_poller' },
"filter-poller:s" => { name => 'filter_poller' }, 'centreon-storage-database:s' => { name => 'centreon_storage_database', default => 'centreon_storage' },
"centreon-storage-database:s" => { name => 'centreon_storage_database', default => 'centreon_storage' },
}); });
return $self; return $self;