Allow to export the host and service detail views to JSON

resolves #12820
This commit is contained in:
Eric Lippmann 2016-12-07 16:43:43 +01:00
parent 4f6c54e62c
commit 1b6e7177a3
1 changed files with 21 additions and 0 deletions

View File

@ -75,6 +75,7 @@ abstract class MonitoredObjectController extends Controller
}
}
$this->object->populate();
$this->handleFormatRequest();
$toggleFeaturesForm = new ToggleObjectFeaturesCommandForm(array(
'backend' => $this->backend,
'objects' => $this->object
@ -134,6 +135,26 @@ abstract class MonitoredObjectController extends Controller
return $form;
}
/**
* Export to JSON if requested
*/
protected function handleFormatRequest($query = null)
{
if ($this->params->get('format') === 'json'
|| $this->getRequest()->getHeader('Accept') === 'application/json'
) {
$payload = (array) $this->object->properties;
$payload += array(
'contacts' => $this->object->contacts->fetchPairs(),
'contact_groups' => $this->object->contactgroups->fetchPairs(),
'vars' => $this->object->customvars
);
$groupName = $this->object->getType() . 'groups';
$payload[$groupName] = $this->object->$groupName;
$this->getResponse()->json()->setSuccessData($payload)->sendResponse();
}
}
/**
* Acknowledge a problem
*/