Skip to content

Commit a77a627

Browse files
Merge pull request #2 from UKCloud/AddAttributesToUptimeModule2083
Add attributes to uptime module (CNAP 2083)
2 parents 1dbfa73 + 28215eb commit a77a627

File tree

3 files changed

+100
-50
lines changed

3 files changed

+100
-50
lines changed

galaxy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace: ukcloud
88
name: pingdom
99

1010
# The version of the collection. Must be compatible with semantic versioning
11-
version: 0.1.0
11+
version: 0.2.0
1212

1313
# The path to the Markdown (.md) readme file. This path is relative to the root of the collection
1414
readme: README.md

plugins/modules/uptime_check.py

Lines changed: 76 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,74 @@
2020
options:
2121
apikey:
2222
required: true
23+
type: string
2324
description:
24-
- api key to auth with Pingdom
25-
url:
25+
- The user's API key used to authorize the log in into Pingdom is taken as a string.
26+
host:
2627
required: true
28+
type: string
2729
description:
28-
- Url of the host to check, eg www.google.com
30+
- The host attribute contains the URL of the destination host which is being targeted by the uptime check. This attribute takes it's value as a string. (e.g. www.google.com).
2931
name:
3032
required: true
33+
type: string
3134
description:
32-
- Name of the check
35+
- A name must be given to identify the uptime check as a string. The name does not have to be unique.
3336
protocol:
3437
required: true
38+
type: string
3539
description:
36-
- The protocol used for the check, eg http, ping etc
40+
- The type of check taking place must be specified as a string (e.g. http, tcp, ping).
3741
tags:
38-
required: true
42+
required: false
43+
type : string
3944
description:
40-
- The tag(s) to add to the check separated with ,
45+
- Tags can be added to an uptime check to make them more organized and discoverable in the user interface. This attribute takes an array of strings where each tag must have a maximum length of 64 characters.
4146
timing:
42-
required: true
47+
required: false
48+
type: string
49+
description:
50+
- The user can specify the number of minutes between each check. This attribute takes an integer, but defaults to 5 if not specified.
51+
port:
52+
required: false
53+
type: string
54+
description:
55+
- A specific port number can be targetted on the destination URL by setting setting the port number as an integer.
56+
encryption:
57+
required: false
58+
type: string
4359
description:
44-
- The timing between the check running in minutes
60+
- The user can specify whether the uptime check uses encryption. This attribute takes a boolean (True or False), but defaults to False if not specified.
61+
verify_certificate:
62+
required: false
63+
type: string
64+
description:
65+
- An uptime check can treat the target site as down if it has an invalid or unverifiable certificate if the boolean verify_certificate attribute is set to True. If not specified, this attribute defaults to False.
66+
probe_filters:
67+
required: false
68+
type: string
69+
description:
70+
- The user can specify filters used for probe selection as an array of strings. Currently only region is supported (e.g. region:EU)
71+
shouldcontain:
72+
required: false
73+
type: string
74+
description:
75+
- The uptime check will only determine that the target site is up if it contains a specified string.
76+
integrationids:
77+
required: false
78+
type: string
79+
description:
80+
- The user can connect integrations which have been set up in the UI to the uptime check by specifying the integration IDs as a list of integers.
81+
url:
82+
required: false
83+
type: string
84+
description:
85+
- A path on the destination server can be set for the uptime check to target. This is taken as a string.
4586
pause:
4687
required: false
88+
type: string
4789
description:
48-
- Not Required. Please set to "y" to pause the check on creation for testing
90+
- This attribute takes a boolean (True/False). If set to True, the created uptime check will not automatically run immediately. If not specified, this attribute defaults to False.
4991
notes:
5092
- More variables can be added following the above formatting and adding
5193
to the fields section within main
@@ -61,11 +103,18 @@ def main():
61103
## Set input variables
62104
fields = {
63105
"apikey": {"type": "str", "required": True, "no_log": True},
64-
"url": {"type": "str", "required": True},
106+
"host": {"type": "str", "required": True},
65107
"name": {"type": "str", "required": True},
66108
"protocol": {"type": "str", "required": True},
67-
"tags": {"type": "str", "required": True},
68-
"timing": {"type": "str", "required": True},
109+
"tags": {"type": "str", "required": False},
110+
"timing": {"type": "str", "required": False},
111+
"port": {"type": "str", "required": False},
112+
"encryption": {"type": "str", "required": False},
113+
"verify_certificate": {"type": "str", "required": False},
114+
"probe_filters": {"type": "str", "required": False},
115+
"shouldcontain": {"type": "str", "required": False},
116+
"integrationids": {"type": "str", "required": False},
117+
"url": {"type": "str", "required": False},
69118
"pause": {"type": "str", "required": False},
70119
}
71120

@@ -75,23 +124,27 @@ def main():
75124
module = AnsibleModule(argument_spec=fields, supports_check_mode=False)
76125
## Assign params to more usable variables
77126
api_key = module.params['apikey']
78-
check_url = module.params['url']
127+
check_host = module.params['host']
79128
check_name = module.params['name']
80129
check_proto = module.params['protocol']
81130
check_tags = module.params['tags']
82131
check_timing = module.params['timing']
132+
check_port = module.params['port']
133+
check_encryption = module.params['encryption']
134+
check_verification = module.params['verify_certificate']
135+
check_filters = module.params['probe_filters']
136+
check_contain = module.params['shouldcontain']
137+
check_ids = module.params['integrationids']
138+
check_url = module.params['url']
139+
check_pause = module.params['pause']
83140
client = pingdompy.Client(apikey=api_key)
84141

85-
## Logic allowing for checks to be paused on creation for testing purposes
86-
if module.params['pause'] == "y":
87-
check_pause = True
88-
else:
89-
check_pause = False
90-
91142
## Creates the check and returns the new checks id + name
92-
check = client.create_check({"host": check_url, "name": check_name, \
143+
check = client.create_check({"host": check_host, "name": check_name, \
93144
"type": check_proto, "tags": check_tags, "resolution": check_timing, \
94-
"paused": check_pause})
145+
"verify_certificate": check_verification, "probe_filters": check_filters, \
146+
"shouldcontain": check_contain, "integrationids": check_ids, "url": check_url, \
147+
"port": check_port, "encryption": check_encryption, "paused": check_pause})
95148

96149
## Returns verification to ansible
97150
module.exit_json(
@@ -100,4 +153,4 @@ def main():
100153
)
101154

102155
if __name__ == '__main__':
103-
main()
156+
main()

tests/test-uptime-check.yml

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,42 @@
11
---
2+
23
- name: Test uptime check functionality
34
hosts: localhost
45
connection: local
56
gather_facts: No
67
vars:
78
apikey: "{{ vault_apikey }}"
89
check_name: "OpenshiftAnsibleCheckTest created from {{ inventory_hostname }}"
9-
check_protocol: http
10-
check_tags: ocp-test,pypingdom-test
10+
check_protocol: "http"
11+
check_tags: "ocp-test,pypingdom-test"
1112
check_timing: "60"
13+
check_port: "8080"
14+
check_encryption: "true"
15+
check_certificate: "true"
16+
check_filters: "region:EU"
17+
check_contain: "google"
18+
check_ids: ""
19+
check_pause: "true"
20+
21+
1222
tasks:
1323
- name: Create uptime check
1424
ukcloud.pingdom.uptime_check:
15-
#state: present
1625
apikey: "{{ apikey }}"
17-
url: "www.google.co.uk"
26+
host: "www.google.co.uk"
1827
name: "{{ check_name }}"
1928
protocol: "{{ check_protocol }}"
2029
tags: "{{ check_tags }}"
2130
timing: "{{ check_timing }}"
22-
pause: y
31+
port: "{{ check_port }}"
32+
encryption: "{{ check_encryption }}"
33+
verify_certificate: "{{ check_certificate }}"
34+
probe_filters: "{{ check_filters }}"
35+
shouldcontain: "{{ check_contain }}"
36+
integrationids: "{{ check_ids }}"
37+
pause: "{{ check_pause }}"
2338
register: check
2439

25-
- debug:
26-
var: check
27-
28-
# - name: Modify uptime check
29-
# ukcloud.pingdom.uptime_check:
30-
# #state: present
31-
# apikey: "{{ apikey }}"
32-
# url: "{{ url }}"
33-
# name: "{{ name }}"
34-
# protocol: "{{ protocol }}"
35-
# tags: "{{ tags }}"
36-
# timing: "{{ timing }}"
37-
# pause: y
38-
# register: response
39-
40-
41-
42-
# - name: Delete uptime check
43-
# ukcloud.pingdom.uptime_check:
44-
# state: absent
45-
# uptimeid: xxx
40+
- name: Print response
41+
debug:
42+
var: check

0 commit comments

Comments
 (0)