edvler / check_mk-btrfs_health

CheckMK Plugin to check the health of btrfs filesystems
GNU General Public License v2.0
3 stars 1 forks source link

[BUG] get_base_infos: IndexError (list index out of range) #4

Open j5k opened 3 months ago

j5k commented 3 months ago

Error:

IndexError (list index out of range)

  File "/omd/sites/general/lib/python3/cmk/base/agent_based/checking/_checking.py", line 413, in get_aggregated_result
    consume_check_results(
  File "/omd/sites/general/lib/python3/cmk/base/api/agent_based/checking_classes.py", line 484, in consume_check_results
    for subr in subresults:
  File "/omd/sites/general/lib/python3/cmk/base/api/agent_based/register/check_plugins.py", line 93, in filtered_generator
    for element in generator(*args, **kwargs):
  File "/omd/sites/general/local/lib/python3/cmk/base/plugins/agent_based/btrfs_health.py", line 314, in check_btrfs_health_usage
    volume, infotype, device = get_base_infos(line)
  File "/omd/sites/general/local/lib/python3/cmk/base/plugins/agent_based/btrfs_health.py", line 38, in get_base_infos
    volume = line[0].split("::")[1]

Local agent output:

[root@localhost] # /usr/lib/check_mk_agent/plugins/btrfs_health
<<<btrfs_health_dstats>>>
btrfs-progs v6.10.1
-EXPERIMENTAL -INJECT -STATIC +LZO +ZSTD +UDEV +FSVERITY +ZONED CRYPTO=libgcrypt
stats::/ [/dev/mapper/luks].write_io_errs    0
stats::/ [/dev/mapper/luks].read_io_errs     0
stats::/ [/dev/mapper/luks].flush_io_errs    0
stats::/ [/dev/mapper/luks].corruption_errs  57
stats::/ [/dev/mapper/luks].generation_errs  0
<<<btrfs_health_usage>>>
btrfs-progs v6.10.1
-EXPERIMENTAL -INJECT -STATIC +LZO +ZSTD +UDEV +FSVERITY +ZONED CRYPTO=libgcrypt
usage::/ Overall:
usage::/     Device size:                    1019896729600
usage::/     Device allocated:                353336557568
usage::/     Device unallocated:                      666560172032
usage::/     Device missing:                             0
usage::/     Device slack:                            3584
usage::/     Used:                            177864826880
usage::/     Free (estimated):                762318467072      (min: 429038381056)
usage::/     Free (statfs, df):               762317414400
usage::/     Data ratio:                                      1.00
usage::/     Metadata ratio:                          2.00
usage::/     Global reserve:                     391888896      (used: 0)
usage::/     Multiple profiles:                         no
usage::/ 
usage::/ Data,single: Size:267370102784, Used:171611807744 (64.19%)
usage::/    /dev/mapper/luks    267370102784
usage::/ 
usage::/ Metadata,DUP: Size:42949672960, Used:3126444032 (7.28%)
usage::/    /dev/mapper/luks    85899345920
usage::/ 
usage::/ System,DUP: Size:33554432, Used:65536 (0.20%)
usage::/    /dev/mapper/luks      67108864
usage::/ 
usage::/ Unallocated:
usage::/    /dev/mapper/luks    666560172032
<<<btrfs_health_scrub>>>
btrfs-progs v6.10.1
-EXPERIMENTAL -INJECT -STATIC +LZO +ZSTD +UDEV +FSVERITY +ZONED CRYPTO=libgcrypt
scrub::/ UUID:             330764a4-2a50-4af3-a622-64eaf28a920e
scrub::/ Scrub started:    Thu Aug  1 22:34:56 2024
scrub::/ Status:           finished
scrub::/ Duration:         0:00:41
scrub::/ Total to scrub:   165.65GiB
scrub::/ Rate:             3.73GiB/s
scrub::/ Error summary:    csum=4
scrub::/   Corrected:      0
scrub::/   Uncorrectable:  4
scrub::/   Unverified:     0

Version: 1.1.3 System: Arch Linux (full updated)

j5k commented 2 months ago

The problem is here: https://github.com/edvler/check_mk-btrfs_health/blob/8cc2449ab15384070af87502af7676e6155d876e/src/local/lib/check_mk/base/plugins/agent_based/btrfs_health.py#L106

btrfs --version has 2 lines and not only 1 line as output:

btrfs-progs v6.10.1
-EXPERIMENTAL -INJECT -STATIC +LZO +ZSTD +UDEV +FSVERITY +ZONED CRYPTO=libgcrypt
madsl commented 1 week ago

I got this issue too. Fixed it locally with something like:

        if (i==0):
            btrfs_version = section[i][1]
            continue
+         if (i==1 and len(section[i]) > 0 and section[i][0] == '-EXPERIMENTAL'):
+             continue

or

        if (i==0):
            btrfs_version = line[1]
            continue
+         if (i==1 and len(line) > 0 and line[0] == '-EXPERIMENTAL'):
+             continue

but I'm not sure if this is the best way of checking if you get two line output or not...