Mk_docker.py under python3 gives error: TypeError: Object of type module is not JSON serializable

CMK version: raw 2.1.0p10
OS version: Debian 10

I can’t get the mk_docker plugin to work in a Debian 10 host, I’ve installed the docker pip3 module but when I run the plugin from cli I get:

Traceback (most recent call last):
  File "./mk_docker.py", line 597, in call_node_sections
    section(client)
  File "./mk_docker.py", line 359, in wrapped
    return func(*args, **kwargs)
  File "./mk_docker.py", line 397, in section_node_info
    section = Section("node_info")
  File "./mk_docker.py", line 174, in __init__
    version_json = json.dumps(Section.version_info)
  File "/usr/lib/python3.7/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib/python3.7/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.7/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib/python3.7/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type module is not JSON serializable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./mk_docker.py", line 685, in <module>
    main()
  File "./mk_docker.py", line 679, in main
    call_node_sections(client, config)
  File "./mk_docker.py", line 601, in call_node_sections
    report_exception_to_server(exc, section.__name__)
  File "./mk_docker.py", line 190, in report_exception_to_server
    sec = Section("node_info")
  File "./mk_docker.py", line 174, in __init__
    version_json = json.dumps(Section.version_info)
  File "/usr/lib/python3.7/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib/python3.7/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.7/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib/python3.7/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type module is not JSON serializable

If I try to use python2 (which I don’t want) it complains about the docker pip module, I guess it’s too old or something like that.

Output of “cmk --debug -vvn hostname”:

Checkmk version 2.1.0p10
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.TCP
[cpu_tracking] Start [7f0cbb851040]
[TCPFetcher] Fetch with cache settings: DefaultAgentFileCache(mad-sis-vm-298, 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 129 sec, allowed is 0 sec)
[TCPFetcher] Execute data source
Connecting via TCP to 172.19.1.10:6556 (5.0s timeout)
Detected transport protocol: TransportProtocol.PLAIN (b'<<')
Reading data from agent
Write data to cache file /omd/sites/cmk/tmp/check_mk/cache/mad-sis-vm-298
Trying to acquire lock on /omd/sites/cmk/tmp/check_mk/cache/mad-sis-vm-298
Got lock on /omd/sites/cmk/tmp/check_mk/cache/mad-sis-vm-298
Releasing lock on /omd/sites/cmk/tmp/check_mk/cache/mad-sis-vm-298
Released lock on /omd/sites/cmk/tmp/check_mk/cache/mad-sis-vm-298
Closing TCP connection to 172.19.1.10:6556
[cpu_tracking] Stop [7f0cbb851040 - Snapshot(process=posix.times_result(user=0.009999999999999787, system=0.0, children_user=0.0, children_system=0.0, elapsed=2.9600000008940697))]
  Source: SourceType.HOST/FetcherType.PIGGYBACK
