mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
eb1214baad
Changes to the metadata format were approved here: https://github.com/ansible/proposals/issues/54 * Update documentation to the new metadata format * Changes to metadata-tool to account for new metadata * Add GPL license header * Add upgrade subcommand to upgrade metadata version * Change default metadata to the new format * Fix exclusion of non-modules from the metadata report * Fix ansible-doc for new module metadata * Exclude metadata version from ansible-doc output * Fix website docs generation for the new metadata * Update metadata schema in valiate-modules test * Update the metadata in all modules to the new version
161 lines
4.3 KiB
Python
161 lines
4.3 KiB
Python
#!/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 <http://www.gnu.org/licenses/>.
|
|
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
|
'status': ['preview'],
|
|
'supported_by': 'community'}
|
|
|
|
|
|
DOCUMENTATION = '''
|
|
|
|
module: pingdom
|
|
short_description: Pause/unpause Pingdom alerts
|
|
description:
|
|
- This module will let you pause/unpause Pingdom alerts
|
|
version_added: "1.2"
|
|
author:
|
|
- "Dylan Silva (@thaumos)"
|
|
- "Justin Johns"
|
|
requirements:
|
|
- "This pingdom python library: https://github.com/mbabineau/pingdom-python"
|
|
options:
|
|
state:
|
|
description:
|
|
- Define whether or not the check should be running or paused.
|
|
required: true
|
|
default: null
|
|
choices: [ "running", "paused" ]
|
|
aliases: []
|
|
checkid:
|
|
description:
|
|
- Pingdom ID of the check.
|
|
required: true
|
|
default: null
|
|
choices: []
|
|
aliases: []
|
|
uid:
|
|
description:
|
|
- Pingdom user ID.
|
|
required: true
|
|
default: null
|
|
choices: []
|
|
aliases: []
|
|
passwd:
|
|
description:
|
|
- Pingdom user password.
|
|
required: true
|
|
default: null
|
|
choices: []
|
|
aliases: []
|
|
key:
|
|
description:
|
|
- Pingdom API key.
|
|
required: true
|
|
default: null
|
|
choices: []
|
|
aliases: []
|
|
notes:
|
|
- This module does not yet have support to add/remove checks.
|
|
'''
|
|
|
|
EXAMPLES = '''
|
|
# Pause the check with the ID of 12345.
|
|
- pingdom:
|
|
uid: example@example.com
|
|
passwd: password123
|
|
key: apipassword123
|
|
checkid: 12345
|
|
state: paused
|
|
|
|
# Unpause the check with the ID of 12345.
|
|
- pingdom:
|
|
uid: example@example.com
|
|
passwd: password123
|
|
key: apipassword123
|
|
checkid: 12345
|
|
state: running
|
|
'''
|
|
|
|
try:
|
|
import pingdom
|
|
HAS_PINGDOM = True
|
|
except:
|
|
HAS_PINGDOM = False
|
|
|
|
|
|
|
|
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 pingdom module (check docs)")
|
|
|
|
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)
|
|
|
|
# import module snippets
|
|
from ansible.module_utils.basic import *
|
|
|
|
if __name__ == '__main__':
|
|
main()
|