diff --git a/modules/monitoring/application/views/scripts/list/statehistorysummary.phtml b/modules/monitoring/application/views/scripts/list/statehistorysummary.phtml
new file mode 100644
index 000000000..aa1bedd0a
--- /dev/null
+++ b/modules/monitoring/application/views/scripts/list/statehistorysummary.phtml
@@ -0,0 +1,159 @@
+
+= $this->tabs ?>
+
+
+
+summary)) {
+ echo 'No entries found
';
+ return;
+}
+
+$cols = array('cnt_events'/*, 'cnt_up', 'cnt_down', 'cnt_ok', 'cnt_critical'*/);
+$show = array('cnt_events');
+
+$max = (object) array();
+
+foreach ($cols as $col) {
+ $max->$col = 0;
+}
+
+foreach ($this->summary as & $row) {
+ foreach ($cols as $col) {
+ if ($row->$col > $max->$col) {
+ $max->$col = $row->$col;
+ }
+ }
+}
+
+$colors->cnt_events = array(
+ $max->cnt_events * 0.80 => '#0b5',
+ $max->cnt_events * 0.60 => '#2b6',
+ $max->cnt_events * 0.40 => '#4b7',
+ $max->cnt_events * 0.20 => '#7b9',
+ 0 => '#9ba',
+);
+
+$colors->cnt_up = array(
+ $max->cnt_up * 0.80 => '#0b5',
+ $max->cnt_up * 0.60 => '#2b6',
+ $max->cnt_up * 0.40 => '#4b7',
+ $max->cnt_up * 0.20 => '#7b9',
+ 0 => '#9ba',
+);
+
+$colors->cnt_ok = array(
+ $max->cnt_ok * 0.80 => '#0b5',
+ $max->cnt_ok * 0.60 => '#2b6',
+ $max->cnt_ok * 0.40 => '#4b7',
+ $max->cnt_ok * 0.20 => '#7b9',
+ 0 => '#9ba',
+);
+
+$colors->cnt_critical = array(
+ $max->cnt_critical * 0.8 => '#f34',
+ $max->cnt_critical * 0.6 => '#f56',
+ $max->cnt_critical * 0.4 => '#f67',
+ $max->cnt_critical * 0.2 => '#f9a',
+ 0 => '#fcd',
+);
+
+$colors->cnt_down = array(
+ $max->cnt_down * 0.8 => '#f34',
+ $max->cnt_down * 0.6 => '#f56',
+ $max->cnt_down * 0.4 => '#f67',
+ $max->cnt_down * 0.2 => '#f9a',
+ 0 => '#fcd',
+);
+
+
+function getColor(& $colors, $value, $what = 'cnt_events') {
+ foreach ($colors->$what as $level => $color) {
+ if ($value >= $level) {
+ return $color;
+ }
+ }
+ return 'red';
+}
+$startDay = '2014-20-02';
+$start = strtotime($day);
+$wday = date('w', $start);
+$week = date('w', $start);
+if ($wday === 0) {
+ $wday = 6;
+} else {
+ $wday--;
+}
+
+?>
+
+
+ |
+M |
+T |
+W |
+T |
+F |
+S |
+S |
+
+
+
+
+
+';
+}
+
+foreach ($this->summary as $row) {
+ $wday--;
+ if ($wday < 0) {
+ $wday = 6;
+ $week--;
+ echo '
';
+
+ }
+ echo '';
+ foreach ($show as $col) {
+ echo '';
+ }
+ echo ' | ';
+}
+
+?>
+
+
+
diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/StateHistorySummaryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/StateHistorySummaryQuery.php
new file mode 100644
index 000000000..a2349e336
--- /dev/null
+++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/StateHistorySummaryQuery.php
@@ -0,0 +1,42 @@
+ array(
+ 'day' => 'DATE(sh.state_time)',
+ 'cnt_events' => 'COUNT(*)',
+ 'cnt_up' => 'SUM(CASE WHEN sho.objecttype_id = 1 AND sh.state = 0 THEN 1 ELSE 0 END)',
+ 'cnt_down_hard' => 'SUM(CASE WHEN sho.objecttype_id = 1 AND sh.state = 1 AND state_type = 1 THEN 1 ELSE 0 END)',
+ 'cnt_down' => 'SUM(CASE WHEN sho.objecttype_id = 1 AND sh.state = 1 THEN 1 ELSE 0 END)',
+ 'cnt_unreachable_hard' => 'SUM(CASE WHEN sho.objecttype_id = 1 AND sh.state = 2 AND state_type = 1 THEN 1 ELSE 0 END)',
+ 'cnt_unreachable' => 'SUM(CASE WHEN sho.objecttype_id = 1 AND sh.state = 2 THEN 1 ELSE 0 END)',
+ 'cnt_unknown_hard' => 'SUM(CASE WHEN sho.objecttype_id = 2 AND sh.state = 3 AND state_type = 1 THEN 1 ELSE 0 END)',
+ 'cnt_unknown' => 'SUM(CASE WHEN sho.objecttype_id = 2 AND sh.state = 3 THEN 1 ELSE 0 END)',
+ 'cnt_unknown_hard' => 'SUM(CASE WHEN sho.objecttype_id = 2 AND sh.state = 3 AND state_type = 1 THEN 1 ELSE 0 END)',
+ 'cnt_critical' => 'SUM(CASE WHEN sho.objecttype_id = 2 AND sh.state = 2 THEN 1 ELSE 0 END)',
+ 'cnt_critical_hard' => 'SUM(CASE WHEN sho.objecttype_id = 2 AND sh.state = 2 AND state_type = 1 THEN 1 ELSE 0 END)',
+ 'cnt_warning' => 'SUM(CASE WHEN sho.objecttype_id = 2 AND sh.state = 1 THEN 1 ELSE 0 END)',
+ 'cnt_warning_hard' => 'SUM(CASE WHEN sho.objecttype_id = 2 AND sh.state = 1 AND state_type = 1 THEN 1 ELSE 0 END)',
+ 'cnt_ok' => 'SUM(CASE WHEN sho.objecttype_id = 2 AND sh.state = 0 THEN 1 ELSE 0 END)',
+ )
+ );
+
+ protected function joinBaseTables()
+ {
+ $this->baseQuery = $this->db->select()->from(
+ array('sh' => $this->prefix . 'statehistory'),
+ array()
+ )->join(
+ array('sho' => $this->prefix . 'objects'),
+ 'sh.object_id = sho.object_id AND sho.is_active = 1',
+ array()
+ )->where('sh.state_time >= ?', '2013-11-20 00:00:00')
+ ->where('sh.state_type = 1')
+ ->where('sh.state = 2')
+ ->group('DATE(sh.state_time)');
+ $this->joinedVirtualTables = array('statehistory' => true);
+ }
+}
diff --git a/modules/monitoring/library/Monitoring/DataView/StateHistorySummary.php b/modules/monitoring/library/Monitoring/DataView/StateHistorySummary.php
new file mode 100644
index 000000000..0f2a27837
--- /dev/null
+++ b/modules/monitoring/library/Monitoring/DataView/StateHistorySummary.php
@@ -0,0 +1,68 @@
+
+ * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
+ * @author Icinga Development Team
+ *
+ */
+// {{{ICINGA_LICENSE_HEADER}}}
+
+namespace Icinga\Module\Monitoring\DataView;
+
+class StateHistorySummary extends DataView
+{
+ /**
+ * Retrieve columns provided by this view
+ *
+ * @return array
+ */
+ public function getColumns()
+ {
+ return array(
+ 'day',
+ 'cnt_events',
+ 'cnt_up',
+ 'cnt_down_hard',
+ 'cnt_down',
+ 'cnt_unreachable_hard',
+ 'cnt_unreachable',
+ 'cnt_unknown_hard',
+ 'cnt_unknown',
+ 'cnt_unknown_hard',
+ 'cnt_critical',
+ 'cnt_critical_hard',
+ 'cnt_warning',
+ 'cnt_warning_hard',
+ 'cnt_ok',
+ );
+ }
+
+ public function getSortRules()
+ {
+ return array(
+ 'day' => array(
+ 'order' => self::SORT_DESC
+ )
+ );
+ }
+}