From 0ddcaf9d779751b50f63cad036a3a48edeed86d9 Mon Sep 17 00:00:00 2001 From: itoussies <65223458+itoussies@users.noreply.github.com> Date: Fri, 10 Jan 2025 14:50:56 +0100 Subject: [PATCH] feat(freebsd-snmp): add storage mode with default ZFS support (#5296) Refs: CTOR-1176 --- .../deb.json | 3 +- .../pkg.json | 5 +- .../rpm.json | 3 +- src/os/freebsd/snmp/mode/storage.pm | 132 ++++++++++++++++++ src/os/freebsd/snmp/plugin.pm | 6 +- tests/os/freebsd/snmp/freebsd.snmpwalk | 64 +++++++++ tests/os/freebsd/snmp/storage.robot | 34 +++++ tests/resources/spellcheck/stopwords.txt | 3 + 8 files changed, 243 insertions(+), 7 deletions(-) create mode 100644 src/os/freebsd/snmp/mode/storage.pm create mode 100644 tests/os/freebsd/snmp/freebsd.snmpwalk create mode 100644 tests/os/freebsd/snmp/storage.robot diff --git a/packaging/centreon-plugin-Operatingsystems-Freebsd-Snmp/deb.json b/packaging/centreon-plugin-Operatingsystems-Freebsd-Snmp/deb.json index d94e32d229..bcb1a852d3 100644 --- a/packaging/centreon-plugin-Operatingsystems-Freebsd-Snmp/deb.json +++ b/packaging/centreon-plugin-Operatingsystems-Freebsd-Snmp/deb.json @@ -1,6 +1,7 @@ { "dependencies": [ "libsnmp-perl", - "libdatetime-perl" + "libdatetime-perl", + "libnet-ntp-perl" ] } \ No newline at end of file diff --git a/packaging/centreon-plugin-Operatingsystems-Freebsd-Snmp/pkg.json b/packaging/centreon-plugin-Operatingsystems-Freebsd-Snmp/pkg.json index 6f4972c8de..7c03747ae0 100644 --- a/packaging/centreon-plugin-Operatingsystems-Freebsd-Snmp/pkg.json +++ b/packaging/centreon-plugin-Operatingsystems-Freebsd-Snmp/pkg.json @@ -14,14 +14,15 @@ "snmp_standard/mode/loadaverage.pm", "snmp_standard/mode/listdiskspath.pm", "snmp_standard/mode/listinterfaces.pm", - "snmp_standard/mode/resources/", - "snmp_standard/mode/listprocesses.pm", + "snmp_standard/mode/resources/", + "snmp_standard/mode/listprocesses.pm", "snmp_standard/mode/liststorages.pm", "snmp_standard/mode/processcount.pm", "snmp_standard/mode/storage.pm", "snmp_standard/mode/swap.pm", "snmp_standard/mode/tcpcon.pm", "snmp_standard/mode/uptime.pm", + "snmp_standard/mode/ntp.pm", "os/freebsd/snmp/" ] } diff --git a/packaging/centreon-plugin-Operatingsystems-Freebsd-Snmp/rpm.json b/packaging/centreon-plugin-Operatingsystems-Freebsd-Snmp/rpm.json index d4922ea47a..f91a6ab68e 100644 --- a/packaging/centreon-plugin-Operatingsystems-Freebsd-Snmp/rpm.json +++ b/packaging/centreon-plugin-Operatingsystems-Freebsd-Snmp/rpm.json @@ -1,6 +1,7 @@ { "dependencies": [ "perl(SNMP)", - "perl(DateTime)" + "perl(DateTime)", + "perl(Net::NTP)" ] } \ No newline at end of file diff --git a/src/os/freebsd/snmp/mode/storage.pm b/src/os/freebsd/snmp/mode/storage.pm new file mode 100644 index 0000000000..3776b3b989 --- /dev/null +++ b/src/os/freebsd/snmp/mode/storage.pm @@ -0,0 +1,132 @@ +# +# Copyright 2024 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::freebsd::snmp::mode::storage; + +use base qw(snmp_standard::mode::storage); + +use strict; +use warnings; + +sub default_storage_type { + my ($self, %options) = @_; + + return '^(hrStorageFixedDisk|hrStorageNetworkDisk|hrFSBerkeleyFFS|hrFSOther)$'; +} + +1; + +__END__ + +=head1 MODE + +Check storage system. + +=over 8 + +=item B<--warning-usage> + +Warning threshold. + +=item B<--critical-usage> + +Critical threshold. + +=item B<--warning-access> + +Warning threshold. + +=item B<--critical-access> + +Critical threshold. +Check if storage is C: C<--critical-access=readOnly> + +=item B<--add-access> + +Check storage access (C, C). + +=item B<--units> + +Units of thresholds (default: '%') ('%', 'B'). + +=item B<--free> + +Thresholds are on free space left. + +=item B<--storage> + +Define the storage filter on IDs (OID indexes, e.g.: 1,2,...). If empty, all storage systems will be monitored. +To filter on storage names, see C<--name>. + +=item B<--name> + +Allows to use storage name with option C<--storage> instead of storage OID index. + +=item B<--regexp> + +Allows to use regexp to filter storage (with option C<--name>). + +=item B<--regexp-insensitive> + +Allows to use regexp non case-sensitive (with C<--regexp>). + +=item B<--path-best-match> + +Allows to select best path mount point (with C<--name>). + +=item B<--reload-cache-time> + +Time in minutes before reloading cache file (default: 180). + +=item B<--oid-filter> + +Choose OID used to filter storage (default: C) (values: C, C). + +=item B<--oid-display> + +Choose OID used to display storage (default: C) (values: C, C). + +=item B<--display-transform-src> B<--display-transform-dst> + +Modify the storage name displayed by using a regular expression. + +Example: adding C<--display-transform-src='dev' --display-transform-dst='run'> will replace all occurrences of C with C. + +=item B<--show-cache> + +Display cache storage data. + +=item B<--space-reservation> + +Some filesystem has space reserved (like ext4 for root). +The value is in percent of total (default: none) (results like 'df' command). + +=item B<--filter-duplicate> + +Filter duplicate storages (in used size and total size). + +=item B<--filter-storage-type> + +Filter storage types with a regexp (default: C<'^(hrStorageFixedDisk|hrStorageNetworkDisk|hrFSBerkeleyFFS|hrFSOther)$'>). +C is needed when the default file system is ZFS. + +=back + +=cut \ No newline at end of file diff --git a/src/os/freebsd/snmp/plugin.pm b/src/os/freebsd/snmp/plugin.pm index b96ada4586..b62e56815c 100644 --- a/src/os/freebsd/snmp/plugin.pm +++ b/src/os/freebsd/snmp/plugin.pm @@ -44,7 +44,7 @@ sub new { 'list-storages' => 'snmp_standard::mode::liststorages', 'memory' => 'os::freebsd::snmp::mode::memory', 'processcount' => 'snmp_standard::mode::processcount', - 'storage' => 'snmp_standard::mode::storage', + 'storage' => 'os::freebsd::snmp::mode::storage', 'swap' => 'snmp_standard::mode::swap', 'time' => 'snmp_standard::mode::ntp', 'tcpcon' => 'snmp_standard::mode::tcpcon', @@ -60,7 +60,7 @@ __END__ =head1 PLUGIN DESCRIPTION -Check Freebsd operating systems in SNMP. -Some modes ('cpu', 'load, 'swap', 'memory') needs 'bsnmp-ucd'. +Check FreeBSD operating systems in SNMP. +Some modes (C, C, C, C) need C. =cut diff --git a/tests/os/freebsd/snmp/freebsd.snmpwalk b/tests/os/freebsd/snmp/freebsd.snmpwalk new file mode 100644 index 0000000000..d4b823321b --- /dev/null +++ b/tests/os/freebsd/snmp/freebsd.snmpwalk @@ -0,0 +1,64 @@ +.1.3.6.1.2.1.25.2.3.1.2.1 = OID: .1.3.6.1.2.1.25.2.1.2 +.1.3.6.1.2.1.25.2.3.1.2.2 = OID: .1.3.6.1.2.1.25.2.1.2 +.1.3.6.1.2.1.25.2.3.1.2.3 = OID: .1.3.6.1.2.1.25.2.1.3 +.1.3.6.1.2.1.25.2.3.1.2.6 = OID: .1.3.6.1.2.1.25.2.1.1 +.1.3.6.1.2.1.25.2.3.1.2.7 = OID: .1.3.6.1.2.1.25.2.1.1 +.1.3.6.1.2.1.25.2.3.1.2.8 = OID: .1.3.6.1.2.1.25.2.1.1 +.1.3.6.1.2.1.25.2.3.1.2.9 = OID: .1.3.6.1.2.1.25.2.1.1 +.1.3.6.1.2.1.25.2.3.1.2.10 = OID: .1.3.6.1.2.1.25.2.1.3 +.1.3.6.1.2.1.25.2.3.1.2.31 = OID: .1.3.6.1.2.1.25.2.1.4 +.1.3.6.1.2.1.25.2.3.1.2.33 = OID: .1.3.6.1.2.1.25.2.1.10 +.1.3.6.1.2.1.25.2.3.1.2.34 = OID: .1.3.6.1.2.1.25.2.1.4 +.1.3.6.1.2.1.25.2.3.1.3.1 = STRING: Physical memory +.1.3.6.1.2.1.25.2.3.1.3.2 = STRING: Real memory +.1.3.6.1.2.1.25.2.3.1.3.3 = STRING: Virtual memory +.1.3.6.1.2.1.25.2.3.1.3.6 = STRING: Memory buffers +.1.3.6.1.2.1.25.2.3.1.3.7 = STRING: Cached memory +.1.3.6.1.2.1.25.2.3.1.3.8 = STRING: Shared virtual memory +.1.3.6.1.2.1.25.2.3.1.3.9 = STRING: Shared real memory +.1.3.6.1.2.1.25.2.3.1.3.10 = STRING: Swap space +.1.3.6.1.2.1.25.2.3.1.3.31 = STRING: / +.1.3.6.1.2.1.25.2.3.1.3.33 = STRING: /dev +.1.3.6.1.2.1.25.2.3.1.3.34 = STRING: /boot/efi +.1.3.6.1.2.1.25.2.3.1.4.1 = INTEGER: 4096 +.1.3.6.1.2.1.25.2.3.1.4.2 = INTEGER: 4096 +.1.3.6.1.2.1.25.2.3.1.4.3 = INTEGER: 4096 +.1.3.6.1.2.1.25.2.3.1.4.6 = INTEGER: 1024 +.1.3.6.1.2.1.25.2.3.1.4.7 = INTEGER: 4096 +.1.3.6.1.2.1.25.2.3.1.4.8 = INTEGER: 4096 +.1.3.6.1.2.1.25.2.3.1.4.9 = INTEGER: 4096 +.1.3.6.1.2.1.25.2.3.1.4.10 = INTEGER: 4096 +.1.3.6.1.2.1.25.2.3.1.4.31 = INTEGER: 4096 +.1.3.6.1.2.1.25.2.3.1.4.33 = INTEGER: 512 +.1.3.6.1.2.1.25.2.3.1.4.34 = INTEGER: 512 +.1.3.6.1.2.1.25.2.3.1.5.1 = INTEGER: 241144 +.1.3.6.1.2.1.25.2.3.1.5.2 = INTEGER: 13053 +.1.3.6.1.2.1.25.2.3.1.5.3 = INTEGER: 134610087 +.1.3.6.1.2.1.25.2.3.1.5.6 = INTEGER: 107088 +.1.3.6.1.2.1.25.2.3.1.5.7 = INTEGER: 164113 +.1.3.6.1.2.1.25.2.3.1.5.8 = INTEGER: 27008 +.1.3.6.1.2.1.25.2.3.1.5.9 = INTEGER: 6541 +.1.3.6.1.2.1.25.2.3.1.5.10 = INTEGER: 0 +.1.3.6.1.2.1.25.2.3.1.5.31 = INTEGER: 2527523 +.1.3.6.1.2.1.25.2.3.1.5.33 = INTEGER: 2 +.1.3.6.1.2.1.25.2.3.1.5.34 = INTEGER: 65528 +.1.3.6.1.2.1.25.2.3.1.6.1 = INTEGER: 230842 +.1.3.6.1.2.1.25.2.3.1.6.2 = INTEGER: 12140 +.1.3.6.1.2.1.25.2.3.1.6.3 = INTEGER: 134587035 +.1.3.6.1.2.1.25.2.3.1.6.6 = INTEGER: 101096 +.1.3.6.1.2.1.25.2.3.1.6.7 = INTEGER: 164113 +.1.3.6.1.2.1.25.2.3.1.6.8 = INTEGER: 6711 +.1.3.6.1.2.1.25.2.3.1.6.9 = INTEGER: 5668 +.1.3.6.1.2.1.25.2.3.1.6.10 = INTEGER: 0 +.1.3.6.1.2.1.25.2.3.1.6.31 = INTEGER: 1106944 +.1.3.6.1.2.1.25.2.3.1.6.33 = INTEGER: 0 +.1.3.6.1.2.1.25.2.3.1.6.34 = INTEGER: 1294 +.1.3.6.1.2.1.25.3.8.1.2.1 = STRING: "/" +.1.3.6.1.2.1.25.3.8.1.2.3 = STRING: "/dev" +.1.3.6.1.2.1.25.3.8.1.2.4 = STRING: "/boot/efi" +.1.3.6.1.2.1.25.3.8.1.5.1 = INTEGER: 1 +.1.3.6.1.2.1.25.3.8.1.5.3 = INTEGER: 1 +.1.3.6.1.2.1.25.3.8.1.5.4 = INTEGER: 1 +.1.3.6.1.2.1.25.3.8.1.7.1 = INTEGER: 31 +.1.3.6.1.2.1.25.3.8.1.7.3 = INTEGER: 33 +.1.3.6.1.2.1.25.3.8.1.7.4 = INTEGER: 34 diff --git a/tests/os/freebsd/snmp/storage.robot b/tests/os/freebsd/snmp/storage.robot new file mode 100644 index 0000000000..8a5353d432 --- /dev/null +++ b/tests/os/freebsd/snmp/storage.robot @@ -0,0 +1,34 @@ +*** Settings *** +Documentation Check storage table + +Resource ${CURDIR}${/}..${/}..${/}..${/}resources/import.resource + +Test Timeout 120s + + +*** Variables *** +${CMD} ${CENTREON_PLUGINS} --plugin=os::freebsd::snmp::plugin + + +*** Test Cases *** +storage ${tc} + [Tags] os freebsd + ${command} Catenate + ... ${CMD} + ... --mode=storage + ... --hostname=${HOSTNAME} + ... --snmp-version=${SNMPVERSION} + ... --snmp-port=${SNMPPORT} + ... --snmp-community=os/freebsd/snmp/freebsd + ... --snmp-version=2c + ... --snmp-timeout=1 + ... ${extra_options} + + Ctn Run Command And Check Result As Strings ${command} ${expected_result} + + Examples: tc extra_options expected_result -- + ... 1 ${EMPTY} OK: All storages are ok | 'count'=3;;;0; 'used_/'=4534042624B;;;0;10352734208 'used_/dev'=0B;;;0;1024 'used_/boot/efi'=662528B;;;0;33550336 + ... 2 --verbose OK: All storages are ok | 'count'=3;;;0; 'used_/'=4534042624B;;;0;10352734208 'used_/dev'=0B;;;0;1024 'used_/boot/efi'=662528B;;;0;33550336 Storage '/' Usage Total: 9.64 GB Used: 4.22 GB (43.80%) Free: 5.42 GB (56.20%) Storage '/dev' Usage Total: 1.00 KB Used: 0.00 B (0.00%) Free: 1.00 KB (100.00%) Storage '/boot/efi' Usage Total: 32.00 MB Used: 647.00 KB (1.97%) Free: 31.36 MB (98.03%) + ... 3 --warning-usage=30 WARNING: Storage '/' Usage Total: 9.64 GB Used: 4.22 GB (43.80%) Free: 5.42 GB (56.20%) | 'count'=3;;;0; 'used_/'=4534042624B;0:3105820262;;0;10352734208 'used_/dev'=0B;0:307;;0;1024 'used_/boot/efi'=662528B;0:10065100;;0;33550336 + ... 4 --critical-usage=30 CRITICAL: Storage '/' Usage Total: 9.64 GB Used: 4.22 GB (43.80%) Free: 5.42 GB (56.20%) | 'count'=3;;;0; 'used_/'=4534042624B;;0:3105820262;0;10352734208 'used_/dev'=0B;;0:307;0;1024 'used_/boot/efi'=662528B;;0:10065100;0;33550336 + ... 5 --name --storage='/' OK: Storage '/' Usage Total: 9.64 GB Used: 4.22 GB (43.80%) Free: 5.42 GB (56.20%) | 'count'=1;;;0; 'used'=4534042624B;;;0;10352734208 diff --git a/tests/resources/spellcheck/stopwords.txt b/tests/resources/spellcheck/stopwords.txt index 6151937d58..cfc63307aa 100644 --- a/tests/resources/spellcheck/stopwords.txt +++ b/tests/resources/spellcheck/stopwords.txt @@ -46,10 +46,12 @@ dns-resolve-time env ESX eth +ext4 fanspeed FCCapacity Fortigate Fortinet +FreeBSD frsevent HashiCorp hashicorpvault @@ -177,3 +179,4 @@ WLAN WLC WSMAN XPath +ZFS \ No newline at end of file