1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

circonus_annotation: DOCUMENTATION & argument_spec cleaning (#26832)

* circonus_annotation: clean description

- add 'default' field
- default value for 'required' field is false
- use formatting function

* circonus_annotation: clean argument_spec

remove useless conversion
default of 'required' False
use 'default' when possible

* circonus_annotation: fix pep8

* circonus_annotation: add RETURN block

* circonus_annotation: check_mode isn't supported, add a note
This commit is contained in:
Pilou 2017-08-15 03:40:00 +02:00 committed by Toshio Kuratomi
parent 46956f0273
commit a3f91274b3
2 changed files with 79 additions and 21 deletions

View file

@ -25,6 +25,8 @@ requirements:
- urllib3 - urllib3
- requests - requests
- time - time
notes:
- Check mode isnt supported.
options: options:
api_key: api_key:
description: description:
@ -44,16 +46,16 @@ options:
required: true required: true
start: start:
description: description:
- Unix timestamp of event start, defaults to now - Unix timestamp of event start
required: false default: I(now)
stop: stop:
description: description:
- Unix timestamp of event end, defaults to now + duration - Unix timestamp of event end
required: false default: I(now) + I(duration)
duration: duration:
description: description:
- Duration in seconds of annotation, defaults to 0 - Duration in seconds of annotation
required: false default: 0
''' '''
EXAMPLES = ''' EXAMPLES = '''
# Create a simple annotation event with a source, defaults to start and end time of now # Create a simple annotation event with a source, defaults to start and end time of now
@ -78,6 +80,65 @@ EXAMPLES = '''
start_time: 1395940006 start_time: 1395940006
end_time: 1395954407 end_time: 1395954407
''' '''
RETURN = '''
annotation:
description: details about the created annotation
returned: success
type: complex
contains:
_cid:
description: annotation identifier
returned: success
type: string
sample: /annotation/100000
_created:
description: creation timestamp
returned: success
type: int
sample: 1502236928
_last_modified:
description: last modification timestamp
returned: success
type: int
sample: 1502236928
_last_modified_by:
description: last modified by
returned: success
type: string
sample: /user/1000
category:
description: category of the created annotation
returned: success
type: string
sample: alerts
title:
description: title of the created annotation
returned: success
type: string
sample: WARNING
description:
description: description of the created annotation
returned: success
type: string
sample: Host is down.
start:
description: timestamp, since annotation applies
returned: success
type: int
sample: Host is down.
stop:
description: timestamp, since annotation ends
returned: success
type: string
sample: Host is down.
rel_metrics:
description: Array of metrics related to this annotation, each metrics is a string.
returned: success
type: list
sample:
- 54321_kbps
'''
import json import json
import time import time
import traceback import traceback
@ -101,10 +162,7 @@ def post_annotation(annotation, api_key):
def create_annotation(module): def create_annotation(module):
''' Takes ansible module object ''' ''' Takes ansible module object '''
annotation = {} annotation = {}
if module.params['duration'] is not None:
duration = module.params['duration'] duration = module.params['duration']
else:
duration = 0
if module.params['start'] is not None: if module.params['start'] is not None:
start = module.params['start'] start = module.params['start']
else: else:
@ -113,8 +171,8 @@ def create_annotation(module):
stop = module.params['stop'] stop = module.params['stop']
else: else:
stop = int(time.time()) + duration stop = int(time.time()) + duration
annotation['start'] = int(start) annotation['start'] = start
annotation['stop'] = int(stop) annotation['stop'] = stop
annotation['category'] = module.params['category'] annotation['category'] = module.params['category']
annotation['description'] = module.params['description'] annotation['description'] = module.params['description']
annotation['title'] = module.params['title'] annotation['title'] = module.params['title']
@ -133,15 +191,16 @@ def main():
'''Main function, dispatches logic''' '''Main function, dispatches logic'''
module = AnsibleModule( module = AnsibleModule(
argument_spec=dict( argument_spec=dict(
start=dict(required=False, type='int'), start=dict(type='int'),
stop=dict(required=False, type='int'), stop=dict(type='int'),
category=dict(required=True), category=dict(required=True),
title=dict(required=True), title=dict(required=True),
description=dict(required=True), description=dict(required=True),
duration=dict(required=False, type='int'), duration=dict(default=0, type='int'),
api_key=dict(required=True, no_log=True) api_key=dict(required=True, no_log=True)
) )
) )
annotation = create_annotation(module) annotation = create_annotation(module)
try: try:
resp = post_annotation(annotation, module.params['api_key']) resp = post_annotation(annotation, module.params['api_key'])

View file

@ -218,7 +218,6 @@ lib/ansible/modules/files/tempfile.py
lib/ansible/modules/files/xattr.py lib/ansible/modules/files/xattr.py
lib/ansible/modules/monitoring/bigpanda.py lib/ansible/modules/monitoring/bigpanda.py
lib/ansible/modules/monitoring/boundary_meter.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/datadog_event.py
lib/ansible/modules/monitoring/icinga2_feature.py lib/ansible/modules/monitoring/icinga2_feature.py
lib/ansible/modules/monitoring/librato_annotation.py lib/ansible/modules/monitoring/librato_annotation.py