Skip to content

Commit

Permalink
* [FIX] Fixed regular expression handling. Related #22
Browse files Browse the repository at this point in the history
  • Loading branch information
nuxsmin authored and nuxsmin committed Apr 11, 2017
1 parent 402fdf8 commit 19bf639
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 25 deletions.
4 changes: 2 additions & 2 deletions css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion css/styles.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 35 additions & 22 deletions inc/SMD/Core/sysMonDash.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -390,31 +403,31 @@ private function getHtmlItems(EventInterface $item, $newItem = false, $newItemUp
$line = '<tr class="item-data ' . $trClass . '" title="' . sprintf(Language::t('Estado %s desde %s'), $statusName, $lastStateTime) . '">' . PHP_EOL;
$line .= '<td class="center">' . $statusName . '</td>';

if (Config::getConfig()->isColLastcheck()) {
if ($this->Config->isColLastcheck()) {
$line .= '<td title="' . sprintf('%s : %s', Language::t('Último check'), $lastCheckDuration) . '" class="center ' . $tdClass . '">' . $lastStateDuration . '</td>' . PHP_EOL;
}

if (Config::getConfig()->isColHost()) {
if ($this->Config->isColHost()) {
if (null !== $link) {
$line .= '<td><a href="' . $link . '" target="blank" title="' . $hostname . '">' . $hostAlias . '</a></td>' . PHP_EOL;
} else {
$line .= '<td>' . $hostAlias . '</td>' . PHP_EOL;
}
}

if (Config::getConfig()->isColStatusInfo()) {
if ($this->Config->isColStatusInfo()) {
if ($item->getFilterStatus() === '' || $newItem) {
$line .= '<td class="statusinfo">' . $item->getPluginOutput() . '</td>' . PHP_EOL;
} else {
$line .= '<td class="statusinfo">' . $item->getPluginOutput() . '<br>Filter: ' . $item->getFilterStatus() . '</td>' . PHP_EOL;
}
}

if (Config::getConfig()->isColService()) {
if ($this->Config->isColService()) {
$line .= '<td class="center">' . $serviceDesc . '</td>' . PHP_EOL;
}

if (Config::getConfig()->isColBackend()) {
if ($this->Config->isColBackend()) {
$line .= '<td class="center">' . $item->getBackendAlias() . '</td>' . PHP_EOL;
}

Expand Down

0 comments on commit 19bf639

Please sign in to comment.