Skip to content

Commit 1dbfa73

Browse files
Merge pull request #3 from UKCloud/documentation-for-lookups
Documentation update for the uptime_checks lookup
2 parents 1320526 + 10105bc commit 1dbfa73

File tree

3 files changed

+108
-19
lines changed

3 files changed

+108
-19
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# Ansible
55
**/*.retry
66
**/*vault.yml
7+
**/vault*.yml
78

89
# Python
910
.venv/

README.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
# Ansible Collection - ukcloud.pingdom
22

3-
An Ansible Collection for managing SolarWinds Pingdom site monitoring. This collection has lookups for reading details from Pingdom as well as modules to create, modify and delete objects in Pingdom.
3+
An Ansible Collection for managing SolarWinds Pingdom site monitoring. This collection has lookups for reading details from Pingdom as well as modules to create objects in Pingdom.
44

55
## Pre-release
66

77
Note this repo is at a pre-release stage. Plugin names and parameters are likely to continue to change until this reaches the first major release 1.0.0
88

99
## Using this collection
1010

11-
Run `ansible-galaxy collection install git+https://github.com/UKCloud/ukcloud.pingdom` to install this collection.
11+
Use the following command to install this collection.
12+
13+
`ansible-galaxy collection install git+https://github.com/UKCloud/ukcloud.pingdom`
14+
1215

