]> Frank Brehm's Git Trees - pixelpark/puppetmaster-webhooks.git/commitdiff
Adding flag to not discover last activity on modules
authorFrank Brehm <frank.brehm@pixelpark.com>
Wed, 25 Aug 2021 11:48:03 +0000 (13:48 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Wed, 25 Aug 2021 11:48:03 +0000 (13:48 +0200)
lib/webhooks/get_module_changes.py

index e9abb19c5e38223ff26c60bbfee979076963b3c5..b4d29395345b4431597617989d59875f38950ebc 100644 (file)
@@ -86,6 +86,7 @@ class GetModuleChangesApp(BaseHookApp):
         self._warn_update_days = self.default_warn_update_days
         self._crit_update_days = self.default_crit_update_days
         self._nagios_mode = False
+        self._no_activity_check = False
 
         description = _(
             "Generates a list of all Puppets modules, which are newer "
@@ -180,6 +181,16 @@ class GetModuleChangesApp(BaseHookApp):
     def nagios_mode(self, value):
         self._nagios_mode = to_bool(value)
 
+    # -----------------------------------------------------------
+    @property
+    def no_activity_check(self):
+        """Flag, that the last activities of modules should not be checked."""
+        return getattr(self, '_no_activity_check', False)
+
+    @no_activity_check.setter
+    def no_activity_check(self, value):
+        self._no_activity_check = to_bool(value)
+
     # -------------------------------------------------------------------------
     def as_dict(self, short=True):
         """
@@ -197,6 +208,7 @@ class GetModuleChangesApp(BaseHookApp):
         res['default_env'] = self.default_env
         res['environment'] = self.environment
         res['nagios_mode'] = self.nagios_mode
+        res['no_activity_check'] = self.no_activity_check
         res['warn_update_days'] = self.warn_update_days
 
         return res
@@ -232,6 +244,20 @@ class GetModuleChangesApp(BaseHookApp):
             help=_("Work in Nagios mode instead of sending mails.")
         )
 
+        activity_group = self.arg_parser.add_mutually_exclusive_group()
+
+        activity_group.add_argument(
+            '-a', '--no-activity-check', dest='no_activity_check', action="store_true",
+            help=_("Don't perform a check about last activity in each module "
+                "(mutually exclusive with {m}).").format(m='--activity-check')
+        )
+
+        activity_group.add_argument(
+            '-A', '--activity-check', dest='no_activity_check', action="store_false",
+            help=_("Perform a check about last activity in each module (the default, "
+                "mutually exclusive with {m}).").format(m='--no-activity-check')
+        )
+
     # -------------------------------------------------------------------------
     def perform_arg_parser(self):
 
@@ -246,6 +272,11 @@ class GetModuleChangesApp(BaseHookApp):
         if self.args.nagios:
             self.nagios_mode = True
 
+        if self.args.no_activity_check:
+            self.no_activity_check = True
+        else:
+            self.no_activity_check = False
+
         LOG.debug("Warning level: {w} days, critical level: {c} days.".format(
             w=self.warn_update_days, c=self.crit_update_days))
 
@@ -288,8 +319,9 @@ class GetModuleChangesApp(BaseHookApp):
         depr_infos = self.check_deprecations(module_infos)
         self.generate_deprecation_msgs(depr_infos)
 
-        update_infos = self.check_updates(module_infos)
-        self.generate_update_msgs(update_infos)
+        if not self.no_activity_check:
+            update_infos = self.check_updates(module_infos)
+            self.generate_update_msgs(update_infos)
 
         self.error_data.append("\n" + _("Checked at: {}").format(self.check_date_str))