This repository has been archived by the owner on Dec 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 240
+ create centreon_health script #5990
Closed
Closed
Changes from 14 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
2545787
Merge pull request #1 from centreon/master
98a3eba
+ WIP - centreon_health script to gather various data
fed4083
+ Still WIP - add partitioning check, rrd outdated, fix headers
f0a1b5a
+ remove overkill checkglobal pm
f1af893
+ finish checkbroker initial module (subject to change)
990d9a8
+ wip - complete working version TODO: output class
8d9c2ae
delete temp copy/paste
11e2efb
remove ssh from misc as it lives in a dedicated ssh module
856129e
+ initial release for centreon_health overview script v1
7a2b905
+ working with perl 5.10 and enhance el6/2.7 compatibility
e71ea14
+ add markdown output (easier for github copy/paste)
c7ef396
- remove unimplemented option
4d7fa58
+ add few things to db check
5562074
+ make markdown github compliant
465ce9b
handle query errors
7595180
+ really launch query ..
67f3dd5
+ better compat with old perl version
c5e3b9d
+ fix division by zero, fix empty value
cgagnaire c62ad7b
Merge pull request #2 from cgagnaire/PR5990-fix-division-by-zero
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/usr/bin/env perl | ||
|
||
use warnings; | ||
use centreon::script::centreon_health; | ||
|
||
centreon::script::centreon_health->new()->run(); | ||
|
||
__END__ | ||
|
||
=head1 NAME | ||
|
||
centreon_health - a tool/script to gather informations about Centreon ("noroot" script) | ||
|
||
=head1 SYNOPSIS | ||
|
||
centreon_health [options] | ||
|
||
=head1 OPTIONS | ||
|
||
=over 8 | ||
|
||
=item B<--centstorage-db> <value> | ||
|
||
Specify the name of your centstorage db if not standard | ||
(default: centreon_storage). | ||
|
||
=item B<--centreon-branch> <value> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it could be better if you get this information in the centreon database directly. |
||
|
||
Specify centreon version (X.Y format) if older than 2.8 | ||
(default: 2.8). | ||
|
||
=item B<--check-protocol> <value> | ||
|
||
Specify favorite check protocol (will be implemented later, 'snmp' is the only one available for now) | ||
|
||
=item B<--snmp-community> <value> | ||
|
||
Specify snmp community to execute plugins | ||
|
||
=item B<--output-type> <value> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Option is --ouput-format |
||
|
||
Specify output type. Can be: 'MARKDOWN', 'JSON', 'TEXT' or 'DUMPER' (last if for debugging only, raw perl struct) | ||
|
||
=item B<--skip-*> | ||
|
||
Skip check that might be long (rrd and db e.g) on large setup or overkill in some situation | ||
Can be : --skip-rrd, --skip-db, --skip-logs | ||
|
||
=head1 DESCRIPTION | ||
|
||
B<centreon_health> will gather some informations about centreon global metrics | ||
sample usage: su - centreon -c "/usr/share/centreon/bin/centreon_health --skip-logs" | ||
|
||
=cut |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# | ||
# Copyright 2017 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 centreon::health::checkbroker; | ||
|
||
use strict; | ||
use warnings; | ||
use JSON; | ||
use POSIX qw(strftime); | ||
use centreon::common::misc; | ||
use centreon::health::ssh; | ||
|
||
sub new { | ||
my $class = shift; | ||
my $self = {}; | ||
$self->{output} = {}; | ||
|
||
bless $self, $class; | ||
return $self; | ||
} | ||
|
||
sub json_parsing { | ||
my ($self, %options) = @_; | ||
|
||
my $json_content = JSON->new->decode($options{json_content}); | ||
foreach my $key (keys %$json_content) { | ||
if ($key =~ m/^endpoint/) { | ||
foreach my $broker_metric (keys %{$json_content->{$key}}) { | ||
next if ($broker_metric !~ m/version|event_processing|last_connection|queued|state/); | ||
$self->{output}->{$options{poller_name}}->{$options{file_name}}->{$broker_metric} = ($broker_metric =~ m/^last_connection/ && $json_content->{$key}->{$broker_metric} != -1) | ||
? strftime("%m/%d/%Y %H:%M:%S",localtime($json_content->{$key}->{$broker_metric})) | ||
: $json_content->{$key}->{$broker_metric} ; | ||
} | ||
} elsif ($key =~ m/version/) { | ||
$self->{output}->{$options{poller_name}}->{$options{file_name}}->{$key} = $json_content->{$key}; | ||
} | ||
|
||
} | ||
|
||
return $self->{output} | ||
|
||
} | ||
|
||
sub run { | ||
my $self = shift; | ||
my ($centreon_db, $server_list, $centreon_version) = @_; | ||
|
||
my $sth; | ||
|
||
if ($centreon_version ne "2.8") { | ||
$self->{output}->{not_compliant} = "Incompatible file format, work only with JSON format"; | ||
return $self->{output} | ||
} | ||
|
||
return if ($centreon_version ne "2.8"); | ||
foreach my $server (keys %$server_list) { | ||
$sth = $centreon_db->query("SELECT config_name, cache_directory | ||
FROM cfg_centreonbroker | ||
WHERE stats_activate='1' | ||
AND ns_nagios_server=".$centreon_db->quote($server).""); | ||
|
||
if ($server_list->{$server}->{localhost} eq "YES") { | ||
while (my $row = $sth->fetchrow_hashref()) { | ||
my ($lerror, $stdout) = centreon::common::misc::backtick(command => "cat " . $row->{cache_directory} . "/" . $row->{config_name} . "-stats.json"); | ||
$self->{output} = $self->json_parsing(json_content => $stdout, | ||
poller_name => $server_list->{$server}->{name}, | ||
file_name => $row->{config_name}. "-stats.json"); | ||
} | ||
} else { | ||
while (my $row = $sth->fetchrow_hashref()) { | ||
my $stdout = centreon::health::ssh->new->main(host => $server_list->{$server}->{address}, | ||
port => $server_list->{$server}->{ssh_port}, | ||
userdata => $row->{cache_directory} . "/" . $row->{config_name} . "-stats.json", | ||
command => "cat " . $row->{cache_directory} . "/" . $row->{config_name} . "-stats.json"); | ||
$self->{output} = $self->json_parsing(json_content => $stdout, | ||
poller_name => $server_list->{$server}->{name}, | ||
file_name => $row->{config_name}. "-stats.json"); | ||
|
||
} | ||
} | ||
|
||
} | ||
return $self->{output} | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# | ||
# Copyright 2017 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 centreon::health::checkdb; | ||
|
||
use strict; | ||
use warnings; | ||
use POSIX qw(strftime); | ||
use centreon::health::misc; | ||
|
||
sub new { | ||
my $class = shift; | ||
my $self = {}; | ||
$self->{output} = {}; | ||
|
||
bless $self, $class; | ||
return $self; | ||
} | ||
|
||
sub run { | ||
my $self = shift; | ||
my ($centreon_db, $centstorage_db, $centstorage_db_name, $flag, $logger) = @_; | ||
my $size = 0; | ||
my ($sth, $status); | ||
|
||
foreach my $db_name ('centreon', $centstorage_db_name) { | ||
$sth = $centreon_db->query("SELECT table_schema AS db_name, SUM(data_length+index_length) AS db_size | ||
FROM information_schema.tables | ||
WHERE table_schema=".$centreon_db->quote($db_name).""); | ||
while (my $row = $sth->fetchrow_hashref) { | ||
$self->{output}->{db_size}->{$row->{db_name}} = centreon::health::misc::format_bytes(bytes_value => $row->{db_size}); | ||
} | ||
next if $db_name !~ /$centstorage_db_name/; | ||
foreach my $table ('data_bin', 'logs', 'log_archive_host', 'log_archive_service', 'downtimes') { | ||
|
||
$sth = $centreon_db->query("SELECT table_name, SUM(data_length+index_length) AS table_size | ||
FROM information_schema.tables | ||
WHERE table_schema=".$centreon_db->quote($db_name)." | ||
AND table_name=".$centreon_db->quote($table).""); | ||
|
||
while (my $row = $sth->fetchrow_hashref()) { | ||
$self->{output}->{table_size}->{$row->{table_name}} = centreon::health::misc::format_bytes(bytes_value =>$row->{table_size}); | ||
} | ||
|
||
next if ($table =~ m/downtimes/); | ||
$sth = $centreon_db->query("SELECT MAX(CONVERT(PARTITION_DESCRIPTION, SIGNED INTEGER)) as lastPart | ||
FROM INFORMATION_SCHEMA.PARTITIONS | ||
WHERE TABLE_NAME='" . $table . "' | ||
AND TABLE_SCHEMA='" . $db_name . "' GROUP BY TABLE_NAME;"); | ||
|
||
while (my $row = $sth->fetchrow_hashref()) { | ||
$self->{output}->{partitioning_last_part}->{$table} = defined($row->{lastPart}) ? strftime("%m/%d/%Y %H:%M:%S",localtime($row->{lastPart})) : $table . " has no partitioning !"; | ||
} | ||
} | ||
|
||
} | ||
|
||
my $var_list = { 'innodb_file_per_table' => 0, | ||
'open_files_limit' => 0, | ||
'read_only' => 0, | ||
'key_buffer_size' => 1, | ||
'sort_buffer_size' => 1, | ||
'join_buffer_size' => 1, | ||
'read_buffer_size' => 1, | ||
'read_rnd_buffer_size' => 1, | ||
'max_allowed_packet' => 1 }; | ||
|
||
foreach my $var (keys $var_list) { | ||
my $sth = $centreon_db->query("SHOW GLOBAL VARIABLES LIKE " . $centreon_db->quote($var)); | ||
my $value = $sth->fetchrow(); | ||
$self->{output}->{interesting_variables}->{$var} = ($var_list->{$var} == 1) ? centreon::health::misc::format_bytes(bytes_value => $value) : $value; | ||
} | ||
|
||
return $self->{output}; | ||
|
||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
# | ||
# Copyright 2017 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 centreon::health::checklogs; | ||
|
||
use strict; | ||
use warnings; | ||
use POSIX qw(strftime); | ||
use centreon::common::misc; | ||
use centreon::health::ssh; | ||
|
||
sub new { | ||
my $class = shift; | ||
my $self = {}; | ||
$self->{logs_path_broker} = {}; | ||
$self->{logs_path_engine} = {}; | ||
$self->{output} = {}; | ||
|
||
bless $self, $class; | ||
return $self; | ||
} | ||
|
||
sub run { | ||
my $self = shift; | ||
my ($centreon_db, $server_list, $centreon_version, $logger) = @_; | ||
|
||
my $sth; | ||
my ($lerror, $stdout); | ||
|
||
foreach my $server (keys %$server_list) { | ||
$sth = $centreon_db->query("SELECT log_file | ||
FROM cfg_nagios | ||
WHERE nagios_id=" . $centreon_db->quote($server)); | ||
|
||
while (my $row = $sth->fetchrow_hashref) { | ||
push @{$self->{logs_path_engine}->{engine}->{$server_list->{$server}->{name}}}, $row->{log_file}; | ||
} | ||
|
||
foreach my $log_file (@{$self->{logs_path_engine}->{engine}->{$server_list->{$server}->{name}}}) { | ||
if ($server_list->{$server}->{localhost} eq "YES") { | ||
($lerror, $self->{output}->{$server_list->{$server}->{name}}->{engine}->{$log_file}) = centreon::common::misc::backtick(command => "tail -n20 " . $log_file); | ||
} else { | ||
$self->{output}->{$server_list->{$server}->{name}}->{engine}->{$log_file} = centreon::health::ssh->new->main(host => $server_list->{$server}->{address}, | ||
port => $server_list->{$server}->{ssh_port}, | ||
userdata => $log_file, | ||
command => "tail -n20 " . $log_file); | ||
} | ||
} | ||
|
||
$sth = $centreon_db->query("SELECT DISTINCT(config_value) FROM cfg_centreonbroker, cfg_centreonbroker_info | ||
WHERE config_group='logger' AND config_key='name' | ||
AND cfg_centreonbroker.config_id=cfg_centreonbroker_info.config_id | ||
AND cfg_centreonbroker.ns_nagios_server=" . $centreon_db->quote($server)); | ||
|
||
while (my $row = $sth->fetchrow_hashref) { | ||
push @{$self->{logs_path_broker}->{broker}->{$server_list->{$server}->{name}}}, $row->{config_value}; | ||
} | ||
|
||
foreach my $log_file (@{$self->{logs_path_broker}->{broker}->{$server_list->{$server}->{name}}}) { | ||
if ($server_list->{$server}->{localhost} eq "YES") { | ||
($lerror, $self->{output}->{$server_list->{$server}->{name}}->{broker}->{$log_file}) = centreon::common::misc::backtick(command => "tail -n20 " . $log_file); | ||
} else { | ||
$self->{output}->{$server_list->{$server}->{name}}->{broker}->{$log_file} = centreon::health::ssh->new->main(host => $server_list->{$server}->{address}, | ||
port => $server_list->{$server}->{ssh_port}, | ||
userdata => $log_file, | ||
command => "tail -n20 " . $log_file); | ||
} | ||
} | ||
|
||
if ($server_list->{$server}->{localhost} eq "YES") { | ||
$sth = $centreon_db->query("SELECT `value` FROM options WHERE `key`='debug_path'"); | ||
|
||
my $centreon_log_path = $sth->fetchrow(); | ||
($lerror, $stdout) = centreon::common::misc::backtick(command => "find " . $centreon_log_path . " -type f -name *.log"); | ||
|
||
foreach my $log_file (split '\n', $stdout) { | ||
($lerror, $self->{output}->{$server_list->{$server}->{name}}->{centreon}->{$log_file}) = centreon::common::misc::backtick(command => "tail -n10 " . $log_file); | ||
} | ||
} | ||
} | ||
|
||
return $self->{output} | ||
} | ||
|
||
1; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should require /etc/centreon/conf.pm to retrieve this information.
The centreon database can also be non standard.