szepeviktor / magento-critical-site-health
Declarative YAML-based Magento 2 site health checks for n98-magerun2
Package info
github.com/szepeviktor/magento-critical-site-health
Type:magento2-module
pkg:composer/szepeviktor/magento-critical-site-health
Requires
- php: ^7.4 || ^8.1
- magento/framework: ^103.0 || ^104.0
- symfony/yaml: ^5.4 || ^6.4
Requires (Dev)
- n98/magerun2: ^7.5
- phpstan/phpstan: ^1.12
README
Declarative YAML-based monitor command for Magento 2, packaged as a Magento module and exposed as an n98-magerun2 custom command.
n98-magerun2 site-health:check dev/tests/ok.yaml
Scope
The command is read-only. It collects warnings, exits with a non-zero status when any warning is found, and exits successfully when all checks pass.
Supported check types:
configenvstoremoduleclasscacheindexerdb_queryshellobject_methodeval
Installation
Install the package into a Magento 2 project. n98-magerun2 discovers the bundled n98-magerun2.yaml file from vendor/ and registers the custom command.
Command
n98-magerun2 site-health:check <yaml-file>
The command fails fast if Magento cannot be detected or bootstrapped.
Configuration
Example:
config: web/secure/use_in_frontend: "1" - path: web/unsecure/base_url scope: stores scope_code: default expected: "https://example.com/" env: crypt/key: "change-me" store: default.is_active: true default.config:web/secure/base_url: "https://example.com/" module: Magento_Catalog: true Vendor_DisabledModule: false class: Magento\Catalog\Api\ProductRepositoryInterface: true cache: config: true full_page: true indexer: catalog_product_price: valid db_query: - sql: "SELECT COUNT(*) FROM core_config_data WHERE path = 'web/secure/base_url'" expected: "1" - sql: "SELECT value FROM core_config_data WHERE path = 'web/secure/base_url' LIMIT 1" expected: "https://example.com/" shell: - command: "test -f app/etc/env.php" - command: "test -d pub/static" expected_exit_code: 0 object_method: Magento\Framework\App\DeploymentConfig::getConfigData: true eval: - "count($storeManager->getStores()) > 0" - "$deploymentConfig->get('install/date') !== null"
Notes
configvalues are read viaScopeConfigInterface.envvalues are read fromDeploymentConfig.storesupportsstore_code.fieldandstore_code.config:path/to/value.object_methodresolves Magento services via the object manager for non-static methods.evalexpressions must returntrue. Parse errors and runtime exceptions are reported as warnings.
Magento Examples
config: web/secure/use_in_frontend: "1" web/seo/use_rewrites: "1" - path: design/theme/theme_id scope: stores scope_code: default expected: "3" env: crypt/key: "your-crypt-key" db/connection/default/host: "mysql" store: default.is_active: true default.base_url: "https://example.com/" default.config:web/secure/base_url: "https://example.com/" module: Magento_Config: true Magento_Indexer: true class: Magento\Framework\App\DeploymentConfig: true Magento\Store\Api\StoreRepositoryInterface: true cache: config: true layout: true full_page: true indexer: catalogrule_rule: valid catalog_product_price: valid catalogsearch_fulltext: valid db_query: - sql: "SELECT COUNT(*) FROM core_config_data WHERE path = 'web/secure/base_url'" expected: "1" - sql: "SELECT value FROM core_config_data WHERE path = 'design/theme/theme_id' LIMIT 1" expected: "3" shell: - command: "test -f app/etc/env.php" - command: "test -d generated/code" object_method: Magento\Framework\App\DeploymentConfig::getConfigData: true eval: - "count($storeManager->getStores()) >= 1" - "$scopeConfig->getValue('web/seo/use_rewrites') === '1'" - "$deploymentConfig->get('crypt/key') !== null" - "$moduleManager->isEnabled('Magento_Catalog')" - "$indexerRegistry->get('catalog_product_price')->getStatus() === 'valid'"