Moved events queries from the Monitors controller to the Monitors model

This commit is contained in:
Kyle Johnson 2013-05-04 19:42:37 -04:00
parent a56ae4ed42
commit d681654e56
3 changed files with 36 additions and 32 deletions

View File

@ -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) {

View File

@ -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'));
}
}
?>

View File

@ -23,10 +23,10 @@
</td>
<td><?php echo $monitor['Monitor']['Host']; ?></td>
<td><?php echo count($monitor['Event']); ?></td>
<td><?php echo $elh[$count][0]['count']; ?></td>
<td><?php echo $eld[$count][0]['count']; ?></td>
<td><?php echo $elw[$count][0]['count']; ?></td>
<td><?php echo $elm[$count][0]['count']; ?></td>
<td><?php echo $eventsLastHour[$count][0]['count']; ?></td>
<td><?php echo $eventsLastDay[$count][0]['count']; ?></td>
<td><?php echo $eventsLastWeek[$count][0]['count']; ?></td>
<td><?php echo $eventsLastMonth[$count][0]['count']; ?></td>
<td></td>
<td><?php echo count($monitor['Zone']); ?></td>
</tr>