From 95a6d0666a55f2e734658b3ee2db9496661bead8 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 29 Oct 2018 09:59:26 -0400 Subject: [PATCH] Improve behaviour and reduce extra logging when db goes away --- web/includes/Event.php | 8 +++--- web/includes/functions.php | 31 ++++++++++++------------ web/skins/classic/includes/functions.php | 2 +- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/web/includes/Event.php b/web/includes/Event.php index 1852bb8b0..fb7af931e 100644 --- a/web/includes/Event.php +++ b/web/includes/Event.php @@ -546,9 +546,11 @@ class Event { } $filters = array(); $result = dbQuery($sql, $values); - $results = $result->fetchALL(); - foreach ( $results as $row ) { - $filters[] = new Event($row); + if ( $result ) { + $results = $result->fetchALL(); + foreach ( $results as $row ) { + $filters[] = new Event($row); + } } return $filters; } diff --git a/web/includes/functions.php b/web/includes/functions.php index 76117ad5a..29f627722 100644 --- a/web/includes/functions.php +++ b/web/includes/functions.php @@ -1909,23 +1909,24 @@ function logState() { # This is an expensive request, as it has to hit every row of the Logs Table $sql = 'SELECT Level, COUNT(Level) AS LevelCount FROM Logs WHERE Level < '.Logger::INFO.' AND TimeKey > unix_timestamp(now() - interval '.ZM_LOG_CHECK_PERIOD.' second) GROUP BY Level ORDER BY Level ASC'; - $counts = dbFetchAll( $sql ); - - foreach ( $counts as $count ) { - if ( $count['Level'] <= Logger::PANIC ) - $count['Level'] = Logger::FATAL; - if ( !($levelCount = $levelCounts[$count['Level']]) ) { - Error( "Unexpected Log level ".$count['Level'] ); - next; - } - if ( $levelCount[1] && $count['LevelCount'] >= $levelCount[1] ) { - $state = 'alarm'; - break; - } elseif ( $levelCount[0] && $count['LevelCount'] >= $levelCount[0] ) { - $state = 'alert'; + $counts = dbFetchAll($sql); + if ( $counts ) { + foreach ( $counts as $count ) { + if ( $count['Level'] <= Logger::PANIC ) + $count['Level'] = Logger::FATAL; + if ( !($levelCount = $levelCounts[$count['Level']]) ) { + Error('Unexpected Log level '.$count['Level']); + next; + } + if ( $levelCount[1] && $count['LevelCount'] >= $levelCount[1] ) { + $state = 'alarm'; + break; + } elseif ( $levelCount[0] && $count['LevelCount'] >= $levelCount[0] ) { + $state = 'alert'; + } } } - return( $state ); + return $state; } function isVector ( &$array ) { diff --git a/web/skins/classic/includes/functions.php b/web/skins/classic/includes/functions.php index ceb12d621..7847e37c7 100644 --- a/web/skins/classic/includes/functions.php +++ b/web/skins/classic/includes/functions.php @@ -345,7 +345,7 @@ if ($reload == 'reload') ob_start(); 90 ? ' class="warning"' : '' ).'>'.translate('DB').':'.$connections.'/'.$max_connections.''; ?>
  • :