From 7cd81b802de061143e596823d86b9726b60a7ccb Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Sat, 12 Aug 2017 01:37:41 -0700 Subject: [PATCH] Fix wildcard imports, remove get_exception, add boilerplate Fixed for monitoring modules --- .../modules/monitoring/airbrake_deployment.py | 26 +++------- lib/ansible/modules/monitoring/bigpanda.py | 38 ++++++-------- .../modules/monitoring/boundary_meter.py | 25 ++-------- .../modules/monitoring/circonus_annotation.py | 28 ++++------- .../modules/monitoring/datadog_event.py | 32 +++++------- .../modules/monitoring/datadog_monitor.py | 49 +++++++------------ .../monitoring/honeybadger_deployment.py | 35 +++++-------- .../modules/monitoring/icinga2_feature.py | 29 +++-------- .../modules/monitoring/librato_annotation.py | 20 ++------ lib/ansible/modules/monitoring/logentries.py | 24 ++++----- .../modules/monitoring/logicmonitor.py | 19 ++----- .../modules/monitoring/logicmonitor_facts.py | 35 +++++-------- .../modules/monitoring/logstash_plugin.py | 26 +++------- lib/ansible/modules/monitoring/monit.py | 25 +++------- lib/ansible/modules/monitoring/nagios.py | 10 ++-- .../modules/monitoring/newrelic_deployment.py | 25 +++------- lib/ansible/modules/monitoring/pagerduty.py | 29 +++++------ .../modules/monitoring/pagerduty_alert.py | 28 ++++------- lib/ansible/modules/monitoring/pingdom.py | 25 +++------- .../modules/monitoring/rollbar_deployment.py | 28 ++++------- lib/ansible/modules/monitoring/sensu_check.py | 46 ++++++----------- .../modules/monitoring/sensu_client.py | 3 +- .../modules/monitoring/sensu_handler.py | 3 +- .../modules/monitoring/sensu_silence.py | 21 ++------ .../modules/monitoring/sensu_subscription.py | 40 ++++++--------- lib/ansible/modules/monitoring/stackdriver.py | 46 ++++++----------- .../monitoring/statusio_maintenance.py | 20 ++------ lib/ansible/modules/monitoring/uptimerobot.py | 38 +++++--------- .../modules/monitoring/zabbix_group.py | 22 +++------ lib/ansible/modules/monitoring/zabbix_host.py | 26 +++------- .../modules/monitoring/zabbix_hostmacro.py | 29 +++-------- .../modules/monitoring/zabbix_maintenance.py | 22 +++------ .../modules/monitoring/zabbix_screen.py | 29 ++++------- test/sanity/code-smell/boilerplate.sh | 2 - test/sanity/code-smell/no-get-exception.sh | 1 - test/sanity/code-smell/no-wildcard-import.sh | 1 - test/sanity/pep8/legacy-files.txt | 3 -- 37 files changed, 289 insertions(+), 619 deletions(-) diff --git a/lib/ansible/modules/monitoring/airbrake_deployment.py b/lib/ansible/modules/monitoring/airbrake_deployment.py index cca63fbc056..cb30ff260f8 100644 --- a/lib/ansible/modules/monitoring/airbrake_deployment.py +++ b/lib/ansible/modules/monitoring/airbrake_deployment.py @@ -2,21 +2,11 @@ # -*- coding: utf-8 -*- # Copyright 2013 Bruce Pennypacker -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -77,8 +67,11 @@ EXAMPLES = ''' revision: '4.2' ''' +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.urls import fetch_url from ansible.module_utils.six.moves.urllib.parse import urlencode + # =========================================== # Module execution. # @@ -129,9 +122,6 @@ def main(): else: module.fail_json(msg="HTTP result code: %d connecting to %s" % (info['status'], url)) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.urls import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/monitoring/bigpanda.py b/lib/ansible/modules/monitoring/bigpanda.py index da2c9e38c54..448edfd2c5a 100644 --- a/lib/ansible/modules/monitoring/bigpanda.py +++ b/lib/ansible/modules/monitoring/bigpanda.py @@ -1,20 +1,11 @@ #!/usr/bin/python # -*- coding: utf-8 -*- +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -117,7 +108,14 @@ EXAMPLES = ''' # =========================================== # Module execution. # +import json import socket +import traceback + +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils._text import to_native +from ansible.module_utils.urls import fetch_url + def main(): @@ -194,13 +192,9 @@ def main(): module.exit_json(changed=True, **deployment) else: module.fail_json(msg=json.dumps(info)) - except Exception: - e = get_exception() - module.fail_json(msg=str(e)) - -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.urls import * -from ansible.module_utils.pycompat24 import get_exception + except Exception as e: + module.fail_json(msg=to_native(e), exception=traceback.format_exc()) + + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/monitoring/boundary_meter.py b/lib/ansible/modules/monitoring/boundary_meter.py index b99d46ddd5a..ab4a6c95399 100644 --- a/lib/ansible/modules/monitoring/boundary_meter.py +++ b/lib/ansible/modules/monitoring/boundary_meter.py @@ -1,26 +1,11 @@ #!/usr/bin/python # -*- coding: utf-8 -*- +# (c) 2013, curtis +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -""" -Ansible module to add boundary meters. +from __future__ import absolute_import, division, print_function +__metaclass__ = type -(c) 2013, curtis - -This file is part of Ansible - -Ansible is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -Ansible is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Ansible. If not, see . -""" ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -162,7 +147,7 @@ def create_meter(module, name, apiid, apikey): for cert_type in types: try: # If we can't open the file it's not there, so we should download it - cert_file = open('%s/%s.pem' % (config_directory,cert_type)) + dummy = open('%s/%s.pem' % (config_directory,cert_type)) except IOError: # Now download the file... rc = download_request(module, name, apiid, apikey, cert_type) diff --git a/lib/ansible/modules/monitoring/circonus_annotation.py b/lib/ansible/modules/monitoring/circonus_annotation.py index 402ba05454e..fa745992eb7 100644 --- a/lib/ansible/modules/monitoring/circonus_annotation.py +++ b/lib/ansible/modules/monitoring/circonus_annotation.py @@ -2,21 +2,11 @@ # -*- coding: utf-8 -*- # # (c) 2014-2015, Epic Games, Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -90,11 +80,12 @@ EXAMPLES = ''' ''' import json import time +import traceback import requests from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.pycompat24 import get_exception +from ansible.module_utils._text import to_native def post_annotation(annotation, api_key): @@ -154,9 +145,8 @@ def main(): annotation = create_annotation(module) try: resp = post_annotation(annotation, module.params['api_key']) - except requests.exceptions.RequestException: - err_str = get_exception() - module.fail_json(msg='Request Failed', reason=err_str) + except requests.exceptions.RequestException as e: + module.fail_json(msg='Request Failed', reason=to_native(e), exception=traceback.format_exc()) module.exit_json(changed=True, annotation=resp.json()) diff --git a/lib/ansible/modules/monitoring/datadog_event.py b/lib/ansible/modules/monitoring/datadog_event.py index f49fc433806..71f75dbbef4 100644 --- a/lib/ansible/modules/monitoring/datadog_event.py +++ b/lib/ansible/modules/monitoring/datadog_event.py @@ -6,21 +6,11 @@ # # This module is proudly sponsored by iGeolise (www.igeolise.com) and # Tiny Lab Productions (www.tinylabproductions.com). -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -113,6 +103,9 @@ EXAMPLES = ''' tags: 'aa,bb,#host:{{ inventory_hostname }}' ''' +import platform +import traceback + # Import Datadog try: from datadog import initialize, api @@ -121,7 +114,7 @@ except: HAS_DATADOG = False from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.pycompat24 import get_exception +from ansible.module_utils._text import to_native def main(): @@ -176,12 +169,9 @@ def _post_event(module): module.fail_json(msg=msg) module.exit_json(changed=True, msg=msg) - except Exception: - e = get_exception() - module.fail_json(msg=str(e)) + except Exception as e: + module.fail_json(msg=to_native(e), exception=traceback.format_exc()) -from ansible.module_utils.basic import * -from ansible.module_utils.urls import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/monitoring/datadog_monitor.py b/lib/ansible/modules/monitoring/datadog_monitor.py index 9cd0b72ce3a..f8c32cca95c 100644 --- a/lib/ansible/modules/monitoring/datadog_monitor.py +++ b/lib/ansible/modules/monitoring/datadog_monitor.py @@ -2,22 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2015, Sebastian Kornehl -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . -# import module snippets +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -168,6 +157,7 @@ datadog_monitor: api_key: "9775a026f1ca7d1c6c5af9d94d9595a4" app_key: "87ce4a24b5553d2e482ea8a8500e71b8ad4554ff" ''' +import traceback # Import Datadog try: @@ -177,7 +167,7 @@ except: HAS_DATADOG = False from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.pycompat24 import get_exception +from ansible.module_utils._text import to_native def main(): @@ -267,9 +257,8 @@ def _post_monitor(module, options): module.fail_json(msg=str(msg['errors'])) else: module.exit_json(changed=True, msg=msg) - except Exception: - e = get_exception() - module.fail_json(msg=str(e)) + except Exception as e: + module.fail_json(msg=to_native(e), exception=traceback.format_exc()) def _equal_dicts(a, b, ignore_keys): @@ -293,9 +282,8 @@ def _update_monitor(module, monitor, options): module.exit_json(changed=False, msg=msg) else: module.exit_json(changed=True, msg=msg) - except Exception: - e = get_exception() - module.fail_json(msg=str(e)) + except Exception as e: + module.fail_json(msg=to_native(e), exception=traceback.format_exc()) def install_monitor(module): @@ -331,9 +319,8 @@ def delete_monitor(module): try: msg = api.Monitor.delete(monitor['id']) module.exit_json(changed=True, msg=msg) - except Exception: - e = get_exception() - module.fail_json(msg=str(e)) + except Exception as e: + module.fail_json(msg=to_native(e), exception=traceback.format_exc()) def mute_monitor(module): @@ -350,9 +337,8 @@ def mute_monitor(module): else: msg = api.Monitor.mute(id=monitor['id'], silenced=module.params['silenced']) module.exit_json(changed=True, msg=msg) - except Exception: - e = get_exception() - module.fail_json(msg=str(e)) + except Exception as e: + module.fail_json(msg=to_native(e), exception=traceback.format_exc()) def unmute_monitor(module): @@ -364,9 +350,8 @@ def unmute_monitor(module): try: msg = api.Monitor.unmute(monitor['id']) module.exit_json(changed=True, msg=msg) - except Exception: - e = get_exception() - module.fail_json(msg=str(e)) + except Exception as e: + module.fail_json(msg=to_native(e), exception=traceback.format_exc()) if __name__ == '__main__': diff --git a/lib/ansible/modules/monitoring/honeybadger_deployment.py b/lib/ansible/modules/monitoring/honeybadger_deployment.py index 607c7af9fca..74af99a5861 100644 --- a/lib/ansible/modules/monitoring/honeybadger_deployment.py +++ b/lib/ansible/modules/monitoring/honeybadger_deployment.py @@ -2,21 +2,10 @@ # -*- coding: utf-8 -*- # Copyright 2014 Benjamin Curtis -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -82,11 +71,13 @@ EXAMPLES = ''' RETURN = '''# ''' -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.pycompat24 import get_exception +import traceback + +from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.six.moves.urllib.parse import urlencode -from ansible.module_utils.urls import * +from ansible.module_utils._text import to_native +from ansible.module_utils.urls import fetch_url + # =========================================== # Module execution. @@ -132,14 +123,14 @@ def main(): try: data = urlencode(params) response, info = fetch_url(module, url, data=data) - except Exception: - e = get_exception() - module.fail_json(msg='Unable to notify Honeybadger: %s' % e) + except Exception as e: + module.fail_json(msg='Unable to notify Honeybadger: %s' % to_native(e), exception=traceback.format_exc()) else: if info['status'] == 201: module.exit_json(changed=True) else: module.fail_json(msg="HTTP result code: %d connecting to %s" % (info['status'], url)) + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/monitoring/icinga2_feature.py b/lib/ansible/modules/monitoring/icinga2_feature.py index ba1cea2c6c8..4926fa487e6 100644 --- a/lib/ansible/modules/monitoring/icinga2_feature.py +++ b/lib/ansible/modules/monitoring/icinga2_feature.py @@ -1,28 +1,14 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -""" +# (c) 2016, Loic Blot +# Sponsored by Infopro Digital. http://www.infopro-digital.com/ +# Sponsored by E.T.A.I. http://www.etai.fr/ +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -Ansible module to manage Icinga2 feature state -(c) 2016, Loic Blot +from __future__ import absolute_import, division, print_function +__metaclass__ = type -Sponsored by Infopro Digital. http://www.infopro-digital.com/ -Sponsored by E.T.A.I. http://www.etai.fr/ - -This file is part of Ansible - -Ansible is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -Ansible is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with Ansible. If not, see . -""" ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -62,9 +48,10 @@ RETURN = ''' # ''' -from ansible.module_utils.basic import AnsibleModule import re +from ansible.module_utils.basic import AnsibleModule + class Icinga2FeatureHelper: def __init__(self, module): diff --git a/lib/ansible/modules/monitoring/librato_annotation.py b/lib/ansible/modules/monitoring/librato_annotation.py index 98c88ff5983..bc24b02403b 100644 --- a/lib/ansible/modules/monitoring/librato_annotation.py +++ b/lib/ansible/modules/monitoring/librato_annotation.py @@ -2,22 +2,10 @@ # -*- coding: utf-8 -*- # # (C) Seth Edwards, 2014 -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . -# +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type ANSIBLE_METADATA = {'metadata_version': '1.0', diff --git a/lib/ansible/modules/monitoring/logentries.py b/lib/ansible/modules/monitoring/logentries.py index 20101460b12..15bdb0273b3 100644 --- a/lib/ansible/modules/monitoring/logentries.py +++ b/lib/ansible/modules/monitoring/logentries.py @@ -2,19 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2013, Ivan Vanderbyl -# -# This module is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This software is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this software. If not, see . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -65,6 +57,9 @@ EXAMPLES = ''' state: absent ''' +from ansible.module_utils.basic import AnsibleModule + + def query_log_status(module, le_path, path, state="present"): """ Returns whether a log is followed or not. """ @@ -75,6 +70,7 @@ def query_log_status(module, le_path, path, state="present"): return False + def follow_log(module, le_path, logs, name=None, logtype=None): """ Follows one or more logs if not already followed. """ @@ -154,8 +150,6 @@ def main(): elif p["state"] in ["absent", "unfollowed"]: unfollow_log(module, le_path, logs) -# import module snippets -from ansible.module_utils.basic import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/monitoring/logicmonitor.py b/lib/ansible/modules/monitoring/logicmonitor.py index c75182d6147..c3b97b231d4 100644 --- a/lib/ansible/modules/monitoring/logicmonitor.py +++ b/lib/ansible/modules/monitoring/logicmonitor.py @@ -2,20 +2,11 @@ # LogicMonitor Ansible module for managing Collectors, Hosts and Hostgroups # Copyright (C) 2015 LogicMonitor -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software Foundation, -# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + RETURN = ''' --- diff --git a/lib/ansible/modules/monitoring/logicmonitor_facts.py b/lib/ansible/modules/monitoring/logicmonitor_facts.py index 6e1eb4bb379..9f9e1237ba3 100644 --- a/lib/ansible/modules/monitoring/logicmonitor_facts.py +++ b/lib/ansible/modules/monitoring/logicmonitor_facts.py @@ -1,21 +1,11 @@ #!/usr/bin/python -# LogicMonitor Ansible module for managing Collectors, Hosts and Hostgroups # Copyright (C) 2015 LogicMonitor -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software Foundation, -# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -136,8 +126,6 @@ RETURN = ''' import socket import types -from ansible.module_utils.six.moves.urllib.parse import urlencode - HAS_LIB_JSON = True try: import json @@ -159,6 +147,11 @@ except ImportError: except SyntaxError: HAS_LIB_JSON = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.six.moves.urllib.parse import urlencode +from ansible.module_utils._text import to_native +from ansible.module_utils.urls import open_url + class LogicMonitor(object): @@ -208,11 +201,10 @@ class LogicMonitor(object): self.fail(msg="Error: " + resp["errmsg"]) else: return raw - except IOError: - ioe = get_exception() + except IOError as ioe: self.fail(msg="Error: Exception making RPC call to " + "https://" + self.company + "." + self.lm_url + - "/rpc/" + action + "\nException" + str(ioe)) + "/rpc/" + action + "\nException" + to_native(ioe)) def get_collectors(self): """Returns a JSON object containing a list of @@ -600,9 +592,6 @@ def main(): selector(module) -from ansible.module_utils.basic import * -from ansible.module_utils.urls import * -from ansible.module_utils.urls import open_url if __name__ == "__main__": main() diff --git a/lib/ansible/modules/monitoring/logstash_plugin.py b/lib/ansible/modules/monitoring/logstash_plugin.py index 748c875f667..ede1f68a447 100644 --- a/lib/ansible/modules/monitoring/logstash_plugin.py +++ b/lib/ansible/modules/monitoring/logstash_plugin.py @@ -1,24 +1,11 @@ #!/usr/bin/python # -*- coding: utf-8 -*- +# (c) 2017, Loic Blot +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -""" -Ansible module to manage elasticsearch plugins -(c) 2017, Loic Blot +from __future__ import absolute_import, division, print_function +__metaclass__ = type -This file is part of Ansible - -Ansible is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -Ansible is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with Ansible. If not, see . -""" ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -85,12 +72,14 @@ EXAMPLES = ''' name: logstash-filter-multiline ''' +from ansible.module_utils.basic import AnsibleModule + + PACKAGE_STATE_MAP = dict( present="install", absent="remove" ) -from ansible.module_utils.basic import AnsibleModule def is_plugin_present(module, plugin_bin, plugin_name): cmd_args = [plugin_bin, "list", plugin_name] @@ -179,5 +168,6 @@ def main(): module.exit_json(changed=changed, cmd=cmd, name=name, state=state, stdout=out, stderr=err) + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/monitoring/monit.py b/lib/ansible/modules/monitoring/monit.py index 4118d3ff0c3..4ca7f9f983e 100644 --- a/lib/ansible/modules/monitoring/monit.py +++ b/lib/ansible/modules/monitoring/monit.py @@ -2,22 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2013, Darryl Stoflet -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . -# +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -64,6 +53,8 @@ EXAMPLES = ''' import time +from ansible.module_utils.basic import AnsibleModule + def main(): arg_spec = dict( @@ -188,8 +179,6 @@ def main(): module.exit_json(changed=False, name=name, state=state) -# import module snippets -from ansible.module_utils.basic import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/monitoring/nagios.py b/lib/ansible/modules/monitoring/nagios.py index f63660d4aaa..ddfe3067873 100644 --- a/lib/ansible/modules/monitoring/nagios.py +++ b/lib/ansible/modules/monitoring/nagios.py @@ -7,12 +7,10 @@ # func-nagios - Schedule downtime and enables/disable notifications # Copyright 2011, Red Hat, Inc. # Tim Bielawa -# -# This software may be freely redistributed under the terms of the GNU -# general public license version 2 or any later version. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type ANSIBLE_METADATA = {'metadata_version': '1.0', diff --git a/lib/ansible/modules/monitoring/newrelic_deployment.py b/lib/ansible/modules/monitoring/newrelic_deployment.py index b67bea14c0f..b44215768ea 100644 --- a/lib/ansible/modules/monitoring/newrelic_deployment.py +++ b/lib/ansible/modules/monitoring/newrelic_deployment.py @@ -2,21 +2,11 @@ # -*- coding: utf-8 -*- # Copyright 2013 Matt Coddington -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -88,6 +78,8 @@ EXAMPLES = ''' revision: '1.0' ''' +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.urls import fetch_url from ansible.module_utils.six.moves.urllib.parse import urlencode # =========================================== @@ -145,9 +137,6 @@ def main(): else: module.fail_json(msg="unable to update newrelic: %s" % info['msg']) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.urls import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/monitoring/pagerduty.py b/lib/ansible/modules/monitoring/pagerduty.py index 8210eb9e915..84e75b6bcb9 100644 --- a/lib/ansible/modules/monitoring/pagerduty.py +++ b/lib/ansible/modules/monitoring/pagerduty.py @@ -1,20 +1,12 @@ #!/usr/bin/python # -*- coding: utf-8 -*- # -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -172,8 +164,12 @@ EXAMPLES=''' service: '{{ pd_window.result.maintenance_window.id }}' ''' -import datetime import base64 +import datetime +import json + +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.urls import fetch_url def auth_header(user, passwd, token): if token: @@ -308,9 +304,6 @@ def main(): module.exit_json(msg="success", result=out, changed=changed) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.urls import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/monitoring/pagerduty_alert.py b/lib/ansible/modules/monitoring/pagerduty_alert.py index 9a0db2fd4d3..8e2a8c40e02 100644 --- a/lib/ansible/modules/monitoring/pagerduty_alert.py +++ b/lib/ansible/modules/monitoring/pagerduty_alert.py @@ -1,20 +1,11 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -116,6 +107,10 @@ EXAMPLES = ''' incident_key: somekey desc: "some text for incident's log" ''' +import json + +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.urls import fetch_url def check(module, name, state, service_key, api_key, incident_key=None): @@ -215,9 +210,6 @@ def main(): module.exit_json(result=out, changed=changed) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.urls import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/monitoring/pingdom.py b/lib/ansible/modules/monitoring/pingdom.py index 28717616591..9de3c170aea 100644 --- a/lib/ansible/modules/monitoring/pingdom.py +++ b/lib/ansible/modules/monitoring/pingdom.py @@ -1,20 +1,12 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], 'supported_by': 'community'} @@ -96,6 +88,7 @@ try: except: HAS_PINGDOM = False +from ansible.module_utils.basic import AnsibleModule def pause(checkid, uid, passwd, key): @@ -154,8 +147,6 @@ def main(): module.exit_json(checkid=checkid, name=name, status=result) -# import module snippets -from ansible.module_utils.basic import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/monitoring/rollbar_deployment.py b/lib/ansible/modules/monitoring/rollbar_deployment.py index b45cfe18a5e..91b92823f9b 100644 --- a/lib/ansible/modules/monitoring/rollbar_deployment.py +++ b/lib/ansible/modules/monitoring/rollbar_deployment.py @@ -2,21 +2,11 @@ # -*- coding: utf-8 -*- # Copyright 2014, Max Riveiro, -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -81,10 +71,11 @@ EXAMPLES = ''' rollbar_user: admin comment: Test Deploy ''' +import traceback from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.pycompat24 import get_exception from ansible.module_utils.six.moves.urllib.parse import urlencode +from ansible.module_utils._text import to_native from ansible.module_utils.urls import fetch_url @@ -130,9 +121,8 @@ def main(): try: data = urlencode(params) response, info = fetch_url(module, url, data=data) - except Exception: - e = get_exception() - module.fail_json(msg='Unable to notify Rollbar: %s' % e) + except Exception as e: + module.fail_json(msg='Unable to notify Rollbar: %s' % to_native(e), exception=traceback.format_exc()) else: if info['status'] == 200: module.exit_json(changed=True) diff --git a/lib/ansible/modules/monitoring/sensu_check.py b/lib/ansible/modules/monitoring/sensu_check.py index e674a01d1e3..2c583bfd785 100644 --- a/lib/ansible/modules/monitoring/sensu_check.py +++ b/lib/ansible/modules/monitoring/sensu_check.py @@ -2,22 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2014, Anders Ingemann -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . -# +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -207,14 +196,11 @@ EXAMPLES = ''' state: absent ''' -try: - import json -except ImportError: - try: - import simplejson as json - except ImportError: - # Let snippet from module_utils/basic.py return a proper error in this case - pass +import json +import traceback + +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils._text import to_native def sensu_check(module, path, name, state='present', backup=False): @@ -226,15 +212,14 @@ def sensu_check(module, path, name, state='present', backup=False): try: stream = open(path, 'r') config = json.load(stream) - except IOError: - e = get_exception() + except IOError as e: if e.errno is 2: # File not found, non-fatal if state == 'absent': reasons.append('file did not exist and state is `absent\'') return changed, reasons config = {} else: - module.fail_json(msg=str(e)) + module.fail_json(msg=to_native(e), exception=traceback.format_exc()) except ValueError: msg = '{path} contains invalid JSON'.format(path=path) module.fail_json(msg=msg) @@ -349,9 +334,8 @@ def sensu_check(module, path, name, state='present', backup=False): try: stream = open(path, 'w') stream.write(json.dumps(config, indent=2) + '\n') - except IOError: - e = get_exception() - module.fail_json(msg=str(e)) + except IOError as e: + module.fail_json(msg=to_native(e), exception=traceback.format_exc()) finally: if stream: stream.close() @@ -404,8 +388,6 @@ def main(): module.exit_json(path=path, changed=changed, msg='OK', name=name, reasons=reasons) -from ansible.module_utils.basic import * -from ansible.module_utils.pycompat24 import get_exception if __name__ == '__main__': main() diff --git a/lib/ansible/modules/monitoring/sensu_client.py b/lib/ansible/modules/monitoring/sensu_client.py index 2bc7de0d5a6..6122b346604 100644 --- a/lib/ansible/modules/monitoring/sensu_client.py +++ b/lib/ansible/modules/monitoring/sensu_client.py @@ -171,10 +171,11 @@ file: sample: "/etc/sensu/conf.d/client.json" ''' -from ansible.module_utils.basic import AnsibleModule import json import os +from ansible.module_utils.basic import AnsibleModule + def main(): module = AnsibleModule( diff --git a/lib/ansible/modules/monitoring/sensu_handler.py b/lib/ansible/modules/monitoring/sensu_handler.py index bb56126202f..db25c22a49e 100644 --- a/lib/ansible/modules/monitoring/sensu_handler.py +++ b/lib/ansible/modules/monitoring/sensu_handler.py @@ -172,10 +172,11 @@ name: sample: "irc" ''' -from ansible.module_utils.basic import AnsibleModule import json import os +from ansible.module_utils.basic import AnsibleModule + def main(): module = AnsibleModule( diff --git a/lib/ansible/modules/monitoring/sensu_silence.py b/lib/ansible/modules/monitoring/sensu_silence.py index 594632b306b..aec8e1e0799 100644 --- a/lib/ansible/modules/monitoring/sensu_silence.py +++ b/lib/ansible/modules/monitoring/sensu_silence.py @@ -2,21 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2017, Steven Bambling -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -111,7 +101,6 @@ try: except ImportError: import simplejson as json -# import module snippets from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.urls import fetch_url diff --git a/lib/ansible/modules/monitoring/sensu_subscription.py b/lib/ansible/modules/monitoring/sensu_subscription.py index b8e006b8b35..68a1d796627 100644 --- a/lib/ansible/modules/monitoring/sensu_subscription.py +++ b/lib/ansible/modules/monitoring/sensu_subscription.py @@ -2,22 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2014, Anders Ingemann -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . -# +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -75,6 +64,10 @@ EXAMPLES = ''' - name: unsubscribe from common checks sensu_subscription: name=common state=absent ''' +import traceback + +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils._text import to_native def sensu_subscription(module, path, name, state='present', backup=False): @@ -88,15 +81,14 @@ def sensu_subscription(module, path, name, state='present', backup=False): try: config = json.load(open(path)) - except IOError: - e = get_exception() + except IOError as e: if e.errno is 2: # File not found, non-fatal if state == 'absent': reasons.append('file did not exist and state is `absent\'') return changed, reasons config = {} else: - module.fail_json(msg=str(e)) + module.fail_json(msg=to_native(e), exception=traceback.format_exc()) except ValueError: msg = '{path} contains invalid JSON'.format(path=path) module.fail_json(msg=msg) @@ -135,9 +127,9 @@ def sensu_subscription(module, path, name, state='present', backup=False): module.backup_local(path) try: open(path, 'w').write(json.dumps(config, indent=2) + '\n') - except IOError: - e = get_exception() - module.fail_json(msg='Failed to write to file %s: %s' % (path, str(e))) + except IOError as e: + module.fail_json(msg='Failed to write to file %s: %s' % (path, to_native(e)), + exception=traceback.format_exc()) return changed, reasons @@ -146,7 +138,7 @@ def main(): arg_spec = {'name': {'type': 'str', 'required': True}, 'path': {'type': 'str', 'default': '/etc/sensu/conf.d/subscriptions.json'}, 'state': {'type': 'str', 'default': 'present', 'choices': ['present', 'absent']}, - 'backup': {'type': 'str', 'default': 'no', 'type': 'bool'}, + 'backup': {'type': 'bool', 'default': 'no'}, } module = AnsibleModule(argument_spec=arg_spec, @@ -161,6 +153,6 @@ def main(): module.exit_json(path=path, name=name, changed=changed, msg='OK', reasons=reasons) -from ansible.module_utils.basic import * + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/monitoring/stackdriver.py b/lib/ansible/modules/monitoring/stackdriver.py index ee68c34437f..c70a788ab37 100644 --- a/lib/ansible/modules/monitoring/stackdriver.py +++ b/lib/ansible/modules/monitoring/stackdriver.py @@ -1,20 +1,12 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], 'supported_by': 'community'} @@ -110,17 +102,11 @@ EXAMPLES = ''' # Stackdriver module specific support methods. # -try: - import json -except ImportError: - try: - import simplejson as json - except ImportError: - # Let snippet from module_utils/basic.py return a proper error in this case - pass +import json +import traceback from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.pycompat24 import get_exception +from ansible.module_utils._text import to_native from ansible.module_utils.urls import fetch_url @@ -216,18 +202,18 @@ def main(): module.fail_json(msg="revision_id required for deploy events") try: send_deploy_event(module, key, revision_id, deployed_by, deployed_to, repository) - except Exception: - e = get_exception() - module.fail_json(msg="unable to sent deploy event: %s" % e) + except Exception as e: + module.fail_json(msg="unable to sent deploy event: %s" % to_native(e), + exception=traceback.format_exc()) if event == 'annotation': if not msg: module.fail_json(msg="msg required for annotation events") try: send_annotation_event(module, key, msg, annotated_by, level, instance_id, event_epoch) - except Exception: - e = get_exception() - module.fail_json(msg="unable to sent annotation event: %s" % e) + except Exception as e: + module.fail_json(msg="unable to sent annotation event: %s" % to_native(e), + exception=traceback.format_exc()) changed = True module.exit_json(changed=changed, deployed_by=deployed_by) diff --git a/lib/ansible/modules/monitoring/statusio_maintenance.py b/lib/ansible/modules/monitoring/statusio_maintenance.py index d6fb39c7f5e..2029ce987c3 100644 --- a/lib/ansible/modules/monitoring/statusio_maintenance.py +++ b/lib/ansible/modules/monitoring/statusio_maintenance.py @@ -2,21 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2015, Benjamin Copeland (@bhcopeland) -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], diff --git a/lib/ansible/modules/monitoring/uptimerobot.py b/lib/ansible/modules/monitoring/uptimerobot.py index 904333f39c4..cd06c4bcdc9 100644 --- a/lib/ansible/modules/monitoring/uptimerobot.py +++ b/lib/ansible/modules/monitoring/uptimerobot.py @@ -1,20 +1,12 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], 'supported_by': 'community'} @@ -70,18 +62,12 @@ EXAMPLES = ''' state: started ''' -try: - import json -except ImportError: - try: - import simplejson as json - except ImportError: - # Let snippet from module_utils/basic.py return a proper error in this case - pass - -import time +import json +from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.six.moves.urllib.parse import urlencode +from ansible.module_utils.urls import fetch_url + API_BASE = "http://api.uptimerobot.com/" @@ -169,7 +155,5 @@ def main(): ) -from ansible.module_utils.basic import * -from ansible.module_utils.urls import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/monitoring/zabbix_group.py b/lib/ansible/modules/monitoring/zabbix_group.py index ce37e7347ee..d9c35feb1e3 100644 --- a/lib/ansible/modules/monitoring/zabbix_group.py +++ b/lib/ansible/modules/monitoring/zabbix_group.py @@ -2,21 +2,10 @@ # -*- coding: utf-8 -*- # # (c) 2013-2014, Epic Games, Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type ANSIBLE_METADATA = {'metadata_version': '1.0', @@ -120,6 +109,8 @@ try: except ImportError: HAS_ZABBIX_API = False +from ansible.module_utils.basic import AnsibleModule + class HostGroup(object): def __init__(self, module, zbx): @@ -226,7 +217,6 @@ def main(): else: module.exit_json(changed=False) -from ansible.module_utils.basic import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/monitoring/zabbix_host.py b/lib/ansible/modules/monitoring/zabbix_host.py index 02120c2c49a..ad717efbb36 100644 --- a/lib/ansible/modules/monitoring/zabbix_host.py +++ b/lib/ansible/modules/monitoring/zabbix_host.py @@ -2,22 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2013-2014, Epic Games, Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . -# +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -163,7 +152,6 @@ EXAMPLES = ''' proxy: a.zabbix.proxy ''' -import logging import copy try: @@ -184,6 +172,9 @@ try: except ImportError: HAS_ZABBIX_API = False +from ansible.module_utils.basic import AnsibleModule + + class Host(object): def __init__(self, module, zbx): self._module = module @@ -576,7 +567,6 @@ def main(): module.exit_json(changed=True, result="Successfully added host %s (%s) and linked with template '%s'" % ( host_name, ip, link_templates)) -from ansible.module_utils.basic import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/monitoring/zabbix_hostmacro.py b/lib/ansible/modules/monitoring/zabbix_hostmacro.py index 3782cbf838d..19e05eaa29e 100644 --- a/lib/ansible/modules/monitoring/zabbix_hostmacro.py +++ b/lib/ansible/modules/monitoring/zabbix_hostmacro.py @@ -2,22 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2013-2014, Epic Games, Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . -# +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -102,9 +91,6 @@ EXAMPLES = ''' state: present ''' -import logging -import copy - try: from zabbix_api import ZabbixAPI, ZabbixAPISubClass @@ -118,6 +104,8 @@ try: except ImportError: HAS_ZABBIX_API = False +from ansible.module_utils.basic import AnsibleModule + class HostMacro(object): def __init__(self, module, zbx): @@ -222,8 +210,6 @@ def main(): host_macro_class_obj = HostMacro(module, zbx) - changed = False - if host_name: host_id = host_macro_class_obj.get_host_id(host_name) host_macro_obj = host_macro_class_obj.get_host_macro(macro_name, host_id) @@ -242,7 +228,6 @@ def main(): # update host macro host_macro_class_obj.update_host_macro(host_macro_obj, macro_name, macro_value) -from ansible.module_utils.basic import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/monitoring/zabbix_maintenance.py b/lib/ansible/modules/monitoring/zabbix_maintenance.py index 3292a57ff41..8939c3e7fd6 100644 --- a/lib/ansible/modules/monitoring/zabbix_maintenance.py +++ b/lib/ansible/modules/monitoring/zabbix_maintenance.py @@ -2,21 +2,10 @@ # -*- coding: utf-8 -*- # (c) 2013, Alexander Bulimov -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type ANSIBLE_METADATA = {'metadata_version': '1.0', @@ -177,6 +166,8 @@ try: except ImportError: HAS_ZABBIX_API = False +from ansible.module_utils.basic import AnsibleModule + def create_maintenance(zbx, group_ids, host_ids, start_time, maintenance_type, period, name, desc): end_time = start_time + period @@ -383,7 +374,6 @@ def main(): module.exit_json(changed=changed) -from ansible.module_utils.basic import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/monitoring/zabbix_screen.py b/lib/ansible/modules/monitoring/zabbix_screen.py index 3f338bc7544..36cdf5ba104 100644 --- a/lib/ansible/modules/monitoring/zabbix_screen.py +++ b/lib/ansible/modules/monitoring/zabbix_screen.py @@ -2,22 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2013-2014, Epic Games, Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . -# +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', @@ -165,6 +154,9 @@ try: except ImportError: HAS_ZABBIX_API = False +from ansible.module_utils.basic import AnsibleModule + + class Screen(object): def __init__(self, module, zbx): self._module = module @@ -291,7 +283,7 @@ class Screen(object): h_size = 2 else: h_size = 3 - v_size = (v_size - 1) / h_size + 1 + v_size = (v_size - 1) // h_size + 1 return h_size, v_size # create screen_items @@ -313,7 +305,7 @@ class Screen(object): if graph_id is not None: self._zapi.screenitem.create({'screenid': screen_id, 'resourcetype': 0, 'resourceid': graph_id, 'width': width, 'height': height, - 'x': i % h_size, 'y': i / h_size, 'colspan': 1, 'rowspan': 1, + 'x': i % h_size, 'y': i // h_size, 'colspan': 1, 'rowspan': 1, 'elements': 0, 'valign': 0, 'halign': 0, 'style': 0, 'dynamic': 0, 'sort_triggers': 0}) else: @@ -436,7 +428,6 @@ def main(): else: module.exit_json(changed=False) -from ansible.module_utils.basic import * if __name__ == '__main__': main() diff --git a/test/sanity/code-smell/boilerplate.sh b/test/sanity/code-smell/boilerplate.sh index 5e7a44a68fd..2d9fe3155ee 100755 --- a/test/sanity/code-smell/boilerplate.sh +++ b/test/sanity/code-smell/boilerplate.sh @@ -24,7 +24,6 @@ metaclass3=$(find ./lib/ansible/modules -path ./lib/ansible/modules/windows -pru -o -path ./lib/ansible/modules/cloud/openstack -prune \ -o -path ./lib/ansible/modules/cloud/cloudstack -prune \ -o -path ./lib/ansible/modules/cloud/amazon -prune \ - -o -path ./lib/ansible/modules/monitoring -prune \ -o -path ./lib/ansible/modules/network/aos -prune \ -o -path ./lib/ansible/modules/network/avi -prune \ -o -path ./lib/ansible/modules/network/cloudengine -prune \ @@ -44,7 +43,6 @@ future3=$(find ./lib/ansible/modules -path ./lib/ansible/modules/windows -prune -o -path ./lib/ansible/modules/cloud/openstack -prune \ -o -path ./lib/ansible/modules/cloud/cloudstack -prune \ -o -path ./lib/ansible/modules/cloud/amazon -prune \ - -o -path ./lib/ansible/modules/monitoring -prune \ -o -path ./lib/ansible/modules/network/aos -prune \ -o -path ./lib/ansible/modules/network/avi -prune \ -o -path ./lib/ansible/modules/network/cloudengine -prune \ diff --git a/test/sanity/code-smell/no-get-exception.sh b/test/sanity/code-smell/no-get-exception.sh index 32510e005c2..cbd2353a8ae 100755 --- a/test/sanity/code-smell/no-get-exception.sh +++ b/test/sanity/code-smell/no-get-exception.sh @@ -9,7 +9,6 @@ get_exception=$(find . -path ./test/runner/.tox -prune \ -o -path ./lib/ansible/module_utils/basic.py -prune \ -o -path ./lib/ansible/modules/storage/netapp -prune \ -o -path ./lib/ansible/modules/packaging/os -prune \ - -o -path ./lib/ansible/modules/monitoring -prune \ -o -path ./lib/ansible/modules/network/panos -prune \ -o -path ./lib/ansible/modules/network/nxos -prune \ -o -path ./lib/ansible/modules/network/junos -prune \ diff --git a/test/sanity/code-smell/no-wildcard-import.sh b/test/sanity/code-smell/no-wildcard-import.sh index 0602c9009ad..4eb1e18b3c0 100755 --- a/test/sanity/code-smell/no-wildcard-import.sh +++ b/test/sanity/code-smell/no-wildcard-import.sh @@ -21,7 +21,6 @@ wildcard_imports=$(find . -path ./test/runner/.tox -prune \ -o -path ./lib/ansible/modules/cloud/amazon -prune \ -o -path ./lib/ansible/modules/cloud/openstack -prune \ -o -path ./lib/ansible/modules/cloud/cloudstack -prune \ - -o -path ./lib/ansible/modules/monitoring -prune \ -o -path ./lib/ansible/modules/network/f5 -prune \ -o -path ./lib/ansible/modules/network/nxos -prune \ -o -path ./lib/ansible/modules/packaging/os -prune \ diff --git a/test/sanity/pep8/legacy-files.txt b/test/sanity/pep8/legacy-files.txt index 82e3556db8d..e12840daf7e 100644 --- a/test/sanity/pep8/legacy-files.txt +++ b/test/sanity/pep8/legacy-files.txt @@ -214,17 +214,14 @@ lib/ansible/modules/files/replace.py lib/ansible/modules/files/synchronize.py lib/ansible/modules/files/tempfile.py lib/ansible/modules/files/xattr.py -lib/ansible/modules/monitoring/airbrake_deployment.py lib/ansible/modules/monitoring/bigpanda.py lib/ansible/modules/monitoring/boundary_meter.py lib/ansible/modules/monitoring/circonus_annotation.py lib/ansible/modules/monitoring/datadog_event.py -lib/ansible/modules/monitoring/honeybadger_deployment.py lib/ansible/modules/monitoring/icinga2_feature.py lib/ansible/modules/monitoring/librato_annotation.py lib/ansible/modules/monitoring/logentries.py lib/ansible/modules/monitoring/logicmonitor.py -lib/ansible/modules/monitoring/logstash_plugin.py lib/ansible/modules/monitoring/nagios.py lib/ansible/modules/monitoring/newrelic_deployment.py lib/ansible/modules/monitoring/pagerduty.py