sapcc / vrops-exporter

Prometheus exporter running python to get metrics out of VMware vRealize Operations
Apache License 2.0
23 stars 16 forks source link

[BUG] Inventory can not recover from getting malformed request #264

Open viennaa opened 12 months ago

viennaa commented 12 months ago

When fetching service_states fails and the reply is malformed, the inventory stops working because the error is not catched.

response.json needs to be catched.

Traceback:

[2023-12-11 09:01:36,943] [ERROR] Problem getting service stats from vrops-vc-... : <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>502 Bad Gateway</title>
</head><body>
<h1>Bad Gateway</h1>
<p>The proxy server received an invalid
response from an upstream server.<br />
</p>
</body></html>

Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/requests/models.py", line 971, in json
    return complexjson.loads(self.text, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/simplejson/__init__.py", line 514, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/simplejson/decoder.py", line 386, in decode
    obj, end = self.raw_decode(s)
               ^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/simplejson/decoder.py", line 416, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/vrops-exporter/./inventory.py", line 96, in <module>
    InventoryBuilder(os.environ.get('TARGET'), os.environ['PORT'], os.environ['SLEEP'])
  File "/vrops-exporter/inventory/Builder.py", line 34, in __init__
    self.query_inventory_permanent()
  File "/vrops-exporter/inventory/Builder.py", line 59, in query_inventory_permanent
    self.query_vrops(self.target, vrops_short_name, self.iteration)
  File "/vrops-exporter/inventory/Builder.py", line 119, in query_vrops
    Vrops.get_service_states(vrops, target, token)
  File "/vrops-exporter/tools/Vrops.py", line 672, in get_service_states
    return response.json(), response.status_code, response.elapsed.total_seconds()
           ^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/requests/models.py", line 975, in json
    raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
viennaa commented 9 months ago

@kevin-fischer good first issue :)