Skip to content

Allow multiple EXPECTED_STATEs #45

@wolfgangkarall

Description

@wolfgangkarall

Use case: constantly restarting unit (the constant restarts are on purpose) that should be monitored and both 'active' and 'activating' are OK states.

Ugly hack that achieves this by allowing comma-separated states in opts.expected_states, but loses the choices= checking the states for correctness:

diff --git a/check_systemd.py b/check_systemd.py
--- a/check_systemd.py
+++ b/check_systemd.py
@@ -447,8 +447,11 @@ class Source:
 
             :return: A Nagios compatible exit code: 0, 1, 2, 3
             """
-            if opts.expected_state and opts.expected_state.lower() != self.active_state:
-                return Critical
+            if opts.expected_state:
+                opts.expected_state = opts.expected_state.split(",")
+                opts.expected_state = [item.lower() for item in opts.expected_state]
+                if self.active_state not in opts.expected_state:
+                    return Critical
             if self.load_state == "error" or self.active_state == "failed":
                 return Critical
             return Ok
@@ -1860,7 +1863,7 @@ def get_argparser() -> argparse.ArgumentParser:
         "--state",
         "--required",
         "--expected-state",
-        choices=get_args(ActiveState),
+        #choices=get_args(ActiveState),
         dest="expected_state",
         help="Specify the active state that the systemd unit must have "
         "(for example: active, inactive)",

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions