Reports Support
Support for querying, importing and running Reports is now available. Access to reports and report results is through the following collections:
/api/reports
/api/results
Querying Reports
Querying Available Reports
GET /api/reports
Querying a Single Report
GET /api/reports/:id
Querying Results of a Particular Reports
GET /api/reports/:id/results
Optionally, expanding all results
GET /api/reports/:id/results?expand=resources
Querying a single result of a report
GET /api/reports/:id/results/:result_id
Querying report results
GET /api/results
Running Reports
Running reports is done via the run action on a report resource as follows:
POST /api/reports/:id
{
"action" : "run"
}
Example for running a report on the following:
{
"href": "http://localhost:3000/api/reports/80",
"id": "80",
"name": "VM Relationships"
}
Response:
{
"success": true,
"message": "running report 80",
"href": "http://localhost:3000/api/reports/80",
"result_id": "27",
"result_href": "http://localhost:3000/api/results/27",
"task_id": "726",
"task_href": "http://localhost:3000/api/tasks/726"
}
The report run’s task can be queried periodically via the task_href specified above as follows:
GET /api/tasks/726
{
"href": "http://localhost:3000/api/tasks/726",
"id": "726",
"name": "Generate Report: 'VM Relationships'",
"state": "Queued",
"status": "Ok",
"message": "Task has been queued",
"userid": "system",
"created_on": "2015-11-09T18:44:41Z",
"updated_on": "2015-11-09T18:44:41Z"
}
{
"href": "http://localhost:3000/api/tasks/726",
"id": "726",
"name": "Generate Report: 'VM Relationships'",
"state": "Finished",
"status": "Ok",
"message": "Generating report complete",
"userid": "system",
"created_on": "2015-11-09T18:44:41Z",
"updated_on": "2015-11-09T18:47:13Z"
}
With the results queried via the result_href provided above:
GET /api/results/27
{
"href": "http://localhost:3000/api/results/27",
"id": "27",
"name": "VM Relationships",
"miq_report_id": "80",
"miq_task_id": "726",
"userid": "system",
"report_source": "Requested by user",
"db": "Vm",
"report": {
"name": "VM Relationships",
"title": "VM Relationships",
"rpt_group": "Relationships - Virtual Machines, Folders, Clusters",
"rpt_type": "Default",
"priority": 10,
"db": "Vm",
"cols": [
"name",
"v_owning_datacenter",
"v_owning_folder",
"v_owning_resource_pool"
],
"include": {
"ext_management_system": {
"columns": [
"name"
]
},
"host": {
"columns": [
"v_owning_cluster",
"hostname"
]
},
"storage": {
"columns": [
"name"
]
}
},
"col_order": [
"name",
"ext_management_system.name",
"v_owning_datacenter",
"host.v_owning_cluster",
"host.hostname",
"v_owning_folder",
"v_owning_resource_pool",
"storage.name"
],
"headers": [
"VM Name",
"Provider Name",
"Datacenter",
"Cluster",
"Host",
"Folder",
"Resource Pool",
"Datastore"
],
"conditions": {
"exp": {
"IS NOT EMPTY": {
"field": "Vm.host-name"
}
},
"col_details": {
"Vm.host-name": {
"data_type": "string",
"virtual_reflection": false,
"virtual_column": false,
"excluded_by_preprocess_options": false,
"tag": false,
"include": {
"host": {
}
},
"format_sub_type": "string"
}
},
"pexp": {
"IS NOT EMPTY": {
"field": "Vm.host-name"
}
},
"ruby": "<value ref=vm, type=string>/virtual/host/name</value> != \"\""
},
"order": "Ascending",
"sortby": [
"name"
],
"filename": "450_Relationships - Virtual Machines, Folders, Clusters/010_VMs Relationships.yaml",
"file_mtime": "2015-08-19T13:23:50Z",
"template_type": "report",
"col_formats": [
],
"rpt_options": {
},
"extras": {
"total_html_rows": 1709
},
"user_categories": [
],
"trend_data": {
}
},
"created_on": "2015-11-09T18:52:48Z",
"last_run_on": "2015-11-09T18:52:56Z",
"last_accessed_on": "2015-11-09T18:52:56Z",
"result_set": [
{
"name": "aab-vm1",
"v_owning_datacenter": "",
"v_owning_folder": "",
"v_owning_resource_pool": "",
"host.v_owning_cluster": "",
"host.hostname": "test-host.testdomain.com",
"storage.name": "StarStorage1"
"id": "320"
},
{
"name": "aab_demo_vm",
"v_owning_datacenter": "",
"v_owning_folder": "",
"v_owning_resource_pool": "",
"host.v_owning_cluster": "",
"host.hostname": "test-host2.testdomain.com",
"storage.name": "StarStorage2",
"id": "1"
},
...
]
}
Note that one can query all the results run for a report as follows:
GET /api/reports/80/results?expand=resources&attributes=created_on
{
"name": "results",
"count": 27,
"subcount": 2,
"resources": [
{
"href": "http://localhost:3000/api/reports/80/results/27",
"id": "27",
"created_on": "2015-11-09T18:52:48Z"
},
{
"href": "http://localhost:3000/api/reports/80/results/13",
"id": "13",
"created_on": "2015-07-29T18:24:35Z"
}
]
}
Importing Reports
Importing reports to the system can be done by posting an import action to the reports collection as follows:
POST /api/reports
{
"action" : "import",
"resource" : {
"report" : { JSON serialized report },
"options" : { "save" : true }
}
}
Here’s an example:
Request:
POST /api/reports
{
"action" : "import",
"resource" : {
"report" : {
"menu_name" : "Test Report",
"col_order" : ["col1", "col2", "col3"],
"cols" : ["col1", "col2", "col3"],
"rpt_type" : "Custom",
"title" : "Test Report",
"db" : "My::Db",
"rpt_group" : "Custom"
},
"options" : { "save" : true }
}
}
Response:
{
"results": [
{
"success": true,
"message": "Imported Report: [Test Report]",
"result": {
"id": "199",
"name": "Test Report",
"title": "Test Report",
"rpt_group": "Custom",
"rpt_type": "Custom",
"db": "My::Db",
"cols": [
"col1",
"col2",
"co3l"
],
"col_order": [
"col1",
"col2",
"col3"
],
"created_on": "2015-11-09T19:44:37Z",
"updated_on": "2015-11-09T19:44:37Z",
"miq_group_id": "1",
"user_id": "1"
}
}
]
}