mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
ce5fc7764a
* fixed validation-modules for plugins/modules/monitoring/bigpanda.py * fixed validation-modules for plugins/modules/monitoring/circonus_annotation.py * fixed validation-modules for plugins/modules/monitoring/honeybadger_deployment.py * fixed validation-modules for plugins/modules/monitoring/icinga2_feature.py * fixed validation-modules for plugins/modules/monitoring/icinga2_host.py * fixed validation-modules for plugins/modules/monitoring/librato_annotation.py * fixed validation-modules for plugins/modules/monitoring/logentries.py * fixed validation-modules for plugins/modules/monitoring/logstash_plugin.py * fixed validation-modules for plugins/modules/monitoring/newrelic_deployment.py * fixed validation-modules for plugins/modules/monitoring/pagerduty_alert.py * fixed validation-modules for plugins/modules/monitoring/pagerduty.py * fixed validation-modules for plugins/modules/monitoring/pingdom.py * fixed validation-modules for plugins/modules/monitoring/rollbar_deployment.py * fixed validation-modules for plugins/modules/monitoring/spectrum_device.py * fixed validation-modules for plugins/modules/monitoring/stackdriver.py * fixed validation-modules for plugins/modules/monitoring/statusio_maintenance.py * fixed validation-modules for plugins/modules/monitoring/uptimerobot.py * fixed validation-modules for plugins/modules/monitoring/datadog/datadog_event.py * fixed validation-modules for plugins/modules/monitoring/datadog/datadog_monitor.py * fixed validation-modules for plugins/modules/monitoring/sensu/sensu_check.py * fixed validation-modules for plugins/modules/monitoring/sensu/sensu_client.py * fixed validation-modules for plugins/modules/monitoring/sensu/sensu_handler.py * fixed validation-modules for plugins/modules/monitoring/sensu/sensu_silence.py * fixed validation-modules for plugins/modules/monitoring/sensu/sensu_subscription.py * fixed trailing space * Enabling validation-modules for monitoring modules * Added line for 2.9 * Update plugins/modules/monitoring/icinga2_host.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/monitoring/datadog/datadog_event.py Co-authored-by: Felix Fontein <felix@fontein.de> * Suggestion from PR * oops, missed the 2.11 ignore file * Update plugins/modules/monitoring/icinga2_host.py Co-authored-by: Felix Fontein <felix@fontein.de> Co-authored-by: Felix Fontein <felix@fontein.de>
141 lines
3.7 KiB
Python
141 lines
3.7 KiB
Python
#!/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
|
|
|
|
|
|
DOCUMENTATION = '''
|
|
|
|
module: pingdom
|
|
short_description: Pause/unpause Pingdom alerts
|
|
description:
|
|
- This module will let you pause/unpause Pingdom alerts
|
|
author:
|
|
- "Dylan Silva (@thaumos)"
|
|
- "Justin Johns (!UNKNOWN)"
|
|
requirements:
|
|
- "This pingdom python library: https://github.com/mbabineau/pingdom-python"
|
|
options:
|
|
state:
|
|
type: str
|
|
description:
|
|
- Define whether or not the check should be running or paused.
|
|
required: true
|
|
choices: [ "running", "paused", "started", "stopped" ]
|
|
checkid:
|
|
type: str
|
|
description:
|
|
- Pingdom ID of the check.
|
|
required: true
|
|
uid:
|
|
type: str
|
|
description:
|
|
- Pingdom user ID.
|
|
required: true
|
|
passwd:
|
|
type: str
|
|
description:
|
|
- Pingdom user password.
|
|
required: true
|
|
key:
|
|
type: str
|
|
description:
|
|
- Pingdom API key.
|
|
required: true
|
|
notes:
|
|
- This module does not yet have support to add/remove checks.
|
|
'''
|
|
|
|
EXAMPLES = '''
|
|
- name: Pause the check with the ID of 12345
|
|
community.general.pingdom:
|
|
uid: example@example.com
|
|
passwd: password123
|
|
key: apipassword123
|
|
checkid: 12345
|
|
state: paused
|
|
|
|
- name: Unpause the check with the ID of 12345
|
|
community.general.pingdom:
|
|
uid: example@example.com
|
|
passwd: password123
|
|
key: apipassword123
|
|
checkid: 12345
|
|
state: running
|
|
'''
|
|
|
|
import traceback
|
|
|
|
PINGDOM_IMP_ERR = None
|
|
try:
|
|
import pingdom
|
|
HAS_PINGDOM = True
|
|
except Exception:
|
|
PINGDOM_IMP_ERR = traceback.format_exc()
|
|
HAS_PINGDOM = False
|
|
|
|
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
|
|
|
|
|
def pause(checkid, uid, passwd, key):
|
|
|
|
c = pingdom.PingdomConnection(uid, passwd, key)
|
|
c.modify_check(checkid, paused=True)
|
|
check = c.get_check(checkid)
|
|
name = check.name
|
|
result = check.status
|
|
# if result != "paused": # api output buggy - accept raw exception for now
|
|
# return (True, name, result)
|
|
return (False, name, result)
|
|
|
|
|
|
def unpause(checkid, uid, passwd, key):
|
|
|
|
c = pingdom.PingdomConnection(uid, passwd, key)
|
|
c.modify_check(checkid, paused=False)
|
|
check = c.get_check(checkid)
|
|
name = check.name
|
|
result = check.status
|
|
# if result != "up": # api output buggy - accept raw exception for now
|
|
# return (True, name, result)
|
|
return (False, name, result)
|
|
|
|
|
|
def main():
|
|
|
|
module = AnsibleModule(
|
|
argument_spec=dict(
|
|
state=dict(required=True, choices=['running', 'paused', 'started', 'stopped']),
|
|
checkid=dict(required=True),
|
|
uid=dict(required=True),
|
|
passwd=dict(required=True, no_log=True),
|
|
key=dict(required=True)
|
|
)
|
|
)
|
|
|
|
if not HAS_PINGDOM:
|
|
module.fail_json(msg=missing_required_lib("pingdom"), exception=PINGDOM_IMP_ERR)
|
|
|
|
checkid = module.params['checkid']
|
|
state = module.params['state']
|
|
uid = module.params['uid']
|
|
passwd = module.params['passwd']
|
|
key = module.params['key']
|
|
|
|
if (state == "paused" or state == "stopped"):
|
|
(rc, name, result) = pause(checkid, uid, passwd, key)
|
|
|
|
if (state == "running" or state == "started"):
|
|
(rc, name, result) = unpause(checkid, uid, passwd, key)
|
|
|
|
if rc != 0:
|
|
module.fail_json(checkid=checkid, name=name, status=result)
|
|
|
|
module.exit_json(checkid=checkid, name=name, status=result)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|