Allow to export the host and service detail views to JSON
resolves #12820
This commit is contained in:
parent
4f6c54e62c
commit
1b6e7177a3
|
@ -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
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue