StackStorm-Exchange / stackstorm-sensu

st2 content pack containing sensu integrations
https://exchange.stackstorm.org/
Apache License 2.0
5 stars 6 forks source link

'sensu.client_delete' fails if client was already deleted #3

Open arm4b opened 7 years ago

arm4b commented 7 years ago

The error

# st2 run sensu.client_delete client=st2-pkg-unstable-u14-ent-d01ba3d6c8.uswest2

.
id: 59372a4badf59216541c7566
status: failed
parameters: 
  client: st2-pkg-unstable-u14-ent-d01ba3d6c8.uswest2
result: 
  exit_code: 1
  result: None
  stderr: "No handlers could be found for logger "pysensu.api"
Traceback (most recent call last):
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/runners/python_action_wrapper.py", line 259, in <module>
    obj.run()
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/runners/python_action_wrapper.py", line 155, in run
    output = action.run(**self._parameters)
  File "/opt/stackstorm/packs/sensu/actions/client_delete.py", line 10, in run
    return self.api.delete_client(client)
  File "/opt/stackstorm/virtualenvs/sensu/lib/python2.7/site-packages/pysensu/api.py", line 99, in delete_client
    self._request('DELETE', '/clients/{}'.format(client))
  File "/opt/stackstorm/virtualenvs/sensu/lib/python2.7/site-packages/pysensu/api.py", line 64, in _request
    raise SensuAPIException('API bad response')
pysensu.api.SensuAPIException: API bad response
"
  stdout: ''

Sensu API response is 404 and it happens when client we want to delete doesn't exist. According to specification this is correct: https://sensuapp.org/docs/latest/api/clients-api.html#clientsclient-delete


We should try to catch the exception and return Success action execution result if client we want to delete is already deleted.

LindsayHill commented 5 years ago

Ideally should use https://github.com/sangoma/pysensu/pull/11, if it ever gets merged.

Otherwise we could maintain our own fork