From: Frank Brehm Date: Mon, 27 Aug 2018 12:13:02 +0000 (+0200) Subject: Adding new commandline and configuration parameter no_error_mail/--no-error-mail X-Git-Tag: 0.10.7^2~3 X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=8abb063947708dfcabcf29f80d344b77c5cd59c4;p=pixelpark%2Fpuppetmaster-webhooks.git Adding new commandline and configuration parameter no_error_mail/--no-error-mail --- diff --git a/.gitignore b/.gitignore index f1a345f..6359c79 100644 --- a/.gitignore +++ b/.gitignore @@ -20,5 +20,7 @@ DEADJOE test*.json +*.local.yaml + tmp/* diff --git a/hooks.yaml b/hooks.yaml index 7847902..1d9e73b 100644 --- a/hooks.yaml +++ b/hooks.yaml @@ -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 ' -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 ' +#data_dir: '/var/lib/webhooks' diff --git a/lib/webhooks/__init__.py b/lib/webhooks/__init__.py index 2aac0a9..c64d470 100644 --- a/lib/webhooks/__init__.py +++ b/lib/webhooks/__init__.py @@ -1,6 +1,6 @@ #!/bin/env python3 # -*- coding: utf-8 -*- -__version__ = '0.10.3' +__version__ = '0.10.4' # vim: ts=4 et list diff --git a/lib/webhooks/base_app.py b/lib/webhooks/base_app.py index e0f6cef..45aab26 100644 --- a/lib/webhooks/base_app.py +++ b/lib/webhooks/base_app.py @@ -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')) # ./.yaml yaml_files.append(os.path.join(self.base_dir, self.appname + '.yaml')) + # ./.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/.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 diff --git a/lib/webhooks/show_modules.py b/lib/webhooks/show_modules.py index 483cb58..8b360ab 100644 --- a/lib/webhooks/show_modules.py +++ b/lib/webhooks/show_modules.py @@ -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):