From 20b024ef02bad116a508c3bc68ba6739ea6e444f Mon Sep 17 00:00:00 2001 From: Kyle Johnson Date: Sat, 4 May 2013 19:22:09 -0400 Subject: [PATCH] Added queries for last events per hour, day, week and month --- web/app/Controller/MonitorsController.php | 31 ++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/web/app/Controller/MonitorsController.php b/web/app/Controller/MonitorsController.php index 0b76a7e7e..b1e3d69e3 100644 --- a/web/app/Controller/MonitorsController.php +++ b/web/app/Controller/MonitorsController.php @@ -2,7 +2,36 @@ class MonitorsController extends AppController { public function index() { - $this->set('monitors', $this->Monitor->find('all')); + $monitoroptions['fields'] = array('Name', 'Id', 'Function', 'Host'); + $this->set('monitors', $this->Monitor->find('all', $monitoroptions)); + + $elhoptions = array( + 'conditions' => array('Event.StartTime > DATE_SUB(NOW(), INTERVAL 1 HOUR)'), + 'group' => array('Event.MonitorId'), + 'fields' => array('count(Event.Id) AS count') + ); + $this->set('elh', $this->Monitor->Event->find('all', $elhoptions)); + + $eldoptions = array( + 'conditions' => array('Event.StartTime > DATE_SUB(NOW(), INTERVAL 1 DAY)'), + 'group' => array('Event.MonitorId'), + 'fields' => array('count(Event.Id) AS count') + ); + $this->set('eld', $this->Monitor->Event->find('all', $eldoptions)); + + $elwoptions = array( + 'conditions' => array('Event.StartTime > DATE_SUB(NOW(), INTERVAL 1 WEEK)'), + 'group' => array('Event.MonitorId'), + 'fields' => array('count(Event.Id) AS count') + ); + $this->set('elw', $this->Monitor->Event->find('all', $elwoptions)); + + $elmoptions = array( + 'conditions' => array('Event.StartTime > DATE_SUB(NOW(), INTERVAL 1 MONTH)'), + 'group' => array('Event.MonitorId'), + 'fields' => array('count(Event.Id) AS count') + ); + $this->set('elm', $this->Monitor->Event->find('all', $elmoptions)); } public function view($id = null) {