From 76fa61b32830f0bdcf612f91db4cf4e902d17401 Mon Sep 17 00:00:00 2001
From: Marius Rieder <marius.rieder@scs.ch>
Date: Fri, 7 Jun 2024 11:29:45 +0000
Subject: [PATCH] Fix some bugs

---
 agent_based/veeam_o365jobs.py    |  2 +-
 package                          |  2 +-
 rulesets/check_parameters.py     | 17 +++++++++++++++--
 rulesets/discovery_parameters.py | 26 ++++++++++++++------------
 4 files changed, 31 insertions(+), 16 deletions(-)

diff --git a/agent_based/veeam_o365jobs.py b/agent_based/veeam_o365jobs.py
index df808eb..89cdba2 100644
--- a/agent_based/veeam_o365jobs.py
+++ b/agent_based/veeam_o365jobs.py
@@ -158,7 +158,7 @@ def check_veeam_o365jobs(item, params, section):
     discovery_ruleset_name='veeam_o365jobs',
     discovery_ruleset_type=RuleSetType.MERGED,
     discovery_default_parameters={},
-    check_function=discovery_veeam_o365jobs,
+    check_function=check_veeam_o365jobs,
     check_ruleset_name='veeam_o365jobs',
     check_default_parameters=VEEAM_O365JOBS_CHECK_DEFAULT_PARAMETERS,
 )
diff --git a/package b/package
index c58612e..5ef9c34 100644
--- a/package
+++ b/package
@@ -20,7 +20,7 @@
     },
     'name': 'veeam_o365',
     'title': u'Veeam for Office 365 Checks',
-    'version': '2.7.0-0',
+    'version': '2.7.0-1',
     'version.min_required': '2.3.0p3',
     'version.packaged': '2.3.0',
     'version.usable_until': '2.4.0'
diff --git a/rulesets/check_parameters.py b/rulesets/check_parameters.py
index 5ea5542..946ae59 100644
--- a/rulesets/check_parameters.py
+++ b/rulesets/check_parameters.py
@@ -70,7 +70,7 @@ def _parameter_form_veeam_o365jobs():
             'states': DictElement(
                 parameter_form=Dictionary(
                     title=Title('State mapping'),
-                    help=Help('Remap the job stat to different monitoring states.'),
+                    help_text=Help('Remap the job stat to different monitoring states.'),
                     elements={
                         'Success': DictElement(
                             parameter_form=ServiceState(
@@ -103,7 +103,20 @@ def _parameter_form_veeam_o365jobs():
                     }
                 ),
                 required=False,
-            )
+            ),
+            'success_maxage': DictElement(
+                parameter_form=SimpleLevels(
+                    title=Title('Maximal time since last successfull run'),
+                    help_text=Help('Thresholds for last successfull run.'),
+                    level_direction=LevelDirection.UPPER,
+                    form_spec_template=TimeSpan(
+                        displayed_magnitudes=[TimeMagnitude.DAY, TimeMagnitude.HOUR, TimeMagnitude.MINUTE]
+                    ),
+                    migrate=migrate_to_float_simple_levels,
+                    prefill_fixed_levels=InputHint(value=(86400, 172800)),
+                ),
+                required=False,
+            ),
         }
     )
 
diff --git a/rulesets/discovery_parameters.py b/rulesets/discovery_parameters.py
index 90fed89..db45510 100644
--- a/rulesets/discovery_parameters.py
+++ b/rulesets/discovery_parameters.py
@@ -20,26 +20,29 @@
 from cmk.rulesets.v1 import Help, Title
 from cmk.rulesets.v1.form_specs import (
     DefaultValue,
+    DictElement,
     Dictionary,
     SingleChoice,
     SingleChoiceElement,
 )
-from cmk.rulesets.v1.rule_specs import DiscoveryParameters, Topic, HostCondition
+from cmk.rulesets.v1.rule_specs import DiscoveryParameters, Topic
 
 
 def _parameter_form_veeam_o365jobs_discovery():
     return Dictionary(
         elements={
-            'item_appearance': SingleChoice(
-                title=Title('Appearance of job'),
-                help_text=Help('This option lets Check_MK use either only the job name, '
-                               'prepend it with the shortend org oder the full org.'),
-                elements=[
-                    SingleChoiceElement(name='name', title=Title('Use only the job name')),
-                    SingleChoiceElement(name='short', title=Title('Use the shortend org and the name')),
-                    SingleChoiceElement(name='full', title=Title('Use the full org and the name')),
-                ],
-                prefill=DefaultValue('name'),
+            'item_appearance': DictElement(
+                parameter_form=SingleChoice(
+                    title=Title('Appearance of job'),
+                    help_text=Help('This option lets Check_MK use either only the job name, '
+                                   'prepend it with the shortend org oder the full org.'),
+                    elements=[
+                        SingleChoiceElement(name='name', title=Title('Use only the job name')),
+                        SingleChoiceElement(name='short', title=Title('Use the shortend org and the name')),
+                        SingleChoiceElement(name='full', title=Title('Use the full org and the name')),
+                    ],
+                    prefill=DefaultValue('name'),
+                )
             )
         },
     )
@@ -53,5 +56,4 @@ def _parameter_form_veeam_o365jobs_discovery():
     help_text=Help('This rule can be used to control the inventory for Veeam for '
                    'Office 365 Jobs. You can configure the service name to include'
                    'the Organisation.'),
-    condition=HostCondition(),
 )