diff --git a/web/app/Controller/MonitorsController.php b/web/app/Controller/MonitorsController.php index b1e3d69e3..aad39bf6c 100644 --- a/web/app/Controller/MonitorsController.php +++ b/web/app/Controller/MonitorsController.php @@ -4,34 +4,10 @@ public function index() { $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)); + $this->set('eventsLastHour', $this->Monitor->getEventsLastHour()); + $this->set('eventsLastDay', $this->Monitor->getEventsLastDay()); + $this->set('eventsLastWeek', $this->Monitor->getEventsLastWeek()); + $this->set('eventsLastMonth', $this->Monitor->getEventsLastMonth()); } public function view($id = null) { diff --git a/web/app/Model/Monitor.php b/web/app/Model/Monitor.php index e4b89bcd8..5e88daf3b 100644 --- a/web/app/Model/Monitor.php +++ b/web/app/Model/Monitor.php @@ -11,5 +11,33 @@ 'foreignKey' => 'MonitorId' ) ); + + public function getEventsLastHour() { + $conditions = array('Event.StartTime > DATE_SUB(NOW(), INTERVAL 1 HOUR)'); + $group = array('Event.MonitorId'); + $fields = array('count(Event.Id) AS count'); + return $this->Event->find('all', compact('conditions', 'group', 'fields')); + } + + public function getEventsLastDay() { + $conditions = array('Event.StartTime > DATE_SUB(NOW(), INTERVAL 1 DAY)'); + $group = array('Event.MonitorId'); + $fields = array('count(Event.Id) AS count'); + return $this->Event->find('all', compact('conditions', 'group', 'fields')); + } + + public function getEventsLastWeek() { + $conditions = array('Event.StartTime > DATE_SUB(NOW(), INTERVAL 1 WEEK)'); + $group = array('Event.MonitorId'); + $fields = array('count(Event.Id) AS count'); + return $this->Event->find('all', compact('conditions', 'group', 'fields')); + } + + public function getEventsLastMonth() { + $conditions = array('Event.StartTime > DATE_SUB(NOW(), INTERVAL 1 MONTH)'); + $group = array('Event.MonitorId'); + $fields = array('count(Event.Id) AS count'); + return $this->Event->find('all', compact('conditions', 'group', 'fields')); + } } ?> diff --git a/web/app/View/Monitors/index.ctp b/web/app/View/Monitors/index.ctp index 38710a677..129a0ef97 100644 --- a/web/app/View/Monitors/index.ctp +++ b/web/app/View/Monitors/index.ctp @@ -23,10 +23,10 @@