[cpu_tracking] Start [7f0cbb851ee0]
[PiggybackFetcher] Fetch with cache settings: NoCache(mad-sis-vm-298, 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, simula
tion=False)
Not using cache (Cache usage disabled)
[PiggybackFetcher] Execute data source
No piggyback files for 'mad-sis-vm-298'. Skip processing.
No piggyback files for '172.19.1.10'. Skip processing.
Not using cache (Cache usage disabled)
[cpu_tracking] Stop [7f0cbb851ee0 - 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.TCP
<<<check_mk>>> / Transition NOOPParser -> HostSectionParser
<<<cmk_agent_ctl_status:sep(0)>>> / Transition HostSectionParser -> HostSectionParser
<<<checkmk_agent_plugins_lnx:sep(0)>>> / Transition HostSectionParser -> HostSectionParser
<<<labels:sep(0)>>> / Transition HostSectionParser -> HostSectionParser
<<<df>>> / Transition HostSectionParser -> HostSectionParser
<<<df>>> / Transition HostSectionParser -> HostSectionParser
<<<systemd_units>>> / Transition HostSectionParser -> HostSectionParser
<<<nfsmounts>>> / Transition HostSectionParser -> HostSectionParser
<<<cifsmounts>>> / Transition HostSectionParser -> HostSectionParser
<<<mounts>>> / Transition HostSectionParser -> HostSectionParser
<<<ps_lnx>>> / Transition HostSectionParser -> HostSectionParser
<<<mem>>> / Transition HostSectionParser -> HostSectionParser
<<<cpu>>> / Transition HostSectionParser -> HostSectionParser
<<<uptime>>> / Transition HostSectionParser -> HostSectionParser
[PiggybackFetcher] Fetch with cache settings: NoCache(mad-sis-vm-298, 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, simula
tion=False)
Not using cache (Cache usage disabled)
[PiggybackFetcher] Execute data source
No piggyback files for 'mad-sis-vm-298'. Skip processing.
No piggyback files for '172.19.1.10'. Skip processing.
Not using cache (Cache usage disabled)
[cpu_tracking] Stop [7f0cbb851ee0 - 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.TCP
<<<check_mk>>> / Transition NOOPParser -> HostSectionParser
<<<cmk_agent_ctl_status:sep(0)>>> / Transition HostSectionParser -> HostSectionParser
<<<checkmk_agent_plugins_lnx:sep(0)>>> / Transition HostSectionParser -> HostSectionParser
<<<labels:sep(0)>>> / Transition HostSectionParser -> HostSectionParser
<<<df>>> / Transition HostSectionParser -> HostSectionParser
<<<df>>> / Transition HostSectionParser -> HostSectionParser
<<<systemd_units>>> / Transition HostSectionParser -> HostSectionParser
<<<nfsmounts>>> / Transition HostSectionParser -> HostSectionParser
<<<cifsmounts>>> / Transition HostSectionParser -> HostSectionParser
<<<mounts>>> / Transition HostSectionParser -> HostSectionParser
<<<ps_lnx>>> / Transition HostSectionParser -> HostSectionParser
<<<mem>>> / Transition HostSectionParser -> HostSectionParser
<<<cpu>>> / Transition HostSectionParser -> HostSectionParser
<<<uptime>>> / Transition HostSectionParser -> HostSectionParser
<<<lnx_if>>> / Transition HostSectionParser -> HostSectionParser
<<<lnx_if:sep(58)>>> / Transition HostSectionParser -> HostSectionParser
<<<tcp_conn_stats>>> / Transition HostSectionParser -> HostSectionParser
<<<diskstat>>> / Transition HostSectionParser -> HostSectionParser
<<<kernel>>> / Transition HostSectionParser -> HostSectionParser
<<<md>>> / Transition HostSectionParser -> HostSectionParser
<<<vbox_guest>>> / Transition HostSectionParser -> HostSectionParser
<<<job>>> / Transition HostSectionParser -> HostSectionParser
<<<timesyncd>>> / Transition HostSectionParser -> HostSectionParser
<<<local:sep(0)>>> / Transition HostSectionParser -> HostSectionParser
No persisted sections
  -> Add sections: ['check_mk', 'checkmk_agent_plugins_lnx', 'cifsmounts', 'cmk_agent_ctl_status', 'cpu', 'df', 'diskstat', 'job', 'kernel', 'labels', 'lnx_if', 'local', 'md', 'mem', 'mounts', 'nfsmounts', 'ps_lnx', 'systemd_units', 'tc
p_conn_stats', 'timesyncd', 'uptime', 'vbox_guest']
  Source: SourceType.HOST/FetcherType.PIGGYBACK
No persisted sections
  -> Add sections: []
Received no piggyback data
Received no piggyback data
[cpu_tracking] Start [7f0cbb7bec10]
value store: synchronizing
Trying to acquire lock on /omd/sites/cmk/tmp/check_mk/counters/mad-sis-vm-298
Got lock on /omd/sites/cmk/tmp/check_mk/counters/mad-sis-vm-298
value store: loading from disk
Releasing lock on /omd/sites/cmk/tmp/check_mk/counters/mad-sis-vm-298
Released lock on /omd/sites/cmk/tmp/check_mk/counters/mad-sis-vm-298
No piggyback files for 'mad-sis-vm-298'. Skip processing.
No piggyback files for '172.19.1.10'. Skip processing.
[cpu_tracking] Stop [7f0cbb7bec10 - Snapshot(process=posix.times_result(user=0.009999999999999787, system=0.0, children_user=0.0, children_system=0.0, elapsed=0.0))]
[agent] Success, execution time 3.0 sec | execution_time=2.960 user_time=0.020 system_time=0.000 children_user_time=0.000 children_system_time=0.000 cmk_time_agent=2.950

Thanks a lot in advance!

Nevermind, I’ve solved it.
Docker pip module latest version (6.0.0) is the culprit, downgraded to 5.0.3 and everything is fine.

2 Likes

Worked like a charm :slight_smile:

here is my command for copy-paste:

 pip3 install --upgrade docker==5

Since --upgrade can also be used for downgrading

2 Likes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed. Contact an admin if you think this should be re-opened.