Skip to content
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

"500 Internal Server Error" instead of "404 Not Found" on non-matching filter in API request #7956

Closed
peteeckel opened this issue Apr 1, 2020 · 0 comments · Fixed by #7958
Assignees
Labels
area/api REST API bug Something isn't working
Milestone

Comments

@peteeckel
Copy link
Contributor

Describe the bug

When a filter expression does not match anything when, for example, creating a comment via the API, Icinga 2 returns a "500 Internal Server Error" instead of the expected "404 Not Found" as the result.

To Reproduce

  1. Create some test hosts (e.g. test-host-0 ... test-host-9) and test services per host.
  2. Create a sufficiently privileged test user (e.g. with "*" permission) on the Icinga 2 server
  3. Run an API request (e.g. 'add-comment' for an existing host/service):
POST /v1/actions/add-comment HTTP/1.1
Accept: application/json
Authorization: Basic YWdncmVnYXRlZDpYb3QleWt5R3BPdG9wSGV4T3gldXFJcTROZ2loT0o0SzNOW3V3TDBnWVJdT2plTFY0cDNMUWk=
Content-Type: application/json; charset=utf-8
Host: 192.168.110.112:5665
Connection: close
User-Agent: Paw/3.1.10 (Macintosh; OS X/10.15.4) GCDHTTPRequest
Content-Length: 138

{"filter":"host.name==\"test-host-1\"&&service.name==\"test-service-1\"","author":"Test User","comment":"Test Comment","type":"Service"}

=> Works fine:

HTTP/1.1 200 OK
Server: Icinga/2.11.3-1
Content-Type: application/json
Content-Length: 263

{"results":[{"code":200.0,"legacy_id":21.0,"name":"test-host-1!test-service-1!8641bb23-a3ea-4372-88b9-4657761144c1","status":"Successfully added comment 'test-host-1!test-service-1!8641bb23-a3ea-4372-88b9-4657761144c1' for object 'test-host-1!test-service-1'."}]}
  1. Now run the same API request with a non-existing service and/or host:
POST /v1/actions/add-comment HTTP/1.1
Accept: application/json
Authorization: Basic YWdncmVnYXRlZDpYb3QleWt5R3BPdG9wSGV4T3gldXFJcTROZ2loT0o0SzNOW3V3TDBnWVJdT2plTFY0cDNMUWk=
Content-Type: application/json; charset=utf-8
Host: 192.168.110.112:5665
Connection: close
User-Agent: Paw/3.1.10 (Macintosh; OS X/10.15.4) GCDHTTPRequest
Content-Length: 139

{"filter":"host.name==\"test-host-11\"&&service.name==\"test-service-1\"","author":"Test User","comment":"Test Comment","type":"Service"}

=> This time, an error 500 is reported:

HTTP/1.1 500 Internal Server Error
Server: Icinga/2.11.3-1
Content-Type: application/json
Content-Length: 14

{"results":[]}

Expected behavior

In accordance with the usual behaviour of the Icinga 2 API and REST services in general, I would expect a 404 error with a sensible error message ("No resource found" or something similar).

Your Environment

  • Version used (icinga2 --version):
[root@master2 ~]# icinga2 --version 
icinga2 - The Icinga 2 network monitoring daemon (version: 2.11.3-1)

Copyright (c) 2012-2020 Icinga GmbH (https://icinga.com/)
License GPLv2+: GNU GPL version 2 or later <https://gnu.org/licenses/gpl2.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

System information:
  Platform: CentOS Linux
  Platform version: 7 (Core)
  Kernel: Linux
  Kernel version: 3.10.0-1062.9.1.el7.x86_64
  Architecture: x86_64

Build information:
  Compiler: GNU 4.8.5
  Build host: runner-LTrJQZ9N-project-322-concurrent-0

Application information:

General paths:
  Config directory: /etc/icinga2
  Data directory: /var/lib/icinga2
  Log directory: /var/log/icinga2
  Cache directory: /var/cache/icinga2
  Spool directory: /var/spool/icinga2
  Run directory: /run/icinga2

Old paths (deprecated):
  Installation root: /usr
  Sysconf directory: /etc
  Run directory (base): /run
  Local state directory: /var

Internal paths:
  Package data directory: /usr/share/icinga2
  State path: /var/lib/icinga2/icinga2.state
  Modified attributes path: /var/lib/icinga2/modified-attributes.conf
  Objects path: /var/cache/icinga2/icinga2.debug
  Vars path: /var/cache/icinga2/icinga2.vars
  PID path: /run/icinga2/icinga2.pid
  • Config validation (icinga2 daemon -C):
[root@master2 ~]# icinga2 daemon -C 
[2020-04-01 16:43:48 +0000] information/cli: Icinga application loader (version: 2.11.3-1)
[2020-04-01 16:43:48 +0000] information/cli: Loading configuration file(s).
[2020-04-01 16:43:48 +0000] information/ConfigItem: Committing config item(s).
[2020-04-01 16:43:48 +0000] information/ApiListener: My API identity: master2.dev.evi.dfs
[2020-04-01 16:43:48 +0000] information/ConfigItem: Instantiated 1 FileLogger.
[2020-04-01 16:43:48 +0000] information/ConfigItem: Instantiated 1 NotificationComponent.
[2020-04-01 16:43:48 +0000] information/ConfigItem: Instantiated 1 IcingaApplication.
[2020-04-01 16:43:48 +0000] information/ConfigItem: Instantiated 10 Hosts.
[2020-04-01 16:43:48 +0000] information/ConfigItem: Instantiated 1 ApiListener.
[2020-04-01 16:43:48 +0000] information/ConfigItem: Instantiated 6 Comments.
[2020-04-01 16:43:48 +0000] information/ConfigItem: Instantiated 1 CheckerComponent.
[2020-04-01 16:43:48 +0000] information/ConfigItem: Instantiated 4 Zones.
[2020-04-01 16:43:48 +0000] information/ConfigItem: Instantiated 4 Endpoints.
[2020-04-01 16:43:48 +0000] information/ConfigItem: Instantiated 2 ApiUsers.
[2020-04-01 16:43:48 +0000] information/ConfigItem: Instantiated 202 CheckCommands.
[2020-04-01 16:43:48 +0000] information/ConfigItem: Instantiated 1 IdoPgsqlConnection.
[2020-04-01 16:43:48 +0000] information/ConfigItem: Instantiated 200 Services.
[2020-04-01 16:43:48 +0000] information/ScriptGlobal: Dumping variables to file '/var/cache/icinga2/icinga2.vars'
[2020-04-01 16:43:48 +0000] information/cli: Finished validating the configuration file(s).

Additional context

The 500 error occurs also when I URLencode the parameters, or when I just use hosts, not services. I can reproduce it on any Icinga 2 instance I'm currently running.

@Al2Klimov Al2Klimov self-assigned this Apr 2, 2020
@Al2Klimov Al2Klimov added the bug Something isn't working label Apr 2, 2020
Al2Klimov added a commit that referenced this issue Apr 2, 2020
@Al2Klimov Al2Klimov added the area/api REST API label Oct 5, 2021
@icinga-probot icinga-probot bot added this to the 2.14.0 milestone Jan 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/api REST API bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants