]> Frank Brehm's Git Trees - pixelpark/puppetmaster-webhooks.git/commitdiff
Adding new commandline and configuration parameter no_error_mail/--no-error-mail
authorFrank Brehm <frank.brehm@pixelpark.com>
Mon, 27 Aug 2018 12:13:02 +0000 (14:13 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Mon, 27 Aug 2018 12:13:02 +0000 (14:13 +0200)
.gitignore
hooks.yaml
lib/webhooks/__init__.py
lib/webhooks/base_app.py
lib/webhooks/show_modules.py

index f1a345f2aba6b455b381f4d009b207495af5b5dc..6359c79e79a0157213c1f7c29db48d54707ef1ad 100644 (file)
@@ -20,5 +20,7 @@ DEADJOE
 
 test*.json
 
+*.local.yaml
+
 tmp/*
 
index 784790265bf6a7a780c2e1034e38c45d5f2f00de..1d9e73b561653091e54d88e6b679456e8d1d191f 100644 (file)
@@ -1,11 +1,12 @@
 ---
-verbose: 0
-do_sudo: true
-log_dir: '/var/log/webhooks'
-default_email: 'puppet@pixelpark.com'
-default_parent_dir: '/etc/puppetlabs/code'
-smtp_server: 'localhost'
-smtp_port: 25
-mail_cc_addresses: []
-sender_address: 'Puppetmaster <puppetmaster@pixelpark.com>'
-data_dir: '/var/lib/webhooks'
+#verbose: 0
+#no_error_mail: true
+#do_sudo: true
+#log_dir: '/var/log/webhooks'
+#default_email: 'puppet@pixelpark.com'
+#default_parent_dir: '/etc/puppetlabs/code'
+#smtp_server: 'localhost'
+#smtp_port: 25
+#mail_cc_addresses: []
+#sender_address: 'Puppetmaster <puppetmaster@pixelpark.com>'
+#data_dir: '/var/lib/webhooks'
index 2aac0a99f51f64d456f41d9119ab64df0588f302..c64d4701e1a2a5f7f789225a5d32c937ad962eb2 100644 (file)
@@ -1,6 +1,6 @@
 #!/bin/env python3
 # -*- coding: utf-8 -*-
 
-__version__ = '0.10.3'
+__version__ = '0.10.4'
 
 # vim: ts=4 et list
index e0f6cef5284a0afccd15fe60288a7cb96701dbd4..45aab26f6fdf204736ac8c49f95967500505f3f6 100644 (file)
@@ -94,6 +94,7 @@ class BaseHookApp(BaseObject):
         self._read_stdin = True
         self.tz_name = self.default_tz_name
         self._html_title = None
+        self._no_error_mail = False
 
         if not hasattr(self, '_output_type'):
             self._output_type = self.default_output_type
@@ -174,6 +175,16 @@ class BaseHookApp(BaseObject):
     def simulate(self, value):
         self._simulate = to_bool(value)
 
+    # -----------------------------------------------------------
+    @property
+    def no_error_mail(self):
+        """Flag to not send any error mails in case of exceptions."""
+        return getattr(self, '_no_error_mail', False)
+
+    @no_error_mail.setter
+    def no_error_mail(self, value):
+        self._no_error_mail = to_bool(value)
+
     # -----------------------------------------------------------
     @property
     def read_stdin(self):
@@ -270,6 +281,7 @@ class BaseHookApp(BaseObject):
         res['output_type'] = self.output_type
         res['mime_type'] = self.mime_type
         res['html_title'] = self.html_title
+        res['no_error_mail'] = self.no_error_mail
 
         return res
 
@@ -281,6 +293,11 @@ class BaseHookApp(BaseObject):
             add_help=False,
         )
 
+        arg_parser.add_argument(
+            "-N", "--no-error-mail", action='store_true', dest='no_error_mail',
+            help="Don't send error messages in case of some exceptions.",
+        )
+
         arg_parser.add_argument(
             "-D", '--data', '--data-dir', metavar='DIR', dest='data_dir',
             help="Data directory, default: {!r}.".format(self.data_dir),
@@ -388,8 +405,12 @@ class BaseHookApp(BaseObject):
         yaml_files = []
         # ./hooks.yaml
         yaml_files.append(os.path.join(self.base_dir, 'hooks.yaml'))
+        # ./hooks.local.yaml
+        yaml_files.append(os.path.join(self.base_dir, 'hooks.local.yaml'))
         # ./<appname>.yaml
         yaml_files.append(os.path.join(self.base_dir, self.appname + '.yaml'))
+        # ./<appname>.local.yaml
+        yaml_files.append(os.path.join(self.base_dir, self.appname + '.local.yaml'))
         # /etc/pixelpark/hooks.yaml
         yaml_files.append(os.sep + os.path.join('etc', 'pixelpark', 'hooks.yaml'))
         # /etc/pixelpark/<appname>.yaml
@@ -436,6 +457,9 @@ class BaseHookApp(BaseObject):
         if 'simulate' in config and not self.simulate:
             self.simulate = config['simulate']
 
+        if 'no_error_mail' in config and not self.no_error_mail:
+            self.no_error_mail = to_bool(config['no_error_mail'])
+
         if 'do_sudo' in config:
             self.do_sudo = to_bool(config['do_sudo'])
 
@@ -767,6 +791,10 @@ class BaseHookApp(BaseObject):
                 r=to_addresses, e=pp(self.error_data),
                 s=self.smtp_server, p=self.smtp_port))
 
+        if self.no_error_mail:
+            LOG.debug("It's undesired to send error mails.")
+            return
+
         if self.simulate:
             LOG.info("Simulation mode, don't sending mail.")
             return
index 483cb5801fafc9cb2b6239fef089b4565e8c1a3d..8b360ab05212df7d645fb4056a65c27c46d2282c 100644 (file)
@@ -101,6 +101,7 @@ class ShowModulesApp(BaseHookApp):
         self.read_stdin = False
         self.cache_file = os.path.join(self.data_dir, 'modules-info.yaml')
         self.init_filters()
+        self.no_error_mail = True
 
         self.initialized = True
 
@@ -143,9 +144,6 @@ class ShowModulesApp(BaseHookApp):
             LOG.error(str(e))
         else:
             self.output_modules(module_infos)
-#            if self.output_type == 'json':
-#                data = {'msg': self.html_title}
-#                self.print_out(json.dumps(data))
 
     # -------------------------------------------------------------------------
     def output_modules(self, module_infos):