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..06710e9cc --- /dev/null +++ b/apps/monitoring/netdata/restapi/mode/listdisks.pm @@ -0,0 +1,93 @@ +# +# 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 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 $fs (@{$self->{fs_list}}) { + $self->{output}->add_disco_entry( + name => $fs->{name}, + status => $fs->{title}, + ); + } +} + +1; + +__END__ + +=head1 MODE + +List system disks using the Netdata agent Restapi. + +=back + +=cut diff --git a/apps/monitoring/netdata/restapi/mode/listinterfaces.pm b/apps/monitoring/netdata/restapi/mode/listinterfaces.pm new file mode 100644 index 000000000..b801b4ac1 --- /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 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 $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 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';