Open NathanQ opened 1 year ago
Files identified in the description:
If these files are incorrect, please update the component name
section of the description or use the !component
bot command.
cc @nate-kingsley click here for bot help
The module should definitely handle this better. In any case, this happens if some kind of error happens during the HTTP request. The return value info['status']
should be checked whether the HTTP status is acceptable, and if not the module should abort with at least telling the user the HTTP status code.
Glad its not just me!
This caused me to look deeper and I think its because the API endpoint the module is using no longer exists.
~/.ansible/collections/ansible_collections/community/general/plugins/modules/monitoring/uptimerobot.py
API_BASE = "https://api.uptimerobot.com/"
API_ACTIONS = dict(
status='getMonitors?',
editMonitor='editMonitor?'
)
API_FORMAT = 'json'
API_NOJSONCALLBACK = 1
CHANGED_STATE = False
SUPPORTS_CHECK_MODE = False
def checkID(module, params):
data = urlencode(params)
full_uri = API_BASE + API_ACTIONS['status'] + data
req, info = fetch_url(module, full_uri)
result = to_text(req.read())
jsonresult = json.loads(result)
req.close()
return jsonresult
Manually assembling full_uri we end up with https://api.uptimerobot.com/getMonitors, but the current API is suffixed by v2 (https://uptimerobot.com/api/)
$ vso -L https://api.uptimerobot.com/getMonitors 2>&1 |grep HTTP
* using HTTP/2
> GET /getMonitors HTTP/2
< HTTP/2 404
vs
$ vso -L https://api.uptimerobot.com/v2/getMonitors 2>&1 |grep HTTP
* using HTTP/2
> GET /v2/getMonitors HTTP/2
< HTTP/2 200
The V1 API was replaced in 2017 but I suppose its possible they finally deprecated an old endpoint and stopped handling its traffic - breaking us here.
FTR the following idiom can be used in the mean time, flip status=1
to start the monitor again
- name: Pause UptimeRobot monitoring
delegate_to: localhost
run_once: true
uri:
body: "api_key={{ ur_api_main_key }}&format=json&id={{ item.id }}&status=0"
body_format: 'form-urlencoded'
method: 'POST'
url: "{{ ur_api_url_base + 'editMonitor' }}"
with_items: "{{ ur_monitors_list.json.monitors }}"
I spoke to uptime robot last night.
They confirmed a change in their infra probably caused the change in behaviour for that API endpoint but stressed v1 was fully retired two years ago.
Summary
Using the uptimerobot module fails with AttributeError: 'NoneType' object has no attribute 'read'.
Issue Type
Bug Report
Component Name
uptimerobot
Ansible Version
Community.general Version
Configuration
OS / Environment
Ubuntu 16.04.7 LTS
Steps to Reproduce
Expected Results
ok
Actual Results
Code of Conduct