Skip to content

Commit

Permalink
robotmk: Add plugin for Robotmk Scheduler Status
Browse files Browse the repository at this point in the history
*Discover Robotmk Scheduler Status service if the configuration is
available in the agent output

CMK-14987

Change-Id: I70784151f4e297e239efde2254fc1282c91c1743
  • Loading branch information
racicLuka committed Nov 2, 2023
1 parent 399f01d commit 353cfb4
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 13 deletions.
10 changes: 10 additions & 0 deletions checkman/robotmk_scheduler_status
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
title: Robotmk Scheduler Status
agents: robotmk
catalog: robotframework
license: GPLv2
distribution: check_mk
description:
Provides information about the scheduler status.

discovery:
One service called "Robotmk Scheduler Status" is created.
14 changes: 1 addition & 13 deletions cmk/base/plugins/agent_based/robotmk.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class Params(TypedDict):

DEFAULT: Params = {"test_runtime": None}


LivestatusFile = Literal["suite_last_log.html", "suite_last_error_log.html"]


Expand Down Expand Up @@ -120,9 +119,6 @@ def discover(section: robotmk_api.Section) -> DiscoveryResult:
ServiceLabel("robotmk/html_last_log", "yes"),
],
)
if isinstance(result, robotmk_api.ConfigFileContent):
for suite in result.config_file_content.suites:
yield Service(item=suite)

if isinstance(result, robotmk_api.SuiteExecutionReport):
yield Service(item=f"Suite {result.suite_name}")
Expand Down Expand Up @@ -160,12 +156,6 @@ def _check_suite_execution_result(
yield _attempt_result(attempt)


def _check_config_file_content(result: robotmk_api.ConfigFileContent, item: str) -> CheckResult:
for suite in result.config_file_content.suites:
if suite == item:
yield Result(state=State.OK, summary="This Suite was discovered!")


def _check_result(params: Params, result: robotmk_api.Result, item: str) -> CheckResult:
for test in result.tests:
if _item(result, test) == item:
Expand All @@ -178,9 +168,7 @@ def _check_result(params: Params, result: robotmk_api.Result, item: str) -> Chec

def check(item: str, params: Params, section: robotmk_api.Section) -> CheckResult:
for result in section:
if isinstance(result, robotmk_api.ConfigFileContent):
yield from _check_config_file_content(result, item)
elif isinstance(result, robotmk_api.Result):
if isinstance(result, robotmk_api.Result):
yield from _check_result(params, result, item)
elif isinstance(result, robotmk_api.SuiteExecutionReport):
yield from _check_suite_execution_result(result, item)
Expand Down
31 changes: 31 additions & 0 deletions cmk/base/plugins/agent_based/robotmk_scheduler_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env python3
# Copyright (C) 2023 Checkmk GmbH - License: GNU General Public License v2
# 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.


from cmk.base.plugins.agent_based.agent_based_api.v1 import register, Result, Service, State
from cmk.base.plugins.agent_based.agent_based_api.v1.type_defs import CheckResult, DiscoveryResult
from cmk.base.plugins.agent_based.utils import robotmk_api # Should be replaced by external package


def discover_scheduler_status(section: robotmk_api.ConfigFileContent | None) -> DiscoveryResult:
if section:
yield Service(item="Robotmk Scheduler Status")


def check_scheduler_status(item: str, section: robotmk_api.ConfigFileContent | None) -> CheckResult:
if not section:
return

# TODO: Determine the conditions for the status
yield Result(state=State.OK, summary="The Scheduler status is OK")


register.check_plugin(
name="robotmk_scheduler_status",
sections=["robotmk_v2"],
service_name="%s",
discovery_function=discover_scheduler_status,
check_function=check_scheduler_status,
)

0 comments on commit 353cfb4

Please sign in to comment.