(plugin) apps::monitoring::ntopng::restapi - initial (#3608)

This commit is contained in:
qgarnier 2022-04-22 10:15:12 +02:00 committed by GitHub
parent ef5507f4be
commit ecb48c3a7d
6 changed files with 978 additions and 0 deletions

View File

@ -0,0 +1,212 @@
#
# Copyright 2022 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::ntopng::restapi::custom::api;
use strict;
use warnings;
use centreon::plugins::http;
use JSON::XS;
sub new {
my ($class, %options) = @_;
my $self = {};
bless $self, $class;
if (!defined($options{output})) {
print "Class Custom: Need to specify 'output' argument.\n";
exit 3;
}
if (!defined($options{options})) {
$options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument.");
$options{output}->option_exit();
}
if (!defined($options{noptions})) {
$options{options}->add_options(arguments => {
'api-username:s' => { name => 'api_username' },
'api-password:s' => { name => 'api_password' },
'hostname:s' => { name => 'hostname' },
'port:s' => { name => 'port' },
'proto:s' => { name => 'proto' },
'timeout:s' => { name => 'timeout' },
'unknown-http-status:s' => { name => 'unknown_http_status' },
'warning-http-status:s' => { name => 'warning_http_status' },
'critical-http-status:s' => { name => 'critical_http_status' }
});
}
$options{options}->add_help(package => __PACKAGE__, sections => 'REST API OPTIONS', once => 1);
$self->{output} = $options{output};
$self->{http} = centreon::plugins::http->new(%options);
return $self;
}
sub set_options {
my ($self, %options) = @_;
$self->{option_results} = $options{option_results};
}
sub set_defaults {}
sub check_options {
my ($self, %options) = @_;
$self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : '';
$self->{port} = (defined($self->{option_results}->{port})) ? $self->{option_results}->{port} : 3000;
$self->{proto} = (defined($self->{option_results}->{proto})) ? $self->{option_results}->{proto} : 'http';
$self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 50;
$self->{api_username} = (defined($self->{option_results}->{api_username})) ? $self->{option_results}->{api_username} : '';
$self->{api_password} = (defined($self->{option_results}->{api_password})) ? $self->{option_results}->{api_password} : '';
$self->{unknown_http_status} = (defined($self->{option_results}->{unknown_http_status})) ? $self->{option_results}->{unknown_http_status} : '%{http_code} < 200 or %{http_code} >= 300';
$self->{warning_http_status} = (defined($self->{option_results}->{warning_http_status})) ? $self->{option_results}->{warning_http_status} : '';
$self->{critical_http_status} = (defined($self->{option_results}->{critical_http_status})) ? $self->{option_results}->{critical_http_status} : '';
if ($self->{hostname} eq '') {
$self->{output}->add_option_msg(short_msg => "Need to specify --hostname option.");
$self->{output}->option_exit();
}
if ($self->{api_username} eq '') {
$self->{output}->add_option_msg(short_msg => "Need to specify --api-username option.");
$self->{output}->option_exit();
}
if ($self->{api_password} eq '') {
$self->{output}->add_option_msg(short_msg => "Need to specify --api-password option.");
$self->{output}->option_exit();
}
return 0;
}
sub build_options_for_httplib {
my ($self, %options) = @_;
$self->{option_results}->{hostname} = $self->{hostname};
$self->{option_results}->{timeout} = $self->{timeout};
$self->{option_results}->{port} = $self->{port};
$self->{option_results}->{proto} = $self->{proto};
$self->{option_results}->{timeout} = $self->{timeout};
$self->{option_results}->{credentials} = 1;
$self->{option_results}->{basic} = 1;
$self->{option_results}->{username} = $self->{api_username};
$self->{option_results}->{password} = $self->{api_password};
}
sub settings {
my ($self, %options) = @_;
return if (defined($self->{settings_done}));
$self->build_options_for_httplib();
$self->{http}->add_header(key => 'Accept', value => 'application/json');
$self->{http}->set_options(%{$self->{option_results}});
$self->{settings_done} = 1;
}
sub get_hostname {
my ($self, %options) = @_;
return $self->{hostname};
}
sub get_port {
my ($self, %options) = @_;
return $self->{port};
}
sub request_api {
my ($self, %options) = @_;
$self->settings();
my $content = $self->{http}->request(
url_path => $options{endpoint},
get_param => $options{get_param},
unknown_status => $self->{unknown_http_status},
warning_status => $self->{warning_http_status},
critical_status => $self->{critical_http_status}
);
if (!defined($content) || $content eq '') {
$self->{output}->add_option_msg(short_msg => "API returns empty content [code: '" . $self->{http}->get_code() . "'] [message: '" . $self->{http}->get_message() . "']");
$self->{output}->option_exit();
}
my $decoded;
eval {
$decoded = JSON::XS->new->utf8->decode($content);
};
if ($@) {
$self->{output}->add_option_msg(short_msg => "Cannot decode response (add --debug option to display returned content)");
$self->{output}->option_exit();
}
if ($decoded->{'rc_str_hr'} ne "Success") {
$self->{output}->add_option_msg(short_msg => "Bad API Answer " . ($decoded->{'rc_str_hr'}));
$self->{output}->option_exit();
}
return $decoded;
}
1;
__END__
=head1 NAME
NtopNG Rest API
=head1 REST API OPTIONS
NtopNG Rest API
=over 8
=item B<--hostname>
Set hostname.
=item B<--port>
Port used (Default: 3000)
=item B<--proto>
Specify https if needed (Default: 'http')
=item B<--api-username>
API username.
=item B<--api-password>
API password.
=item B<--timeout>
Set timeout in seconds (Default: 50).
=back
=head1 DESCRIPTION
B<custom>.
=cut

View File

@ -0,0 +1,232 @@
#
# Copyright 2018 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::ntopng::restapi::mode::alerts;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
sub custom_type_perfdata {
my ($self, %options) = @_;
my $instances = [ $self->{result_values}->{name} ];
if (defined($self->{result_values}->{type})) {
push @$instances, $self->{result_values}->{type};
}
$self->{output}->perfdata_add(
nlabel => 'alerts.type.detected.count',
instances => [ $self->{result_values}->{type} ],
value => $self->{result_values}->{value},
min => 0
);
}
sub custom_status_output {
my ($self, %options) = @_;
return sprintf(
"alert [severity: %s] [type: %s] %s",
$self->{result_values}->{severity},
$self->{result_values}->{type},
scalar(localtime($self->{result_values}->{timeraised}))
);
}
sub prefix_global_output {
my ($self, %options) = @_;
return 'Alerts severity ';
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' },
{
name => 'alarms', type => 2, message_multiple => '0 alerts detected', format_output => '%s alerts detected', display_counter_problem => { nlabel => 'alerts.detected.count', min => 0 },
group => [ { name => 'alarm', skipped_code => { -11 => 1 } } ]
},
{ name => 'alarm_types', type => 1 }
];
$self->{maps_counters}->{global} = [];
foreach ('info', 'warning', 'error') {
push @{$self->{maps_counters}->{global}}, {
label => 'severity-' . $_, nlabel => 'alerts.severity.' . $_ . '.count', display_ok => 0, set => {
key_values => [ { name => $_ } ],
output_template => $_ . ': %s',
perfdatas => [
{ template => '%s', min => 0 }
]
}
};
}
$self->{maps_counters}->{alarm} = [
{
label => 'status',
type => 2,
warning_default => '%{severity} =~ /warning/i',
critical_default => '%{severity} =~ /error/i',
set => {
key_values => [
{ name => 'timeraised' }, { name => 'type' }, { name => 'severity' }
],
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold_ng
}
}
];
$self->{maps_counters}->{alarm_types} = [
{ label => 'type', threshold => 0, display_ok => 0, set => {
key_values => [ { name => 'value' }, { name => 'type' } ],
output_template => '',
closure_custom_threshold_check => sub { return 'ok'; },
closure_custom_perfdata => $self->can('custom_type_perfdata')
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
'filter-type:s' => { name => 'filter_type' },
'filter-severity:s' => { name => 'filter_severity' },
'interface:i' => { name => 'interface', default => 0 },
'period:s' => { name => 'period', default => 'last-5mns' }
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
if ( $self->{option_results}->{period} eq 'last-5mns') {
$self->{option_results}->{epochend} = time();
$self->{option_results}->{epochbegin} = time() - 300;
} elsif ($self->{option_results}->{period} eq 'last-hour') {
$self->{option_results}->{epochend} = time();
$self->{option_results}->{epochbegin} = time() - 3600;
} else {
$self->{output}->add_option_msg(short_msg => "Period " . $self->{option_results}->{period} . " not known !");
$self->{output}->option_exit();
}
}
my $map_severity = {
3 => 'info', 4 => 'warning', 5 => 'error'
};
sub manage_selection {
my ($self, %options) = @_;
my $results = $options{custom}->request_api(
endpoint => "/lua/rest/v2/get/flow/alert/list.lua",
get_param => ['ifid=' . $self->{option_results}->{interface}, 'epoch_begin=' . $self->{option_results}->{epochbegin} , 'epoch_end=' . $self->{option_results}->{epochend}]
);
$self->{global} = { info => 0, warning => 0, error => 0 };
$self->{alarms}->{global} = { alarm => {} };
$self->{alarm_types} = {};
for my $entry (@{$results->{rsp}->{records}}) {
my $severity = $map_severity->{ $entry->{severity}->{value} };
if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' &&
$entry->{msg}->{name} !~ /$self->{option_results}->{filter_type}/) {
$self->{output}->output_add(long_msg => "skipping '" . $entry->{msg}->{name} . "': no matching filter.", debug => 1);
next;
}
if (defined($self->{option_results}->{filter_severity}) && $self->{option_results}->{filter_severity} ne '' &&
$severity !~ /$self->{option_results}->{filter_severity}/) {
$self->{output}->output_add(long_msg => "skipping '" . $entry->{msg}->{name} . "': no matching filter.", debug => 1);
next;
}
$self->{global}->{$severity}++;
$self->{alarms}->{global}->{alarm}->{ $entry->{row_id} } = {
type => $entry->{msg}->{name},
severity => $severity,
timeraised => $entry->{tstamp}->{value}
};
if (!defined($self->{alarm_types}->{ $entry->{msg}->{name} })) {
$self->{alarm_types}->{ $entry->{msg}->{name} } = { type => $entry->{msg}->{name}, value => 0 };
}
$self->{alarm_types}->{ $entry->{msg}->{name} }->{value}++;
}
}
1;
__END__
=head1 MODE
Check alerts.
=over 8
=item B<--filter-type>
Filter alerts by type (can be a regexp).
=item B<--filter-severity>
Only get alerts by severity (can be a regexp).
=item B<--interface>
Interface name to check (0 by default)
=item B<--period>
Set period to check new alarms.
Can be: 'last-5mns' (default), 'last-hour'
=item B<--warning-status>
Set warning threshold for status (Default: '%{severity} =~ /minor/i')
Can used special variables like: %{severity}, %{type}, %{timeraised}
=item B<--critical-status>
Set critical threshold for status (Default: '%{severity} =~ /major|critical/i').
Can used special variables like: %{severity}, %{type}, %{timeraised}
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'severity-info', 'severity-warning', 'severity-error'.
=back
=cut

View File

@ -0,0 +1,166 @@
#
# Copyright 2018 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::ntopng::restapi::mode::hostflows;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
sub custom_packet_perfdata {
my ($self) = @_;
$self->{output}->perfdata_add(
nlabel => $self->{nlabel},
unit => '/s',
instances => [ $self->{result_values}->{ip} ],
value => sprintf('%.2f', $self->{result_values}->{ $self->{key_values}->[0]->{name} }),
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}),
min => 0
);
}
sub custom_traffic_perfdata {
my ($self) = @_;
$self->{output}->perfdata_add(
nlabel => $self->{nlabel},
unit => 'b/s',
instances => [ $self->{result_values}->{ip} ],
value => sprintf('%d', $self->{result_values}->{ $self->{key_values}->[0]->{name} }),
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}),
min => 0
);
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' }
];
$self->{maps_counters}->{global} = [
{ label => 'packets-received', nlabel => 'host.packets.received.persecond', set => {
key_values => [ { name => 'packetsReceived', per_second => 1 }, { name => 'ip' } ],
output_template => 'packets received: %.2f/s',
closure_custom_perfdata => $self->can('custom_packet_perfdata')
}
},
{ label => 'packets-sent', nlabel => 'host.packets.sent.persecond', set => {
key_values => [ { name => 'packetsSent', per_second => 1 }, { name => 'ip' } ],
output_template => 'packets sent: %.2f/s',
closure_custom_perfdata => $self->can('custom_packet_perfdata')
}
},
{ label => 'traffic-in', nlabel => 'host.traffic.in.bitspersecond', set => {
key_values => [ { name => 'bytesReceived', per_second => 1 }, { name => 'ip' } ],
output_template => 'traffic in: %s%s/s',
output_change_bytes => 2,
closure_custom_perfdata => $self->can('custom_traffic_perfdata')
}
},
{ label => 'traffic-out', nlabel => 'host.traffic.out.bitspersecond', set => {
key_values => [ { name => 'bytesSent', per_second => 1 }, { name => 'ip' } ],
output_template => 'traffic out: %s%s/s',
output_change_bytes => 2,
closure_custom_perfdata => $self->can('custom_traffic_perfdata')
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1, statefile => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
'interface:i' => { name => 'interface', default => 0 },
'ip:s' => { name => 'ip' }
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
if (!defined($self->{option_results}->{ip}) || $self->{option_results}->{ip} eq '') {
$self->{output}->add_option_msg(short_msg => "Need to specify ip argument");
$self->{output}->option_exit();
}
}
sub manage_selection {
my ($self, %options) = @_;
my $results = $options{custom}->request_api(
endpoint => "/lua/rest/v2/get/host/data.lua",
get_param => ['ifid=' . $self->{option_results}->{interface}, 'host=' . $self->{option_results}->{ip} ]
);
$self->{global} = {
ip => $self->{option_results}->{ip},
packetsSent => $results->{rsp}->{'packets.sent'},
packetsReceived => $results->{rsp}->{'packets.rcvd'},
bytesSent => $results->{rsp}->{'bytes.sent'} * 8,
bytesReceived => $results->{rsp}->{'bytes.rcvd'} * 8
};
$self->{cache_name} = 'ntopng_' . $options{custom}->get_hostname() . '_' . $self->{mode} . '_' .
md5_hex(
defined($self->{option_results}->{filter_counters}) ? $self->{option_results}->{filter_counters} : '' . '_' .
defined($self->{option_results}->{interface}) ? $self->{option_results}->{interface} : '' . '_' .
defined($self->{option_results}->{ip}) ? $self->{option_results}->{ip} : ''
);
}
1;
__END__
=head1 MODE
Check host flows.
=over 8
=item B<--interface>
Interface name to check (0 by default).
=item B<--ip>
Set IP Address to monitor (Required).
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'packets-received', 'packets-sent', 'traffic-in', 'traffic-out'.
=back
=cut

View File

@ -0,0 +1,190 @@
#
# Copyright 2018 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::ntopng::restapi::mode::netflowhealth;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
sub custom_alerted_output {
my ($self, %options) = @_;
return sprintf(
'%s flows (%s with alerts - %.2f%%)',
$self->{result_values}->{flows},
$self->{result_values}->{alertedFlows},
$self->{result_values}->{alertedFlowsPrct}
);
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0 }
];
$self->{maps_counters}->{global} = [
{ label => 'flows-detected', nlabel => 'flows.detected.count', display_ok => 0, set => {
key_values => [ { name => 'flows' } ],
output_template => 'number of flows: %s',
perfdatas => [
{ template => '%s', min => 0 }
]
}
},
{ label => 'flows-alerted-detected', nlabel => 'flows.alerted.detected.count', display_ok => 0, set => {
key_values => [ { name => 'alertedFlows' } ],
output_template => 'number of alerted flows: %s',
perfdatas => [
{ template => '%s', min => 0 }
]
}
},
{ label => 'flows-alerted-prct', nlabel => 'flows.alerted.percentage', set => {
key_values => [ { name => 'alertedFlowsPrct' }, { name => 'alertedFlows' }, { name => 'flows' } ],
closure_custom_output => $self->can('custom_alerted_output'),
perfdatas => [
{ template => '%s', unit => '%', min => 0, max => 100 }
]
}
},
{ label => 'packets-download', nlabel => 'packets.download.persecond', display_ok => 0, set => {
key_values => [ { name => 'packetsDownload', per_second => 1 } ],
output_template => 'packets download: %.2f/s',
perfdatas => [
{ template => '%.2f', unit => '/s', min => 0 }
]
}
},
{ label => 'packets-upload', nlabel => 'packets.upload.persecond', display_ok => 0, set => {
key_values => [ { name => 'packetsUpload', per_second => 1 } ],
output_template => 'packets upload: %.2f/s',
perfdatas => [
{ template => '%.2f', unit => '/s', min => 0 }
]
}
},
{ label => 'packets-dropped', nlabel => 'packets.dropped.persecond', display_ok => 0, set => {
key_values => [ { name => 'packetsDropped', per_second => 1 } ],
output_template => 'packets dropped: %.2f/s',
perfdatas => [
{ template => '%.2f', unit => '/s', min => 0 }
]
}
},
{ label => 'traffic-in', nlabel => 'traffic.in.bitspersecond', display_ok => 0, set => {
key_values => [ { name => 'bytesDownload', per_second => 1 } ],
output_template => 'traffic in: %s%s/s',
output_change_bytes => 2,
perfdatas => [
{ template => '%d', unit => 'bps', min => 0 }
]
}
},
{ label => 'traffic-out', nlabel => 'traffic.out.bitspersecond', display_ok => 0, set => {
key_values => [ { name => 'bytesUpload', per_second => 1 } ],
output_template => 'traffic out: %s%s/s',
output_change_bytes => 2,
perfdatas => [
{ template => '%d', unit => 'bps', min => 0 }
]
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1, statefile => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
'interface:i' => { name => 'interface', default => 0 }
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
}
sub manage_selection {
my ($self, %options) = @_;
$self->{global} = {
'info' => 0, 'warning' => 0, 'error' => 0
};
$self->{alarms}->{global} = { alarm => {} };
my $results = $options{custom}->request_api(
endpoint => "/lua/rest/v2/get/interface/data.lua",
get_param => ['ifid=' . $self->{option_results}->{interface} ]
);
$self->{global} = {
alertedFlows => $results->{rsp}->{alerted_flows},
flows => $results->{rsp}->{num_flows},
alertedFlowsPrct => $results->{rsp}->{num_flows} > 0 ? 100 * $results->{rsp}->{alerted_flows} / $results->{rsp}->{num_flows} : 0,
packetsDownload => $results->{rsp}->{packets_download},
packetsUpload => $results->{rsp}->{packets_upload},
packetsDropped => $results->{rsp}->{drops},
bytesUpload => $results->{rsp}->{bytes_upload} * 8,
bytesDownload => $results->{rsp}->{bytes_download} * 8
};
#my $percent_alerted = sprintf("%.2f", 100*$results->{rsp}->{alerted_flows} / $results->{rsp}->{num_flows});
#$self->{output}->output_add(severity => 'OK', short_msg => $self->{global}->{flows} . " flows (" . $self->{global}->{alerted_flows} . " with alerts - $percent_alerted%)" );
$self->{cache_name} = 'ntopng_' . $options{custom}->get_hostname() . '_' . $self->{mode} . '_' .
md5_hex(
defined($self->{option_results}->{filter_counters}) ? $self->{option_results}->{filter_counters} : '' . '_' .
defined($self->{option_results}->{interface}) ? $self->{option_results}->{interface} : ''
);
}
1;
__END__
=head1 MODE
Check netflow health.
=over 8
=item B<--interface>
Interface name to check (0 by default).
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'flows-detected', 'flows-alerted-detected', 'flows-alerted-prct',
'packets-download', 'packets-upload', 'packets-dropped', 'traffic-in', 'traffic-out'.
=back
=cut

View File

@ -0,0 +1,127 @@
#
# Copyright 2018 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::ntopng::restapi::mode::probehealth;
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 }
];
$self->{maps_counters}->{global} = [
{ label => 'cpu-utilization', nlabel => 'cpu.utilization.percentage', set => {
key_values => [ { name => 'cpuUtil' } ],
output_template => 'cpu utilization: %.2f%%',
perfdatas => [
{ template => '%.2f', min => 0, max => 100, unit => '%' }
]
}
},
{ label => 'cpu-load', nlabel => 'cpu.load.percentage', set => {
key_values => [ { name => 'cpuLoad' } ],
output_template => 'cpu load: %.2f',
perfdatas => [
{ template => '%.2f', min => 0 }
]
}
},
{ label => 'memory-usage', nlabel => 'memory.usage.percentage', set => {
key_values => [ { name => 'memoryUsed' } ],
output_template => 'memory used: %.2f %%',
perfdatas => [
{ template => '%.2f', min => 0, max => 100, unit => '%' }
]
}
},
{ label => 'dropped-alerts', nlabel => 'alerts.dropped.persecond', set => {
key_values => [ { name => 'droppedAlerts', per_second => 1 } ],
output_template => 'dropped alerts: %.2f/s',
perfdatas => [
{ template => '%.2f', min => 0, unit => '/s' }
]
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1, statefile => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
'interface:i' => { name => 'interface', default => 0 }
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
my $results = $options{custom}->request_api(
endpoint => "/lua/rest/v2/get/interface/data.lua",
get_param => ['ifid=' . $self->{option_results}->{interface} ]
);
$self->{global} = {
memoryUsed => 100 * $results->{rsp}->{system_host_stats}->{mem_used} / $results->{rsp}->{system_host_stats}->{mem_total},
cpuUtil => 100 - $results->{rsp}->{system_host_stats}->{cpu_states}->{idle},
cpuLoad => $results->{rsp}->{system_host_stats}->{cpu_load},
droppedAlerts => $results->{rsp}->{system_host_stats}->{dropped_alerts}
};
$self->{cache_name} = 'ntopng_' . $options{custom}->get_hostname() . '_' . $self->{mode} . '_' .
md5_hex(
defined($self->{option_results}->{filter_counters}) ? $self->{option_results}->{filter_counters} : '' . '_' .
defined($self->{option_results}->{interface}) ? $self->{option_results}->{interface} : ''
);
}
1;
__END__
=head1 MODE
Check ntopng probe health.
=over 8
=item B<--interface>
Interface name to check (0 by default).
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'cpu-utilization', 'cpu-load', 'memory-usage', 'dropped-alerts'.
=back
=cut

View File

@ -0,0 +1,51 @@
#
# Copyright 2022 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::ntopng::restapi::plugin;
use strict;
use warnings;
use base qw(centreon::plugins::script_custom);
sub new {
my ( $class, %options ) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{modes} = {
'alerts' => 'apps::monitoring::ntopng::restapi::mode::alerts',
'host-flows' => 'apps::monitoring::ntopng::restapi::mode::hostflows',
'probe-health' => 'apps::monitoring::ntopng::restapi::mode::probehealth',
'netflow-health' => 'apps::monitoring::ntopng::restapi::mode::netflowhealth'
};
$self->{custom_modes}->{api} = 'apps::monitoring::ntopng::restapi::custom::api';
return $self;
}
1;
__END__
=head1 PLUGIN DESCRIPTION
Check NtopNG using Rest API.
=cut