From 70ea4cb65d07ec743c2d7709a1089dd14d7d4682 Mon Sep 17 00:00:00 2001 From: thibaults-centreon Date: Mon, 29 Jun 2020 17:38:57 +0200 Subject: [PATCH 1/4] add(plugin): svc discovery modes --- apps/monitoring/netdata/restapi/mode/disks.pm | 2 +- .../netdata/restapi/mode/listdisks.pm | 99 +++++++++++++++++++ .../netdata/restapi/mode/listinterfaces.pm | 92 +++++++++++++++++ apps/monitoring/netdata/restapi/mode/load.pm | 2 +- apps/monitoring/netdata/restapi/plugin.pm | 22 +++-- 5 files changed, 205 insertions(+), 12 deletions(-) create mode 100644 apps/monitoring/netdata/restapi/mode/listdisks.pm create mode 100644 apps/monitoring/netdata/restapi/mode/listinterfaces.pm diff --git a/apps/monitoring/netdata/restapi/mode/disks.pm b/apps/monitoring/netdata/restapi/mode/disks.pm index 3f80b0168..c4f206210 100644 --- a/apps/monitoring/netdata/restapi/mode/disks.pm +++ b/apps/monitoring/netdata/restapi/mode/disks.pm @@ -175,7 +175,7 @@ Check disks FS usage of *nix based servers using the Netdata agent RestAPI. Example: perl centreon_plugins.pl --plugin=apps::monitoring::netdata::restapi::plugin ---mode=diskusage --hostname=10.0.0.1 --chart-period=300 --chart-statistics=average --warning-usage-prct=80 --critical-usage-prct=90 --verbose +--mode=disks --hostname=10.0.0.1 --chart-period=300 --chart-statistics=average --warning-usage-prct=80 --critical-usage-prct=90 --verbose More information on'https://learn.netdata.cloud/docs/agent/web/api'. diff --git a/apps/monitoring/netdata/restapi/mode/listdisks.pm b/apps/monitoring/netdata/restapi/mode/listdisks.pm new file mode 100644 index 000000000..e30ea2f1f --- /dev/null +++ b/apps/monitoring/netdata/restapi/mode/listdisks.pm @@ -0,0 +1,99 @@ +# +# Copyright 2020 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 apps::monitoring::netdata::restapi::mode::listdisks; + +use strict; +use warnings; + +use base qw(centreon::plugins::mode); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub run { + my ($self, %options) = @_; + + my $full_list = $options{custom}->list_charts(); + + foreach my $chart (values %{$full_list->{charts}}) { + next if ($chart->{name} !~ 'disk_space._'); + push @{$self->{fs_list}}, $chart->{name}; + $chart->{name} =~s/disk_space.//; + $chart->{name} =~ s/_/\//g; + $self->{output}->output_add( + long_msg => sprintf( + "[name = %s][title = %s]", + $chart->{name}, + $chart->{title}, + ) + ); + } + + $self->{output}->output_add(severity => 'OK', short_msg => 'Server interfaces:'); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); +} + +sub disco_format { + my ($self, %options) = @_; + + $self->{output}->add_disco_format(elements => [ 'name', 'title' ]); +} + +sub disco_show { + my ($self, %options) = @_; + + $self->run(%options); + foreach my $fs (@{$self->{fs_list}}) { + $self->{output}->add_disco_entry( + name => $fs->{name}, + status => $fs->{title}, + ); + } +} + +1; + +__END__ + +=head1 MODE + +List Mulesoft Anypoint applications. + +=over 8 + +=item B<--filter-name> + +Filter application name (Can be a regexp). + +=back + +=cut \ No newline at end of file diff --git a/apps/monitoring/netdata/restapi/mode/listinterfaces.pm b/apps/monitoring/netdata/restapi/mode/listinterfaces.pm new file mode 100644 index 000000000..c17fd1082 --- /dev/null +++ b/apps/monitoring/netdata/restapi/mode/listinterfaces.pm @@ -0,0 +1,92 @@ +# +# Copyright 2020 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 apps::monitoring::netdata::restapi::mode::listinterfaces; + +use strict; +use warnings; + +use base qw(centreon::plugins::mode); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub run { + my ($self, %options) = @_; + + my $full_list = $options{custom}->list_charts(); + + foreach my $chart (values %{$full_list->{charts}}) { + next if ($chart->{name} !~ '^net\.'); + push @{$self->{fs_list}}, $chart->{name}; + $chart->{name} =~ s/net.//; + $self->{output}->output_add( + long_msg => sprintf( + "[name = %s][title = %s]", + $chart->{name}, + $chart->{title}, + ) + ); + } + + $self->{output}->output_add(severity => 'OK', short_msg => 'Server disks:'); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); +} + +sub disco_format { + my ($self, %options) = @_; + + $self->{output}->add_disco_format(elements => [ 'name', 'title' ]); +} + +sub disco_show { + my ($self, %options) = @_; + + $self->run(%options); + foreach my $interface (@{$self->{fs_list}}) { + $self->{output}->add_disco_entry( + name => $interface->{name}, + status => $interface->{title}, + ); + } +} + +1; + +__END__ + +=head1 MODE + +List system interfaces using the Netdata agent Restapi. + +=back + +=cut \ No newline at end of file diff --git a/apps/monitoring/netdata/restapi/mode/load.pm b/apps/monitoring/netdata/restapi/mode/load.pm index 175d8c470..893af1013 100644 --- a/apps/monitoring/netdata/restapi/mode/load.pm +++ b/apps/monitoring/netdata/restapi/mode/load.pm @@ -111,7 +111,7 @@ Check the average load of *nix based servers using the Netdata agent RestAPI. Example: perl centreon-plugins/centreon_plugins.pl --plugin=apps::monitoring::netdata::restapi::plugin ---mode=loadaverage --hostname=10.0.0.1 --chart-period=300 --warning-load15='4' --critical-load15='5' --verbose +--mode=load --hostname=10.0.0.1 --chart-period=300 --warning-load15='4' --critical-load15='5' --verbose More information on 'https://learn.netdata.cloud/docs/agent/web/api'. diff --git a/apps/monitoring/netdata/restapi/plugin.pm b/apps/monitoring/netdata/restapi/plugin.pm index 1b4f3c299..7b495d386 100644 --- a/apps/monitoring/netdata/restapi/plugin.pm +++ b/apps/monitoring/netdata/restapi/plugin.pm @@ -31,16 +31,18 @@ sub new { $self->{version} = '1.0'; $self->{modes} = { - 'alarms' => 'apps::monitoring::netdata::restapi::mode::alarms', - 'cpu' => 'apps::monitoring::netdata::restapi::mode::cpu', - 'disks' => 'apps::monitoring::netdata::restapi::mode::disks', - 'get-chart' => 'apps::monitoring::netdata::restapi::mode::getchart', - 'inodes' => 'apps::monitoring::netdata::restapi::mode::inodes', - 'list-charts' => 'apps::monitoring::netdata::restapi::mode::listcharts', - 'load' => 'apps::monitoring::netdata::restapi::mode::load', - 'memory' => 'apps::monitoring::netdata::restapi::mode::memory', - 'swap' => 'apps::monitoring::netdata::restapi::mode::swap', - 'traffic' => 'apps::monitoring::netdata::restapi::mode::traffic' + 'alarms' => 'apps::monitoring::netdata::restapi::mode::alarms', + 'cpu' => 'apps::monitoring::netdata::restapi::mode::cpu', + 'disks' => 'apps::monitoring::netdata::restapi::mode::disks', + 'get-chart' => 'apps::monitoring::netdata::restapi::mode::getchart', + 'inodes' => 'apps::monitoring::netdata::restapi::mode::inodes', + 'list-charts' => 'apps::monitoring::netdata::restapi::mode::listcharts', + 'list-disks' => 'apps::monitoring::netdata::restapi::mode::listdisks', + 'list-interfaces' => 'apps::monitoring::netdata::restapi::mode::listinterfaces', + 'load' => 'apps::monitoring::netdata::restapi::mode::load', + 'memory' => 'apps::monitoring::netdata::restapi::mode::memory', + 'swap' => 'apps::monitoring::netdata::restapi::mode::swap', + 'traffic' => 'apps::monitoring::netdata::restapi::mode::traffic' }; $self->{custom_modes}->{restapi} = 'apps::monitoring::netdata::restapi::custom::api'; From ba40ef4a6617344b4963a5ba3f1b4e31fb88b641 Mon Sep 17 00:00:00 2001 From: thibaults-centreon Date: Mon, 29 Jun 2020 17:39:53 +0200 Subject: [PATCH 2/4] add(plugin): svc discovery modes --- apps/monitoring/netdata/restapi/mode/listdisks.pm | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/apps/monitoring/netdata/restapi/mode/listdisks.pm b/apps/monitoring/netdata/restapi/mode/listdisks.pm index e30ea2f1f..e618ecc9b 100644 --- a/apps/monitoring/netdata/restapi/mode/listdisks.pm +++ b/apps/monitoring/netdata/restapi/mode/listdisks.pm @@ -86,13 +86,7 @@ __END__ =head1 MODE -List Mulesoft Anypoint applications. - -=over 8 - -=item B<--filter-name> - -Filter application name (Can be a regexp). +List system disks using the Netdata agent Restapi. =back From e6d339f3be8d8d070ffc9c1e05f0eafc76e89924 Mon Sep 17 00:00:00 2001 From: Thibault S <48209914+thibaults-centreon@users.noreply.github.com> Date: Mon, 29 Jun 2020 17:49:54 +0200 Subject: [PATCH 3/4] Update listdisks.pm --- apps/monitoring/netdata/restapi/mode/listdisks.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/monitoring/netdata/restapi/mode/listdisks.pm b/apps/monitoring/netdata/restapi/mode/listdisks.pm index e618ecc9b..06710e9cc 100644 --- a/apps/monitoring/netdata/restapi/mode/listdisks.pm +++ b/apps/monitoring/netdata/restapi/mode/listdisks.pm @@ -57,7 +57,7 @@ sub run { ); } - $self->{output}->output_add(severity => 'OK', short_msg => 'Server interfaces:'); + $self->{output}->output_add(severity => 'OK', short_msg => 'Server disks:'); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); } @@ -90,4 +90,4 @@ List system disks using the Netdata agent Restapi. =back -=cut \ No newline at end of file +=cut From 99b587c8556fd7282f91668cd96307681d3f6cde Mon Sep 17 00:00:00 2001 From: Thibault S <48209914+thibaults-centreon@users.noreply.github.com> Date: Mon, 29 Jun 2020 17:50:13 +0200 Subject: [PATCH 4/4] Update listinterfaces.pm --- apps/monitoring/netdata/restapi/mode/listinterfaces.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/monitoring/netdata/restapi/mode/listinterfaces.pm b/apps/monitoring/netdata/restapi/mode/listinterfaces.pm index c17fd1082..b801b4ac1 100644 --- a/apps/monitoring/netdata/restapi/mode/listinterfaces.pm +++ b/apps/monitoring/netdata/restapi/mode/listinterfaces.pm @@ -56,7 +56,7 @@ sub run { ); } - $self->{output}->output_add(severity => 'OK', short_msg => 'Server disks:'); + $self->{output}->output_add(severity => 'OK', short_msg => 'Server interfaces:'); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); } @@ -89,4 +89,4 @@ List system interfaces using the Netdata agent Restapi. =back -=cut \ No newline at end of file +=cut