datagutten / apc-smartconnect-py

A Python class to get info from APC SmartConnect
GNU General Public License v3.0
5 stars 0 forks source link

schneider maintenance mode crashes script output #3

Closed vmpr closed 1 year ago

vmpr commented 1 year ago

hi, we have integrated your script into our icinga and we monitor a smart ups.

we've got that error message when the website was in maintenance mode, can you catch that error and configure the output to be warning?

Traceback (most recent call last):File "/usr/lib/nagios/plugins/apc-smartconnect/apc-smartconnect-info.py", line 12, in smart.login(sys.argv[1], sys.argv[2]) File "/usr/lib/nagios/plugins/apc-smartconnect/apc_smartconnect/APCSmartConnect.py", line 70, in login response = self.session.get(response.headers['Location']) File "/usr/lib/python3/dist-packages/requests/sessions.py", line 555, in get return self.request('GET', url, **kwargs) File "/usr/lib/python3/dist-packages/requests/sessions.py", line 528, in request prep = self.prepare_request(req) File "/usr/lib/python3/dist-packages/requests/sessions.py", line 456, in prepare_request p.prepare( File "/usr/lib/python3/dist-packages/requests/models.py", line 316, in prepare self.prepare_url(url, params) File "/usr/lib/python3/dist-packages/requests/models.py", line 390, in prepare_url raise MissingSchema(error) requests.exceptions.MissingSchema: Invalid URL '/maintenance': No schema supplied. Perhaps you meant http:///maintenance?

thanks and have a great day! cheers Ringo

datagutten commented 1 year ago

You should be able to handle an exception from your call, but instead of requests throwing a MissingSchema, I have added a check and throw a ValueError if the URL is not valid. 09ff98813fd0e7dc8c1b56b80e8126cecac39352