Project

General

Profile

Actions

Feature #847

closed

Retrieve last report information per host via the api

Added by Andy Sykes over 13 years ago. Updated over 13 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
API
Target version:
Difficulty:
Triaged:
Fixed in Releases:
Found in Releases:

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
<!DOCTYPE html PUBLIC "
//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml&quot; 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)

Actions #1

Updated by Ohad Levy over 13 years ago

Hi Andy,

You are correct, at the moment JSON output is not implemented for reports.

I guess the real question, is what exactly should we output?

asking for all reports might be a lot of data to output.
Foreman (currently in git version) supports urls such as /hosts/fqdn/reports or alternatively the new search functionality, but if you are looking into getting the status (not the metrics), you are better off querying the dashboard page (again in latest git version) and filtering down the results using the new search functionality.

its fairly easy to add json output to reports, I'm just not 100% sure if it makes any sense to return all reports, as its probably going to be a fairly big chunk of data

Actions #2

Updated by Andy Sykes over 13 years ago

The version I have installed (which was pulled off git about three weeks ago and reports as 0.2) does not emit JSON from /hosts/fqdn/reports. That's really the data I'm after, so I can produce a Nagios plugin that checks a host's puppet_status, and provides a bit of information about why a run failed.

Does the current git revision emit JSON from /hosts/fqdn/reports?

You're right, I think. Dumping all the reports would probably not have much utility, and with larger systems could take quite some time to generate. Perhaps this ticket should be retargeted to "remove reference to /reports from API documentation" :)

Actions #3

Updated by Ohad Levy over 13 years ago

  • Status changed from New to Feedback

so I can suggest the following:

something like /hosts/fqdn/reports/last --> generate the status of the last report, including metrics (how much time, how many changes) and the logs.

alternatively, if you only looking for basic status (ok,error,active,out of sync), you can fetch that data over the dashboard url (using git from a couple of weeks ago or so).

/dashboard?search=+name+%3D+fqdn&format=json

will reply with something like: {"good_hosts":1,"percentage":100,"active_hosts":0,"out_of_sync_hosts":0,"total_hosts":1,"disabled_hosts":0,"bad_hosts":0}

you could change the name to a group, or what ever search criteria.

Actions #4

Updated by Andy Sykes over 13 years ago

Your first suggestion of /hosts/fqdn/reports/last is ideal. Anyone with external monitoring systems could find this information useful.

Thanks for taking the time to reply to me - Foreman is an excellent piece of software.

Actions #5

Updated by Ohad Levy over 13 years ago

  • Tracker changed from Bug to Feature
  • Subject changed from Reports REST API doesn't return JSON to Retrieve last report information per host via the api
  • Status changed from Feedback to Assigned
  • Assignee set to Ohad Levy
  • Target version set to 0.3
Actions #6

Updated by Ohad Levy over 13 years ago

  • Status changed from Assigned to Ready For Testing
  • % Done changed from 0 to 100
Actions #7

Updated by Ohad Levy over 13 years ago

  • Status changed from Ready For Testing to Closed
Actions

Also available in: Atom PDF