Skip to content

HTTP not found on Alert Obj #8

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

Open
rrajeevan opened this issue Dec 13, 2017 · 3 comments
Open

HTTP not found on Alert Obj #8

rrajeevan opened this issue Dec 13, 2017 · 3 comments

Comments

@rrajeevan
Copy link
Contributor

rrajeevan commented Dec 13, 2017

I faced this in the alert object but I suspect it occurs across all objects.

Issue: Per documentation, the check to see if alert exists only works if the alert exists.
If it doesn't, it throws httplib.NOT_FOUND(404) exception from here. Traceback below.

All actions including Alert creation/modification should be idempotent. So DELETE and PUT is the way to go. We just need a better mechanism for handling the error.
May be instead of raise, just catch the exception and gently let the calling function know? Thoughts?

Exception:

Traceback (most recent call last):
  File "alert.py", line 32, in <module>
    alertobj = argus.alerts.get_user_alert(user, alert_name, shared=False)
  File "client.py", line 473, in get_user_alert
    alerts = self.argus._request("get", "alerts/meta", params=dict(alertname=alertName, ownername=ownerName, shared=shared))
  File "client.py", line 555, in with_retry
    return f(*args, **kwargs)
  File "client.py", line 588, in with_auth_token
    return f(*args, **kwargs)
  File "client.py", line 708, in _request
    return self._request_no_auth(method, path, params, dataObj, encCls, decCls)
  File "client.py", line 730, in _request_no_auth
    res = check_success(resp, decCls)
  File "client.py", line 744, in check_success
    raise ArgusException("Object not found at endpoint: %s message: %s" % (resp.request.url, resp.text))
argusclient.client.ArgusException: Object not found at endpoint: 
https://<argus_url>/argusws/alerts/meta?shared=False&ownername=<owner_name>&alertname=<alert_name> 
message: {"status":404,"message":"Not Found"}
@hdara-sfdc
Copy link
Contributor

hdara-sfdc commented Dec 14, 2017

So DELETE and PUT is the way to go.

Not sure what you mean by this, are you suggesting to use one of these methods instead of GET ?

We just need a better mechanism for handling the error.May be instead of raise, just catch the exception and gently let the calling function know?

Perhaps you have something like returning a None to the caller in mind, but throwing an exception is in general better and consistent with many other APIs. However, instead of a generic ArgusException, it could throw a special exception meant to indicate this very condition, say ArgusObjectNotFoundException. The caller can then catch this and handle it appropriately, which is similar to checking for a None return value.

@rrajeevan
Copy link
Contributor Author

  1. I meant whatever we are trying to do with lookup to see if alert exists and delete it and then recreate is the right way.

  2. +1 to the idea of the new Exception. I'll send you a PR soon, let me know what you think.

@hdara-sfdc
Copy link
Contributor

Sure, please send the PR, thank you. You will need to update the unit tests too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants