-
Notifications
You must be signed in to change notification settings - Fork 14
Open
Milestone
Description
The current Warn class should be Warning or WARNING to conform to the Nagios Development Guidelines on return codes. However, simply renaming the class would occlude the Python Warning exception class.
A better approach would be if the return code/state values were an enum.
import enum
class State(enum.IntEnum):
Ok = enum.auto()
Warning = enum.auto()
Critical = enum.auto()
Unknown = enum.auto()The nagiosplugin.states.worst() helper also becomes a lot simpler, if it's even necessary anymore.
def worst(states):
if not states:
return State.Ok
return sorted(states)[-1]Usage for this would fix the issue raised by #26, and would look something like this:
>>> from nagiosplugin.enums import State, worst
>>> State.Ok
<State.Ok: 1>
>>> State.Ok.value
1
>>> State.Ok.name
'Ok'
>>> State.Ok.name.lower()
'ok'
>>> State.Ok > State.Critical
False
>>> State.Critical > State.Ok
True
>>> worst([State.Critical, State.Ok, State.Unknown])
<State.Unknown: 4>Metadata
Metadata
Assignees
Labels
No labels