Update graylog-metrics so it'll work in CheckMK 2.3.

This commit is contained in:
Marsell Kukuljevic 2025-11-04 10:39:42 +01:00
parent 7fb9a07709
commit 6323fabd31
3 changed files with 16 additions and 36 deletions

View File

@ -17,24 +17,11 @@ urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
cmk.utils.password_store.replace_passwords() cmk.utils.password_store.replace_passwords()
class GraylogSection(NamedTuple):
name: str
uri: str
def main(argv=None): def main(argv=None):
if argv is None: if argv is None:
argv = sys.argv[1:] argv = sys.argv[1:]
args = parse_arguments(argv) args = parse_arguments(argv)
try:
handle_request(args) handle_request(args)
except Exception:
if args.debug:
return 1
return 0
def handle_request(args): # pylint: disable=too-many-branches def handle_request(args): # pylint: disable=too-many-branches
@ -106,8 +93,6 @@ def handle_response(url, args):
return requests.get(url, auth=(args.user, args.password), verify=not args.no_cert_check) return requests.get(url, auth=(args.user, args.password), verify=not args.no_cert_check)
except requests.exceptions.RequestException as e: except requests.exceptions.RequestException as e:
sys.stderr.write("Error: %s\n" % e) sys.stderr.write("Error: %s\n" % e)
if args.debug:
raise
def handle_output(value): def handle_output(value):
@ -136,9 +121,6 @@ def parse_arguments(argv):
parser.add_argument( parser.add_argument(
"-p", "--port", default=443, type=int, help="Use alternative port (default: 443)" "-p", "--port", default=443, type=int, help="Use alternative port (default: 443)"
) )
parser.add_argument(
"--debug", action="store_true", help="Debug mode: let Python exceptions come through"
)
parser.add_argument( parser.add_argument(
"--no-cert-check", action="store_true", help="Disable SSL certificate validation" "--no-cert-check", action="store_true", help="Disable SSL certificate validation"
) )

View File

@ -10,12 +10,7 @@
# 'password': 'yeah', # 'password': 'yeah',
# } # }
from typing import Any, Mapping, Optional, Sequence, Union def agent_graylog_input_metrics_arguments(params, hostname, ipaddress):
def agent_graylog_input_metrics_arguments(
params: Mapping[str, Any], hostname: str, ipaddress: Optional[str]
) -> Sequence[Union[str, tuple[str, str, str]]]:
args = [ args = [
"-P", "-P",
params["protocol"], params["protocol"],

View File

@ -7,6 +7,9 @@
# resolving legacy discovery results such as [("SUMMARY", "diskstat_default_levels")]. Furthermore, # resolving legacy discovery results such as [("SUMMARY", "diskstat_default_levels")]. Furthermore,
# it might also remove variables needed for accessing discovery rulesets. # it might also remove variables needed for accessing discovery rulesets.
import json import json
from cmk.base.check_api import check_levels, LegacyCheckDefinition
from cmk.base.config import check_info
from cmk.agent_based.v2 import Service
#<<<graylog_input_metrics:sep(0)>>> #<<<graylog_input_metrics:sep(0)>>>
# {"641e88d05d447a677efde199": {"input_state": "FAILED", "input_name": "kafka_cef_test", # {"641e88d05d447a677efde199": {"input_state": "FAILED", "input_name": "kafka_cef_test",
@ -29,7 +32,7 @@ def parse_graylog_input_metrics(section):
def inventory_graylog_input_metrics(parsed): def inventory_graylog_input_metrics(parsed):
for input_id, input_info in parsed.items(): for input_id, input_info in parsed.items():
input_name = input_info["input_name"] input_name = input_info["input_name"]
yield Service(f"{input_name} ({input_id})") yield Service(item=f"{input_name} ({input_id})")
def check_graylog_input_metrics(item, params, parsed): def check_graylog_input_metrics(item, params, parsed):
@ -71,11 +74,11 @@ def check_graylog_input_metrics(item, params, parsed):
infoname=infotext infoname=infotext
) )
check_info["graylog_input_metrics"] = { check_info["graylog_input_metrics"] = LegacyCheckDefinition(
"parse_function": parse_graylog_input_metrics, parse_function = parse_graylog_input_metrics,
"check_function": check_graylog_input_metrics, check_function = check_graylog_input_metrics,
"inventory_function": inventory_graylog_input_metrics, discovery_function = inventory_graylog_input_metrics,
"service_description": "Graylog Input %s", service_name = "Graylog Input %s",
"has_perfdata": True, check_ruleset_name = "graylog_input_metrics",
"group": "graylog_input_metrics", check_default_parameters={},
} )