Missing required argument 'item' but it is present

I followed the provided examples for making a plugin that has more than one item. Below is the code:

 from .agent_based_api.v1 import *

 def discover_lfs_df(section):
     yield Service(item="fs-0")


 def check_lfs_df(item, section):
     yield Result(state=State.OK, summary="all good")


 register.check_plugin(
     name="lfs_df",
     service_name="Lustre Filesystem %s",
     discovery_function=discover_lfs_df,
     check_function=check_lfs_df,
 )


register.agent_section(
     name = "lfs_df",
 )

When i attempt to run the check it errors out with the following traceback:

Traceback (most recent call last):
  File "/omd/sites/mysite/bin/cmk", line 98, in <module>
    exit_status = modes.call("--check", None, opts, args)
  File "/omd/sites/mysite/lib/python3/cmk/base/modes/__init__.py", line 69, in call
    return handler(*handler_args)
  File "/omd/sites/mysite/lib/python3/cmk/base/modes/check_mk.py", line 1804, in mode_check
    checking.commandline_checking(
  File "/omd/sites/mysite/lib/python3/cmk/base/agent_based/decorator.py", line 43, in wrapped_check_func
    status, output_text = _combine_texts(check_func(hostname, *args, **kwargs))
  File "/omd/sites/mysite/lib/python3/cmk/base/agent_based/checking/__init__.py", line 121, in commandline_checking
    return _execute_checkmk_checks(
  File "/omd/sites/mysite/lib/python3/cmk/base/agent_based/checking/__init__.py", line 174, in _execute_checkmk_checks
    num_success, plugins_missing_data = check_host_services(
  File "/omd/sites/mysite/lib/python3/cmk/base/agent_based/checking/__init__.py", line 322, in check_host_services
    success = _execute_check(
  File "/omd/sites/mysite/lib/python3/cmk/base/agent_based/checking/__init__.py", line 382, in _execute_check
    submittable = get_aggregated_result(
  File "/omd/sites/mysite/lib/python3/cmk/base/agent_based/checking/__init__.py", line 470, in get_aggregated_result
    result = _aggregate_results(
  File "/omd/sites/mysite/lib/python3/cmk/base/agent_based/checking/__init__.py", line 578, in _aggregate_results
    perfdata, results = _consume_and_dispatch_result_types(subresults)
  File "/omd/sites/mysite/lib/python3/cmk/base/agent_based/checking/__init__.py", line 622, in _consume_and_dispatch_result_types
    for subr in subresults:
  File "/omd/sites/mysite/lib/python3/cmk/base/api/agent_based/register/check_plugins.py", line 94, in filtered_generator
    for element in generator(*args, **kwargs):
TypeError: check_lfs_df() missing 1 required positional argument: 'item'

It is claiming I am missing an argument but it is obviously there. Am I missing something? Or is there a bug?

With only a quick look i miss the definition of the section.
Here it is only the code for the check itself but without the section.

Definition of the section?

The code block is an edited version of the code provided here: Writing your own check plug-ins 3.3. The example — a recap.

I have no agent based check without an “register.agent_section” like it is described here
13. Taming complex agent outputs using parse function
In your case the filename is also “lfs_df.py” or?

I have edited the code to include the “register.agent_section” (edit above). The error is still generated. Yes the file is named “lfs_df.py”. Thank you for taking a look.

I tested with your original code and got no errors.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from .agent_based_api.v1 import *


def discover_lfs_df(section):
    yield Service(item="fs-0")


def check_lfs_df(item, section):
    yield Result(state=State.OK, summary="all good")


register.check_plugin(
    name="lfs_df",
    service_name="Lustre Filesystem %s",
    discovery_function=discover_lfs_df,
    check_function=check_lfs_df,
)

discovery output

cmk --debug -vvI lfs
Discovering services and host labels on: lfs
lfs:
+ FETCHING DATA
  Source: SourceType.HOST/FetcherType.PROGRAM
[cpu_tracking] Start [7f3dcc5098e0]
[ProgramFetcher] Fetch with cache settings: DefaultAgentFileCache(lfs, base_path=/omd/sites/cmk/tmp/check_mk/cache, max_age=MaxAge(checking=0, discovery=120, inventory=120), disabled=False, use_outdated=False, simulation=False)
Using data from cache file /omd/sites/cmk/tmp/check_mk/cache/lfs
Got 18 bytes data from cache
[ProgramFetcher] Use cached data
[cpu_tracking] Stop [7f3dcc5098e0 - Snapshot(process=posix.times_result(user=0.0, system=0.0, children_user=0.0, children_system=0.0, elapsed=0.0))]
  Source: SourceType.HOST/FetcherType.PIGGYBACK
[cpu_tracking] Start [7f3dcc5095b0]
[PiggybackFetcher] Fetch with cache settings: NoCache(lfs, base_path=/omd/sites/cmk/tmp/check_mk/data_source_cache/piggyback, max_age=MaxAge(checking=0, discovery=120, inventory=120), disabled=True, use_outdated=False, simulation=False)
Not using cache (Cache usage disabled)
[PiggybackFetcher] Execute data source
No piggyback files for 'lfs'. Skip processing.
No piggyback files for '127.0.0.1'. Skip processing.
Not using cache (Cache usage disabled)
[cpu_tracking] Stop [7f3dcc5095b0 - Snapshot(process=posix.times_result(user=0.0, system=0.0, children_user=0.0, children_system=0.0, elapsed=0.0))]
+ PARSE FETCHER RESULTS
  Source: SourceType.HOST/FetcherType.PROGRAM
<<<lfs_df>>> / Transition NOOPParser -> HostSectionParser
No persisted sections
  -> Add sections: ['lfs_df']
  Source: SourceType.HOST/FetcherType.PIGGYBACK
No persisted sections
  -> Add sections: []
Received no piggyback data
Received no piggyback data
+ ANALYSE DISCOVERED HOST LABELS
Trying host label discovery with: lfs_df
Trying host label discovery with: 
SUCCESS - Found no new host labels
+ ANALYSE DISCOVERED SERVICES
+ EXECUTING DISCOVERY PLUGINS (1)
  Trying discovery with: lfs_df
  1 lfs_df
SUCCESS - Found 1 services

Check result

cmk --debug -vvn lfs
Checkmk version 2.1.0p11
Try license usage history update.
Trying to acquire lock on /omd/sites/cmk/var/check_mk/license_usage/next_run
Got lock on /omd/sites/cmk/var/check_mk/license_usage/next_run
Trying to acquire lock on /omd/sites/cmk/var/check_mk/license_usage/history.json
Got lock on /omd/sites/cmk/var/check_mk/license_usage/history.json
Next run time has not been reached yet. Abort.
Releasing lock on /omd/sites/cmk/var/check_mk/license_usage/history.json
Released lock on /omd/sites/cmk/var/check_mk/license_usage/history.json
Releasing lock on /omd/sites/cmk/var/check_mk/license_usage/next_run
Released lock on /omd/sites/cmk/var/check_mk/license_usage/next_run
+ FETCHING DATA
  Source: SourceType.HOST/FetcherType.PROGRAM
[cpu_tracking] Start [7fa9b8841340]
[ProgramFetcher] Fetch with cache settings: DefaultAgentFileCache(lfs, base_path=/omd/sites/cmk/tmp/check_mk/cache, max_age=MaxAge(checking=0, discovery=120, inventory=120), disabled=False, use_outdated=False, simulation=False)
Not using cache (Too old. Age is 47 sec, allowed is 0 sec)
[ProgramFetcher] Execute data source
Calling: cat ~/local/tmp/lfs.txt
Write data to cache file /omd/sites/cmk/tmp/check_mk/cache/lfs
Trying to acquire lock on /omd/sites/cmk/tmp/check_mk/cache/lfs
Got lock on /omd/sites/cmk/tmp/check_mk/cache/lfs
Releasing lock on /omd/sites/cmk/tmp/check_mk/cache/lfs
Released lock on /omd/sites/cmk/tmp/check_mk/cache/lfs
[cpu_tracking] Stop [7fa9b8841340 - Snapshot(process=posix.times_result(user=0.0, system=0.0, children_user=0.0, children_system=0.0, elapsed=0.009999997913837433))]
  Source: SourceType.HOST/FetcherType.PIGGYBACK
[cpu_tracking] Start [7fa9b8841760]
[PiggybackFetcher] Fetch with cache settings: NoCache(lfs, base_path=/omd/sites/cmk/tmp/check_mk/data_source_cache/piggyback, max_age=MaxAge(checking=0, discovery=120, inventory=120), disabled=True, use_outdated=False, simulation=False)
Not using cache (Cache usage disabled)
[PiggybackFetcher] Execute data source
No piggyback files for 'lfs'. Skip processing.
No piggyback files for '127.0.0.1'. Skip processing.
Not using cache (Cache usage disabled)
[cpu_tracking] Stop [7fa9b8841760 - Snapshot(process=posix.times_result(user=0.0, system=0.0, children_user=0.0, children_system=0.0, elapsed=0.0))]
+ PARSE FETCHER RESULTS
  Source: SourceType.HOST/FetcherType.PROGRAM
<<<lfs_df>>> / Transition NOOPParser -> HostSectionParser
No persisted sections
  -> Add sections: ['lfs_df']
  Source: SourceType.HOST/FetcherType.PIGGYBACK
No persisted sections
  -> Add sections: []
Received no piggyback data
Received no piggyback data
[cpu_tracking] Start [7fa9b880b310]
value store: synchronizing
Trying to acquire lock on /omd/sites/cmk/tmp/check_mk/counters/lfs
Got lock on /omd/sites/cmk/tmp/check_mk/counters/lfs
value store: loading from disk
Releasing lock on /omd/sites/cmk/tmp/check_mk/counters/lfs
Released lock on /omd/sites/cmk/tmp/check_mk/counters/lfs
Lustre Filesystem fs-0 all good
No piggyback files for 'lfs'. Skip processing.
No piggyback files for '127.0.0.1'. Skip processing.
[cpu_tracking] Stop [7fa9b880b310 - Snapshot(process=posix.times_result(user=0.010000000000000009, system=0.0, children_user=0.0, children_system=0.0, elapsed=0.009999997913837433))]
[agent] Success, execution time 0.0 sec | execution_time=0.020 user_time=0.010 system_time=0.000 children_user_time=0.000 children_system_time=0.000 cmk_time_ds=0.010 cmk_time_agent=0.000

That the check will be found a made a dummy agent section like this.

<<<lfs_df>>>
test

I ran the code again, this time as you presented it. I still encountered the error I reported.

I then tried an edit as follows…

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from .agent_based_api.v1 import *


def discover_lfs_df(section):
    yield Service(item="fs-0")


def check_lfs_df(item="", section=None):
    yield Result(state=State.OK, summary="all good")


register.check_plugin(
    name="lfs_df",
    service_name="Lustre Filesystem %s",
    discovery_function=discover_lfs_df,
    check_function=check_lfs_df,
)

This worked as expected. Maybe this is a difference between 2.1.0p9 (version I am using) and 2.1.0p11 (version you are using). Thank you for your time and looking into this.