From 19bf6390462816282ca297f0026ebf1b327930a1 Mon Sep 17 00:00:00 2001 From: nuxsmin Date: Tue, 11 Apr 2017 11:03:11 +0200 Subject: [PATCH] * [FIX] Fixed regular expression handling. Related #22 --- css/styles.css | 4 +-- css/styles.min.css | 2 +- inc/SMD/Core/sysMonDash.class.php | 57 +++++++++++++++++++------------ 3 files changed, 38 insertions(+), 25 deletions(-) diff --git a/css/styles.css b/css/styles.css index 16fbe80..a87278b 100644 --- a/css/styles.css +++ b/css/styles.css @@ -96,8 +96,8 @@ tr.item-data > td, thead > th { background-color: #5c6bc0; } -.critical, .warning, .unknown, .downtime, .acknowledged, .new-up, .average, .information, -.critical a, .warning a, .unknown a, .downtime a, .acknowledged a, .new-up a { +.critical, .warning, .unknown, .downtime, .acknowledged, .new-up, .up, .average, .information, +.critical a, .warning a, .unknown a, .downtime a, .acknowledged a, .new-up a, .up a { color: #fff; font-size: 1em; font-weight: bold; diff --git a/css/styles.min.css b/css/styles.min.css index 46745df..4e4e4af 100644 --- a/css/styles.min.css +++ b/css/styles.min.css @@ -1 +1 @@ -@font-face{font-family:'noto_sansregular';src:url('fonts/NotoSans-Regular-webfont.eot');src:url('fonts/NotoSans-Regular-webfont.eot?#iefix') format('embedded-opentype'),url('fonts/NotoSans-Regular-webfont.woff') format('woff'),url('fonts/NotoSans-Regular-webfont.svg#noto_sansregular') format('svg');font-weight:normal;font-style:normal}*{margin:0;padding:0;font-family:noto_sansregular,Arial,helvetica,verdana,tahoma,"sans serif",serif}body{line-height:1.3em;font-size:1.1em;overflow-x:hidden;background-color:#f5f5f5}table{border-collapse:collapse;width:100%}tr.item-data>td,thead>th{padding:.3em 1em;border-bottom:1px solid #fff}.head{background:#d9d9d9;color:#555;text-align:center}.head th{padding:.2em 10px}.new{font-weight:bold;background-color:#ff0;color:#333}.up a,.new a{color:#999}.up,.new-up{background-color:#66bb6a}.critical{background-color:#ef5350}.warning{background-color:#ffa726}.unknown{background:#7e57c2}.downtime{background:#42a5f5}.acknowledged{background:#78909c}.flapping{background:#d4e157;color:#555}.flapping,.flapping a{color:#555}.average{background-color:#fb8c00}.high{background-color:#ef9a9a}.information{background-color:#5c6bc0}.critical,.warning,.unknown,.downtime,.acknowledged,.new-up,.average,.information,.critical a,.warning a,.unknown a,.downtime a,.acknowledged a,.new-up a{color:#fff;font-size:1em;font-weight:bold}.statusinfo{font-size:.7em !important}.a-nodecorate{text-decoration:none}#total{font-size:.7em;color:#777;text-align:right;padding:.3em 1em}#total a{color:#777}#loading{background:transparent url(../imgs/throbber.gif) no-repeat center center;width:214px;height:13px;display:inline-block}#refreshing{color:gray}#refreshing_countdown{display:inline-block;width:15px;text-align:center}#refreshing,#loading{line-height:50px;font-size:1em}#icinga_header{border:0;overflow:hidden;height:80px;width:100%}#monitor-data{margin:1em 0;width:100%}footer{text-align:right;color:#c9c9c9;font-size:.8em;margin-bottom:2em;border-top:1px solid #d9d9d9;padding:.5em 0}footer a,footer a:visited{color:#c9c9c9}footer #project{margin-right:2em}footer #project a{vertical-align:baseline}.action-link,.action-link img{font-size:10px;vertical-align:middle;padding:0}.action-link img{margin:0 1em;width:20px;height:20px}#logo{padding:1em;text-align:left;background-color:#555;-webkit-box-shadow:0 3px 5px 0 rgba(50,50,50,0.5);-moz-box-shadow:0 3px 5px 0 rgba(50,50,50,0.5);box-shadow:0 3px 5px 0 rgba(50,50,50,0.5)}#logo img{border:0}#hora{position:absolute;top:0;left:0;width:100%;margin:0 auto;text-align:center;color:#fff;font-size:1.3em;line-height:1.5em;display:inline-block}#hora h1{font-size:1.2em}#titulo{position:absolute;top:0;right:1em;text-align:right;color:#fff}#titulo h1,#titulo h2{font-size:1.2em}#nomessages{width:30%;margin:1em auto;color:green;text-align:center;background-color:#f2f2f2;padding:1em;border-radius:5px}#nomessages.full{width:90%;padding:.5em}#nomessages.error{border-top:1px solid #f44336;border-bottom:1px solid #f44336;color:#f44336;background-color:#ffebee;border-radius:0}div#nagvis-view{margin:0;margin-left:auto;margin-right:auto;width:1280px;height:500px;border:1px solid #d9d9d9;border-radius:5px;background-color:#fff;overflow-x:hidden;overflow-y:hidden;margin-bottom:2em}div#nagvis-view>iframe{width:100%;height:100%;border:0;overflow-x:hidden;overflow-y:hidden}#tblDowntime{margin-top:1em;font-size:14px}#tblDowntime thead.head{background-color:#dfdfdf;color:#777;text-align:center}#tblDowntime tbody tr{color:#fff;background-color:#42a5f5;text-align:center}div.title{width:100%;margin:0 auto;color:#777;text-align:center;border-top:1px solid #d9d9d9;padding:.5em 0}.center{text-align:center}footer #updates{display:inline-block;margin-right:.5em}footer #updates i{color:#26a69a;font-size:1.5em} \ No newline at end of file +@font-face{font-family:'noto_sansregular';src:url('fonts/NotoSans-Regular-webfont.eot');src:url('fonts/NotoSans-Regular-webfont.eot?#iefix') format('embedded-opentype'),url('fonts/NotoSans-Regular-webfont.woff') format('woff'),url('fonts/NotoSans-Regular-webfont.svg#noto_sansregular') format('svg');font-weight:normal;font-style:normal}*{margin:0;padding:0;font-family:noto_sansregular,Arial,helvetica,verdana,tahoma,"sans serif",serif}body{line-height:1.3em;font-size:1.1em;overflow-x:hidden;background-color:#f5f5f5}table{border-collapse:collapse;width:100%}tr.item-data>td,thead>th{padding:.3em 1em;border-bottom:1px solid #fff}.head{background:#d9d9d9;color:#555;text-align:center}.head th{padding:.2em 10px}.new{font-weight:bold;background-color:#ff0;color:#333}.up a,.new a{color:#999}.up,.new-up{background-color:#66bb6a}.critical{background-color:#ef5350}.warning{background-color:#ffa726}.unknown{background:#7e57c2}.downtime{background:#42a5f5}.acknowledged{background:#78909c}.flapping{background:#d4e157;color:#555}.flapping,.flapping a{color:#555}.average{background-color:#fb8c00}.high{background-color:#ef9a9a}.information{background-color:#5c6bc0}.critical,.warning,.unknown,.downtime,.acknowledged,.new-up,.up,.average,.information,.critical a,.warning a,.unknown a,.downtime a,.acknowledged a,.new-up a,.up a{color:#fff;font-size:1em;font-weight:bold}.statusinfo{font-size:.7em!important}.a-nodecorate{text-decoration:none}#total{font-size:.7em;color:#777;text-align:right;padding:.3em 1em}#total a{color:#777}#loading{background:transparent url(../imgs/throbber.gif) no-repeat center center;width:214px;height:13px;display:inline-block}#refreshing{color:gray}#refreshing_countdown{display:inline-block;width:15px;text-align:center}#refreshing,#loading{line-height:50px;font-size:1em}#icinga_header{border:0;overflow:hidden;height:80px;width:100%}#monitor-data{margin:1em 0;width:100%}footer{text-align:right;color:#c9c9c9;font-size:.8em;margin-bottom:2em;border-top:1px solid #d9d9d9;padding:.5em 0}footer a,footer a:visited{color:#c9c9c9}footer #project{margin-right:2em}footer #project a{vertical-align:baseline}.action-link,.action-link img{font-size:10px;vertical-align:middle;padding:0}.action-link img{margin:0 1em;width:20px;height:20px}#logo{padding:1em;text-align:left;background-color:#555;-webkit-box-shadow:0 3px 5px 0 rgba(50,50,50,0.5);-moz-box-shadow:0 3px 5px 0 rgba(50,50,50,0.5);box-shadow:0 3px 5px 0 rgba(50,50,50,0.5)}#logo img{border:0}#hora{position:absolute;top:0;left:0;width:100%;margin:0 auto;text-align:center;color:#fff;font-size:1.3em;line-height:1.5em;display:inline-block}#hora h1{font-size:1.2em}#titulo{position:absolute;top:0;right:1em;text-align:right;color:#fff}#titulo h1,#titulo h2{font-size:1.2em}#nomessages{width:30%;margin:1em auto;color:green;text-align:center;background-color:#f2f2f2;padding:1em;border-radius:5px}#nomessages.full{width:90%;padding:.5em}#nomessages.error{border-top:1px solid #f44336;border-bottom:1px solid #f44336;color:#f44336;background-color:#ffebee;border-radius:0}div#nagvis-view{margin:0;margin-left:auto;margin-right:auto;width:1280px;height:500px;border:1px solid #d9d9d9;border-radius:5px;background-color:#fff;overflow-x:hidden;overflow-y:hidden;margin-bottom:2em}div#nagvis-view>iframe{width:100%;height:100%;border:0;overflow-x:hidden;overflow-y:hidden}#tblDowntime{margin-top:1em;font-size:14px}#tblDowntime thead.head{background-color:#dfdfdf;color:#777;text-align:center}#tblDowntime tbody tr{color:#fff;background-color:#42a5f5;text-align:center}div.title{width:100%;margin:0 auto;color:#777;text-align:center;border-top:1px solid #d9d9d9;padding:.5em 0}.center{text-align:center}footer #updates{display:inline-block;margin-right:.5em}footer #updates i{color:#26a69a;font-size:1.5em} \ No newline at end of file diff --git a/inc/SMD/Core/sysMonDash.class.php b/inc/SMD/Core/sysMonDash.class.php index 8dfc4fe..00a0c72 100644 --- a/inc/SMD/Core/sysMonDash.class.php +++ b/inc/SMD/Core/sysMonDash.class.php @@ -74,6 +74,18 @@ class sysMonDash * @var array */ private $errors = array(); + /** + * @var ConfigData + */ + private $Config; + + /** + * sysMonDash constructor. + */ + public function __construct() + { + $this->Config = Config::getConfig(); + } /** * Función para obtener los eventos de los backends y devolver los avisos en formato HTML @@ -103,7 +115,7 @@ public function getItems() // Ordenar los rawItems por tiempo de último cambio Util::arraySortByProperty($rawItems, 'lastHardStateChange'); - $newItemTime = Config::getConfig()->getNewItemTime(); + $newItemTime = $this->Config->getNewItemTime(); // Recorremos el array y mostramos los elementos foreach ($rawItems as $item) { @@ -189,21 +201,23 @@ public function getBackends() */ private function filterItems(EventInterface $item) { - if ($this->getFilterHosts($item) === false || $this->getFilterServices($item) === false) { - return ($item->isAcknowledged() - || $this->getFilterIsFlapping($item) - || $this->getFilterState($item) - || $this->getFilterUnreachable($item) - || $this->getFilterScheduled($item) - || $this->getFilterLevel($item) - ); + if (($this->Config->getRegexHostShow() !== '' && $this->getFilterHosts($item) === false) + || ($this->Config->getRegexServiceNoShow() !== '' && $this->getFilterServices($item) === false) + ) { + return false; } - return true; + return ($item->isAcknowledged() + || $this->getFilterIsFlapping($item) + || $this->getFilterState($item) + || $this->getFilterUnreachable($item) + || $this->getFilterScheduled($item) + || $this->getFilterLevel($item) + ); } /** - * Comprobar si el host se encuentra en la expresión regular + * Comprobar si el host se encuentra en la expresión regular o en elementos críticos * * @param EventInterface $item * @return bool @@ -212,8 +226,8 @@ private function getFilterHosts(EventInterface $item) { $hostname = $item->getHostDisplayName() ?: $item->getDisplayName(); - if (!preg_match('#' . Config::getConfig()->getRegexHostShow() . '#i', $hostname) - && !in_array($hostname, Config::getConfig()->getCriticalItems()) + if (!preg_match('#' . $this->Config->getRegexHostShow() . '#i', $hostname) + && !in_array($hostname, $this->Config->getCriticalItems()) ) { $item->setFilterStatus('No Regex Host & No Critical'); return true; @@ -231,9 +245,8 @@ private function getFilterHosts(EventInterface $item) private function getFilterServices(EventInterface $item) { - if (Config::getConfig()->getRegexServiceNoShow() !== '' - && preg_match('#' . Config::getConfig()->getRegexServiceNoShow() . '#i', $item->getDisplayName()) - && !in_array($item->getDisplayName(), Config::getConfig()->getCriticalItems()) + if (preg_match('#' . $this->Config->getRegexServiceNoShow() . '#i', $item->getDisplayName()) + && !in_array($item->getDisplayName(), $this->Config->getCriticalItems()) ) { $item->setFilterStatus('Regex Service & No Critical'); return true; @@ -307,7 +320,7 @@ private function getFilterUnreachable(EventInterface $item) private function getFilterScheduled(EventInterface $item) { if ($item->getScheduledDowntimeDepth() >= 1 || $item->getHostScheduledDowntimeDepth() >= 1) { - if (!Config::getConfig()->isShowScheduled()) { + if (!$this->Config->isShowScheduled()) { $item->setFilterStatus('Scheduled & Show'); return true; } @@ -390,11 +403,11 @@ private function getHtmlItems(EventInterface $item, $newItem = false, $newItemUp $line = '' . PHP_EOL; $line .= '' . $statusName . ''; - if (Config::getConfig()->isColLastcheck()) { + if ($this->Config->isColLastcheck()) { $line .= '' . $lastStateDuration . '' . PHP_EOL; } - if (Config::getConfig()->isColHost()) { + if ($this->Config->isColHost()) { if (null !== $link) { $line .= '' . $hostAlias . '' . PHP_EOL; } else { @@ -402,7 +415,7 @@ private function getHtmlItems(EventInterface $item, $newItem = false, $newItemUp } } - if (Config::getConfig()->isColStatusInfo()) { + if ($this->Config->isColStatusInfo()) { if ($item->getFilterStatus() === '' || $newItem) { $line .= '' . $item->getPluginOutput() . '' . PHP_EOL; } else { @@ -410,11 +423,11 @@ private function getHtmlItems(EventInterface $item, $newItem = false, $newItemUp } } - if (Config::getConfig()->isColService()) { + if ($this->Config->isColService()) { $line .= '' . $serviceDesc . '' . PHP_EOL; } - if (Config::getConfig()->isColBackend()) { + if ($this->Config->isColBackend()) { $line .= '' . $item->getBackendAlias() . '' . PHP_EOL; }