Release 20230912 (#4654)

This commit is contained in:
omercier 2023-09-12 10:37:05 +02:00 committed by GitHub
commit ce09f6e361
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
56 changed files with 10751 additions and 465 deletions

View File

@ -149,3 +149,28 @@ jobs:
nexus_password: ${{ secrets.nexus_password }}
cache_key: ${{ github.sha }}-${{ github.run_id }}-deb-${{ matrix.distrib }}
stability: ${{ inputs.stability }}
release-tag:
if: ${{ inputs.stability == 'stable' && github.event_name == 'push' }}
runs-on: ubuntu-22.04
steps:
- name: Checkout sources
uses: actions/checkout@v3
- name: Push git release tag
run: |
RELEASE=plugins-$(date '+%Y%m%d')
EXISTING_TAG=$(git tag --list "$RELEASE" | head -n 1)
git config --global user.email "release@centreon.com"
git config --global user.name "Centreon"
if [ -z "$EXISTING_TAG" ]; then
git tag -a "$RELEASE" -m "release $RELEASE"
git push --follow-tags
else
echo "::warning::Release tag $RELEASE already exists"
fi
shell: bash

View File

@ -19,8 +19,6 @@ on:
- '.github/workflows/plugins.yml'
- 'src/**'
- 'packaging/**'
tags:
- centreon-plugins-*
jobs:
get-environment:

View File

@ -12,6 +12,7 @@ on:
- 'src/**'
- 'tests/functional/**'
- 'tests/resources/mockoon/**'
- 'tests/resources/snmp/**'
jobs:
functional-tests-with-robot:
@ -19,51 +20,54 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Install libs
run: |
sudo apt update
sudo apt-get install -y libcurl4-openssl-dev
sudo apt-get install -qqy snmpsim
- name: Install Node.js
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: "16.x"
node-version: 16
- name: Install Mockoon CLI
run: npm install -g -D @mockoon/cli@3.1.0
- name: Install libs
run: sudo apt-get install libcurl4-openssl-dev
- name: Install perl dependencies
uses: shogo82148/actions-setup-perl@v1
with:
perl-version: '5.34'
install-modules-with: cpm
install-modules: |
Alien::SNMP
DateTime
Digest::MD5
Encode
ExtUtils::PkgConfig
HTTP::ProxyPAC
IO::Socket::SSL
JSON::XS
LWP::Protocol::https
LWP::UserAgent
MIME::Base64
Net::Curl::Easy
Paws
POSIX
Storable
URI
Net::SNMP
URI::Encode
XML::LibXML
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
python-version: '3.11'
- name: Install Robot Framework
run: pip3 install robotframework
run: pip3.11 install robotframework
shell: bash
- name: Run Robot Framework tests
- name: Run Robot Framework API tests
run: |
sudo mkdir -p /var/lib/centreon/centplugins/
sudo chmod 777 /var/lib/centreon/centplugins/
robot tests/functional/
robot tests/functional/api
- name: Run Robot Framework SNMP tests
run: |
sudo useradd snmp
sudo mkdir -p /usr/snmpsim/data
sudo cp tests/resources/snmp/* /usr/snmpsim/data/
snmpsimd --agent-udpv4-endpoint=127.0.0.1:2024 --process-user=snmp --process-group=snmp &
robot tests/functional/snmp

View File

@ -0,0 +1,5 @@
{
"dependencies": [
"libsnmp-perl"
]
}

View File

@ -0,0 +1,14 @@
{
"pkg_name": "centreon-plugin-Hardware-Devices-Camera-Optelecom-Snmp",
"pkg_summary": "Centreon Plugin to monitor Optelecom camera using SNMP",
"plugin_name": "centreon_camera_optelecom_snmp.pl",
"files": [
"centreon/plugins/script_snmp.pm",
"centreon/plugins/snmp.pm",
"snmp_standard/mode/interfaces.pm",
"snmp_standard/mode/listinterfaces.pm",
"snmp_standard/mode/resources/",
"snmp_standard/mode/uptime.pm",
"hardware/devices/camera/optelecom/snmp/"
]
}

View File

@ -0,0 +1,5 @@
{
"dependencies": [
"perl(SNMP)"
]
}

View File

@ -13,6 +13,7 @@
"snmp_standard/mode/inodes.pm",
"snmp_standard/mode/interfaces.pm",
"snmp_standard/mode/loadaverage.pm",
"snmp_standard/mode/listdiskio.pm",
"snmp_standard/mode/listdiskspath.pm",
"snmp_standard/mode/listinterfaces.pm",
"snmp_standard/mode/resources/",

View File

@ -0,0 +1,214 @@
#
# Copyright 2023 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::kadiska::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 prefix_global_output {
my ($self, %options) = @_;
return 'Rules: ';
}
sub prefix_rules_output {
my ($self, %options) = @_;
return sprintf('Rule id: "%s", Rule name: "%s" ',
$options{instance_value}->{id},
$options{instance_value}->{name});
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, cb_prefix_output => 'prefix_global_output'},
{ name => 'rules', type => 1, cb_prefix_output => 'prefix_rules_output' }
];
$self->{maps_counters}->{global} = [
{ label => 'rules-total-count', nlabel => 'rules.total.count', set => {
key_values => [ { name => 'total' } ],
output_template => 'total rules: %s',
perfdatas => [ { template => '%d', min => 0 } ]
}
},
{ label => 'rules-criticals-total-count', nlabel => 'rules.criticals.count', set => {
key_values => [ { name => 'total_critical' } ],
output_template => 'total criticals: %s',
perfdatas => [ { template => '%d', min => 0 } ]
}
},
{ label => 'rules-warnings-total-count', nlabel => 'rules.warnings.count', set => {
key_values => [ { name => 'total_warning' } ],
output_template => 'total warnings: %s',
perfdatas => [ { template => '%d', min => 0 } ]
}
},
{ label => 'rules-nodata-total-count', nlabel => 'rules.nodata.count', set => {
key_values => [ { name => 'total_nodata' } ],
output_template => 'total no data: %s',
perfdatas => [ { template => '%d', min => 0 } ]
}
}
];
$self->{maps_counters}->{rules} = [
{ label => 'rule-ok-count', nlabel => 'rule.ok.count', set => {
key_values => [ { name => 'ok_count' } ],
output_template => 'ok count: %s',
display_ok => 0,
perfdatas => [ {template => '%s', min => 0, label_extra_instance => 1, instance_use => 'name' } ]
}
},
{ label => 'rule-warning-count', nlabel => 'rule.warning.count', set => {
key_values => [ { name => 'warning_count' } ],
output_template => 'warning count: %s',
display_ok => 0,
perfdatas => [ {template => '%s', min => 0, label_extra_instance => 1, instance_use => 'name' } ]
}
},
{ label => 'rule-critical-count', nlabel => 'rule.critical.count', set => {
key_values => [ { name => 'critical_count' } ],
output_template => 'critical count: %s',
display_ok => 0,
perfdatas => [ {template => '%s', min => 0, label_extra_instance => 1, instance_use => 'name' } ]
}
},
{ label => 'rule-nodata-count', nlabel => 'rule.nodata.count', set => {
key_values => [ { name => 'nodata_count' } ],
output_template => 'no data count: %s',
display_ok => 0,
perfdatas => [ {template => '%s', min => 0, label_extra_instance => 1, instance_use => 'name' } ]
}
}
];
}
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-name:s' => { name => 'filter_name' }
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
my $raw_form_post = {
"select" => [
{
"rule_id:group" => "rule_id"
},
{
"rule_name:any" => ["any","rule_name"]
},
{
["any","rule_name"] => ["any","rule_id"]
},
{
"critical:count" => ["sum","critical_count"]
},
{
"warning:count" => ["sum","warning_count"]
},
{
"ok:count" => ["sum","ok_count"]
},
{
"nodata:count" => ["sum","nodata_count"]
}
],
"from" => "alert",
"groupby" => [
"rule_id:group"
],
"orderby" => [
["rule_name:any","desc"]
],
"offset" => 0,
"limit" => 61
};
my $results = $options{custom}->request_api(
method => 'POST',
endpoint => 'query',
query_form_post => $raw_form_post
);
#Check if bad API request is submit
if (!exists $results->{data}) {
$self->{output}->add_option_msg(short_msg => 'No data result in API request.');
$self->{output}->option_exit();
}
$self->{global} = { total_critical => 0, total_warning => 0, total_nodata => 0 };
foreach (@{$results->{data}}) {
my $rule = $_;
next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$rule->{'rule_name:any'} !~ /$self->{option_results}->{filter_name}/);
$self->{rules}->{$rule->{'rule_id:group'}} = {
id => $rule->{'rule_id:group'},
name => $rule->{'rule_name:any'},
ok_count => $rule->{'ok:count'},
warning_count => $rule->{'warning:count'},
critical_count => $rule->{'critical:count'},
nodata_count => $rule->{'nodata:count'}
};
$self->{global}->{total_critical}+=$rule->{'critical:count'};
$self->{global}->{total_warning}+=$rule->{'warning:count'};
$self->{global}->{total_nodata}+=$rule->{'nodata:count'};
}
$self->{global}->{total} = scalar (keys %{$self->{rules}});
if (scalar(keys %{$self->{rules}}) <= 0) {
$self->{output}->add_option_msg(short_msg => 'No rule found.');
$self->{output}->option_exit();
}
}
1;
__END__
=head1 MODE
Check Kadiska rules alerts status.
=over 8
=item B<--filter-name>
Only get rules by name (can be a regexp).
=back
=cut

View File

@ -0,0 +1,155 @@
#
# Copyright 2023 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::kadiska::mode::listalertrules;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments => {
"filter-name:s" => { name => 'filter_name' },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
}
sub manage_selection {
my ($self, %options) = @_;
my $raw_form_post = {
"select" => [
{
"rule_id:group" => "rule_id"
},
{
"rule_name:any" => ["any","rule_name"]
},
{
["any","rule_name"] => ["any","rule_id"]
}
],
"from" => "alert",
"groupby" => [
"rule_id:group"
],
"orderby" => [
["rule_name:any","desc"]
],
"offset" => 0,
"limit" => 61
};
my $results = $options{custom}->request_api(
method => 'POST',
endpoint => 'query',
query_form_post => $raw_form_post
);
#Check if bad API request is submit
if (!exists $results->{data}) {
$self->{output}->add_option_msg(short_msg => 'No data result in API request.');
$self->{output}->option_exit();
}
foreach (@{$results->{data}}) {
my $rule = $_;
next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$rule->{'rule_name:any'} !~ /$self->{option_results}->{filter_name}/);
my @tags;
foreach my $tag (@{$rule->{tags}}) {
push @tags, (keys %{$tag})[0] . ':' . (values %{$tag})[0];
}
$self->{rules}->{$rule->{'rule_id:group'}} = {
id => $rule->{'rule_id:group'},
name => $rule->{'rule_name:any'}
}
}
if (scalar(keys %{$self->{rules}}) <= 0) {
$self->{output}->add_option_msg(short_msg => 'No rule found.');
$self->{output}->option_exit();
}
}
sub run {
my ($self, %options) = @_;
$self->manage_selection(%options);
foreach my $rule (sort keys %{$self->{rules}}) {
$self->{output}->output_add(long_msg => sprintf("[name = %s] [id = %s]",
$self->{rules}->{$rule}->{name},
$self->{rules}->{$rule}->{id}));
}
$self->{output}->output_add(severity => 'OK',
short_msg => 'List alert rules:');
$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', 'id']);
}
sub disco_show {
my ($self, %options) = @_;
$self->manage_selection(%options);
foreach my $rule (sort keys %{$self->{rules}}) {
$self->{output}->add_disco_entry(
name => $self->{rules}->{$rule}->{name},
id => $self->{rules}->{$rule}->{id}
);
}
}
1;
__END__
=head1 MODE
List kadiska alert rules.
=over 8
=item B<--filter-name>
Filter rule name (can be a regexp).
=back
=cut

View File

@ -30,11 +30,13 @@ sub new {
bless $self, $class;
$self->{modes} = {
'list-watchers' => 'apps::monitoring::kadiska::mode::listwatchers',
'alerts' => 'apps::monitoring::kadiska::mode::alerts',
'list-alert-rules' => 'apps::monitoring::kadiska::mode::listalertrules',
'list-runners' => 'apps::monitoring::kadiska::mode::listrunners',
'list-targets' => 'apps::monitoring::kadiska::mode::listtargets',
'watcher-statistics' => 'apps::monitoring::kadiska::mode::watcherstatistics',
'nettracer-statistics' => 'apps::monitoring::kadiska::mode::nettracerstatistics'
'list-watchers' => 'apps::monitoring::kadiska::mode::listwatchers',
'nettracer-statistics' => 'apps::monitoring::kadiska::mode::nettracerstatistics',
'watcher-statistics' => 'apps::monitoring::kadiska::mode::watcherstatistics'
};
$self->{custom_modes}->{api} = 'apps::monitoring::kadiska::custom::api';

View File

@ -1256,6 +1256,68 @@ sub exec_func_scale {
}
}
sub exec_func_second2human {
my ($self, %options) = @_;
#{
# "type": "second2human",
# "src": "%(duration)",
# "save_value": "%(humanDuration)",
# "start": "d",
#}
if (!defined($options{src}) || $options{src} eq '') {
$self->{output}->add_option_msg(short_msg => "$self->{current_section} please set src attribute");
$self->{output}->option_exit();
}
my $result = $self->parse_special_variable(chars => [split //, $options{src}], start => 0);
if ($result->{type} !~ /^(?:0|4)$/) {
$self->{output}->add_option_msg(short_msg => $self->{current_section} . " special variable type not allowed in src attribute");
$self->{output}->option_exit();
}
my $data = $self->get_special_variable_value(%$result);
my ($str, $str_append) = ('', '');
my $periods = [
{ unit => 'y', value => 31556926 },
{ unit => 'M', value => 2629743 },
{ unit => 'w', value => 604800 },
{ unit => 'd', value => 86400 },
{ unit => 'h', value => 3600 },
{ unit => 'm', value => 60 },
{ unit => 's', value => 1 },
];
my %values = ('y' => 1, 'M' => 2, 'w' => 3, 'd' => 4, 'h' => 5, 'm' => 6, 's' => 7);
my $sign = '';
if ($data < 0) {
$sign = '-';
$data = abs($data);
}
foreach (@$periods) {
next if (defined($options{start}) && $values{$_->{unit}} < $values{$options{start}});
my $count = int($data / $_->{value});
next if ($count == 0);
$str .= $str_append . $count . $_->{unit};
$data = $data % $_->{value};
$str_append = ' ';
}
if ($str eq '') {
$str = $data;
$str .= $options{start} if (defined($options{start}));
}
if (defined($options{save_value}) && $options{save_value} ne '') {
my $var_save_value = $self->parse_special_variable(chars => [split //, $options{save_value}], start => 0);
if ($var_save_value->{type} !~ /^(?:0|4)$/) {
$self->{output}->add_option_msg(short_msg => $self->{current_section} . " special variable type not allowed in save_value attribute");
$self->{output}->option_exit();
}
$self->set_special_variable_value(value => $sign . $str, %$var_save_value);
}
}
sub exec_func_date2epoch {
my ($self, %options) = @_;
@ -1591,6 +1653,8 @@ sub set_functions {
$self->exec_func_map(%$_);
} elsif ($_->{type} eq 'scale') {
$self->exec_func_scale(%$_);
} elsif ($_->{type} eq 'second2human') {
$self->exec_func_second2human(%$_);
} elsif (lc($_->{type}) eq 'date2epoch') {
$self->exec_func_date2epoch(%$_);
} elsif (lc($_->{type}) eq 'epoch2date') {
@ -1766,7 +1830,6 @@ sub add_selection_loop {
$self->{output}->option_exit();
}
next if (!defined($self->{http_collected}->{tables}->{ $result->{table} }));
foreach my $instance (keys %{$self->{http_collected}->{tables}->{ $result->{table} }}) {
$self->{expand} = $self->set_constants();
$self->set_builtin();

View File

@ -983,6 +983,68 @@ sub exec_func_scale {
}
}
sub exec_func_second2human {
my ($self, %options) = @_;
#{
# "type": "second2human",
# "src": "%(duration)",
# "save_value": "%(humanDuration)",
# "start": "d",
#}
if (!defined($options{src}) || $options{src} eq '') {
$self->{output}->add_option_msg(short_msg => "$self->{current_section} please set src attribute");
$self->{output}->option_exit();
}
my $result = $self->parse_special_variable(chars => [split //, $options{src}], start => 0);
if ($result->{type} !~ /^(?:0|4)$/) {
$self->{output}->add_option_msg(short_msg => $self->{current_section} . " special variable type not allowed in src attribute");
$self->{output}->option_exit();
}
my $data = $self->get_special_variable_value(%$result);
my ($str, $str_append) = ('', '');
my $periods = [
{ unit => 'y', value => 31556926 },
{ unit => 'M', value => 2629743 },
{ unit => 'w', value => 604800 },
{ unit => 'd', value => 86400 },
{ unit => 'h', value => 3600 },
{ unit => 'm', value => 60 },
{ unit => 's', value => 1 },
];
my %values = ('y' => 1, 'M' => 2, 'w' => 3, 'd' => 4, 'h' => 5, 'm' => 6, 's' => 7);
my $sign = '';
if ($data < 0) {
$sign = '-';
$data = abs($data);
}
foreach (@$periods) {
next if (defined($options{start}) && $values{$_->{unit}} < $values{$options{start}});
my $count = int($data / $_->{value});
next if ($count == 0);
$str .= $str_append . $count . $_->{unit};
$data = $data % $_->{value};
$str_append = ' ';
}
if ($str eq '') {
$str = $data;
$str .= $options{start} if (defined($options{start}));
}
if (defined($options{save_value}) && $options{save_value} ne '') {
my $var_save_value = $self->parse_special_variable(chars => [split //, $options{save_value}], start => 0);
if ($var_save_value->{type} !~ /^(?:0|4)$/) {
$self->{output}->add_option_msg(short_msg => $self->{current_section} . " special variable type not allowed in save_value attribute");
$self->{output}->option_exit();
}
$self->set_special_variable_value(value => $sign . $str, %$var_save_value);
}
}
sub exec_func_date2epoch {
my ($self, %options) = @_;
@ -1339,6 +1401,8 @@ sub set_functions {
$self->exec_func_map(%$_);
} elsif ($_->{type} eq 'scale') {
$self->exec_func_scale(%$_);
} elsif ($_->{type} eq 'second2human') {
$self->exec_func_second2human(%$_);
} elsif (lc($_->{type}) eq 'date2epoch') {
$self->exec_func_date2epoch(%$_);
} elsif (lc($_->{type}) eq 'epoch2date') {

View File

@ -41,12 +41,6 @@ sub custom_radio_channel_util_calc {
return 0;
}
sub skip_global {
my ($self, %options) = @_;
scalar(keys %{$self->{ap}}) == 1 ? return(1) : return(0);
}
sub prefix_global_output {
my ($self, %options) = @_;
@ -75,7 +69,7 @@ sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, cb_prefix_output => 'prefix_global_output', cb_init => 'skip_global', },
{ name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' },
{ name => 'ap', type => 3, cb_prefix_output => 'prefix_ap_output', cb_long_output => 'ap_long_output', indent_long_output => ' ', message_multiple => 'All access points are ok',
group => [
{ name => 'ap_global', type => 0 },

View File

@ -0,0 +1,81 @@
#
# Copyright 2023 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::common::powershell::windows::certificates;
use strict;
use warnings;
use centreon::common::powershell::functions;
sub get_powershell {
my (%options) = @_;
my $ps = '
$ProgressPreference = "SilentlyContinue"
$WarningPreference = "SilentlyContinue"
$culture = new-object "System.Globalization.CultureInfo" "en-us"
[System.Threading.Thread]::CurrentThread.CurrentUICulture = $culture
';
$ps .= centreon::common::powershell::functions::escape_jsonstring(%options);
$ps .= centreon::common::powershell::functions::convert_to_json(%options);
$ps .= '
Try {
$ErrorActionPreference = "Stop"
$items = New-Object System.Collections.Generic.List[Hashtable];
Get-ChildItem -Path cert: -Recurse | ForEach-Object {
if ($_.GetType().fullName -eq "System.Security.Cryptography.X509Certificates.X509Certificate2") {
$item = @{}
$item.subject = $_.Subject
$item.thumbprint = $_.Thumbprint
$item.notAfter = (get-date -date $_.NotAfter.ToUniversalTime() -UFormat ' . "'%s'" . ')
$item.PSParentPath = $_.PSParentPath
$item.archived = $_.Archived
$items.Add($item)
}
}
$jsonString = $items | ConvertTo-JSON-20 -forceArray $true
Write-Host $jsonString
} Catch {
Write-Host $Error[0].Exception
exit 1
}
exit 0
';
return $ps;
}
1;
__END__
=head1 DESCRIPTION
Method to get windows certificates.
=cut

View File

@ -897,6 +897,68 @@ sub exec_func_scale {
}
}
sub exec_func_second2human {
my ($self, %options) = @_;
#{
# "type": "second2human",
# "src": "%(duration)",
# "save_value": "%(humanDuration)",
# "start": "d",
#}
if (!defined($options{src}) || $options{src} eq '') {
$self->{output}->add_option_msg(short_msg => "$self->{current_section} please set src attribute");
$self->{output}->option_exit();
}
my $result = $self->parse_special_variable(chars => [split //, $options{src}], start => 0);
if ($result->{type} !~ /^(?:0|4)$/) {
$self->{output}->add_option_msg(short_msg => $self->{current_section} . " special variable type not allowed in src attribute");
$self->{output}->option_exit();
}
my $data = $self->get_special_variable_value(%$result);
my ($str, $str_append) = ('', '');
my $periods = [
{ unit => 'y', value => 31556926 },
{ unit => 'M', value => 2629743 },
{ unit => 'w', value => 604800 },
{ unit => 'd', value => 86400 },
{ unit => 'h', value => 3600 },
{ unit => 'm', value => 60 },
{ unit => 's', value => 1 },
];
my %values = ('y' => 1, 'M' => 2, 'w' => 3, 'd' => 4, 'h' => 5, 'm' => 6, 's' => 7);
my $sign = '';
if ($data < 0) {
$sign = '-';
$data = abs($data);
}
foreach (@$periods) {
next if (defined($options{start}) && $values{$_->{unit}} < $values{$options{start}});
my $count = int($data / $_->{value});
next if ($count == 0);
$str .= $str_append . $count . $_->{unit};
$data = $data % $_->{value};
$str_append = ' ';
}
if ($str eq '') {
$str = $data;
$str .= $options{start} if (defined($options{start}));
}
if (defined($options{save_value}) && $options{save_value} ne '') {
my $var_save_value = $self->parse_special_variable(chars => [split //, $options{save_value}], start => 0);
if ($var_save_value->{type} !~ /^(?:0|4)$/) {
$self->{output}->add_option_msg(short_msg => $self->{current_section} . " special variable type not allowed in save_value attribute");
$self->{output}->option_exit();
}
$self->set_special_variable_value(value => $sign . $str, %$var_save_value);
}
}
sub exec_func_date2epoch {
my ($self, %options) = @_;
@ -1232,6 +1294,8 @@ sub set_functions {
$self->exec_func_map(%$_);
} elsif ($_->{type} eq 'scale') {
$self->exec_func_scale(%$_);
} elsif ($_->{type} eq 'second2human') {
$self->exec_func_second2human(%$_);
} elsif (lc($_->{type}) eq 'date2epoch') {
$self->exec_func_date2epoch(%$_);
} elsif (lc($_->{type}) eq 'epoch2date') {

View File

@ -53,7 +53,7 @@ sub custom_string_output {
eval {
local $SIG{__WARN__} = sub { $message = $_[0]; };
local $SIG{__DIE__} = sub { $message = $_[0]; };
$msg = sprintf("$self->{instance_mode}->{option_results}->{printf_format}", eval $self->{instance_mode}->{option_results}->{printf_value});
$msg = sprintf("$self->{instance_mode}->{option_results}->{printf_format}", $self->{result_values}->{ $self->{instance_mode}->{printf_value} });
};
} else {
$msg = sprintf("'%s'", $self->{result_values}->{value_field});
@ -62,6 +62,7 @@ sub custom_string_output {
if (defined($message)) {
$self->{output}->output_add(long_msg => 'output value issue: ' . $message);
}
return $msg;
}
@ -91,6 +92,16 @@ sub check_options {
$self->{output}->add_option_msg(short_msg => "Need to specify '--sql-statement' option.");
$self->{output}->option_exit();
}
$self->{printf_value} = 'value_field';
if (defined($self->{option_results}->{printf_value}) && $self->{option_results}->{printf_value} ne '') {
$self->{printf_value} = $1
if ($self->{option_results}->{printf_value} =~ /\$self->{result_values}->{(value_field|key_field)}/);
$self->{printf_value} = $1
if ($self->{option_results}->{printf_value} =~ /\%{(value_field|key_field)}/);
$self->{printf_value} = $1
if ($self->{option_results}->{printf_value} =~ /\%\((value_field|key_field)\)/);
}
}
sub manage_selection {
@ -155,12 +166,12 @@ Value column (must be one of the selected field). MANDATORY
=item B<--printf-format>
Specify a custom output message relying on printf formatting
Specify a custom output message relying on printf formatting. If this option is set --printf-value is mandatory.
=item B<--printf-value>
Specify scalar used to replace in printf
(Can be: $self->{result_values}->{key_field}, $self->{result_values}->{value_field})
Specify scalar used to replace in printf. If this option is set --printf-format is mandatory.
(Can be: %{key_field}, %{value_field})
=item B<--warning-string>

View File

@ -28,7 +28,7 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_
sub custom_status_perfdata {
my ($self, %options) = @_;
foreach my $key (@{$self->{instance_mode}->{custom_keys}}) {
$self->{output}->perfdata_add(
label => $key,
@ -61,13 +61,13 @@ sub custom_status_calc {
$self->{result_values}->{$key} = $options{new_datas}->{$self->{instance} . '_' . $key};
}
$self->{result_values}->{time} = time();
return 0;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'queries_results', type => 1,
message_multiple => 'All queries results are ok', skipped_code => { -11 => 1 } }
@ -89,7 +89,7 @@ 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 => {
'query:s@' => { name => 'query' },
'instance:s' => { name => 'instance' },
@ -104,27 +104,27 @@ sub new {
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
if (!defined($self->{option_results}->{output}) || $self->{option_results}->{output} eq '') {
$self->{output}->add_option_msg(short_msg => "Need to specify --output option.");
$self->{output}->option_exit();
}
if (!defined($self->{option_results}->{instance}) || $self->{option_results}->{instance} eq '') {
$self->{output}->add_option_msg(short_msg => "Need to specify --instance option.");
$self->{output}->option_exit();
}
if (!defined($self->{option_results}->{query})) {
$self->{output}->add_option_msg(short_msg => "Need to specify --query option.");
$self->{output}->option_exit();
}
$self->{custom_keys} = [];
$self->{queries} = {};
$self->{queries} = [];
foreach my $query (@{$self->{option_results}->{query}}) {
next if ($query !~ /^(.*?),(.*)$/);
$self->{queries}->{$1} = $2;
push @{$self->{queries}}, { label => $1, value => $2 };
push @{$self->{maps_counters}->{queries_results}->[0]->{set}->{key_values}}, { name => $1 };
push @{$self->{custom_keys}}, $1;
}
@ -136,25 +136,31 @@ sub manage_selection {
my ($self, %options) = @_;
$self->{queries_results} = {};
my (@results, @queries);
my $query_index = -1;
foreach my $label (keys %{$self->{queries}}) {
$query_index++;
@queries = ();
push @queries, $self->{queries}->{$label};
my $query_index = 0;
foreach my $query (@{$self->{queries}}) {
my $queries_results = $options{custom}->query(queries => [$query->{value}]);
my $queries_results = $options{custom}->query(queries => \@queries);
foreach my $result (@$queries_results) {
next if (!defined($result->{tags}->{ $self->{option_results}->{instance} }));
my ($column_index) = grep { $result->{columns}->[$_] eq $self->{custom_keys}->[$query_index] } (0 .. @{$result->{columns}} - 1);
my $value;
$value = $options{custom}->compute(aggregation => $self->{option_results}->{aggregation}, values => $result->{values}, column => $column_index) if (defined($result->{values}));
$self->{queries_results}->{ $result->{tags}->{ $self->{option_results}->{instance} } }->{instance} = $result->{tags}->{ $self->{option_results}->{instance} };
my $column_index = 0;
foreach (@{$result->{columns}}) {
last if ($_ eq $self->{custom_keys}->[$query_index]);
$column_index++;
}
my $value = $options{custom}->compute(aggregation => $self->{option_results}->{aggregation}, values => $result->{values}, column => $column_index) if (defined($result->{values}));
if (!defined($self->{queries_results}->{ $result->{tags}->{ $self->{option_results}->{instance} } })) {
$self->{queries_results}->{ $result->{tags}->{ $self->{option_results}->{instance} } } = {
instance => $result->{tags}->{ $self->{option_results}->{instance} }
};
}
$self->{queries_results}->{ $result->{tags}->{ $self->{option_results}->{instance} } }->{ $result->{columns}->[$column_index] } = $value;
}
$query_index++;
}
if (scalar(keys %{$self->{queries_results}}) <= 0) {

View File

@ -0,0 +1,417 @@
#
# Copyright 2023 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 hardware::devices::camera::optelecom::snmp::mode::alarms;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
sub custom_alarm_output {
my ($self, %options) = @_;
return sprintf(
"alarm: %s",
$self->{result_values}->{alarm}
);
}
sub device_long_output {
my ($self, %options) = @_;
return sprintf(
"checking device '%s'",
$options{instance_value}->{deviceName}
);
}
sub prefix_device_output {
my ($self, %options) = @_;
return sprintf(
"device '%s' ",
$options{instance_value}->{deviceName}
);
}
sub custom_alarm_perfdata {
my ($self, %options) = @_;
$self->{output}->perfdata_add(
nlabel => 'alarm.enabled.count',
instances => [$self->{result_values}->{deviceName}, $self->{result_values}->{alarmName}],
value => sprintf('%s', $self->{result_values}->{alarmValue})
);
}
sub prefix_alarm_output {
my ($self, %options) = @_;
return "alarm '" . $options{instance_value}->{alarmName} . "' ";
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'devices', type => 3, cb_prefix_output => 'prefix_device_output', cb_long_output => 'device_long_output',
indent_long_output => ' ', message_multiple => 'All devices are ok',
group => [
{ name => 'alarms', type => 1, cb_prefix_output => 'prefix_alarm_output', message_multiple => 'all alarms are ok', skipped_code => { -10 => 1 } }
]
}
];
$self->{maps_counters}->{alarms} = [
{
label => 'alarm-status',
type => 2,
critical_default => '%{alarm} eq "enabled"',
set => {
key_values => [
{ name => 'alarm' }, { name => 'alarmValue' }, { name => 'alarmName' }, { name => 'deviceName' }
],
closure_custom_output => $self->can('custom_alarm_output'),
closure_custom_threshold_check => \&catalog_status_threshold_ng,
closure_custom_perfdata => $self->can('custom_alarm_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-device-name:s' => { name => 'filter_device_name' }
});
return $self;
}
my $mapping_device = {
serial => { oid => '.1.3.6.1.4.1.17534.2.2.1.1.1.6' }, # optcSerialNumber
userLabel1 => { oid => '.1.3.6.1.4.1.17534.2.2.1.1.1.8' }, # optcUserLabel1
userLabel2 => { oid => '.1.3.6.1.4.1.17534.2.2.1.1.1.9' } # optcUserLabel2
};
my $mapping_stream = {
streamDesc => { oid => '.1.3.6.1.4.1.17534.2.2.2.2.1.5' }, # optcStreamDescription
streamDownAlarm => { oid => '.1.3.6.1.4.1.17534.2.2.2.2.1.10' } # optcStreamDownAlarm
};
my $mapping_input = {
inputDesc => { oid => '.1.3.6.1.4.1.17534.2.2.2.3.1.4' }, # optcInputDescription
signalLostAlarm => { oid => '.1.3.6.1.4.1.17534.2.2.2.3.1.7' }, # optcSignalLostAlarm
formatAlarm => { oid => '.1.3.6.1.4.1.17534.2.2.2.3.1.8' } # optcFormatAlarm
};
my $mapping_image_quality = {
badContrastAlarm => { oid => '.1.3.6.1.4.1.17534.2.2.3.1.1.5' }, # optcBadContrastAlarm
badExposureAlarm => { oid => '.1.3.6.1.4.1.17534.2.2.3.1.1.6' }, # optcBadExposureAlarm
lowDetailAlarm => { oid => '.1.3.6.1.4.1.17534.2.2.3.1.1.7' }, # optcLowDetailAlarm
lowSnrAlarm => { oid => '.1.3.6.1.4.1.17534.2.2.3.1.1.8' } # optcLowSnrAlarm
};
my $mapping_tampering = {
noMatchAlarm => { oid => '.1.3.6.1.4.1.17534.2.2.3.2.1.3' }, # optcNoMatchAlarm
positionChangedAlarm => { oid => '.1.3.6.1.4.1.17534.2.2.3.2.1.4' } # optcPositionChangedAlarm
};
sub add_stream_alarm {
my ($self, %options) = @_;
my $oid_streamTable = '.1.3.6.1.4.1.17534.2.2.2.2.1'; # optcStreamEntry
my $snmp_result = $options{snmp}->get_table(
oid => $oid_streamTable,
start => $mapping_stream->{streamDesc}->{oid}
);
foreach (keys %$snmp_result) {
next if (! /\.(\d+)\.(\d+)$/);
my ($deviceIndex, $streamIndex) = ($1, $2);
next if (!defined($self->{devices}->{$deviceIndex}));
my $result = $options{snmp}->map_instance(mapping => $mapping_stream, results => $snmp_result, instance => $deviceIndex . '.' . $streamIndex);
my $name = 'streamDown ' . $result->{streamDesc};
$self->{devices}->{$deviceIndex}->{alarms}->{$name} = {
deviceName => $self->{devices}->{$deviceIndex}->{deviceName},
alarmName => $name,
alarmValue => $result->{streamDownAlarm} =~ /1|true/i ? 1 : 0,
alarm => $result->{streamDownAlarm} =~ /1|true/i ? 'enabled' : 'disabled'
};
}
}
sub add_input_alarm {
my ($self, %options) = @_;
my $oid_inputTable = '.1.3.6.1.4.1.17534.2.2.2.3.1'; # optcInputEntry
my $snmp_result = $options{snmp}->get_table(
oid => $oid_inputTable,
start => $mapping_stream->{inputDesc}->{oid}
);
$self->{inputs} = {};
foreach (keys %$snmp_result) {
next if (! /\.(\d+)\.(\d+)$/);
my ($deviceIndex, $inputIndex) = ($1, $2);
next if (!defined($self->{devices}->{$deviceIndex}));
my $result = $options{snmp}->map_instance(mapping => $mapping_input, results => $snmp_result, instance => $deviceIndex . '.' . $inputIndex);
$self->{inputs}->{$deviceIndex . $inputIndex} = $result->{inputDesc};
my $name = 'signalLost ' . $result->{inputDesc};
$self->{devices}->{$deviceIndex}->{alarms}->{$name} = {
deviceName => $self->{devices}->{$deviceIndex}->{deviceName},
alarmName => $name,
alarmValue => $result->{signalLostAlarm} =~ /1|true/i ? 1 : 0,
alarm => $result->{signalLostAlarm} =~ /1|true/i ? 'enabled' : 'disabled'
};
$name = 'format ' . $result->{inputDesc};
$self->{devices}->{$deviceIndex}->{alarms}->{$name} = {
deviceName => $self->{devices}->{$deviceIndex}->{deviceName},
alarmName => $name,
alarmValue => $result->{formatAlarm} =~ /1|true/i ? 1 : 0,
alarm => $result->{formatAlarm} =~ /1|true/i ? 'enabled' : 'disabled'
};
}
}
sub add_image_quality_alarm {
my ($self, %options) = @_;
my $oid_imageQualityTable = '.1.3.6.1.4.1.17534.2.2.3.1.1'; # optcImageQualityEntry
my $snmp_result = $options{snmp}->get_table(
oid => $oid_imageQualityTable,
start => $mapping_image_quality->{badContrastAlarm}->{oid}
);
foreach (keys %$snmp_result) {
next if (! /\.(\d+)\.(\d+)$/);
my ($deviceIndex, $inputIndex) = ($1, $2);
next if (!defined($self->{devices}->{$deviceIndex}));
my $result = $options{snmp}->map_instance(mapping => $mapping_image_quality, results => $snmp_result, instance => $deviceIndex . '.' . $inputIndex);
my $name = 'badContrast ' . $self->{inputs}->{$deviceIndex . $inputIndex};
$self->{devices}->{$deviceIndex}->{alarms}->{$name} = {
deviceName => $self->{devices}->{$deviceIndex}->{deviceName},
alarmName => $name,
alarmValue => $result->{badContrastAlarm} =~ /1|true/i ? 1 : 0,
alarm => $result->{badContrastAlarm} =~ /1|true/i ? 'enabled' : 'disabled'
};
$name = 'badExposure ' . $self->{inputs}->{$deviceIndex . $inputIndex};
$self->{devices}->{$deviceIndex}->{alarms}->{$name} = {
deviceName => $self->{devices}->{$deviceIndex}->{deviceName},
alarmName => $name,
alarmValue => $result->{badExposureAlarm} =~ /1|true/i ? 1 : 0,
alarm => $result->{badExposureAlarm} =~ /1|true/i ? 'enabled' : 'disabled'
};
$name = 'lowDetail ' . $self->{inputs}->{$deviceIndex . $inputIndex};
$self->{devices}->{$deviceIndex}->{alarms}->{$name} = {
deviceName => $self->{devices}->{$deviceIndex}->{deviceName},
alarmName => $name,
alarmValue => $result->{lowDetailAlarm} =~ /1|true/i ? 1 : 0,
alarm => $result->{lowDetailAlarm} =~ /1|true/i ? 'enabled' : 'disabled'
};
$name = 'lowSnr ' . $self->{inputs}->{$deviceIndex . $inputIndex};
$self->{devices}->{$deviceIndex}->{alarms}->{$name} = {
deviceName => $self->{devices}->{$deviceIndex}->{deviceName},
alarmName => $name,
alarmValue => $result->{lowSnrAlarm} =~ /1|true/i ? 1 : 0,
alarm => $result->{lowSnrAlarm} =~ /1|true/i ? 'enabled' : 'disabled'
};
}
}
sub add_tampering_alarm {
my ($self, %options) = @_;
my $oid_tamperingTable = '.1.3.6.1.4.1.17534.2.2.3.2.1'; # optcTamperingEntry
my $snmp_result = $options{snmp}->get_table(
oid => $oid_tamperingTable,
start => $mapping_tampering->{noMatchAlarm}->{oid}
);
foreach (keys %$snmp_result) {
next if (! /\.(\d+)\.(\d+)$/);
my ($deviceIndex, $inputIndex) = ($1, $2);
next if (!defined($self->{devices}->{$deviceIndex}));
my $result = $options{snmp}->map_instance(mapping => $mapping_tampering, results => $snmp_result, instance => $deviceIndex . '.' . $inputIndex);
my $name = 'noMatchoptcNoMatchAlarm ' . $self->{inputs}->{$deviceIndex . $inputIndex};
$self->{devices}->{$deviceIndex}->{alarms}->{$name} = {
deviceName => $self->{devices}->{$deviceIndex}->{deviceName},
alarmName => $name,
alarmValue => $result->{noMatchAlarm} =~ /1|true/i ? 1 : 0,
alarm => $result->{noMatchAlarm} =~ /1|true/i ? 'enabled' : 'disabled'
};
$name = 'positionChanged ' . $self->{inputs}->{$deviceIndex . $inputIndex};
$self->{devices}->{$deviceIndex}->{alarms}->{$name} = {
deviceName => $self->{devices}->{$deviceIndex}->{deviceName},
alarmName => $name,
alarmValue => $result->{positionChangedAlarm} =~ /1|true/i ? 1 : 0,
alarm => $result->{positionChangedAlarm} =~ /1|true/i ? 'enabled' : 'disabled'
};
}
}
sub add_network_alarm {
my ($self, %options) = @_;
my $oid_networkOverloadAlarm = '.1.3.6.1.4.1.17534.2.2.2.4.1.2';
my $snmp_result = $options{snmp}->get_table(
oid => $oid_networkOverloadAlarm
);
foreach (keys %$snmp_result) {
/\.(\d+)$/;
my $deviceIndex = $1;
next if (!defined($self->{devices}->{$deviceIndex}));
my $name = 'networkOverload';
$self->{devices}->{$deviceIndex}->{alarms}->{$name} = {
deviceName => $self->{devices}->{$deviceIndex}->{deviceName},
alarmName => $name,
alarmValue => $snmp_result->{$_} =~ /1|true/i ? 1 : 0,
alarm => $snmp_result->{$_} =~ /1|true/i ? 'enabled' : 'disabled'
};
}
}
sub add_psu_alarm {
my ($self, %options) = @_;
# it's not linked to a device... weird..
my $oid_powerSupplyAlarm = '.1.3.6.1.4.1.17534.2.2.1.3.3.0';
my $snmp_result = $options{snmp}->get_leef(
oids => [$oid_powerSupplyAlarm]
);
if (defined($snmp_result->{$oid_powerSupplyAlarm})) {
foreach (keys %{$self->{devices}}) {
my $name = 'powersupply';
$self->{devices}->{$_}->{alarms}->{$name} = {
deviceName => $self->{devices}->{$_}->{deviceName},
alarmName => $name,
alarmValue => $snmp_result->{$oid_powerSupplyAlarm} =~ /1|true/i ? 1 : 0,
alarm => $snmp_result->{$oid_powerSupplyAlarm} =~ /1|true/i ? 'enabled' : 'disabled'
};
}
}
}
sub manage_selection {
my ($self, %options) = @_;
my $oid_deviceTable = '.1.3.6.1.4.1.17534.2.2.1.1.1'; # optcSysInfoEntry
my $snmp_result = $options{snmp}->get_table(
oid => $oid_deviceTable,
start => $mapping_device->{serial}->{oid},
end => $mapping_device->{userLabel2}->{oid},
nothing_quit => 1
);
$self->{devices} = {};
foreach (keys %$snmp_result) {
next if (! /^$mapping_device->{serial}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $options{snmp}->map_instance(mapping => $mapping_device, results => $snmp_result, instance => $instance);
my $name = defined($result->{userLabel1}) && $result->{userLabel1} ne '' ? $result->{userLabel1} : $result->{serial};
next if (defined($self->{option_results}->{filter_device_name}) && $self->{option_results}->{filter_device_name} ne '' &&
$name !~ /$self->{option_results}->{filter_device_name}/);
$self->{devices}->{$instance} = { deviceName => $name, alarms => {} };
}
my $oid_temperatureAlarm = '.1.3.6.1.4.1.17534.2.2.1.3.1.1.5'; # optcTemperatureAlarm
$snmp_result = $options{snmp}->get_table(oid => $oid_temperatureAlarm);
foreach (keys %$snmp_result) {
next if (! /\.(\d+).(\d+)$/);
my ($deviceIndex, $probeIndex) = ($1, $2);
next if (!defined($self->{devices}->{$deviceIndex}));
my $name = 'temperature ' . $probeIndex;
$self->{devices}->{$deviceIndex}->{alarms}->{$name} = {
deviceName => $self->{devices}->{$deviceIndex}->{deviceName},
alarmName => $name,
alarmValue => $snmp_result->{$_} =~ /1|true/i ? 1 : 0,
alarm => $snmp_result->{$_} =~ /1|true/i ? 'enabled' : 'disabled'
};
}
$self->add_stream_alarm(snmp => $options{snmp});
$self->add_input_alarm(snmp => $options{snmp});
$self->add_image_quality_alarm(snmp => $options{snmp});
$self->add_tampering_alarm(snmp => $options{snmp});
$self->add_network_alarm(snmp => $options{snmp});
$self->add_psu_alarm(snmp => $options{snmp});
}
1;
__END__
=head1 MODE
Check alarms.
=over 8
=item B<--filter-device-name>
Filter devices by name (can be a regexp).
=item B<--unknown-alarm-status>
Define the conditions to match for the status to be UNKNOWN.
You can use the following variables: %{alarm}, %{alarmName}, %{deviceName}
=item B<--warning-alarm-status>
Define the conditions to match for the status to be WARNING.
You can use the following variables: %{alarm}, %{alarmName}, %{deviceName}
=item B<--critical-alarm-status>
Define the conditions to match for the status to be CRITICAL (default: '%{alarm} eq "enabled"').
You can use the following variables: %{alarm}, %{alarmName}, %{deviceName}
=back
=cut

View File

@ -0,0 +1,180 @@
#
# Copyright 2023 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 hardware::devices::camera::optelecom::snmp::mode::interfaces;
use base qw(snmp_standard::mode::interfaces);
use strict;
use warnings;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
return $self;
}
1;
__END__
=head1 MODE
Check interfaces.
=over 8
=item B<--add-global>
Check global port statistics (By default if no --add-* option is set).
=item B<--add-status>
Check interface status.
=item B<--add-duplex-status>
Check duplex status (with --warning-status and --critical-status).
=item B<--add-traffic>
Check interface traffic.
=item B<--add-errors>
Check interface errors.
=item B<--add-cast>
Check interface cast.
=item B<--add-speed>
Check interface speed.
=item B<--add-volume>
Check interface data volume between two checks (not supposed to be graphed, useful for BI reporting).
=item B<--check-metrics>
If the expression is true, metrics are checked (Default: '%{opstatus} eq "up"').
=item B<--warning-status>
Define the conditions to match for the status to be WARNING.
You can use the following variables: %{admstatus}, %{opstatus}, %{duplexstatus}, %{display}
=item B<--critical-status>
Define the conditions to match for the status to be CRITICAL (Default: '%{admstatus} eq "up" and %{opstatus} ne "up"').
You can use the following variables: %{admstatus}, %{opstatus}, %{duplexstatus}, %{display}
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'total-port', 'total-admin-up', 'total-admin-down', 'total-oper-up', 'total-oper-down',
'in-traffic', 'out-traffic', 'in-error', 'in-discard', 'out-error', 'out-discard',
'in-ucast', 'in-bcast', 'in-mcast', 'out-ucast', 'out-bcast', 'out-mcast',
'speed' (b/s).
=item B<--units-traffic>
Units of thresholds for the traffic (Default: 'percent_delta') ('percent_delta', 'bps', 'counter').
=item B<--units-errors>
Units of thresholds for errors/discards (Default: 'percent_delta') ('percent_delta', 'percent', 'delta', 'deltaps', 'counter').
=item B<--units-cast>
Units of thresholds for communication types (Default: 'percent_delta') ('percent_delta', 'percent', 'delta', 'deltaps', 'counter').
=item B<--nagvis-perfdata>
Display traffic perfdata to be compatible with nagvis widget.
=item B<--interface>
Set the interface (number expected) ex: 1,2,... (empty means 'check all interfaces').
=item B<--name>
Allows you to define the interface (in option --interface) by name instead of OID index. The name matching mode supports regular expressions.
=item B<--speed>
Set interface speed for incoming/outgoing traffic (in Mb).
=item B<--speed-in>
Set interface speed for incoming traffic (in Mb).
=item B<--speed-out>
Set interface speed for outgoing traffic (in Mb).
=item B<--map-speed-dsl>
Get interface speed configuration for interface type 'adsl' and 'vdsl2'.
Syntax: --map-speed-dsl=interface-src-name,interface-dsl-name
E.g: --map-speed-dsl=Et0.835,Et0-vdsl2
=item B<--force-counters64>
Force to use 64 bits counters only. Can be used to improve performance.
=item B<--force-counters32>
Force to use 32 bits counters (even in snmp v2c and v3). Should be used when 64 bits counters are buggy.
=item B<--reload-cache-time>
Time in minutes before reloading cache file (default: 180).
=item B<--oid-filter>
Define the OID to be used to filter interfaces (default: ifName) (values: ifDesc, ifAlias, ifName, IpAddr).
=item B<--oid-display>
Define the OID that will be used to name the interfaces (default: ifName) (values: ifDesc, ifAlias, ifName, IpAddr).
=item B<--oid-extra-display>
Add an OID to display.
=item B<--display-transform-src> B<--display-transform-dst>
Modify the interface name displayed by using a regular expression.
Eg: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens'
=item B<--show-cache>
Display cache interface datas.
=back
=cut

View File

@ -0,0 +1,201 @@
#
# Copyright 2023 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 hardware::devices::camera::optelecom::snmp::mode::networks;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
sub device_long_output {
my ($self, %options) = @_;
return sprintf(
"checking device '%s'",
$options{instance_value}->{deviceName}
);
}
sub prefix_device_output {
my ($self, %options) = @_;
return sprintf(
"device '%s' ",
$options{instance_value}->{deviceName}
);
}
sub prefix_network_output {
my ($self, %options) = @_;
return sprintf(
"network '%s' ",
$options{instance_value}->{ipAddress}
);
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'devices', type => 3, cb_prefix_output => 'prefix_device_output', cb_long_output => 'device_long_output',
indent_long_output => ' ', message_multiple => 'All devices are ok',
group => [
{ name => 'networks', type => 1, cb_prefix_output => 'prefix_network_output', message_multiple => 'all networks are ok', skipped_code => { -10 => 1 } }
]
}
];
$self->{maps_counters}->{networks} = [
{ label => 'traffic-in', nlabel => 'network.traffic.in.bitspersecond', set => {
key_values => [ { name => 'trafficIn' }, { name => 'deviceName' }, { name => 'ipAddress' } ],
output_template => 'in: %s %s/s',
output_change_bytes => 2,
closure_custom_perfdata => sub {
my ($self, %options) = @_;
$self->{output}->perfdata_add(
nlabel => $self->{nlabel},
unit => 'b/s',
instances => [$self->{result_values}->{deviceName}, $self->{result_values}->{ipAddress}],
value => $self->{result_values}->{trafficIn},
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}),
min => 0
);
}
}
},
{ label => 'traffic-out', nlabel => 'network.traffic.out.bitspersecond', set => {
key_values => [ { name => 'trafficOut' }, { name => 'deviceName' }, { name => 'ipAddress' } ],
output_template => 'out: %s %s/s',
output_change_bytes => 2,
closure_custom_perfdata => sub {
my ($self, %options) = @_;
$self->{output}->perfdata_add(
nlabel => $self->{nlabel},
unit => 'b/s',
instances => [$self->{result_values}->{deviceName}, $self->{result_values}->{ipAddress}],
value => $self->{result_values}->{trafficOut},
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 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-device-name:s' => { name => 'filter_device_name' }
});
return $self;
}
my $mapping_device = {
serial => { oid => '.1.3.6.1.4.1.17534.2.2.1.1.1.6' }, # optcSerialNumber
userLabel1 => { oid => '.1.3.6.1.4.1.17534.2.2.1.1.1.8' }, # optcUserLabel1
userLabel2 => { oid => '.1.3.6.1.4.1.17534.2.2.1.1.1.9' } # optcUserLabel2
};
my $mapping_network = {
ipAddress => { oid => '.1.3.6.1.4.1.17534.2.2.1.4.1.4' }, # optcIPAddress
trafficOut => { oid => '.1.3.6.1.4.1.17534.2.2.1.5.1.1' }, # optcTotalTxBitrate
trafficIn => { oid => '.1.3.6.1.4.1.17534.2.2.1.5.1.2' } # optcTotalRxBitrate
};
sub manage_selection {
my ($self, %options) = @_;
my $oid_deviceTable = '.1.3.6.1.4.1.17534.2.2.1.1.1'; # optcSysInfoEntry
my $snmp_result = $options{snmp}->get_table(
oid => $oid_deviceTable,
start => $mapping_device->{serial}->{oid},
end => $mapping_device->{userLabel2}->{oid},
nothing_quit => 1
);
$self->{devices} = {};
foreach (keys %$snmp_result) {
next if (! /^$mapping_device->{serial}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $options{snmp}->map_instance(mapping => $mapping_device, results => $snmp_result, instance => $instance);
my $name = defined($result->{userLabel1}) && $result->{userLabel1} ne '' ? $result->{userLabel1} : $result->{serial};
next if (defined($self->{option_results}->{filter_device_name}) && $self->{option_results}->{filter_device_name} ne '' &&
$name !~ /$self->{option_results}->{filter_device_name}/);
$self->{devices}->{$instance} = { deviceName => $name, networks => {} };
}
my $oid_networkTable = '.1.3.6.1.4.1.17534.2.2.1.4.1'; # optcNetworkSettingsEntry
my $oid_networkStatsTable = '.1.3.6.1.4.1.17534.2.2.1.5.1'; # optcNetworkStatisticsEntry
$snmp_result = $options{snmp}->get_multiple_table(
oids => [ { oid => $oid_networkTable }, { oid => $oid_networkStatsTable } ],
return_type => 1
);
foreach (keys %$snmp_result) {
next if (! /^$mapping_network->{ipAddress}->{oid}\.(\d+).(\d+)$/);
my ($deviceIndex, $netIndex) = ($1, $2);
next if (!defined($self->{devices}->{$deviceIndex}));
my $result = $options{snmp}->map_instance(mapping => $mapping_network, results => $snmp_result, instance => $deviceIndex . '.' . $netIndex);
$self->{devices}->{$deviceIndex}->{networks}->{$netIndex} = {
deviceName => $self->{devices}->{$deviceIndex}->{deviceName},
ipAddress => $result->{ipAddress},
trafficIn => $result->{trafficIn} * 1000,
trafficOut => $result->{trafficOut} * 1000
};
}
}
1;
__END__
=head1 MODE
Check networks traffic.
=over 8
=item B<--filter-device-name>
Filter devices by name (can be a regexp).
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'traffic-in', 'traffic-out'.
=back
=cut

View File

@ -0,0 +1,219 @@
#
# Copyright 2023 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 hardware::devices::camera::optelecom::snmp::mode::temperatures;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
sub custom_alarm_output {
my ($self, %options) = @_;
return sprintf(
"alarm: %s",
$self->{result_values}->{alarm}
);
}
sub device_long_output {
my ($self, %options) = @_;
return sprintf(
"checking device '%s'",
$options{instance_value}->{deviceName}
);
}
sub prefix_device_output {
my ($self, %options) = @_;
return sprintf(
"device '%s' ",
$options{instance_value}->{deviceName}
);
}
sub prefix_temperature_output {
my ($self, %options) = @_;
return "temperature probe '" . $options{instance_value}->{probeIndex} . "' ";
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'devices', type => 3, cb_prefix_output => 'prefix_device_output', cb_long_output => 'device_long_output',
indent_long_output => ' ', message_multiple => 'All devices are ok',
group => [
{ name => 'temperatures', type => 1, cb_prefix_output => 'prefix_temperature_output', message_multiple => 'all temperatures are ok', skipped_code => { -10 => 1 } }
]
}
];
$self->{maps_counters}->{temperatures} = [
{ label => 'probe-temperature', nlabel => 'probe.temperature.celsius', set => {
key_values => [ { name => 'actual' }, { name => 'probeIndex' }, { name => 'deviceName' } ],
output_template => 'temperature: %.2f C',
closure_custom_perfdata => sub {
my ($self, %options) = @_;
$self->{output}->perfdata_add(
nlabel => $self->{nlabel},
unit => 'C',
instances => [$self->{result_values}->{deviceName}, $self->{result_values}->{probeIndex}],
value => sprintf('%.2f', $self->{result_values}->{actual}),
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel})
);
}
}
},
{
label => 'alarm-status',
type => 2,
critical_default => '%{alarm} eq "enabled"',
set => {
key_values => [
{ name => 'alarm' }, { name => 'alarmValue' }, { name => 'probeIndex' }, { name => 'deviceName' }
],
closure_custom_output => $self->can('custom_alarm_output'),
closure_custom_threshold_check => \&catalog_status_threshold_ng,
closure_custom_perfdata => sub {
my ($self, %options) = @_;
$self->{output}->perfdata_add(
nlabel => 'probe.temperature.alarm.enabled.count',
instances => [$self->{result_values}->{deviceName}, $self->{result_values}->{probeIndex}],
value => sprintf('%s', $self->{result_values}->{alarmValue})
);
}
}
}
];
}
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-device-name:s' => { name => 'filter_device_name' }
});
return $self;
}
my $mapping_device = {
serial => { oid => '.1.3.6.1.4.1.17534.2.2.1.1.1.6' }, # optcSerialNumber
userLabel1 => { oid => '.1.3.6.1.4.1.17534.2.2.1.1.1.8' }, # optcUserLabel1
userLabel2 => { oid => '.1.3.6.1.4.1.17534.2.2.1.1.1.9' } # optcUserLabel2
};
my $mapping_temperature = {
actual => { oid => '.1.3.6.1.4.1.17534.2.2.1.3.1.1.2' }, # optcActualTemperature
alarm => { oid => '.1.3.6.1.4.1.17534.2.2.1.3.1.1.5' }, # optcTemperatureAlarm
};
sub manage_selection {
my ($self, %options) = @_;
my $oid_deviceTable = '.1.3.6.1.4.1.17534.2.2.1.1.1'; # optcSysInfoEntry
my $snmp_result = $options{snmp}->get_table(
oid => $oid_deviceTable,
start => $mapping_device->{serial}->{oid},
end => $mapping_device->{userLabel2}->{oid},
nothing_quit => 1
);
$self->{devices} = {};
foreach (keys %$snmp_result) {
next if (! /^$mapping_device->{serial}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $options{snmp}->map_instance(mapping => $mapping_device, results => $snmp_result, instance => $instance);
my $name = defined($result->{userLabel1}) && $result->{userLabel1} ne '' ? $result->{userLabel1} : $result->{serial};
next if (defined($self->{option_results}->{filter_device_name}) && $self->{option_results}->{filter_device_name} ne '' &&
$name !~ /$self->{option_results}->{filter_device_name}/);
$self->{devices}->{$instance} = { deviceName => $name, temperatures => {} };
}
my $oid_temperatureTable = '.1.3.6.1.4.1.17534.2.2.1.3.1.1'; # optcTemperatureEntry
$snmp_result = $options{snmp}->get_table(oid => $oid_temperatureTable);
foreach (keys %$snmp_result) {
next if (! /^$mapping_temperature->{actual}->{oid}\.(\d+).(\d+)$/);
my ($deviceIndex, $probeIndex) = ($1, $2);
next if (!defined($self->{devices}->{$deviceIndex}));
my $result = $options{snmp}->map_instance(mapping => $mapping_temperature, results => $snmp_result, instance => $deviceIndex . '.' . $probeIndex);
$self->{devices}->{$deviceIndex}->{temperatures}->{$probeIndex} = {
probeIndex => $probeIndex,
deviceName => $self->{devices}->{$deviceIndex}->{deviceName},
actual => $result->{actual},
alarmValue => $result->{alarm} =~ /1|true/i ? 1 : 0,
alarm => $result->{alarm} =~ /1|true/i ? 'enabled' : 'disabled'
};
}
}
1;
__END__
=head1 MODE
Check temperatures.
=over 8
=item B<--filter-device-name>
Filter devices by name (can be a regexp).
=item B<--unknown-alarm-status>
Define the conditions to match for the status to be UNKNOWN.
You can use the following variables: %{alarm}, %{probeIndex}, %{deviceName}
=item B<--warning-alarm-status>
Define the conditions to match for the status to be WARNING.
You can use the following variables: %{alarm}, %{probeIndex}, %{deviceName}
=item B<--critical-alarm-status>
Define the conditions to match for the status to be CRITICAL (default: '%{alarm} eq "enabled"').
You can use the following variables: %{alarm}, %{probeIndex}, %{deviceName}
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'probe-temperature'.
=back
=cut

View File

@ -0,0 +1,77 @@
#
# Copyright 2023 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 hardware::devices::camera::optelecom::snmp::mode::uptime;
use base qw(snmp_standard::mode::uptime);
use strict;
use warnings;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
return $self;
}
1;
__END__
=head1 MODE
Check system uptime.
=over 8
=item B<--warning-uptime>
Warning threshold.
=item B<--critical-uptime>
Critical threshold.
=item B<--add-sysdesc>
Display system description.
=item B<--force-oid>
Can choose your oid (numeric format only).
=item B<--check-overload>
Uptime counter limit is 4294967296 and overflow.
With that option, we manage the counter going back. But there is a few chance we can miss a reboot.
=item B<--reboot-window>
To be used with check-overload option. Time in milliseconds (Default: 5000)
You increase the chance of not missing a reboot if you decrease that value.
=item B<--unit>
Select the unit for performance data and thresholds. May be 's' for seconds, 'm' for minutes,
'h' for hours, 'd' for days, 'w' for weeks. Default is seconds
=back

View File

@ -0,0 +1,52 @@
#
# Copyright 2023 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 hardware::devices::camera::optelecom::snmp::plugin;
use strict;
use warnings;
use base qw(centreon::plugins::script_snmp);
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{modes} = {
'alarms' => 'hardware::devices::camera::optelecom::snmp::mode::alarms',
'interfaces' => 'hardware::devices::camera::optelecom::snmp::mode::interfaces',
'list-interfaces' => 'snmp_standard::mode::listinterfaces',
'networks' => 'hardware::devices::camera::optelecom::snmp::mode::networks',
'temperatures' => 'hardware::devices::camera::optelecom::snmp::mode::temperatures',
'uptime' => 'hardware::devices::camera::optelecom::snmp::mode::uptime'
};
return $self;
}
1;
__END__
=head1 PLUGIN DESCRIPTION
Check Optelecom camera (TKH Group siqura) in SNMP.
=cut

View File

@ -90,7 +90,6 @@ sub set_counters {
},
{ label => 'status', type => 2, set => {
key_values => [ { name => 'last_cause' } ],
closure_custom_calc => \&catalog_status_calc,
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold_ng

View File

@ -24,10 +24,10 @@ use strict;
use warnings;
my %map_psu_status = (
0 => 'normal',
0 => 'not supported',
1 => 'not present',
2 => 'failed',
3 => 'not supported',
3 => 'normal',
);
my $mapping = {
@ -68,4 +68,4 @@ sub check {
}
}
1;
1;

View File

@ -190,6 +190,7 @@ sub add_members {
my $oid_status = $options{map} eq 'new' ? '.1.3.6.1.4.1.3375.2.2.5.6.2.1.5' : '.1.3.6.1.4.1.3375.2.2.5.3.2.1.15';
my $snmp_result = $options{snmp}->get_table(oid => $oid_status);
my $loaded = 0;
foreach my $oid (keys %$snmp_result) {
$oid =~ /^$oid_status\.(.*)$/;
my $instance = $1;
@ -202,6 +203,7 @@ sub add_members {
next if (!defined($self->{pools}->{$poolInstance}));
$loaded = 1;
$options{snmp}->load(
oids => [ map($_->{oid}, values(%{$mapping_members->{ $options{map} }})) ],
instances => [$instance],
@ -216,6 +218,8 @@ sub add_members {
};
}
return if ($loaded == 0);
$snmp_result = $options{snmp}->get_leef();
foreach (keys %$snmp_result) {
next if (! /^$mapping_members->{ $options{map} }->{state}->{oid}\.(.*)$/);

View File

@ -73,7 +73,7 @@ sub run {
$self->{output}->option_exit();
}
my $mktFrequenOid = '.1.3.6.1.4.1.14988.1.1.1.3.1.4';
my $mktFrequenOid = '.1.3.6.1.4.1.14988.1.1.1.3.1.4.';
foreach (sort @{$self->{datas}->{all_ids}}) {
my $display_value = $self->get_display_value(id => $_);

View File

@ -107,7 +107,7 @@ sub set_counters {
output_template => 'CPU(s) average usage is %.2f %%',
output_use => 'prct_used', threshold_use => 'prct_used',
perfdatas => [
{ label => 'total_cpu_avg', value => 'prct_used', template => '%.2f',
{ value => 'prct_used', template => '%.2f',
min => 0, max => 100, unit => '%' }
]
}
@ -124,7 +124,7 @@ sub set_counters {
output_template => 'usage : %.2f %%',
output_use => 'prct_used', threshold_use => 'prct_used',
perfdatas => [
{ label => 'cpu', value => 'prct_used', template => '%.2f',
{ value => 'prct_used', template => '%.2f',
min => 0, max => 100, unit => '%', label_extra_instance => 1 }
]
}
@ -140,7 +140,7 @@ sub prefix_cpu_core_output {
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {

View File

@ -41,7 +41,7 @@ my $maps = [
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
@ -50,7 +50,7 @@ sub new {
foreach (@{$maps}) {
$options{options}->add_options(arguments => {
'warning-' . $_->{counter} . ':s' => { name => 'warning_' . $_->{counter} },
'critical-' . $_->{counter} . ':s' => { name => 'critical_' . $_->{counter} },
'critical-' . $_->{counter} . ':s' => { name => 'critical_' . $_->{counter} }
});
}
@ -108,6 +108,7 @@ sub run {
$new_datas->{$cpu_number} = { total => 0 };
$old_datas->{$cpu_number} = { total => 0 };
}
$new_datas->{$cpu_number}->{$_->{counter}} = $values[$_->{position}];
$save_datas->{'cpu' . $cpu_number . '_' . $_->{counter}} = $values[$_->{position}];
my $tmp_value = $self->{statefile_cache}->get(name => 'cpu' . $cpu_number . '_' . $_->{counter});
@ -115,6 +116,7 @@ sub run {
$buffer_creation = 1;
next;
}
if ($new_datas->{$cpu_number}->{$_->{counter}} < $tmp_value) {
$buffer_creation = 1;
next;
@ -129,24 +131,30 @@ sub run {
$self->{statefile_cache}->write(data => $save_datas);
if ($buffer_creation == 1) {
$self->{output}->output_add(severity => 'OK',
short_msg => "Buffer creation...");
$self->{output}->output_add(
severity => 'OK',
short_msg => "Buffer creation..."
);
if ($exit == 0) {
$self->{output}->display();
$self->{output}->exit();
}
}
$self->{output}->output_add(severity => 'OK',
short_msg => "CPUs usages are ok.");
$self->{output}->output_add(
severity => 'OK',
short_msg => "CPUs usages are ok."
);
foreach my $cpu_number (sort keys(%$new_datas)) {
# In buffer creation. New cpu
next if (scalar(keys %{$old_datas->{$cpu_number}}) <= 1);
if ($new_datas->{$cpu_number}->{total} - $old_datas->{$cpu_number}->{total} == 0) {
$self->{output}->output_add(severity => 'OK',
short_msg => "Counter not moved. Have to wait.");
$self->{output}->output_add(
severity => 'OK',
short_msg => "Counter not moved. Have to wait."
);
$self->{output}->display();
$self->{output}->exit();
}
@ -175,25 +183,36 @@ sub run {
my $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $_->{counter});
my $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $_->{counter});
$self->{output}->perfdata_add(label => 'cpu' . $cpu_number . '_' . $_->{counter}, unit => '%',
value => sprintf("%.2f", $value),
warning => $warning,
critical => $critical,
min => 0, max => 100);
$self->{output}->perfdata_add(
nlabel => 'core.cpu.utilization.percentage',
unit => '%',
instances => [$cpu_number, $_->{counter}],
value => sprintf("%.2f", $value),
warning => $warning,
critical => $critical,
min => 0, max => 100
);
}
$self->{output}->output_add(long_msg => $str_output);
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => $str_output);
$self->{output}->output_add(
severity => $exit,
short_msg => $str_output
);
}
}
# We can display a total (some buffer creation and counters have moved)
if ($total_cpu_num != 0) {
foreach my $counter (sort keys %{$total_datas}) {
$self->{output}->perfdata_add(label => 'total_cpu_' . $counter . '_avg', unit => '%',
value => sprintf("%.2f", $total_datas->{$counter} / $total_cpu_num),
min => 0, max => 100);
$self->{output}->perfdata_add(
nlabel => 'cpu.utilization.percentage',
instances => $counter,
unit => '%',
value => sprintf("%.2f", $total_datas->{$counter} / $total_cpu_num),
min => 0, max => 100
);
}
}

View File

@ -1,153 +0,0 @@
#
# Copyright 2023 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 os::linux::local::mode::directlvmusage;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::misc;
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'dlvm', type => 1, cb_prefix_output => 'prefix_dlvm_output', message_multiple => 'All direct LVM are ok' }
];
$self->{maps_counters}->{dlvm} = [
{ label => 'data-usage', set => {
key_values => [ { name => 'data' }, { name => 'display' } ],
output_template => 'Data Usage : %.2f %%',
perfdatas => [
{ label => 'data_used', template => '%.2f',
unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'meta-usage', set => {
key_values => [ { name => 'meta' }, { name => 'display' } ],
output_template => 'Meta Usage : %.2f %%',
perfdatas => [
{ label => 'meta_used', template => '%.2f',
unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }
]
}
}
];
}
sub prefix_dlvm_output {
my ($self, %options) = @_;
return "Direct LVM '" . $options{instance_value}->{display} . "' ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments => {
'filter-lv:s' => { name => 'filter_lv' },
'filter-vg:s' => { name => 'filter_vg' }
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
my ($stdout, $exit_code) = $options{custom}->execute_command(
command => 'lvs',
command_options => '--separator="," 2>&1',
no_quit => 1
);
$self->{dlvm} = {};
# LV,VG,Attr,LSize,Pool,Origin,Data%,Meta%,Move,Log,Cpy%Sync,Convert
# thinpool,docker,twi-aot---,71.25g,,,1.95,0.06,,,,
# lv_controlm,vg_sys,-wi-ao----,5.00g,,,,,,,,
# ...
my @lines = split /\n/, $stdout;
shift @lines;
foreach my $line (@lines) {
my @fields = split /,/, $line;
my ($vg, $lv, $data, $meta) = ($fields[1], $fields[0], $fields[6], $fields[7]);
next if (!defined($data) || $data !~ /[0-9]/);
my $display = centreon::plugins::misc::trim($vg) . '.' . centreon::plugins::misc::trim($lv);
if (defined($self->{option_results}->{filter_lv}) && $self->{option_results}->{filter_lv} ne '' &&
$lv !~ /$self->{option_results}->{filter_lv}/) {
$self->{output}->output_add(long_msg => "skipping '" . $display . "': no matching filter.", debug => 1);
next;
}
if (defined($self->{option_results}->{filter_vg}) && $self->{option_results}->{filter_vg} ne '' &&
$vg !~ /$self->{option_results}->{filter_vg}/) {
$self->{output}->output_add(long_msg => "skipping '" . $display . "': no matching filter.", debug => 1);
next;
}
$self->{dlvm}->{$display} = { display => $display, data => $data, meta => $meta };
}
if (scalar(keys %{$self->{dlvm}}) <= 0) {
if ($exit_code != 0) {
$self->{output}->output_add(long_msg => "command output:" . $stdout);
}
$self->{output}->add_option_msg(short_msg => "No direct lvm found (filters or command issue)");
$self->{output}->option_exit();
}
}
1;
__END__
=head1 MODE
Check directl lvm usage.
Command used: lvs --separator="," 2>&1
=over 8
=item B<--warning-*>
Warning threshold.
Can be: 'data-usage' (%), 'meta-usage' (%).
=item B<--critical-*>
Critical threshold.
Can be: 'data-usage' (%), 'meta-usage' (%).
=item B<--filter-vg>
Filter virtual group (regexp can be used).
=item B<--filter-lv>
Filter logical volume (regexp can be used).
=back
=cut

View File

@ -28,7 +28,7 @@ use centreon::plugins::misc;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
@ -115,8 +115,11 @@ sub run {
short_msg => sprintf('%s: %s seconds (time: %s)', $name, $diff_time, scalar(localtime($time)))
);
}
$self->{output}->perfdata_add(
label => $name, unit => 's',
nlabel => 'file.mtime.last.seconds',
instances => $name,
unit => 's',
value => $diff_time,
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical')

View File

@ -28,7 +28,7 @@ use centreon::plugins::misc;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
@ -123,7 +123,9 @@ sub run {
);
}
$self->{output}->perfdata_add(
label => $name, unit => 'B',
nlabel => 'file.size.bytes',
instances => $name,
unit => 'B',
value => $size,
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning_one'),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical_one'),
@ -145,7 +147,8 @@ sub run {
);
}
$self->{output}->perfdata_add(
label => 'total', unit => 'B',
nlabel => 'files.size.bytes',
unit => 'B',
value => $total_size,
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning_total'),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical_total'),

View File

@ -39,7 +39,7 @@ sub set_counters {
];
$self->{maps_counters}->{inodes} = [
{ label => 'usage', set => {
{ label => 'usage', nlabel => 'storage.inodes.usage.percentage', set => {
key_values => [ { name => 'used' }, { name => 'display' } ],
output_template => 'used: %s %%',
perfdatas => [
@ -53,7 +53,7 @@ sub set_counters {
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {

View File

@ -0,0 +1,268 @@
#
# Copyright 2023 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 os::linux::local::mode::lvm;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::misc;
sub custom_space_usage_output {
my ($self, %options) = @_;
my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
return sprintf(
'space usage total: %s used: %s (%.2f%%) free: %s (%.2f%%)',
$total_size_value . " " . $total_size_unit,
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}
);
}
sub prefix_vg_output {
my ($self, %options) = @_;
return sprintf(
"VG '%s' ",
$options{instance_value}->{name}
);
}
sub prefix_dlv_output {
my ($self, %options) = @_;
return sprintf(
"direct LV '%s' [VG: %s] ",
$options{instance_value}->{lvName},
$options{instance_value}->{vgName}
);
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0 },
{ name => 'vg', type => 1, cb_prefix_output => 'prefix_vg_output', message_multiple => 'All VGs are ok' },
{ name => 'dlv', type => 1, cb_prefix_output => 'prefix_dlv_output', message_multiple => 'All direct LVs are ok' }
];
$self->{maps_counters}->{global} = [
{ label => 'lv-detected', display_ok => 0, nlabel => 'lv.detected.count', set => {
key_values => [ { name => 'lv_detected' } ],
output_template => 'number of direct LV detected: %s',
perfdatas => [
{ template => '%s', min => 0 }
]
}
},
{ label => 'vg-detected', display_ok => 0, nlabel => 'vg.detected.count', set => {
key_values => [ { name => 'vg_detected' } ],
output_template => 'number of direct VG detected: %s',
perfdatas => [
{ template => '%s', min => 0 }
]
}
}
];
$self->{maps_counters}->{dlv} = [
{ label => 'lv-data-usage', nlabel => 'lv.data.usage.percentage', set => {
key_values => [ { name => 'data' }, { name => 'vgName' }, { name => 'lvName' } ],
output_template => 'data usage: %.2f %%',
closure_custom_perfdata => sub {
my ($self, %options) = @_;
$self->{output}->perfdata_add(
nlabel => $self->{nlabel},
unit => '%',
instances => [$self->{result_values}->{vgName}, $self->{result_values}->{lvName}],
value => sprintf('%.2f', $self->{result_values}->{data}),
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}),
min => 0,
max => 100
);
}
}
},
{ label => 'lv-meta-usage', nlabel => 'lv.meta.usage.percentage', set => {
key_values => [ { name => 'meta' }, { name => 'vgName' }, { name => 'lvName' } ],
output_template => 'meta usage: %.2f %%',
closure_custom_perfdata => sub {
my ($self, %options) = @_;
$self->{output}->perfdata_add(
nlabel => $self->{nlabel},
unit => '%',
instances => [$self->{result_values}->{vgName}, $self->{result_values}->{lvName}],
value => sprintf('%.2f', $self->{result_values}->{meta}),
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}),
min => 0,
max => 100
);
}
}
}
];
$self->{maps_counters}->{vg} = [
{ label => 'vg-space-usage', nlabel => 'vg.space.usage.bytes', set => {
key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ],
closure_custom_output => $self->can('custom_space_usage_output'),
perfdatas => [
{ template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1, label_extra_instance => 1 }
]
}
},
{ label => 'vg-space-usage-free', nlabel => 'vg.space.free.bytes', display_ok => 0, set => {
key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ],
closure_custom_output => $self->can('custom_space_usage_output'),
perfdatas => [
{ template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1, label_extra_instance => 1 }
]
}
},
{ label => 'vg-space-usage-prct', nlabel => 'vg.space.usage.percentage', display_ok => 0, set => {
key_values => [ { name => 'prct_used' }, { name => 'used' }, { name => 'free' }, { name => 'prct_free' }, { name => 'total' } ],
closure_custom_output => $self->can('custom_space_usage_output'),
perfdatas => [
{ template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1 }
]
}
}
];
}
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-lv:s' => { name => 'filter_lv' },
'filter-vg:s' => { name => 'filter_vg' }
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
my ($stdout, $exit_code) = $options{custom}->execute_command(
command => 'lvs',
command_options => '--separator=, 2>&1',
no_quit => 1
);
$self->{global} = { lv_detected => 0, vg_detected => 0 };
$self->{dlv} = {};
# LV,VG,Attr,LSize,Pool,Origin,Data%,Meta%,Move,Log,Cpy%Sync,Convert
# thinpool,docker,twi-aot---,71.25g,,,1.95,0.06,,,,
# lv_controlm,vg_sys,-wi-ao----,5.00g,,,,,,,,
my @lines = split(/\n/, $stdout);
shift @lines;
my $i = 0;
foreach my $line (@lines) {
my @fields = split(/,/, $line);
next if (!defined($fields[6]) || $fields[6] !~ /[0-9]/);
my ($vg, $lv, $data, $meta) = (centreon::plugins::misc::trim($fields[1]), centreon::plugins::misc::trim($fields[0]), $fields[6], $fields[7]);
next if (defined($self->{option_results}->{filter_lv}) && $self->{option_results}->{filter_lv} ne '' &&
$lv !~ /$self->{option_results}->{filter_lv}/);
next if (defined($self->{option_results}->{filter_vg}) && $self->{option_results}->{filter_vg} ne '' &&
$vg !~ /$self->{option_results}->{filter_vg}/);
$self->{lv_detected}++;
$self->{dlv}->{$i} = { lvName => $lv, vgName => $vg, data => $data, meta => $meta };
$i++;
}
($stdout, $exit_code) = $options{custom}->execute_command(
command => 'vgs',
command_options => '--separator=, --units=b 2>&1',
no_quit => 1
);
# VG,#PV,#LV,#SN,Attr,VSize,VFree
# test,1,1,0,wz--n-,5364514816B,3217031168B
$self->{vg} = {};
@lines = split(/\n/, $stdout);
shift @lines;
foreach my $line (@lines) {
my @fields = split(/,/, $line);
next if (!defined($fields[5]) || $fields[5] !~ /[0-9]/);
my $vg = centreon::plugins::misc::trim($fields[0]);
$fields[5] =~ /^(\d+)/;
my $size = $1;
$fields[6] =~ /^(\d+)/;
my $free = $1;
next if (defined($self->{option_results}->{filter_vg}) && $self->{option_results}->{filter_vg} ne '' &&
$vg !~ /$self->{option_results}->{filter_vg}/);
$self->{vg_detected}++;
$self->{vg}->{$vg} = {
name => $vg,
total => $size,
free => $free,
used => $size - $free,
prct_free => $free * 100 / $size,
prct_used => ($size - $free) * 100 / $size
};
}
}
1;
__END__
=head1 MODE
Check direct LV and VG free space.
Command used: lvs --separator="," 2>&1
=over 8
=item B<--filter-vg>
Filter volume group (regexp can be used).
=item B<--filter-lv>
Filter logical volume (regexp can be used).
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'lv-detected', 'vg-detected',
'vg-space-usage', 'vg-space-usage-free', 'vg-space-usage-prct',
'lv-data-usage', 'lv-meta-usage'.
=back
=cut

View File

@ -75,46 +75,46 @@ sub set_counters {
closure_custom_threshold_check => \&catalog_status_threshold_ng
}
},
{ label => 'in-discard', set => {
{ label => 'in-discard', nlabel => 'interface.packets.in.discard.percentage', set => {
key_values => [ { name => 'discard_in', diff => 1 }, { name => 'total_in', diff => 1 }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_packet_calc'), closure_custom_calc_extra_options => { type => 'discard', label_ref => 'in' },
closure_custom_output => $self->can('custom_packet_output'), output_error_template => 'Discard In : %s',
threshold_use => 'result_prct',
perfdatas => [
{ label => 'packets_discard_in', value => 'result_prct', template => '%.2f', min => 0, max => 100,
{ value => 'result_prct', template => '%.2f', min => 0, max => 100,
unit => '%', label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'out-discard', set => {
{ label => 'out-discard', nlabel => 'interface.packets.out.discard.percentage', set => {
key_values => [ { name => 'discard_out', diff => 1 }, { name => 'total_out', diff => 1 }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_packet_calc'), closure_custom_calc_extra_options => { type => 'discard', label_ref => 'out' },
closure_custom_output => $self->can('custom_packet_output'), output_error_template => 'Discard Out : %s',
threshold_use => 'result_prct',
perfdatas => [
{ label => 'packets_discard_out', value => 'result_prct', template => '%.2f', min => 0, max => 100,
{ value => 'result_prct', template => '%.2f', min => 0, max => 100,
unit => '%', label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'in-error', set => {
{ label => 'in-error', nlabel => 'interface.packets.in.error.percentage', set => {
key_values => [ { name => 'error_in', diff => 1 }, { name => 'total_in', diff => 1 }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_packet_calc'), closure_custom_calc_extra_options => { type => 'error', label_ref => 'in' },
closure_custom_output => $self->can('custom_packet_output'), output_error_template => 'Error In : %s',
threshold_use => 'result_prct',
perfdatas => [
{ label => 'packets_error_in', value => 'result_prct', template => '%.2f', min => 0, max => 100,
{ value => 'result_prct', template => '%.2f', min => 0, max => 100,
unit => '%', label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'out-error', set => {
{ label => 'out-error', nlabel => 'interface.packets.out.error.percentage', set => {
key_values => [ { name => 'error_out', diff => 1 }, { name => 'total_out', diff => 1 }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_packet_calc'), closure_custom_calc_extra_options => { type => 'error', label_ref => 'out' },
closure_custom_output => $self->can('custom_packet_output'), output_error_template => 'Error In : %s',
threshold_use => 'result_prct',
perfdatas => [
{ label => 'packets_error_out', value => 'result_prct', template => '%.2f', min => 0, max => 100,
{ value => 'result_prct', template => '%.2f', min => 0, max => 100,
unit => '%', label_extra_instance => 1, instance_use => 'display' }
]
}
@ -124,7 +124,7 @@ sub set_counters {
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
@ -235,6 +235,21 @@ Command used: /sbin/ip -s addr 2>&1
=over 8
=item B<--unknown-status>
Define the conditions to match for the status to be UNKNOWN.
You can use the following variables: %{status}, %{display}
=item B<--warning-status>
Define the conditions to match for the status to be WARNING.
You can use the following variables: %{status}, %{display}
=item B<--critical-status>
Define the conditions to match for the status to be CRITICAL (default: '%{status} ne "RU"').
You can use the following variables: %%{status}, %{display}
=item B<--warning-*>
Warning threshold in percent of total packets. Can be:

View File

@ -343,7 +343,7 @@ sub add_extra_metrics {
$self->set_timestamp(timestamp => Time::HiRes::time());
my ($content) = $options{custom}->execute_command(
command => 'bash',
command_options => "-c 'tail -n +1 /proc/$proc_arg/$files_arg'",
command_options => "-c 'tail -vn +1 /proc/$proc_arg/$files_arg'",
no_quit => 1
);

View File

@ -28,13 +28,13 @@ use warnings;
sub custom_usage_perfdata {
my ($self, %options) = @_;
my ($extra_label, $unit) = ('', '');
my $unit = '';
$unit = 'B' if ($self->{result_values}->{label_ref} eq 'data');
if (!defined($options{extra_instance}) || $options{extra_instance} != 0) {
$extra_label .= '_' . $self->{result_values}->{display};
}
$self->{output}->perfdata_add(
label => $self->{result_values}->{label_ref} . '_used' . $extra_label, unit => $unit,
nlabel => $self->{nlabel},
unit => $unit,
instances => $self->{result_values}->{display},
value => $self->{result_values}->{used},
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{result_values}->{warn_label}, total => $self->{result_values}->{total}, cast_int => 1),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{result_values}->{crit_label}, total => $self->{result_values}->{total}, cast_int => 1),
@ -72,7 +72,7 @@ sub custom_usage_output {
}
return sprintf(
"%s Used: %s%s%s",
"%s used: %s%s%s",
ucfirst($self->{result_values}->{label_ref}),
$value,
$limit_soft, $limit_hard
@ -120,7 +120,7 @@ sub set_counters {
];
$self->{maps_counters}->{quota} = [
{ label => 'data-usage', set => {
{ label => 'data-usage', nlabel => 'quota.data.usage.bytes', set => {
key_values => [ { name => 'display' }, { name => 'data_used' }, { name => 'data_soft' }, { name => 'data_hard' } ],
closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_calc_extra_options => { label_ref => 'data' },
closure_custom_output => $self->can('custom_usage_output'),
@ -128,7 +128,7 @@ sub set_counters {
closure_custom_threshold_check => $self->can('custom_usage_threshold')
}
},
{ label => 'inode-usage', set => {
{ label => 'inode-usage', nlabel => 'quota.files.usage.count', set => {
key_values => [ { name => 'display' }, { name => 'inode_used' }, { name => 'inode_soft' }, { name => 'inode_hard' } ],
closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_calc_extra_options => { label_ref => 'inode' },
closure_custom_output => $self->can('custom_usage_output'),
@ -141,7 +141,7 @@ sub set_counters {
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {

View File

@ -28,10 +28,10 @@ use warnings;
sub custom_usage_perfdata {
my ($self, %options) = @_;
my $label = 'used';
my $label = $self->{nlabel};
my $value_perf = $self->{result_values}->{used};
if (defined($self->{instance_mode}->{option_results}->{free})) {
$label = 'free';
$label = 'storage.space.free.bytes';
$value_perf = $self->{result_values}->{free};
}
@ -42,8 +42,9 @@ sub custom_usage_perfdata {
}
$self->{output}->perfdata_add(
label => $label, unit => 'B',
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef,
nlabel => $label,
unit => 'B',
instances => $self->{result_values}->{display},
value => $value_perf,
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, %total_options),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, %total_options),
@ -110,7 +111,7 @@ sub set_counters {
];
$self->{maps_counters}->{disks} = [
{ label => 'usage', set => {
{ label => 'usage', nlabel => 'storage.space.usage.bytes', set => {
key_values => [ { name => 'display' }, { name => 'used' }, { name => 'free' }, { name => 'total' } ],
closure_custom_calc => $self->can('custom_usage_calc'),
closure_custom_output => $self->can('custom_usage_output'),
@ -123,7 +124,7 @@ sub set_counters {
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {

View File

@ -0,0 +1,180 @@
#
# Copyright 2023 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 os::linux::local::mode::systemdjournal;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use DateTime;
use Digest::MD5 qw(md5_hex);
use JSON::XS;
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0 }
];
$self->{maps_counters}->{global} = [
{ label => 'entries', nlabel => 'journal.entries.count', set => {
key_values => [ { name => 'entries' } ],
output_template => 'Journal entries: %s',
perfdatas => [
{ template => '%s', min => 0 }
]
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
'unit:s' => { name => 'unit' },
'filter-message:s' => { name => 'filter_message' },
'since:s' => { name => 'since', default => 'cache' },
'timezone:s' => { name => 'timezone', default => 'local' }
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
$self->{cache_name} = 'cache_linux_local_' . $options{custom}->get_identifier() . '_' . $self->{mode} . '_' .
(defined($self->{option_results}->{filter_message}) ? md5_hex($self->{option_results}->{filter_message}) : md5_hex('all')) . '_' .
(defined($self->{option_results}->{since}) ? md5_hex($self->{option_results}->{since}) : md5_hex('all'));
my $command_options = '--output json --output-fields MESSAGE --no-pager';
if (defined($self->{option_results}->{unit}) && $self->{option_results}->{unit} ne '') {
$command_options .= ' --unit ' . $self->{option_results}->{unit};
}
if (defined($self->{option_results}->{since}) && $self->{option_results}->{since} ne '') {
if ($self->{option_results}->{since} eq "cache") {
my $last_timestamp = $self->read_statefile_key(key => 'last_timestamp');
$last_timestamp = time() - (5 * 60) if (!defined($last_timestamp));
my $dt = DateTime->from_epoch(epoch => $last_timestamp);
$dt->set_time_zone($self->{option_results}->{timezone});
$command_options .= ' --since "' . $dt->ymd . ' ' . $dt->hms . '"';
} elsif ($self->{option_results}->{since} =~ /\d+/) {
$command_options .= ' --since "' . $self->{option_results}->{since} . ' minutes ago"';
}
}
my ($stdout) = $options{custom}->execute_command(
command => 'journalctl',
command_options => $command_options . ' 2>&1'
);
$self->{global} = { entries => 0 };
my @lines = split /\n/, $stdout;
foreach (@lines) {
my $decoded;
eval {
$decoded = JSON::XS->new->utf8->decode($_);
};
if ($@) {
$self->{output}->add_option_msg(short_msg => "Cannot decode json response");
$self->{output}->option_exit();
}
next if (defined($self->{option_results}->{filter_message}) && $self->{option_results}->{filter_message} ne '' &&
$decoded->{MESSAGE} !~ /$self->{option_results}->{filter_message}/);
$self->{global}->{entries}++;
}
}
1;
__END__
=head1 MODE
Count journal entries.
Command used: journalctl --output json --output-fields MESSAGE --no-pager
Examples:
Look for sent emails by Postfix:
# perl centreon_plugins.pl --plugin=os::linux::local::plugin --mode=systemd-journal --unit=postfix.service
--filter-message='status=sent' --since=10 --change-short-output='Journal entries~Emails sent'
--change-perfdata='journal.entries.count,emails.sent.count'
OK: Emails sent: 17 | 'emails.sent.count'=17;;;0;
Look for Puppet errors:
# perl centreon_plugins.pl --plugin=os::linux::local::plugin --mode=systemd-journal
--unit=puppet.service --filter-message='error' --since=30
OK: Journal entries: 1 | 'journal.entries.count'=1;;;0;
Look for the number of Centreon Engine reloads
# perl centreon_plugins.pl --plugin=os::linux::local::plugin --mode=systemd-journal
--unit=centengine.service --filter-message='Reloaded.*Engine' --since=60
--change-short-output='Journal entries~Centreon Engine reloads over the last hour'
--change-perfdata='journal.entries.count,centreon.engine.reload.count'
OK: Centreon Engine reloads over the last hour: 0 | 'centreon.engine.reload.count'=0;;;0;
=over 8
=item B<--unit>
Only look for messages of the specified unit, ie the
name of the systemd service who created the message.
=item B<--filter-message>
Filter on message content (can be a regexp).
=item B<--since>
Defines the amount of time to look back at messages.
Can be minutes (ie 5 "minutes ago") or 'cache' to use the
timestamp from last execution. (Default: 'cache')
=item B<--timezone>
Defines the timezone to convert date/time to the host
timezone when using timestamp from cache. (Default: 'local')
=item B<--warning-entries> B<--critical-entries>
Thresholds on the number of entries found
in the journal for the specified parameters.
=back
=cut

View File

@ -46,8 +46,9 @@ sub custom_traffic_perfdata {
}
$self->{output}->perfdata_add(
label => 'traffic_' . $self->{result_values}->{label}, unit => 'b/s',
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef,
label => $self->{nlabel},
unit => 'b/s',
instances => $self->{result_values}->{display},
value => sprintf("%.2f", $self->{result_values}->{traffic_per_seconds}),
warning => $warning,
critical => $critical,
@ -117,7 +118,7 @@ sub set_counters {
closure_custom_threshold_check => \&catalog_status_threshold_ng
}
},
{ label => 'in', set => {
{ label => 'in', nlabel => 'interface.traffic.in.bitspersecond', set => {
key_values => [ { name => 'in', diff => 1 }, { name => 'speed_in' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'in' },
closure_custom_output => $self->can('custom_traffic_output'), output_error_template => 'Traffic In : %s',
@ -125,7 +126,7 @@ sub set_counters {
closure_custom_threshold_check => $self->can('custom_traffic_threshold')
}
},
{ label => 'out', set => {
{ label => 'out', nlabel => 'interface.traffic.out.bitspersecond', set => {
key_values => [ { name => 'out', diff => 1 }, { name => 'speed_out' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'out' },
closure_custom_output => $self->can('custom_traffic_output'), output_error_template => 'Traffic Out : %s',
@ -138,7 +139,7 @@ sub set_counters {
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {

View File

@ -28,7 +28,7 @@ use POSIX;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
@ -77,7 +77,8 @@ sub run {
threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]
);
$self->{output}->perfdata_add(
label => 'uptime', unit => 's',
nlabel => 'system.uptime.seconds',
unit => 's',
value => floor($uptime),
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),

View File

@ -29,14 +29,12 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '0.1';
$self->{modes} = {
'check-plugin' => 'os::linux::local::mode::checkplugin',
'cpu' => 'os::linux::local::mode::cpu',
'cpu-detailed' => 'os::linux::local::mode::cpudetailed',
'cmd-return' => 'os::linux::local::mode::cmdreturn',
'connections' => 'os::linux::local::mode::connections',
'directlvm-usage' => 'os::linux::local::mode::directlvmusage',
'discovery-snmp' => 'os::linux::local::mode::discoverysnmp',
'discovery-snmpv3' => 'os::linux::local::mode::discoverysnmpv3',
'diskio' => 'os::linux::local::mode::diskio',
@ -44,6 +42,7 @@ sub new {
'files-date' => 'os::linux::local::mode::filesdate',
'inodes' => 'os::linux::local::mode::inodes',
'load' => 'os::linux::local::mode::loadaverage',
'lvm' => 'os::linux::local::mode::lvm',
'list-interfaces' => 'os::linux::local::mode::listinterfaces',
'list-partitions' => 'os::linux::local::mode::listpartitions',
'list-storages' => 'os::linux::local::mode::liststorages',
@ -59,6 +58,7 @@ sub new {
'quota' => 'os::linux::local::mode::quota',
'storage' => 'os::linux::local::mode::storage',
'swap' => 'os::linux::local::mode::swap',
'systemd-journal' => 'os::linux::local::mode::systemdjournal',
'systemd-sc-status' => 'os::linux::local::mode::systemdscstatus',
'traffic' => 'os::linux::local::mode::traffic',
'uptime' => 'os::linux::local::mode::uptime'

View File

@ -39,6 +39,7 @@ sub new {
'inodes' => 'snmp_standard::mode::inodes',
'interfaces' => 'snmp_standard::mode::interfaces',
'load' => 'snmp_standard::mode::loadaverage',
'list-diskio' => 'snmp_standard::mode::listdiskio',
'list-diskspath' => 'snmp_standard::mode::listdiskspath',
'list-interfaces' => 'snmp_standard::mode::listinterfaces',
'list-processes' => 'snmp_standard::mode::listprocesses',

View File

@ -0,0 +1,297 @@
#
# Copyright 2023 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 os::windows::local::mode::certificates;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::common::powershell::windows::certificates;
use centreon::plugins::misc;
use JSON::XS;
use POSIX;
my $unitdiv = { s => 1, w => 604800, d => 86400, h => 3600, m => 60 };
my $unitdiv_long = { s => 'seconds', w => 'weeks', d => 'days', h => 'hours', m => 'minutes' };
sub custom_expires_perfdata {
my ($self, %options) = @_;
$self->{output}->perfdata_add(
nlabel => $self->{nlabel} . '.' . $unitdiv_long->{ $self->{instance_mode}->{option_results}->{unit} },
unit => $self->{instance_mode}->{option_results}->{unit},
instances => $self->{result_values}->{subject},
value => floor($self->{result_values}->{expires_seconds} / $unitdiv->{ $self->{instance_mode}->{option_results}->{unit} }),
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_expires_threshold {
my ($self, %options) = @_;
return $self->{perfdata}->threshold_check(
value => floor($self->{result_values}->{expires_seconds} / $unitdiv->{ $self->{instance_mode}->{option_results}->{unit} }),
threshold => [
{ label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' },
{ label => 'warning-'. $self->{thlabel}, exit_litteral => 'warning' },
{ label => 'unknown-'. $self->{thlabel}, exit_litteral => 'unknown' }
]
);
}
sub custom_expires_output {
my ($self, %options) = @_;
my $msg = 'expires in ' . $self->{result_values}->{expires_human};
if ($self->{result_values}->{expires_seconds} == 0) {
$msg = 'expired';
}
return $msg;
}
sub prefix_certificate_output {
my ($self, %options) = @_;
return sprintf(
"Certificate '%s' [path: %s] ",
$options{instance_value}->{subject},
$options{instance_value}->{path}
);
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0 },
{ name => 'certificates', type => 1, cb_prefix_output => 'prefix_certificate_output', message_multiple => 'All certificates are ok', skipped_code => { -10 => 1 } }
];
$self->{maps_counters}->{global} = [
{ label => 'certificates-detected', nlabel => 'certificates.detected.count', set => {
key_values => [ { name => 'detected' } ],
output_template => 'number of certificates: %s',
perfdatas => [
{ template => '%s', min => 0 }
]
}
}
];
$self->{maps_counters}->{certificates} = [
{ label => 'certificate-expires', nlabel => 'certificate.expires', set => {
key_values => [ { name => 'expires_seconds' }, { name => 'expires_human' }, { name => 'subject' } ],
closure_custom_output => $self->can('custom_expires_output'),
closure_custom_perfdata => $self->can('custom_expires_perfdata'),
closure_custom_threshold_check => $self->can('custom_expires_threshold')
}
}
];
}
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 => {
'timeout:s' => { name => 'timeout', default => 50 },
'command:s' => { name => 'command' },
'command-path:s' => { name => 'command_path' },
'command-options:s' => { name => 'command_options' },
'no-ps' => { name => 'no_ps' },
'ps-exec-only' => { name => 'ps_exec_only' },
'ps-display' => { name => 'ps_display' },
'filter-thumbprint:s' => { name => 'filter_thumbprint' },
'filter-subject:s' => { name => 'filter_subject' },
'filter-path:s' => { name => 'filter_path' },
'unit:s' => { name => 'unit', default => 's' }
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
centreon::plugins::misc::check_security_command(
output => $self->{output},
command => $self->{option_results}->{command},
command_options => $self->{option_results}->{command_options},
command_path => $self->{option_results}->{command_path}
);
$self->{option_results}->{command} = 'powershell.exe'
if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq '');
$self->{option_results}->{command_options} = '-InputFormat none -NoLogo -EncodedCommand'
if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq '');
if ($self->{option_results}->{unit} eq '' || !defined($unitdiv->{$self->{option_results}->{unit}})) {
$self->{option_results}->{unit} = 's';
}
}
sub manage_selection {
my ($self, %options) = @_;
if (!defined($self->{option_results}->{no_ps})) {
my $ps = centreon::common::powershell::windows::certificates::get_powershell();
if (defined($self->{option_results}->{ps_display})) {
$self->{output}->output_add(
severity => 'OK',
short_msg => $ps
);
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();
}
$self->{option_results}->{command_options} .= " " . centreon::plugins::misc::powershell_encoded($ps);
}
my ($stdout) = centreon::plugins::misc::execute(
output => $self->{output},
options => $self->{option_results},
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options}
);
if (defined($self->{option_results}->{ps_exec_only})) {
$self->{output}->output_add(
severity => 'OK',
short_msg => $stdout
);
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();
}
my $decoded;
eval {
$decoded = JSON::XS->new->decode($stdout);
};
if ($@) {
$self->{output}->add_option_msg(short_msg => "Cannot decode json response: $@");
$self->{output}->option_exit();
}
#[
# {"subject":"CN=Microsoft Development Root Certificate Authority 2014, O=Microsoft Corporation, L=Redmond, S=Washington, C=US","PSParentPath":"Microsoft.PowerShell.Security\\Certificate::LocalMachine\\FlightRoot","thumbprint":"F8DB7E1C16F1FFD4AAAD4AAD8DFF0F2445184AEB","archived":false,"notAfter":"2190214308"},
# {"subject":"CN=Microsoft ECC Development Root Certificate Authority 2018, O=Microsoft Corporation, L=Redmond, S=Washington, C=US","PSParentPath":"Microsoft.PowerShell.Security\\Certificate::LocalMachine\\FlightRoot","thumbprint":"6CA22E5501CC80885FF281DD8B3338E89398EE18","archived":false,"notAfter":"2308682336"}
# ...
#]
$self->{global} = { total => 0 };
$self->{certificates} = {};
my $current_time = time();
foreach my $cert (@$decoded) {
next if ($cert->{archived} =~ /true|1/i);
next if (defined($self->{option_results}->{filter_thumbprint}) && $self->{option_results}->{filter_thumbprint} ne '' &&
$cert->{thumbprint} !~ /$self->{option_results}->{filter_thumbprint}/);
next if (defined($self->{option_results}->{filter_subject}) && $self->{option_results}->{filter_subject} ne '' &&
$cert->{subject} !~ /$self->{option_results}->{filter_subject}/);
next if (defined($self->{option_results}->{filter_path}) && $self->{option_results}->{filter_path} ne '' &&
$cert->{PSParentPath} !~ /$self->{option_results}->{filter_path}/);
$self->{certificates}->{ $cert->{thumbprint} } = {
subject => $cert->{subject},
path => $cert->{PSParentPath}
};
if (defined($cert->{notAfter})) {
my $expires_in = $cert->{notAfter} - $current_time;
$expires_in = 0 if ($expires_in < 0);
$self->{certificates}->{ $cert->{thumbprint} }->{expires_seconds} = $expires_in;
$self->{certificates}->{ $cert->{thumbprint} }->{expires_human} = centreon::plugins::misc::change_seconds(
value => $expires_in
);
}
$self->{global}->{detected}++;
}
}
1;
__END__
=head1 MODE
Check local certificates.
=over 8
=item B<--timeout>
Set timeout time for command execution (Default: 50 sec)
=item B<--no-ps>
Don't encode powershell. To be used with --command and 'type' command.
=item B<--command>
Command to get information (Default: 'powershell.exe').
Can be changed if you have output in a file. To be used with --no-ps option!!!
=item B<--command-path>
Command path (Default: none).
=item B<--command-options>
Command options (Default: '-InputFormat none -NoLogo -EncodedCommand').
=item B<--ps-display>
Display powershell script.
=item B<--ps-exec-only>
Print powershell output.
=item B<--filter-thumbprint>
Filter certificate by thumbprint (can be a regexp).
=item B<--filter-subject>
Filter certificate by subject (can be a regexp).
=item B<--filter-path>
Filter certificate by path (can be a regexp).
=item B<--unit>
Select the unit for expires threshold. May be 's' for seconds, 'm' for minutes,
'h' for hours, 'd' for days, 'w' for weeks. Default is seconds.
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'certificates-detected', 'certificate-expires'.
=back
=cut

View File

@ -0,0 +1,195 @@
#
# Copyright 2023 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 os::windows::local::mode::listcertificates;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::common::powershell::windows::certificates;
use centreon::plugins::misc;
use JSON::XS;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments => {
'no-ps' => { name => 'no_ps', },
'timeout:s' => { name => 'timeout', default => 50 },
'command:s' => { name => 'command', default => 'powershell.exe' },
'command-path:s' => { name => 'command_path' },
'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' },
'ps-exec-only' => { name => 'ps_exec_only', },
'ps-display' => { name => 'ps_display' }
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
}
my $map_type = {
0 => 'unknown',
1 => 'noRootDirectory',
2 => 'removableDisk',
3 => 'localDisk',
4 => 'networkDrive',
5 => 'compactDisc',
6 => 'ramDisk'
};
sub manage_selection {
my ($self, %options) = @_;
if (!defined($self->{option_results}->{no_ps})) {
my $ps = centreon::common::powershell::windows::certificates::get_powershell();
if (defined($self->{option_results}->{ps_display})) {
$self->{output}->output_add(
severity => 'OK',
short_msg => $ps
);
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();
}
$self->{option_results}->{command_options} .= " " . centreon::plugins::misc::powershell_encoded($ps);
}
my ($stdout) = centreon::plugins::misc::execute(
output => $self->{output},
options => $self->{option_results},
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options}
);
if (defined($self->{option_results}->{ps_exec_only})) {
$self->{output}->output_add(
severity => 'OK',
short_msg => $stdout
);
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();
}
my $decoded;
eval {
$decoded = JSON::XS->new->utf8->decode($stdout);
};
if ($@) {
$self->{output}->add_option_msg(short_msg => "Cannot decode json response: $@");
$self->{output}->option_exit();
}
return $decoded;
}
sub run {
my ($self, %options) = @_;
my $result = $self->manage_selection();
foreach (@$result) {
$self->{output}->output_add(
long_msg => sprintf(
"[subject: %s][path: %s][thumbprint: %s][archived: %s]",
$_->{subject},
$_->{PSParentPath},
$_->{thumbprint},
$_->{archived} =~ /true|1/i ? 1 : 0
)
);
}
$self->{output}->output_add(
severity => 'OK',
short_msg => 'List certificates:'
);
$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 => ['subject', 'path', 'thumbprint', 'archived']);
}
sub disco_show {
my ($self, %options) = @_;
my $result = $self->manage_selection();
foreach (@$result) {
$self->{output}->add_disco_entry(
subject => $_->{subject},
path => $_->{PSParentPath},
thumbprint => $_->{thumbprint},
archived => $_->{archived} =~ /true|1/i ? 1 : 0
);
}
}
1;
__END__
=head1 MODE
List Windows local certificates.
=over 8
=item B<--timeout>
Set timeout time for command execution (Default: 50 sec)
=item B<--no-ps>
Don't encode powershell. To be used with --command and 'type' command.
=item B<--command>
Command to get information (Default: 'powershell.exe').
Can be changed if you have output in a file. To be used with --no-ps option!!!
=item B<--command-path>
Command path (Default: none).
=item B<--command-options>
Command options (Default: '-InputFormat none -NoLogo -EncodedCommand').
=item B<--ps-display>
Display powershell script.
=item B<--ps-exec-only>
Print powershell output.
=back
=cut

View File

@ -30,12 +30,14 @@ sub new {
bless $self, $class;
$self->{modes} = {
'cmd-return' => 'os::windows::local::mode::cmdreturn',
'list-storages' => 'os::windows::local::mode::liststorages',
'pending-reboot' => 'os::windows::local::mode::pendingreboot',
'sessions' => 'os::windows::local::mode::sessions',
'time' => 'os::windows::local::mode::ntp',
'updates' => 'os::windows::local::mode::updates'
'certificates' => 'os::windows::local::mode::certificates',
'cmd-return' => 'os::windows::local::mode::cmdreturn',
'list-certificates' => 'os::windows::local::mode::listcertificates',
'list-storages' => 'os::windows::local::mode::liststorages',
'pending-reboot' => 'os::windows::local::mode::pendingreboot',
'sessions' => 'os::windows::local::mode::sessions',
'time' => 'os::windows::local::mode::ntp',
'updates' => 'os::windows::local::mode::updates'
};
return $self;

View File

@ -0,0 +1,127 @@
#
# Copyright 2023 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 snmp_standard::mode::listdiskio;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
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 manage_selection {
my ($self, %options) = @_;
my $mapping = {
index => { oid => '.1.3.6.1.4.1.2021.13.15.1.1.1' }, # diskioindex
name => { oid => '.1.3.6.1.4.1.2021.13.15.1.1.2' } # diskiodevice
};
# parent oid for all the mapping usage
my $oid_diskioEntry = '.1.3.6.1.4.1.2021.13.15.1.1';
my $snmp_result = $options{snmp}->get_table(
oid => $oid_diskioEntry,
start => $mapping->{index}->{oid}, # First oid of the mapping
end => $mapping->{name}->{oid} # Last oid of the mapping
);
my $results = {};
# Iterate for all oids catch in snmp result above
foreach my $oid (keys %$snmp_result) {
next if ($oid !~ /^$mapping->{index}->{oid}\.(.*)$/);
my $oid_path = $1;
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $oid_path);
$results->{$oid_path} = {
index => $result->{index},
name => $result->{name}
};
}
return $results;
}
sub run {
my ($self, %options) = @_;
my $results = $self->manage_selection(snmp => $options{snmp});
foreach my $oid_path (sort keys %$results) {
$self->{output}->output_add(
long_msg => sprintf(
'[oid_path: %s] [index: %s] [name: %s]',
$oid_path,
$results->{$oid_path}->{index},
$results->{$oid_path}->{name}
)
);
}
$self->{output}->output_add(
severity => 'OK',
short_msg => 'List disk IO device'
);
$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 => ['index','name']);
}
sub disco_show {
my ($self, %options) = @_;
my $results = $self->manage_selection(snmp => $options{snmp});
foreach my $oid_path (sort keys %$results) {
$self->{output}->add_disco_entry(
index => $results->{$oid_path}->{index},
name => $results->{$oid_path}->{name}
);
}
}
1;
__END__
=head1 MODE
List disk IO device (UCD-DISKIO-MIB).
Need to enable "includeAllDisks 10%" on snmpd.conf.
=over 8
=back
=cut

View File

@ -43,9 +43,22 @@ sub check {
next if ($self->check_filter(section => 'shelf', instance => $shelf_instance));
foreach my $fru (@{$shelf->{frus}}) {
my $instance = $fru->{serial_number};
my $name = $fru->{type} . ':' . $fru->{id};
if ($fru->{installed} !~ /true|1/i) {
$self->{output}->output_add(
long_msg => sprintf(
"fru '%s' shelf '%s' is uninstalled",
$name,
$shelf_name
)
);
next;
}
my $instance = $fru->{serial_number};
next if ($self->check_filter(section => 'fru', instance => $instance));
$self->{components}->{fru}->{total}++;

View File

@ -96,7 +96,7 @@ Check hardware.
=item B<--component>
Which component to check (Default: '.*').
Can be: 'shelf', 'bay', 'fru'.
Can be: 'bay', 'disk', 'fru', 'shelf'.
=item B<--filter>

View File

@ -7,11 +7,12 @@ Library String
Suite Setup Start Mockoon
Suite Teardown Stop Mockoon
Test Timeout 120s
*** Variables ***
${CENTREON_PLUGINS} ${CURDIR}${/}..${/}..${/}src${/}centreon_plugins.pl
${MOCKOON_JSON} ${CURDIR}${/}..${/}resources${/}mockoon${/}cloud-aws-cloudtrail.json
${CENTREON_PLUGINS} ${CURDIR}${/}..${/}..${/}..${/}src${/}centreon_plugins.pl
${MOCKOON_JSON} ${CURDIR}${/}..${/}..${/}resources${/}mockoon${/}cloud-aws-cloudtrail.json
${CMD} perl ${CENTREON_PLUGINS} --plugin=cloud::aws::cloudtrail::plugin --custommode=paws --region=eu-west --aws-secret-key=secret --aws-access-key=key
@ -150,53 +151,53 @@ AWS CloudTrail check trail status
[Documentation] Check AWS CloudTrail trail status
[Tags] cloud aws cloudtrail
FOR ${checktrailstatus_value} IN @{checktrailstatus_values}
${output} = Run
${output} Run
... ${CMD} --mode=checktrailstatus --endpoint=http://localhost:3000/cloudtrail/gettrailstatus/${checktrailstatus_value.trailstatus} --trail-name=${checktrailstatus_value.trailname}
Should Be Equal As Strings
... ${output}
... ${checktrailstatus_value.result}
... msg=Wrong output result for check trail status of ${checktrailstatus_value}
... Wrong output result for check trail status of ${checktrailstatus_value}.{\n}Command output:{\n}${output}
END
AWS CloudTrail count events
[Documentation] Check AWS CloudTrail count events
[Tags] cloud aws cloudtrail
FOR ${countevents_value} IN @{countevents_values}
${command} = Catenate
${command} Catenate
... ${CMD}
... --mode=countevents
... --endpoint=http://localhost:3000/cloudtrail/events/AwsApiCall/${countevents_value.AwsApiCall}/AwsServiceEvent/${countevents_value.AwsServiceEvent}/AwsConsoleAction/${countevents_value.AwsConsoleAction}/AwsConsoleSignIn/${countevents_value.AwsConsoleSignIn}/NextToken/${countevents_value.NextToken}
${length} = Get Length ${countevents_value.eventtype}
${length} Get Length ${countevents_value.eventtype}
IF ${length} > 0
${command} = Catenate ${command} --event-type=${countevents_value.eventtype}
${command} Catenate ${command} --event-type=${countevents_value.eventtype}
END
${length} = Get Length ${countevents_value.delta}
${length} Get Length ${countevents_value.delta}
IF ${length} > 0
${command} = Catenate ${command} --delta=${countevents_value.delta}
${command} Catenate ${command} --delta=${countevents_value.delta}
END
${length} = Get Length ${countevents_value.errormessage}
${length} Get Length ${countevents_value.errormessage}
IF ${length} > 0
${command} = Catenate ${command} --error-message=${countevents_value.errormessage}
${command} Catenate ${command} --error-message=${countevents_value.errormessage}
END
${length} = Get Length ${countevents_value.warningcount}
${length} Get Length ${countevents_value.warningcount}
IF ${length} > 0
${command} = Catenate ${command} --warning-count=${countevents_value.warningcount}
${command} Catenate ${command} --warning-count=${countevents_value.warningcount}
END
${length} = Get Length ${countevents_value.criticalcount}
${length} Get Length ${countevents_value.criticalcount}
IF ${length} > 0
${command} = Catenate ${command} --critical-count=${countevents_value.criticalcount}
${command} Catenate ${command} --critical-count=${countevents_value.criticalcount}
END
${output} = Run ${command}
${output} Run ${command}
Should Be Equal As Strings
... ${output}
... ${countevents_value.result}
... msg=Wrong output result for count events of ${countevents_value}
... Wrong output result for count events of ${countevents_value}.{\n}Command output:{\n}${output}
END
*** Keywords ***
Start Mockoon
${executionresult} = Run Process
${process} Start Process
... mockoon-cli
... start
... --data
@ -204,12 +205,12 @@ Start Mockoon
... --port
... 3000
... --pname
... azure-policyinsights
Should Be Empty ${executionresult.stderr}
... aws-cloudtrail
Wait For Process ${process}
Stop Mockoon
${executionresult} = Run Process
${process} Start Process
... mockoon-cli
... stop
... mockoon-azure-policyinsights
Should Be Empty ${executionresult.stderr}
... mockoon-aws-cloudtrail
Wait For Process ${process}

View File

@ -7,11 +7,12 @@ Library String
Suite Setup Start Mockoon
Suite Teardown Stop Mockoon
Test Timeout 120s
*** Variables ***
${CENTREON_PLUGINS} ${CURDIR}${/}..${/}..${/}src${/}centreon_plugins.pl
${MOCKOON_JSON} ${CURDIR}${/}..${/}resources${/}mockoon${/}cloud-azure-policyinsights-policystates.json
${CENTREON_PLUGINS} ${CURDIR}${/}..${/}..${/}..${/}src${/}centreon_plugins.pl
${MOCKOON_JSON} ${CURDIR}${/}..${/}..${/}resources${/}mockoon${/}cloud-azure-policyinsights-policystates.json
${LOGIN_ENDPOINT} http://localhost:3000/login
${CMD} perl ${CENTREON_PLUGINS} --plugin=cloud::azure::policyinsights::policystates::plugin --subscription=subscription --tenant=tenant --client-id=client_id --client-secret=secret --login-endpoint=${LOGIN_ENDPOINT}
@ -48,33 +49,33 @@ Azure PolicyInsights PolicyStates compliance
[Documentation] Check Azure PolicyInsights PolicyStates compliance
[Tags] cloud azure policyinsights policystates
FOR ${compliance_value} IN @{compliance_values}
${command} = Catenate
${command} Catenate
... ${CMD}
... --mode=compliance
... --management-endpoint=${compliance_value.endpoint}
${length} = Get Length ${compliance_value.policyname}
${length} Get Length ${compliance_value.policyname}
IF ${length} > 0
${command} = Catenate ${command} --policy-name=${compliance_value.policyname}
${command} Catenate ${command} --policy-name=${compliance_value.policyname}
END
${length} = Get Length ${compliance_value.resourcelocation}
${length} Get Length ${compliance_value.resourcelocation}
IF ${length} > 0
${command} = Catenate ${command} --resource-location=${compliance_value.resourcelocation}
${command} Catenate ${command} --resource-location=${compliance_value.resourcelocation}
END
${length} = Get Length ${compliance_value.resourcetype}
${length} Get Length ${compliance_value.resourcetype}
IF ${length} > 0
${command} = Catenate ${command} --resource-type=${compliance_value.resourcetype}
${command} Catenate ${command} --resource-type=${compliance_value.resourcetype}
END
${output} = Run ${command}
${output} Run ${command}
Should Be Equal As Strings
... ${output}
... ${compliance_value.result}
... msg=Wrong output result for compliance of ${compliance_value}
... Wrong output result for compliance of ${compliance_value}.{\n}Command output:{\n}${output}
END
*** Keywords ***
Start Mockoon
${executionresult} = Run Process
${process} Start Process
... mockoon-cli
... start
... --data
@ -83,11 +84,11 @@ Start Mockoon
... 3000
... --pname
... azure-policyinsights
Should Be Empty ${executionresult.stderr}
Wait For Process ${process}
Stop Mockoon
${executionresult} = Run Process
${process} Start Process
... mockoon-cli
... stop
... mockoon-azure-policyinsights
Should Be Empty ${executionresult.stderr}
Wait For Process ${process}

View File

@ -1,34 +0,0 @@
#!/bin/bash
current_dir="$( cd "$(dirname "$0")/../../../../.." >/dev/null 2>&1 || exit ; pwd -P )"
cmd="perl $current_dir/src/centreon_plugins.pl --plugin=cloud::aws::cloudtrail::plugin --custommode=paws --region=eu-west --aws-secret-key=secret --aws-access-key=key"
nb_tests=0
nb_tests_ok=0
test_status_ok=$($cmd --mode=checktrailstatus --endpoint=http://localhost:3000/cloudtrail/gettrailstatus/true --trail-name=TrailName)
((nb_tests++))
if [[ $test_status_ok = "OK: Trail is logging: 1 | 'trail_is_logging'=1;;;0;" ]]
then
((nb_tests_ok++))
else
echo "test_status_ok ko"
echo $test_status_ok
fi
test_status_critical=$($cmd --mode=checktrailstatus --endpoint=http://localhost:3000/cloudtrail/gettrailstatus/false --trail-name=TrailName)
((nb_tests++))
if [[ $test_status_critical = "CRITICAL: Trail is logging: 0 | 'trail_is_logging'=0;;;0;" ]]
then
((nb_tests_ok++))
else
echo "test_status_critical ko"
echo $test_status_critical
fi
if [[ $nb_tests_ok = $nb_tests ]]
then
echo "OK: "$nb_tests_ok"/"$nb_tests" tests OK"
else
echo "NOK: "$nb_tests_ok"/"$nb_tests" tests OK"
fi

View File

@ -1,106 +0,0 @@
#!/bin/bash
current_dir="$( cd "$(dirname "$0")/../../../../.." >/dev/null 2>&1 || exit ; pwd -P )"
cmd="perl $current_dir/src/centreon_plugins.pl --plugin=cloud::aws::cloudtrail::plugin --custommode=paws --region=eu-west --aws-secret-key=secret --aws-access-key=key"
nb_tests=0
nb_tests_ok=0
endpoint_url="http://localhost:3000/cloudtrail/events/AwsApiCall/4/AwsServiceEvent/2/AwsConsoleAction/1/AwsConsoleSignIn/3/NextToken/t"
test_ok=$($cmd --mode=countevents --endpoint=$endpoint_url)
((nb_tests++))
if [[ $test_ok = "OK: Number of events: 10.00 | 'events_count'=10.00;;;0;" ]]
then
((nb_tests_ok++))
else
echo "test_ok ko"
echo $test_ok
fi
test_oknexttoken=$($cmd --mode=countevents --endpoint=$endpoint_url"rue")
((nb_tests++))
if [[ $test_oknexttoken = "OK: Number of events: 20.00 | 'events_count'=20.00;;;0;" ]]
then
((nb_tests_ok++))
else
echo "test_oknexttoken ko"
echo $test_oknexttoken
fi
test_okeventtype=$($cmd --mode=countevents --endpoint=$endpoint_url --event-type=AwsApiCall)
((nb_tests++))
if [[ $test_okeventtype = "OK: Number of events: 4.00 | 'events_count'=4.00;;;0;" ]]
then
((nb_tests_ok++))
else
echo "test_okeventtype ko"
echo $test_okeventtype
fi
test_okeventtypenexttoken=$($cmd --mode=countevents --endpoint=$endpoint_url"rue" --event-type=AwsServiceEvent)
((nb_tests++))
if [[ $test_okeventtypenexttoken = "OK: Number of events: 4.00 | 'events_count'=4.00;;;0;" ]]
then
((nb_tests_ok++))
else
echo "test_okeventtypenexttoken ko"
echo $test_okeventtypenexttoken
fi
test_okdelta=$($cmd --mode=countevents --endpoint=$endpoint_url --event-type=AwsApiCall --delta=10)
((nb_tests++))
if [[ $test_okdelta = "OK: Number of events: 4.00 | 'events_count'=4.00;;;0;" ]]
then
((nb_tests_ok++))
else
echo "test_okdelta ko"
echo $test_okdelta
fi
test_okerrormessage=$($cmd --mode=countevents --endpoint=$endpoint_url --error-message='Login error')
((nb_tests++))
if [[ $test_okerrormessage = "OK: Number of events: 3.00 | 'events_count'=3.00;;;0;" ]]
then
((nb_tests_ok++))
else
echo "test_okerrormessage ko"
echo $test_okerrormessage
fi
test_okerrormessagepartial=$($cmd --mode=countevents --endpoint=$endpoint_url --error-message='.*error')
((nb_tests++))
if [[ $test_okerrormessagepartial = "OK: Number of events: 4.00 | 'events_count'=4.00;;;0;" ]]
then
((nb_tests_ok++))
else
echo "test_okerrormessagepartial ko"
echo $test_okerrormessagepartial
fi
test_warning=$($cmd --mode=countevents --endpoint=$endpoint_url --warning-count=3)
((nb_tests++))
if [[ $test_warning = "WARNING: Number of events: 10.00 | 'events_count'=10.00;;;0;" ]]
then
((nb_tests_ok++))
else
echo "test_warning ko"
echo $test_warning
fi
test_critical=$($cmd --mode=countevents --endpoint=$endpoint_url --critical-count=5)
((nb_tests++))
if [[ $test_critical = "CRITICAL: Number of events: 10.00 | 'events_count'=10.00;;;0;" ]]
then
((nb_tests_ok++))
else
echo "test_critical ko"
echo $test_critical
fi
if [[ $nb_tests_ok = $nb_tests ]]
then
echo "OK: "$nb_tests_ok"/"$nb_tests" tests OK"
else
echo "NOK: "$nb_tests_ok"/"$nb_tests" tests OK"
fi

View File

@ -0,0 +1,48 @@
*** Settings ***
Documentation OS Linux SNMP plugin
Library OperatingSystem
Library XML
Test Timeout 120s
*** Variables ***
${CENTREON_PLUGINS} ${CURDIR}${/}..${/}..${/}..${/}src${/}centreon_plugins.pl
${CMD} perl ${CENTREON_PLUGINS} --plugin=os::linux::snmp::plugin
&{list_diskio_test1}
... snmpcommunity=os_linux_snmp_plugin
... nbresults=10
&{list_diskio_test2}
... snmpcommunity=os_linux_snmp_plugin_2
... nbresults=4
@{list_diskio_tests}
... &{list_diskio_test1}
... &{list_diskio_test2}
*** Test Cases ***
Linux SNMP list diskio devices
[Documentation] List Linux diskio devices
[Tags] os linux snmp
FOR ${list_diskio_test} IN @{list_diskio_tests}
${command} Catenate
... ${CMD}
... --mode=list-diskio
... --hostname=127.0.0.1
... --snmp-version=2
... --snmp-port=2024
... --disco-show
${command} Catenate ${command} --snmp-community=${list_diskio_test.snmpcommunity}
${output} Run ${command}
Log To Console ${command}
${nb_results} Get Element Count
... ${output}
... label
Should Be Equal As Integers
... ${list_diskio_test.nbresults}
... ${nb_results}
... Wrong output result for list diskio devices: ${list_diskio_test}.{\n}Command output:{\n}${output}
END

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff