At the moment we are facing issues with a certain GitLab CI Runner (hifis-runner-manager-1) that execute your GitLab CI pipelines. We are working on it to bring them back to service again. Please excuse the inconveniences.

Commit 59e5ab99 authored by Hueser, Christian (FWCC) - 138593's avatar Hueser, Christian (FWCC) - 138593
Browse files

Merge branch...

Merge branch '1-exception-exception-localhost-8060-a-bytes-like-object-is-required-not-str' into 'main'

Fix exception when running the nginx agent plugin with Python 3.8

Closes #1

See merge request !6
parents eba0f54d 4a17d3cd
Pipeline #75551 canceled with stages
in 3 minutes and 45 seconds
......@@ -16,6 +16,16 @@ Group your changes into these categories:
`Added`, `Changed`, `Deprecated`, `Removed`, `Fixed`, `Security`.
## [0.2.1](https://gitlab.hzdr.de/hifis-software-deployment/checkmk-role/-/releases/v0.2.1) - 2021-06-03
[List of commits](https://gitlab.hzdr.de/hifis-software-deployment/checkmk-role/-/compare/v0.2.0...v0.2.1)
## Fixed
* Fix exception when running the nginx agent plugin with Python 3.8
([!6](https://gitlab.com/hifis/ansible/keepalived-role/-/merge_requests/6)
by [tobiashuste](https://gitlab.hzdr.de/frust45)).
## [0.2.0](https://gitlab.hzdr.de/hifis-software-deployment/checkmk-role/-/releases/v0.2.0) - 2021-06-03
[List of commits](https://gitlab.hzdr.de/hifis-software-deployment/checkmk-role/-/compare/v0.1.0...v0.2.0)
......
......@@ -8,7 +8,7 @@
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
# conditions defined in the file COPYING, which is part of this source code package.
__version__ = "2.0.0"
__version__ = "2.1.0i1"
# Checkmk-Agent-Plugin - Nginx Server Status
#
......@@ -42,6 +42,38 @@ else:
import urllib
urllib.getproxies = lambda: {} # type: ignore[attr-defined]
PY2 = sys.version_info[0] == 2
PY3 = sys.version_info[0] == 3
if PY3:
text_type = str
binary_type = bytes
else:
text_type = unicode # pylint: disable=undefined-variable
binary_type = str
# Borrowed from six
def ensure_str(s, encoding='utf-8', errors='strict'):
"""Coerce *s* to `str`.
For Python 2:
- `unicode` -> encoded to `str`
- `str` -> `str`
For Python 3:
- `str` -> `str`
- `bytes` -> decoded to `str`
"""
if not isinstance(s, (text_type, binary_type)):
raise TypeError("not expecting type '%s'" % type(s))
if PY2 and isinstance(s, text_type):
s = s.encode(encoding, errors)
elif PY3 and isinstance(s, binary_type):
s = s.decode(encoding, errors)
return s
config_dir = os.getenv("MK_CONFDIR", "/etc/check_mk")
config_file = config_dir + "/nginx_status.cfg"
......@@ -136,7 +168,7 @@ for server in servers:
else:
raise
for line in fd.read().split('\n'):
for line in ensure_str(fd.read()).split('\n'):
if not line.strip():
continue
if line.lstrip()[0] == '<':
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment