Add API function to return event counts for console view

This commit is contained in:
Kyle Johnson 2014-11-19 15:49:38 +00:00
parent 5eaedae973
commit a0f12575fe
1 changed files with 20 additions and 1 deletions

View File

@ -108,4 +108,23 @@ class EventsController extends AppController {
} else {
return $this->flash(__('The event could not be deleted. Please, try again.'), array('action' => 'index'));
}
}}
}
public function consoleEvents($interval = null) {
$this->Event->recursive = -1;
$results = array();
$query = $this->Event->query("select MonitorId, COUNT(*) AS Count from Events WHERE StartTime >= (DATE_SUB(NOW(), interval $interval)) GROUP BY MonitorId;");
foreach ($query as $result) {
$results[$result['Events']['MonitorId']] = $result[0]['Count'];
}
$this->set(array(
'results' => $results,
'_serialize' => array('results')
));
}
}