1316
This collection uses the python `pingdompy` library, the source can be found at [https://github.com/UKCloud/pingdompy](https://github.com/UKCloud/pingdompy). This library needs to be available to the python interpreter running Ansible. One way to do this is to use pip to install Ansible and the pingdompy library.
1417

@@ -66,15 +69,11 @@ timing - The timing between the check running in minutes
6669

6770
### uptime_checks
6871

69-
TBC
70-
71-
### maintenance_windows
72-
73-
TBC
72+
Once this collection is installed, run `ansible-doc -t lookup ukcloud.pingdom.uptime_checks` to view the documentation for the uptime_checks lookup, which includes examples of how to call this lookup and the structure of the data returned.
7473

7574
## Development
7675

77-
If you want to develop new content for this collection or improve what is already here, the easiest way to work on the collection is to clone it into one of the default [`COLLECTIONS_PATH`](https://docs.ansible.com/ansible/latest/reference_appendices/config.html#collections-paths), and work on it there.
76+
If you want to develop new content for this collection or make any changes, the easiest way to work on the collection is to clone it into one of the default [`COLLECTIONS_PATH`](https://docs.ansible.com/ansible/latest/reference_appendices/config.html#collections-paths), and edit it there.
7877

7978
```bash
8079
git clone git@github.com:UKCloud/ukcloud.pingdom.git ~/.ansible/collections/ansible_collections/ukcloud/pingdom
@@ -84,9 +83,9 @@ You can find more information in the [developer guide for collections](https://d
8483

8584
## Testing
8685

87-
There are some basic testing playbooks in the /tests folder which exercise the uptime_check and maintenance_window modules. The playbooks require a Pingdom API key is passed in a variable called `vault_apikey`. Ansible Vault is one way to pass in this parameter.
86+
There are some basic integration test playbooks in the /tests folder which exercise the uptime_check and maintenance_window modules. The playbooks require a Pingdom API key is passed in a variable called `vault_apikey`. Ansible Vault is one way to pass in this parameter.
8887

89-
The tests will create uptime checks and maintenance windows in Pingdom which will need to be manually deleted until `state: absent` is implemented in the modules.
88+
The integration tests require a valid Pingdom account and will create uptime checks and maintenance windows in Pingdom which need to be manually deleted afterwards.
9089

9190
See [here](https://docs.ansible.com/ansible/devel/dev_guide/developing_collections.html#testing-collections) also.
9291

plugins/lookup/uptime_checks.py

Lines changed: 98 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929

3030
EXAMPLES = """
3131
# Get details of all uptime checks
32-
- hosts: all
32+
- hosts: localhost
33+
connection: local
34+
gather_facts: No
3335
vars:
3436
all_uptime_checks: "{{ lookup('ukcloud.pingdom.uptime_checks', api_token=<token>)}}"
3537
tasks:
@@ -38,7 +40,9 @@
3840
var: all_uptime_checks
3941
4042
# Get details of uptime checks tagged with "production"
41-
- hosts: all
43+
- hosts: localhost
44+
connection: local
45+
gather_facts: No
4246
vars:
4347
tagged_uptime_checks: "{{ lookup('ukcloud.pingdom.uptime_checks', api_token=<token>, tags='production')}}"
4448
tasks:
@@ -49,8 +53,97 @@
4953

5054
RETURN = """
5155
checks:
52-
description: List of checks from Pingdom
53-
type: list
56+
description: List of checks from Pingdom
57+
type: list
58+
elements: dict
59+
contains:
60+
created:
61+
description: Unix epoch representation of when the uptime check was created.
62+
returned: always
63+
type: str
64+
sample: '1548851044'
65+
hostname:
66+
description: Domain name, including sub-domain, of the target for the uptime check.
67+
returned: always
68+
type: str
69+
sample: 'google.com'
70+
id:
71+
description: Unique identifier to the uptime check.
72+
returned: always
73+
type: str
74+
sample: '1234567'
75+
ipv6: false
76+
description: Whether the uptime check uses ipv6 instead of ipv4.
77+
returned: always
78+
type: str
79+
sample: 'false'
80+
lastdownend: 1615034565
81+
description: Unix epoch representation of the end of the last downtime period.
82+
returned: Only returned if the uptime check has ever been considered down.
83+
type: str
84+
sample: '1548851044'
85+
lastdownstart:
86+
description: Unix epoch representation of the start of the last downtime period.
87+
returned: Only returned if the uptime check has ever been considered down.
88+
type: str
89+
sample: '1548851044'
90+
lasterrortime:
91+
description: Unix epoch representation of when the uptime check last threw an error when it ran.
92+
returned: Only returned if the uptime check has ever thrown an error when run.
93+
type: str
94+
sample: '1615034507'
95+
lastresponsetime:
96+
description: Unix epoch representation of the uptime_check response time.
97+
returned: always
98+
type: str
99+
sample: '123'
100+
lasttesttime:
101+
description: Unix epoch representation of when the uptime check was last checked.
102+
returned: always
103+
type: str
104+
sample: '1615808445'
105+
maintenanceids:
106+
description: Ids of all maintenance windows which cover this uptime check.
107+
returned: Only returned if there are any maintenance windows which reference this uptime check.
108+
type: list
109+
elements: str
110+
sample:
111+
- '12345'
112+
- '67890'
113+
name:
114+
description: Name of the uptime check in Pingdom.
115+
returned: always
116+
type: str
117+
sample: 'Production host uptime check'
118+
probe_filters:
119+
description:
120+
- List of probe filters applied to the uptime check.
121+
- These limit geographically the uptime check is called from.
122+
returned: Only returned when probe filters are configured for the uptime check.
123+
type: list
124+
elements: str
125+
sample:
126+
- "region: EU"
127+
resolution:
128+
description: Frequency the uptime check will be run, in minutes.
129+
returned: always
130+
type: str
131+
sample: '5'
132+
status: up
133+
description: Whenther the uptime check is currently considered "up" or "down".
134+
returned: always
135+
type: str
136+
sample: 'down'
137+
type: http
138+
description: Protocol used by the uptime check, "http" or "https".
139+
returned: always
140+
type: str
141+
sample: 'https'
142+
verify_certificate: true
143+
description: Whether to consider the validity of the endpoints ssl certificate in the uptime check status.
144+
returned: always
145+
type: str
146+
sample: 'true'
54147
"""
55148

56149

@@ -62,15 +155,11 @@ class LookupModule(LookupBase):
62155
def run(self, terms, variables=None, **kwargs):
63156
""" main entrypoint for the lookup """
64157
display = Display()
65-
display.debug(f"DEBUG: lookup uptime_checks called with terms = {terms}")
66-
display.debug(f"DEBUG: lookup uptime_checks called with kwargs = {kwargs}")
67158

68159
api_token = kwargs.get("api_token")
69-
display.vvv(f"DEBUG: Got api_token of {api_token}")
70-
tags = kwargs.get("tags")
71-
display.vvv(f"DEBUG: Got tags of {tags}")
72160
if not api_token:
73161
raise AnsibleError(message="'api_token' must be passed to the ukcloud.pingdom.uptime_checks lookup.")
162+
tags = kwargs.get("tags")
74163
data = get_checks(api_token, tags)
75164

76165
return [data]

0 commit comments

Comments
 (0)