# Buggy code
def main():
    module = AnsibleModule(
        argument_spec=dict(
            api_key=dict(required=True, no_log=True),
            api_host=dict(required=False),
            app_key=dict(required=True, no_log=True),
            state=dict(required=True, choices=["present", "absent", "mute", "unmute"]),
            type=dict(
                required=False,
                choices=[
                    "metric alert",
                    "service check",
                    "event alert",
                    "process alert",
                ],
            ),
            name=dict(required=True),
            query=dict(required=False),
            message=dict(required=False, default=None),
            silenced=dict(required=False, default=None, type="dict"),
            notify_no_data=dict(required=False, default=False, type="bool"),
            no_data_timeframe=dict(required=False, default=None),
            timeout_h=dict(required=False, default=None),
            renotify_interval=dict(required=False, default=None),
            escalation_message=dict(required=False, default=None),
            notify_audit=dict(required=False, default=False, type="bool"),
            thresholds=dict(required=False, type="dict", default=None),
            tags=dict(required=False, type="list", default=None),
            locked=dict(required=False, default=False, type="bool"),
            require_full_window=dict(required=False, default=None, type="bool"),
            new_host_delay=dict(required=False, default=None),
            evaluation_delay=dict(required=False, default=None),
            id=dict(required=False),
        )
    )

    # Prepare Datadog
    if not HAS_DATADOG:
        module.fail_json(
            msg=missing_required_lib("datadogpy"), exception=DATADOG_IMP_ERR
        )

    options = {
        "api_key": module.params["api_key"],
        "api_host": module.params["api_host"],
        "app_key": module.params["app_key"],
    }

    initialize(**options)

    # Check if api_key and app_key is correct or not
    # if not, then fail here.
    response = api.Monitor.get_all()
    if isinstance(response, dict):
        msg = response.get("errors", None)
        if msg:
            module.fail_json(
                msg="Failed to connect Datadog server using given app_key and api_key : {0}".format(
                    msg[0]
                )
            )

    if module.params["state"] == "present":
        install_monitor(module)
    elif module.params["state"] == "absent":
        delete_monitor(module)
    elif module.params["state"] == "mute":
        mute_monitor(module)
    elif module.params["state"] == "unmute":
        unmute_monitor(module)


# Traceback (TypeError)
The full traceback is:
Traceback (most recent call last):
File "/home/kevin/.ansible/tmp/ansible-tmp-1536342721.9100335-54055516095596/AnsiballZ_datadog_monitor.py", line 113, in <module>
_ansiballz_main()
File "/home/kevin/.ansible/tmp/ansible-tmp-1536342721.9100335-54055516095596/AnsiballZ_datadog_monitor.py", line 105, in _ansiballz_main
invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
File "/home/kevin/.ansible/tmp/ansible-tmp-1536342721.9100335-54055516095596/AnsiballZ_datadog_monitor.py", line 48, in invoke_module
imp.load_module('__main__', mod, module, MOD_DESC)
File "/usr/lib64/python3.6/imp.py", line 235, in load_module
return load_source(name, filename, file)
File "/usr/lib64/python3.6/imp.py", line 170, in load_source
module = _exec(spec, sys.modules[name])
File "<frozen importlib._bootstrap>", line 618, in _exec
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/tmp/ansible_datadog_monitor_payload_2zuzk2lj/__main__.py", line 343, in <module>
File "/tmp/ansible_datadog_monitor_payload_2zuzk2lj/__main__.py", line 179, in main
File "/tmp/ansible_datadog_monitor_payload_2zuzk2lj/ansible_datadog_monitor_payload.zip/ansible/module_utils/basic.py", line 900, in __init__
File "/tmp/ansible_datadog_monitor_payload_2zuzk2lj/ansible_datadog_monitor_payload.zip/ansible/module_utils/basic.py", line 2242, in _log_invocation
File "/tmp/ansible_datadog_monitor_payload_2zuzk2lj/ansible_datadog_monitor_payload.zip/ansible/module_utils/basic.py", line 2200, in log
TypeError: send() got multiple values for keyword argument 'MESSAGE'

# Fixed code
def main():
    module = AnsibleModule(
        argument_spec=dict(
            api_key=dict(required=True, no_log=True),
            api_host=dict(required=False),
            app_key=dict(required=True, no_log=True),
            state=dict(required=True, choices=["present", "absent", "mute", "unmute"]),
            type=dict(
                required=False,
                choices=[
                    "metric alert",
                    "service check",
                    "event alert",
                    "process alert",
                ],
            ),
            name=dict(required=True),
            query=dict(required=False),
            notification_message=dict(
                required=False,
                default=None,
                aliases=["message"],
                deprecated_aliases=[dict(name="message", version="2.14")],
            ),
            silenced=dict(required=False, default=None, type="dict"),
            notify_no_data=dict(required=False, default=False, type="bool"),
            no_data_timeframe=dict(required=False, default=None),
            timeout_h=dict(required=False, default=None),
            renotify_interval=dict(required=False, default=None),
            escalation_message=dict(required=False, default=None),
            notify_audit=dict(required=False, default=False, type="bool"),
            thresholds=dict(required=False, type="dict", default=None),
            tags=dict(required=False, type="list", default=None),
            locked=dict(required=False, default=False, type="bool"),
            require_full_window=dict(required=False, default=None, type="bool"),
            new_host_delay=dict(required=False, default=None),
            evaluation_delay=dict(required=False, default=None),
            id=dict(required=False),
        )
    )

    # Prepare Datadog
    if not HAS_DATADOG:
        module.fail_json(
            msg=missing_required_lib("datadogpy"), exception=DATADOG_IMP_ERR
        )

    if "message" in module.params:
        module.fail_json(
            msg="'message' is reserved keyword, please change this parameter to 'notification_message'"
        )

    options = {
        "api_key": module.params["api_key"],
        "api_host": module.params["api_host"],
        "app_key": module.params["app_key"],
    }

    initialize(**options)

    # Check if api_key and app_key is correct or not
    # if not, then fail here.
    response = api.Monitor.get_all()
    if isinstance(response, dict):
        msg = response.get("errors", None)
        if msg:
            module.fail_json(
                msg="Failed to connect Datadog server using given app_key and api_key : {0}".format(
                    msg[0]
                )
            )

    if module.params["state"] == "present":
        install_monitor(module)
    elif module.params["state"] == "absent":
        delete_monitor(module)
    elif module.params["state"] == "mute":
        mute_monitor(module)
    elif module.params["state"] == "unmute":
        unmute_monitor(module)