-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from dachcom-digital/log
refactor checks
- Loading branch information
Showing
12 changed files
with
193 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
monitoring.fetch: | ||
path: /monitoring/fetch | ||
defaults: { _controller: MonitoringBundle\Controller\WatchDogController::fetchAction } | ||
controller: MonitoringBundle\Controller\CheckController::fetchAction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace MonitoringBundle\Check; | ||
|
||
use Pimcore\Extension\Document\Areabrick\AreabrickManager; | ||
|
||
class BricksCheck implements CheckInterface | ||
{ | ||
public function __construct(protected AreabrickManager $areaBrickManager) | ||
{ | ||
} | ||
|
||
public function getCheckReportIdentifier(): string | ||
{ | ||
return 'bricks'; | ||
} | ||
|
||
public function getCheckReport(): array | ||
{ | ||
$bricks = []; | ||
|
||
foreach ($this->areaBrickManager->getBricks() as $brickName => $brickInfo) { | ||
$brick = $this->areaBrickManager->getBrick($brickName); | ||
|
||
$desc = $brick->getDescription(); | ||
if (empty($desc) && $newDesc = $brick->getId()) { | ||
$desc = $newDesc; | ||
} | ||
|
||
$bricks[$brickName] = [ | ||
'description' => $desc, | ||
'name' => $brick->getName(), | ||
'isEnabled' => true, | ||
]; | ||
} | ||
|
||
return $bricks; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace MonitoringBundle\Check; | ||
|
||
class Check | ||
{ | ||
public function __construct(protected iterable $checks) | ||
{ | ||
} | ||
|
||
public function dispatchCheck(): array | ||
{ | ||
$checks = []; | ||
/** @var CheckInterface $check */ | ||
foreach ($this->checks as $check) { | ||
$checks[$check->getCheckReportIdentifier()] = $check->getCheckReport(); | ||
} | ||
|
||
return $checks; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace MonitoringBundle\Check; | ||
|
||
interface CheckInterface | ||
{ | ||
public function getCheckReportIdentifier(): string; | ||
|
||
public function getCheckReport(): array; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace MonitoringBundle\Check; | ||
|
||
use Pimcore\Version; | ||
|
||
class CoreCheck implements CheckInterface | ||
{ | ||
public function getCheckReportIdentifier(): string | ||
{ | ||
return 'core'; | ||
} | ||
|
||
public function getCheckReport(): array | ||
{ | ||
return [ | ||
'version' => Version::getVersion(), | ||
'revision' => Version::getRevision() | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace MonitoringBundle\Check; | ||
|
||
use Pimcore\Extension\Bundle\PimcoreBundleManager; | ||
|
||
class ExtensionCheck implements CheckInterface | ||
{ | ||
public function __construct(protected PimcoreBundleManager $pimcoreBundleManager) | ||
{ | ||
} | ||
|
||
public function getCheckReportIdentifier(): string | ||
{ | ||
return 'extensions'; | ||
} | ||
|
||
public function getCheckReport(): array | ||
{ | ||
$extensions = []; | ||
|
||
foreach ($this->pimcoreBundleManager->getActiveBundles() as $bundle) { | ||
$extensions[] = [ | ||
'title' => $bundle->getNiceName(), | ||
'version' => $bundle->getVersion(), | ||
'identifier' => $this->pimcoreBundleManager->getBundleIdentifier($bundle), | ||
'isInstalled' => $this->pimcoreBundleManager->isInstalled($bundle), | ||
]; | ||
} | ||
|
||
return $extensions; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace MonitoringBundle\Check; | ||
|
||
use MonitoringBundle\Check\CheckInterface; | ||
use Pimcore\Model\User; | ||
use Pimcore\Version; | ||
|
||
class UserCheck implements CheckInterface | ||
{ | ||
public function getCheckReportIdentifier(): string | ||
{ | ||
return 'users'; | ||
} | ||
|
||
public function getCheckReport(): array | ||
{ | ||
$userListing = new User\Listing(); | ||
|
||
$users = []; | ||
foreach ($userListing->getUsers() as $user) { | ||
|
||
if (!$user instanceof User) { | ||
continue; | ||
} | ||
|
||
$lastLogin = 0; | ||
|
||
try { | ||
$lastLogin = $user->getLastLogin(); | ||
} catch (\Throwable) { | ||
// fail silently: "User::$lastLogin must not be accessed before initialization" | ||
} | ||
|
||
$users[] = [ | ||
'name' => $user->getName(), | ||
'active' => $user->isActive(), | ||
'is_admin' => $user->isAdmin(), | ||
'last_login' => $lastLogin, | ||
]; | ||
} | ||
|
||
return $users; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.