Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update statuscake_uptime.py #17

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions library/statuscake_uptime.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@
description:
- Alert delay rate
default: 5
basic_user:
description:
- A Basic Auth User account to use to login
required: false
basic_pass:
description:
- If BasicUser is set then this should be the password for the BasicUser
required: false
'''

Expand Down Expand Up @@ -155,6 +162,8 @@
do_not_find: 0
post_raw: ""
trigger_rate: 0
basic_user: "my_username"
basic_pass: "my_password"

- name: List all statuscake tests
statuscake_uptime:
Expand Down Expand Up @@ -227,7 +236,7 @@ def __init__(self, module, username, api_key, name, url, state,
test_tags, check_rate, test_type, port, contact_group, paused,
node_locations, confirmation, timeout, status_codes, host,
custom_header, follow_redirect, find_string, do_not_find,
post_raw,trigger_rate):
post_raw, trigger_rate, basic_user, basic_pass):

self.headers = {"Username": username, "API": api_key}
self.module = module
Expand All @@ -250,6 +259,8 @@ def __init__(self, module, username, api_key, name, url, state,
self.port = port
self.post_raw = post_raw
self.trigger_rate = trigger_rate
self.basic_user = basic_user
self.basic_pass = basic_pass

if not check_rate:
self.check_rate = 300
Expand Down Expand Up @@ -282,6 +293,8 @@ def __init__(self, module, username, api_key, name, url, state,
"Port": self.port,
"DoNotFind": self.do_not_find,
"TriggerRate": self.trigger_rate,
"BasicUser": self.basic_user,
"BasicPass": self.basic_pass,
}

if self.custom_header:
Expand Down Expand Up @@ -363,7 +376,7 @@ def create_test(self):
str(test_id))
response = requests.get(url_details_test, headers=self.headers)
req_data = self.convert(response.json())
diffkeys = ([k for k in self.data if self.data[k] and
diffkeys = ([k for k in self.data if self.data[k] and k in req_data and
str(self.data[k]) != str(req_data[k])])
if self.module.check_mode:
if len(diffkeys) != 0:
Expand Down Expand Up @@ -418,7 +431,7 @@ def run_module():
check_rate=dict(type='int', required=False),
test_type=dict(type='str', required=False),
port=dict(type='int', required=False),
contact_group=dict(type='int', required=False),
contact_group=dict(type='str', required=False),
paused=dict(type='int', required=False),
node_locations=dict(type='str', required=False),
confirmation=dict(type='int', required=False),
Expand All @@ -431,6 +444,8 @@ def run_module():
do_not_find=dict(type='int', required=False),
post_raw=dict(type='str', required=False),
trigger_rate=dict(type='int', required=False),
basic_user=dict(type='str', required=False),
basic_pass=dict(type='str', required=False, no_log=True),
)

module = AnsibleModule(
Expand Down Expand Up @@ -465,6 +480,8 @@ def run_module():
do_not_find = module.params['do_not_find']
post_raw = module.params['post_raw']
trigger_rate = module.params['trigger_rate']
basic_user = module.params['basic_user']
basic_pass = module.params['basic_pass']

if not (username and api_key) and \
os.environ.get('STATUSCAKE_USERNAME') and \
Expand Down Expand Up @@ -500,7 +517,9 @@ def run_module():
find_string,
do_not_find,
post_raw,
trigger_rate)
trigger_rate,
basic_user,
basic_pass)

if state == "absent":
test.delete_test()
Expand Down