YPSI-SAS / centctl

Centctl is a Go CLI which allows to manage multiple Centreon servers.
MIT License
11 stars 4 forks source link

Centctl needs to handle 403 errors #23

Closed olivier-monaco closed 1 year ago

olivier-monaco commented 1 year ago

When I list hosts using centctl, the list is empty:

18:28:47 olivier@xxxx ~/sysadmin/$ CENTCTL_CONF=config/centctl.yml centctl list host
{
 "server": {
  "name": "xxx",
  "hosts": null
 }
}

Enabling debug message, give more more info:

18:29:26 olivier@xxxx ~/sysadmin/$ CENTCTL_CONF=config/centctl.yml centctl --DEBUG list host
[INFO]  2023/04/12 18:29:27 centctl authentification - successful authentification, token generate 
[INFO]  2023/04/12 18:29:27 centctl list host - Body request: {"action":"show","object":"host"}
[INFO]  2023/04/12 18:29:27 centctl list host - URL: https://xxxxxxx/api/index.php?action=action&object=centreon_clapi
[ERROR] 2023/04/12 18:29:27 centctl/debug.Show:debug.go:46 centctl list host - statusCode: 403
[ERROR] 2023/04/12 18:29:27 centctl/debug.Show:debug.go:47 centctl list host - Body response: "Forbidden"

{
 "server": {
  "name": "xxx",
  "hosts": null
 }
}

Calling manually the URL https://xxxxxxx/api/index.php?action=action&object=centreon_clapi return an 403 error:

HTTP/2 403 Unauthorized
server: nginx
date: ...
content-type: application/json;charset=utf-8
vary: User-Agent
X-Firefox-Spdy: h2

"Unauthorized"

Fixing access right on Centreon resolves my issue but I think Centctl needs to handle 403 errors.

MelissaB79 commented 1 year ago

hello,

I just corrected that in the last release.

Thank you for your contribution to improving the tool.