GET /api/hostgroups recently started returning 404

Problem:
Trying to get the list of hostgroups returns 404. This started happening about a month ago, but I haven’t changed the foreman version. It used to work.

Expected outcome:
the list of hostgroups would be provided

Foreman and Proxy versions:
Foreman Version 1.14.3
Proxy TFTP, DNS, DHCP, Puppet, Puppet CA, Logs, Dynflow, and SSH
1.14.3

Foreman and Proxy plugin versions:

Name Description Author Version
foreman-tasks The goal of this plugin is to unify the way of showing task statuses across the Foreman instance. It defines Task model for keeping the information about the tasks and Lock for assigning the tasks to resources. The locking allows dealing with preventing multiple colliding tasks to be run on the same resource. It also optionally provides Dynflow infrastructure for using it for managing the tasks. Ivan Nečas 0.8.6
foreman_hooks Plugin engine for Foreman that enables running custom hook scripts on Foreman events Dominic Cleal 0.3.14
foreman_host_peers Description of ForemanHostPeers. Rob King 0.0.1
foreman_remote_execution A plugin bringing remote execution to the Foreman, completing the config management functionality with remote management functionality. Foreman Remote Execution team 1.2.2
foreman_xen Provision and manage XEN Server from Foreman. Pavel Nemirovsky, Michal Piotrowski, and Avi Israeli 0.5.2

Distribution and version:
CentOS Linux release 7.3.1611 (Core)
Linux 3.10.0-514.6.1.el7.x86_64 #1 SMP Wed Jan 18 13:06:36 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

Other relevant data:

logs:
2022-01-26 10:54:13 ce0f4fd4 [app] [I] Started GET "/api/hostgroups?order=title&page=1" for 10.16.24.4 at 2022-01-26 10:54:13 -0500
2022-01-26 10:54:13 ce0f4fd4 [app] [I] Processing by Api::V2::HostgroupsController#index as JSON
2022-01-26 10:54:13 ce0f4fd4 [app] [I]   Parameters: {"order"=>"title", "page"=>"1", "apiv"=>"v2"}
2022-01-26 10:54:13 ce0f4fd4 [app] [D] Setting current user thread-local variable to foreman_admin
2022-01-26 10:54:13 ce0f4fd4 [app] [D] Setting current user thread-local variable to nil
2022-01-26 10:54:13 ce0f4fd4 [app] [D] Setting current user thread-local variable to foreman_admin
2022-01-26 10:54:13 ce0f4fd4 [app] [D] Setting current user thread-local variable to nil
2022-01-26 10:54:13 ce0f4fd4 [app] [D] Setting current user thread-local variable to admin
2022-01-26 10:54:13 ce0f4fd4 [app] [I] Authorized user admin(Admin User)
2022-01-26 10:54:13 ce0f4fd4 [app] [D] Setting current user thread-local variable to admin
2022-01-26 10:54:15 ce0f4fd4 [app] [I]   Rendered api/v2/hostgroups/index.json.rabl within api/v2/layouts/index_layout (2768.3ms)
2022-01-26 10:54:15 ce0f4fd4 [app] [I] Couldn't find Hostgroup with 'id'=235 (ActiveRecord::RecordNotFound)
2022-01-26 10:54:15 ce0f4fd4 [app] [I]   Rendered api/v2/errors/not_found.json.rabl within api/v2/layouts/error_layout (2.6ms)
2022-01-26 10:54:15 ce0f4fd4 [app] [I] Completed 404 Not Found in 2830ms (Views: 5.8ms | ActiveRecord: 180.8ms)


$ curl -v -u admin 'https://foreman.example.com/api/hostgroups?order=title&page=1'
Enter host password for user 'admin':
* About to connect() to foreman.example.com port 443 (#0)
*   Trying 10.16.24.130...
* Connected to foreman.example.com (10.16.24.130) port 443 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
*   CAfile: /etc/pki/tls/certs/ca-bundle.crt
CApath: none
* SSL connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
* Server certificate:
*       subject: CN=*.example.com
*       start date: Oct 13 00:00:00 2021 GMT
*       expire date: Feb 27 23:59:59 2022 GMT
*       common name: *.example.com
*       issuer: CN=DigiCert SHA2 High Assurance Server CA,OU=www.digicert.com,O=DigiCert Inc,C=US
* Server auth using Basic with user 'admin'
> GET /api/hostgroups?order=title&page=1 HTTP/1.1
> Authorization: Basic XXXXX
> User-Agent: curl/7.29.0
> Host: foreman.example.com
> Accept: */*
> 
< HTTP/1.1 404 Not Found
< Date: Wed, 26 Jan 2022 15:42:38 GMT
< Server: Apache/2.4.6 (CentOS)
< Foreman_version: 1.14.3
< Foreman_api_version: 2
< Apipie-Checksum: ae4390d62b416468bde21525edb78cf0
< Cache-Control: no-cache
< X-Request-Id: 398156e1-8f9a-4d90-97af-ea9cd68bbf05
< X-Runtime: 2.680239
< Content-Security-Policy: default-src 'self'; child-src 'self'; connect-src 'self' ws: wss:; img-src 'self' data: *.gravatar.com; script-src 'unsafe-eval' 'unsafe-inline' 'self'; style-src 'un
safe-inline' 'self'
< Strict-Transport-Security: max-age=631152000; includeSubdomains
< X-Content-Type-Options: nosniff
< X-Download-Options: noopen
< X-Frame-Options: sameorigin
< X-Permitted-Cross-Domain-Policies: none
< X-XSS-Protection: 1; mode=block
< X-Powered-By: Phusion Passenger 4.0.53
< Set-Cookie: _session_id=XXXXXXXX; path=/; secure; HttpOnly
< Status: 404 Not Found
< Transfer-Encoding: chunked
< Content-Type: application/json; charset=utf-8
< 
{
  "error": {"message":"Resource hostgroup not found by id ''"}
}
* Connection #0 to host foreman.example.com left intact

Would you consider upgrading? Whatever that is happening might be directly related to some issue that has been fixed a long time ago?

@mcorr I am in the process of building a new foreman server, which will be running the latest version. In the mean time, I’m trying to see why this suddenly started failing.

1 Like

I also noticed that there is a missing hostgroup with id 235, which may be related to this 404.

I created a hostgroup manually with the missing I’d, by manipulating the database directly, and this was resolved. The odd thing is that the missing hostgroup was deleted via the GUI, which I would have thought would be a normal operation.

1 Like