Feature #847
closedRetrieve last report information per host via the api
Description
If you query the reports API as this page says (http://theforeman.org/projects/foreman/wiki/API) you do not get JSON returned. Instead, you get HTML. If you request JSON with the GET parameter ?format=json the server throws a 500 error and complains about a missing template.
Example:
$ curl -H "Content-Type:application/json" -H "Accept:application/json" http://foreman/reports
[reams of HTML output]
If you try, as suggested on the page, adding ?format=json, you get a 500 error page in HTML:
$ curl H "Content-Type:application/json" -H "Accept:application/json" http://foreman/reports//W3C//DTD XHTML 1.0 Transitional//EN"
<!DOCTYPE html PUBLIC "
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>We're sorry, but something went wrong (500)</title>
<style type="text/css">
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
div.dialog {
width: 25em;
padding: 0 4em;
margin: 4em auto 0 auto;
border: 1px solid #ccc;
border-right-color: #999;
border-bottom-color: #999;
}
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
</style>
</head>
<body>
<div class="dialog">
<h1>We're sorry, but something went wrong.</h1>
<p>We've been notified about this issue and we'll take a look at it shortly.</p>
</div>
</body>
</html>
The logs on the server show:
Processing ReportsController#index to json (for 10.0.22.17 at 2011-04-15 16:51:56) [GET]
Parameters: {"format"=>"json", "action"=>"index", "controller"=>"reports"}
[[4;36;1mUser Load (0.4ms)[[0m [[0;1mSELECT * FROM `users` WHERE (`users`.`login` = 'admin') LIMIT 1[[0m
[[4;35;1mReport Load (0.5ms)[[0m [[0mSELECT * FROM `reports` ORDER BY reports.created_at DESC LIMIT 0, 20[[0m
[[4;36;1mSQL (0.2ms)[[0m ^[[0;1mSELECT count(*) AS count_all FROM `reports` ^[[0m
ActionView::MissingTemplate (Missing template reports/index.erb in view path app/views):
passenger (3.0.5) lib/phusion_passenger/rack/request_handler.rb:96:in `process_request'
passenger (3.0.5) lib/phusion_passenger/abstract_request_handler.rb:513:in `accept_and_process_next_request'
passenger (3.0.5) lib/phusion_passenger/abstract_request_handler.rb:274:in `main_loop'
passenger (3.0.5) lib/phusion_passenger/classic_rails/application_spawner.rb:321:in `start_request_handler'
passenger (3.0.5) lib/phusion_passenger/classic_rails/application_spawner.rb:275:in `send'
passenger (3.0.5) lib/phusion_passenger/classic_rails/application_spawner.rb:275:in `handle_spawn_application'
passenger (3.0.5) lib/phusion_passenger/utils.rb:479:in `safe_fork'
passenger (3.0.5) lib/phusion_passenger/classic_rails/application_spawner.rb:270:in `handle_spawn_application'
passenger (3.0.5) lib/phusion_passenger/abstract_server.rb:357:in `__send__'
passenger (3.0.5) lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
passenger (3.0.5) lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
passenger (3.0.5) lib/phusion_passenger/abstract_server.rb:180:in `start'
passenger (3.0.5) lib/phusion_passenger/classic_rails/application_spawner.rb:149:in `start'
passenger (3.0.5) lib/phusion_passenger/spawn_manager.rb:219:in `spawn_rails_application'
passenger (3.0.5) lib/phusion_passenger/abstract_server_collection.rb:132:in `lookup_or_add'
passenger (3.0.5) lib/phusion_passenger/spawn_manager.rb:214:in `spawn_rails_application'
passenger (3.0.5) lib/phusion_passenger/abstract_server_collection.rb:82:in `synchronize'
passenger (3.0.5) lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize'
passenger (3.0.5) lib/phusion_passenger/spawn_manager.rb:213:in `spawn_rails_application'
passenger (3.0.5) lib/phusion_passenger/spawn_manager.rb:132:in `spawn_application'
passenger (3.0.5) lib/phusion_passenger/spawn_manager.rb:275:in `handle_spawn_application'
passenger (3.0.5) lib/phusion_passenger/abstract_server.rb:357:in `__send__'
passenger (3.0.5) lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
passenger (3.0.5) lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
passenger (3.0.5) helper-scripts/passenger-spawn-server:99
Rendering /puppet/foreman/public/500.html (500 Internal Server Error)