Version Notes
HeartBeat Released
Download this release
Release Info
Developer | Gorilla Team |
Extension | heartbeat-extension-for-magento |
Version | 0.0.1 |
Comparing to | |
See all releases |
Version 0.0.1
- app/code/local/Gorilla/Heartbeat/Helper/Data.php +9 -0
- app/code/local/Gorilla/Heartbeat/Model/Tests/Api.php +117 -0
- app/code/local/Gorilla/Heartbeat/Model/Tests/Catalog.php +44 -0
- app/code/local/Gorilla/Heartbeat/Model/Tests/Database.php +51 -0
- app/code/local/Gorilla/Heartbeat/Model/Tests/Filesystem.php +62 -0
- app/code/local/Gorilla/Heartbeat/Model/Tests/Flattable.php +72 -0
- app/code/local/Gorilla/Heartbeat/Model/Tests/Index.php +47 -0
- app/code/local/Gorilla/Heartbeat/Model/Tests/Log.php +47 -0
- app/code/local/Gorilla/Heartbeat/Model/TestsCollector.php +109 -0
- app/code/local/Gorilla/Heartbeat/Model/TestsInterface.php +27 -0
- app/code/local/Gorilla/Heartbeat/controllers/IndexController.php +49 -0
- app/code/local/Gorilla/Heartbeat/etc/adminhtml.xml +49 -0
- app/code/local/Gorilla/Heartbeat/etc/config.xml +38 -0
- app/code/local/Gorilla/Heartbeat/etc/system.xml +42 -0
- app/etc/modules/Gorilla_Heartbeat.xml +8 -0
- package.xml +21 -0
app/code/local/Gorilla/Heartbeat/Helper/Data.php
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Data helper
|
4 |
+
* @package
|
5 |
+
*/
|
6 |
+
class Gorilla_Heartbeat_Helper_Data extends Mage_Core_Helper_Abstract
|
7 |
+
{
|
8 |
+
|
9 |
+
}
|
app/code/local/Gorilla/Heartbeat/Model/Tests/Api.php
ADDED
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Api test model.
|
4 |
+
* @package
|
5 |
+
*/
|
6 |
+
class Gorilla_Heartbeat_Model_Tests_Api
|
7 |
+
extends Mage_Core_Model_Abstract
|
8 |
+
implements Gorilla_Heartbeat_Model_TestsInterface
|
9 |
+
{
|
10 |
+
/**
|
11 |
+
* Returns true if test enabled
|
12 |
+
* @return boolean
|
13 |
+
*/
|
14 |
+
public function isEnabled()
|
15 |
+
{
|
16 |
+
return true;
|
17 |
+
}
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Returns true if test passed
|
21 |
+
* @return boolean
|
22 |
+
*/
|
23 |
+
public function isPassed()
|
24 |
+
{
|
25 |
+
foreach ($this->_collectActiveUrls() as $url) {
|
26 |
+
if (! $this->_request($url) && strstr($url, 'http')) {
|
27 |
+
return false;
|
28 |
+
}
|
29 |
+
}
|
30 |
+
|
31 |
+
return true;
|
32 |
+
}
|
33 |
+
|
34 |
+
/**
|
35 |
+
* Returns result of the rest
|
36 |
+
* @return mixed
|
37 |
+
*/
|
38 |
+
public function getResult()
|
39 |
+
{
|
40 |
+
return true;
|
41 |
+
}
|
42 |
+
|
43 |
+
/**
|
44 |
+
* Making request to the $url
|
45 |
+
* @param string $url
|
46 |
+
* @param string $request
|
47 |
+
* @return string
|
48 |
+
*/
|
49 |
+
private function _request($url, $request = '')
|
50 |
+
{
|
51 |
+
$ch = curl_init();
|
52 |
+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
53 |
+
curl_setopt($ch, CURLOPT_URL, $url);
|
54 |
+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
|
55 |
+
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
|
56 |
+
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
|
57 |
+
$responseBody = curl_exec($ch);
|
58 |
+
curl_close($ch);
|
59 |
+
|
60 |
+
return $responseBody;
|
61 |
+
}
|
62 |
+
|
63 |
+
/**
|
64 |
+
* Collecting active magento third-party integrations. Returns array of urls.
|
65 |
+
* @return array
|
66 |
+
*/
|
67 |
+
private function _collectActiveUrls()
|
68 |
+
{
|
69 |
+
$urls = array();
|
70 |
+
|
71 |
+
if (Mage::getStoreConfig('carriers/ups/active')) {
|
72 |
+
if (Mage::getStoreConfig('carriers/ups/type') == 'UPS_XML') {
|
73 |
+
$urls[] = Mage::getStoreConfig('carriers/ups/gateway_xml_url');
|
74 |
+
}
|
75 |
+
if (Mage::getStoreConfig('carriers/ups/type') == 'UPS') {
|
76 |
+
$urls[] = Mage::getStoreConfig('carriers/ups/gateway_url');
|
77 |
+
}
|
78 |
+
$urls[] = Mage::getStoreConfig('carriers/ups/tracking_xml_url');
|
79 |
+
|
80 |
+
}
|
81 |
+
|
82 |
+
if (Mage::getStoreConfig('carriers/usps/active')) {
|
83 |
+
$urls[] = Mage::getStoreConfig('carriers/usps/gateway_url');
|
84 |
+
$urls[] = Mage::getStoreConfig('carriers/usps/gateway_secure_url');
|
85 |
+
|
86 |
+
}
|
87 |
+
|
88 |
+
if (Mage::getStoreConfig('carriers/fedex/active')) {
|
89 |
+
$urls[] = 'https://wsbeta.fedex.com:443/web-services/rate';
|
90 |
+
$urls[] = 'https://ws.fedex.com:443/web-services/rate';
|
91 |
+
|
92 |
+
}
|
93 |
+
|
94 |
+
if (Mage::getStoreConfig('carriers/dhl/active')) {
|
95 |
+
$urls[] = Mage::getStoreConfig('carriers/dhl/gateway_url');
|
96 |
+
|
97 |
+
}
|
98 |
+
|
99 |
+
if (Mage::getStoreConfig('payment/authorizenet/active')) {
|
100 |
+
if (Mage::getStoreConfig('payment/authorizenet_directpost/active')) {
|
101 |
+
$urls[] = Mage::getStoreConfig('payment/authorizenet_directpost/cgi_url');
|
102 |
+
} else {
|
103 |
+
$urls[] = Mage::getStoreConfig('payment/authorizenet/cgi_url');
|
104 |
+
}
|
105 |
+
}
|
106 |
+
|
107 |
+
if (Mage::getStoreConfig('payment/ogone/active')) {
|
108 |
+
$urls[] = Mage::getStoreConfig('payment/ogone/ogone_gateway');
|
109 |
+
}
|
110 |
+
|
111 |
+
return $urls;
|
112 |
+
}
|
113 |
+
|
114 |
+
public function getRecommendations() {
|
115 |
+
return 'One of the APIs in not reachable.';
|
116 |
+
}
|
117 |
+
}
|
app/code/local/Gorilla/Heartbeat/Model/Tests/Catalog.php
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* catalog test model.
|
4 |
+
* @package
|
5 |
+
*/
|
6 |
+
class Gorilla_Heartbeat_Model_Tests_Catalog
|
7 |
+
extends Mage_Core_Model_Abstract
|
8 |
+
implements Gorilla_Heartbeat_Model_TestsInterface
|
9 |
+
{
|
10 |
+
/**
|
11 |
+
* Returns true if test enabled
|
12 |
+
* @return boolean
|
13 |
+
*/
|
14 |
+
public function isEnabled()
|
15 |
+
{
|
16 |
+
return true;
|
17 |
+
}
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Returns true if test passed
|
21 |
+
* @return boolean
|
22 |
+
*/
|
23 |
+
public function isPassed()
|
24 |
+
{
|
25 |
+
if (is_int(Mage::getModel('catalog/product')->getCollection()->count())) {
|
26 |
+
return true;
|
27 |
+
}
|
28 |
+
|
29 |
+
return false;
|
30 |
+
}
|
31 |
+
|
32 |
+
/**
|
33 |
+
* Returns result of the rest
|
34 |
+
* @return mixed
|
35 |
+
*/
|
36 |
+
public function getResult()
|
37 |
+
{
|
38 |
+
return true;
|
39 |
+
}
|
40 |
+
|
41 |
+
public function getRecommendations() {
|
42 |
+
return 'Magento catalog is not reachable. Please check the database integrity.';
|
43 |
+
}
|
44 |
+
}
|
app/code/local/Gorilla/Heartbeat/Model/Tests/Database.php
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* database test model.
|
4 |
+
* @package
|
5 |
+
*/
|
6 |
+
class Gorilla_Heartbeat_Model_Tests_Database
|
7 |
+
extends Mage_Core_Model_Abstract
|
8 |
+
implements Gorilla_Heartbeat_Model_TestsInterface
|
9 |
+
{
|
10 |
+
/**
|
11 |
+
* Returns true if test enabled
|
12 |
+
* @return boolean
|
13 |
+
*/
|
14 |
+
public function isEnabled()
|
15 |
+
{
|
16 |
+
return true;
|
17 |
+
}
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Returns true if test passed
|
21 |
+
* @return boolean
|
22 |
+
*/
|
23 |
+
public function isPassed()
|
24 |
+
{
|
25 |
+
//$write = Mage::getSingleton('core/resource')->getConnection('core_write');
|
26 |
+
//$writeItem = $write->query("INSERT INTO core_config_data (`value`, `path`) VALUES ('test', 'heartbeat/test/test') ON DUPLICATE KEY UPDATE `value` = 'test'");
|
27 |
+
|
28 |
+
$read = Mage::getSingleton('core/resource')->getConnection('core_read');
|
29 |
+
$readItem = $read->query('SELECT * FROM `core_config_data` LIMIT 1')->fetch();
|
30 |
+
|
31 |
+
if ($readItem /*&& $writeItem*/) {
|
32 |
+
return true;
|
33 |
+
}
|
34 |
+
|
35 |
+
return false;
|
36 |
+
}
|
37 |
+
|
38 |
+
/**
|
39 |
+
* Returns result of the rest
|
40 |
+
* @return mixed
|
41 |
+
*/
|
42 |
+
public function getResult()
|
43 |
+
{
|
44 |
+
return true;
|
45 |
+
}
|
46 |
+
|
47 |
+
public function getRecommendations() {
|
48 |
+
return 'Database is not reachable. Please check the database credentials.';
|
49 |
+
}
|
50 |
+
|
51 |
+
}
|
app/code/local/Gorilla/Heartbeat/Model/Tests/Filesystem.php
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* filesystem test model.
|
4 |
+
* @package
|
5 |
+
*/
|
6 |
+
class Gorilla_Heartbeat_Model_Tests_Filesystem
|
7 |
+
extends Mage_Core_Model_Abstract
|
8 |
+
implements Gorilla_Heartbeat_Model_TestsInterface
|
9 |
+
{
|
10 |
+
/**
|
11 |
+
* Returns true if test enabled
|
12 |
+
* @return boolean
|
13 |
+
*/
|
14 |
+
public function isEnabled()
|
15 |
+
{
|
16 |
+
return true;
|
17 |
+
}
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Returns true if test passed
|
21 |
+
* @return boolean
|
22 |
+
*/
|
23 |
+
public function isPassed()
|
24 |
+
{
|
25 |
+
$file = new Varien_Io_File();
|
26 |
+
$filename = Mage::getBaseDir('var') . DS . 'test.txt';
|
27 |
+
$dirname = Mage::getBaseDir('var');
|
28 |
+
|
29 |
+
if (file_exists($filename)) {
|
30 |
+
if (!is_writeable($filename)) {
|
31 |
+
return false;
|
32 |
+
}
|
33 |
+
}
|
34 |
+
|
35 |
+
if (!is_writable($dirname)) {
|
36 |
+
return false;
|
37 |
+
}
|
38 |
+
|
39 |
+
$file->open($dirname);
|
40 |
+
$file->write($filename, 'testcontent');
|
41 |
+
$fileContent = $file->read($filename);
|
42 |
+
|
43 |
+
if ($fileContent == 'testcontent') {
|
44 |
+
return true;
|
45 |
+
}
|
46 |
+
|
47 |
+
return false;
|
48 |
+
}
|
49 |
+
|
50 |
+
/**
|
51 |
+
* Returns result of the rest
|
52 |
+
* @return mixed
|
53 |
+
*/
|
54 |
+
public function getResult()
|
55 |
+
{
|
56 |
+
return true;
|
57 |
+
}
|
58 |
+
|
59 |
+
public function getRecommendations() {
|
60 |
+
return 'Cant write file to the var folder. Not enough rights or hard drive is full.';
|
61 |
+
}
|
62 |
+
}
|
app/code/local/Gorilla/Heartbeat/Model/Tests/Flattable.php
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* flat table test model.
|
4 |
+
* @package
|
5 |
+
*/
|
6 |
+
class Gorilla_Heartbeat_Model_Tests_Flattable
|
7 |
+
extends Mage_Core_Model_Abstract
|
8 |
+
implements Gorilla_Heartbeat_Model_TestsInterface
|
9 |
+
{
|
10 |
+
/**
|
11 |
+
* Returns true if test enabled
|
12 |
+
* @return boolean
|
13 |
+
*/
|
14 |
+
public function isEnabled()
|
15 |
+
{
|
16 |
+
/* if flat catalog is active */
|
17 |
+
if (Mage::getStoreConfig('catalog/frontend/flat_catalog_product')) {
|
18 |
+
return true;
|
19 |
+
}
|
20 |
+
|
21 |
+
return false;
|
22 |
+
}
|
23 |
+
|
24 |
+
/**
|
25 |
+
* Returns true if test passed
|
26 |
+
* @return boolean
|
27 |
+
*/
|
28 |
+
public function isPassed()
|
29 |
+
{
|
30 |
+
$read = Mage::getSingleton('core/resource')->getConnection('core_read');
|
31 |
+
$flatTables = $read->query('SHOW TABLES LIKE "catalog_product_flat_%"')->fetchAll();
|
32 |
+
|
33 |
+
$flatProductIds = array();
|
34 |
+
foreach ($flatTables as $flatTable) {
|
35 |
+
$items = $read->query('SELECT `entity_id` FROM `' . array_pop($flatTable) . '`')->fetchAll();
|
36 |
+
|
37 |
+
foreach ($items as $item) {
|
38 |
+
$flatProductIds[$item['entity_id']] = $item['entity_id'];
|
39 |
+
}
|
40 |
+
}
|
41 |
+
|
42 |
+
$productsCountArray = $read->query("
|
43 |
+
SELECT COUNT(DISTINCT `cpe`.`entity_id`) FROM `catalog_product_entity` AS `cpe`, `catalog_product_entity_int` AS `cpei`, `eav_attribute` AS `ea`, `eav_entity_type` AS `eet`
|
44 |
+
WHERE `eet`.`entity_type_code` = 'catalog_product'
|
45 |
+
AND `eet`.`entity_type_id` = `ea`.`entity_type_id`
|
46 |
+
AND `ea`.`attribute_code` = 'status'
|
47 |
+
AND `cpei`.`attribute_id` = `ea`.`attribute_id`
|
48 |
+
AND `cpei`.`entity_id` = `cpe`.`entity_id`
|
49 |
+
AND `cpei`.`value` = '1'")
|
50 |
+
->fetch();
|
51 |
+
$productsCount = array_pop($productsCountArray);
|
52 |
+
|
53 |
+
if ($productsCount == count($flatProductIds)) {
|
54 |
+
return true;
|
55 |
+
}
|
56 |
+
|
57 |
+
return false;
|
58 |
+
}
|
59 |
+
|
60 |
+
/**
|
61 |
+
* Returns result of the rest
|
62 |
+
* @return mixed
|
63 |
+
*/
|
64 |
+
public function getResult()
|
65 |
+
{
|
66 |
+
return true;
|
67 |
+
}
|
68 |
+
|
69 |
+
public function getRecommendations() {
|
70 |
+
return 'Please try to make reindex.';
|
71 |
+
}
|
72 |
+
}
|
app/code/local/Gorilla/Heartbeat/Model/Tests/Index.php
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* index test model.
|
4 |
+
* @package
|
5 |
+
*/
|
6 |
+
class Gorilla_Heartbeat_Model_Tests_Index
|
7 |
+
extends Mage_Core_Model_Abstract
|
8 |
+
implements Gorilla_Heartbeat_Model_TestsInterface
|
9 |
+
{
|
10 |
+
/**
|
11 |
+
* Returns true if test enabled
|
12 |
+
* @return boolean
|
13 |
+
*/
|
14 |
+
public function isEnabled()
|
15 |
+
{
|
16 |
+
return true;
|
17 |
+
}
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Returns true if test passed
|
21 |
+
* @return boolean
|
22 |
+
*/
|
23 |
+
public function isPassed()
|
24 |
+
{
|
25 |
+
$read = Mage::getSingleton('core/resource')->getConnection('core_read');
|
26 |
+
$indexes = $read->query("SELECT * FROM `index_process` WHERE `status` = 'require_reindex'")->fetch();
|
27 |
+
|
28 |
+
if (!$indexes) {
|
29 |
+
return true;
|
30 |
+
}
|
31 |
+
|
32 |
+
return false;
|
33 |
+
}
|
34 |
+
|
35 |
+
/**
|
36 |
+
* Returns result of the rest
|
37 |
+
* @return mixed
|
38 |
+
*/
|
39 |
+
public function getResult()
|
40 |
+
{
|
41 |
+
return true;
|
42 |
+
}
|
43 |
+
|
44 |
+
public function getRecommendations() {
|
45 |
+
return 'Indexes are invalidated. Please try to make reindex.';
|
46 |
+
}
|
47 |
+
}
|
app/code/local/Gorilla/Heartbeat/Model/Tests/Log.php
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Logs test model.
|
4 |
+
* @package
|
5 |
+
*/
|
6 |
+
class Gorilla_Heartbeat_Model_Tests_Log
|
7 |
+
extends Mage_Core_Model_Abstract
|
8 |
+
implements Gorilla_Heartbeat_Model_TestsInterface
|
9 |
+
{
|
10 |
+
/**
|
11 |
+
* Returns true if test enabled
|
12 |
+
* @return boolean
|
13 |
+
*/
|
14 |
+
public function isEnabled()
|
15 |
+
{
|
16 |
+
return true;
|
17 |
+
}
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Returns true if test passed
|
21 |
+
* @return boolean
|
22 |
+
*/
|
23 |
+
public function isPassed()
|
24 |
+
{
|
25 |
+
|
26 |
+
$logFile = Mage::getStoreConfig('dev/log/exception_file');
|
27 |
+
$logDir = Mage::getBaseDir('var') . DS . 'log';
|
28 |
+
if (file_exists($logDir . DS . $logFile) && file_get_contents($logDir. DS .$logFile)) {
|
29 |
+
return false;
|
30 |
+
}
|
31 |
+
|
32 |
+
return true;
|
33 |
+
}
|
34 |
+
|
35 |
+
/**
|
36 |
+
* Returns result of the rest
|
37 |
+
* @return mixed
|
38 |
+
*/
|
39 |
+
public function getResult()
|
40 |
+
{
|
41 |
+
return true;
|
42 |
+
}
|
43 |
+
|
44 |
+
public function getRecommendations() {
|
45 |
+
return 'You have exception log in your var/log folder.';
|
46 |
+
}
|
47 |
+
}
|
app/code/local/Gorilla/Heartbeat/Model/TestsCollector.php
ADDED
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Collector model.
|
4 |
+
* @package
|
5 |
+
*/
|
6 |
+
class Gorilla_Heartbeat_Model_TestsCollector extends Mage_Core_Model_Abstract
|
7 |
+
{
|
8 |
+
private $_start_time;
|
9 |
+
private $_end_time;
|
10 |
+
|
11 |
+
private $_errors = array();
|
12 |
+
|
13 |
+
/**
|
14 |
+
* Returns directory with test models
|
15 |
+
* @return string
|
16 |
+
*/
|
17 |
+
private function _getTestsDir()
|
18 |
+
{
|
19 |
+
return Mage::getConfig()->getModuleDir(null, 'Gorilla_Heartbeat') . DS . 'Model' . DS . 'Tests';
|
20 |
+
}
|
21 |
+
|
22 |
+
/**
|
23 |
+
* Collects test modeles
|
24 |
+
* @return Varien_Data_Collection
|
25 |
+
*/
|
26 |
+
private function _getTestsCollection()
|
27 |
+
{
|
28 |
+
$handle = new Varien_Io_File();
|
29 |
+
$handle->cd($this->_getTestsDir());
|
30 |
+
$listOfFiles = $handle->ls('files_only');
|
31 |
+
|
32 |
+
$collection = new Varien_Data_Collection();
|
33 |
+
foreach ($listOfFiles as $file) {
|
34 |
+
try {
|
35 |
+
$modelName = strtolower(str_replace('.php', '', $file['text']));
|
36 |
+
$testModel = Mage::getModel('heartbeat/tests_' . $modelName);
|
37 |
+
|
38 |
+
if ($testModel->isEnabled()) {
|
39 |
+
$collection->addItem(
|
40 |
+
new Varien_Object(
|
41 |
+
array(
|
42 |
+
'test_object' => $testModel,
|
43 |
+
)
|
44 |
+
)
|
45 |
+
);
|
46 |
+
}
|
47 |
+
} catch (Exception $e) {
|
48 |
+
Mage::log('Cant load test ' . $modelName . '(' . $e->getMessage() . ')', null, 'gorilla_heartbeat.log');
|
49 |
+
}
|
50 |
+
}
|
51 |
+
|
52 |
+
return $collection;
|
53 |
+
}
|
54 |
+
|
55 |
+
/**
|
56 |
+
* Retunr true if all test passed
|
57 |
+
* @return boolean
|
58 |
+
*/
|
59 |
+
public function isAllPassed()
|
60 |
+
{
|
61 |
+
/* start timer */
|
62 |
+
$this->_start_time = $this->_getTime();
|
63 |
+
|
64 |
+
foreach ($this->_getTestsCollection() as $item) {
|
65 |
+
if (!$item->getTestObject()->isPassed()) {
|
66 |
+
$this->_errors[] = $item->getTestObject()->getRecommendations() . ' Error Class: ' . get_class($item->getTestObject());
|
67 |
+
}
|
68 |
+
}
|
69 |
+
|
70 |
+
if (count($this->_errors)) {
|
71 |
+
return false;
|
72 |
+
}
|
73 |
+
|
74 |
+
/* end timer */
|
75 |
+
$this->_end_time = $this->_getTime();
|
76 |
+
|
77 |
+
return true;
|
78 |
+
}
|
79 |
+
|
80 |
+
/**
|
81 |
+
* Return tests passing time
|
82 |
+
* @return float
|
83 |
+
*/
|
84 |
+
public function getPassingTime()
|
85 |
+
{
|
86 |
+
return round($this->_end_time * 1000 - $this->_start_time * 1000, 3) >= 0? round($this->_end_time * 1000 - $this->_start_time * 1000, 3) : 0;
|
87 |
+
}
|
88 |
+
|
89 |
+
/**
|
90 |
+
* Return current time in seconds
|
91 |
+
* @return float
|
92 |
+
*/
|
93 |
+
private function _getTime()
|
94 |
+
{
|
95 |
+
/* detect the time */
|
96 |
+
$timeNow = microtime();
|
97 |
+
/* separates seconds and milliseconds in array */
|
98 |
+
$arrayTime = explode(' ', $timeNow);
|
99 |
+
/* we put together seconds and milliseconds */
|
100 |
+
$timeReturn = floatval($arrayTime[1]) + floatval($arrayTime[0]);
|
101 |
+
|
102 |
+
return $timeReturn;
|
103 |
+
}
|
104 |
+
|
105 |
+
public function getErrors()
|
106 |
+
{
|
107 |
+
return $this->_errors;
|
108 |
+
}
|
109 |
+
}
|
app/code/local/Gorilla/Heartbeat/Model/TestsInterface.php
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
interface Gorilla_Heartbeat_Model_TestsInterface
|
3 |
+
{
|
4 |
+
/**
|
5 |
+
* Must return true if test is enabled
|
6 |
+
* @return boolean
|
7 |
+
*/
|
8 |
+
public function isEnabled();
|
9 |
+
|
10 |
+
/**
|
11 |
+
* Must return true if test passed
|
12 |
+
* @return boolean
|
13 |
+
*/
|
14 |
+
public function isPassed();
|
15 |
+
|
16 |
+
/**
|
17 |
+
* Must return result of the rest
|
18 |
+
* @return mixed
|
19 |
+
*/
|
20 |
+
public function getResult();
|
21 |
+
|
22 |
+
/**
|
23 |
+
* Must return recmmendations how to fix the
|
24 |
+
* @return string
|
25 |
+
*/
|
26 |
+
public function getRecommendations();
|
27 |
+
}
|
app/code/local/Gorilla/Heartbeat/controllers/IndexController.php
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Index controller
|
4 |
+
* @package
|
5 |
+
*/
|
6 |
+
class Gorilla_Heartbeat_IndexController extends Mage_Core_Controller_Front_Action
|
7 |
+
{
|
8 |
+
|
9 |
+
/**
|
10 |
+
* Index action.
|
11 |
+
* Checks if all tests is passes. Returns responce code in heders 200 if OK of 500 if something is wrong.
|
12 |
+
* Alse returns XML statistics in headers for pingdom in format
|
13 |
+
* <pingdom_http_custom_check>
|
14 |
+
* <status>CODE</status>
|
15 |
+
* <response_time>TIME</response_time>
|
16 |
+
* </pingdom_http_custom_check>
|
17 |
+
*/
|
18 |
+
public function indexAction()
|
19 |
+
{
|
20 |
+
if (!Mage::getStoreConfig('heartbeat/general/enable')) {
|
21 |
+
$this->_redirect('/');
|
22 |
+
return false;
|
23 |
+
}
|
24 |
+
|
25 |
+
$code = 500;
|
26 |
+
$textCode = 'ERROR';
|
27 |
+
if (Mage::getSingleton('heartbeat/testsCollector')->isAllPassed()) {
|
28 |
+
$code = 200;
|
29 |
+
$textCode = 'OK';
|
30 |
+
}
|
31 |
+
|
32 |
+
$errorCodes = '<errors>';
|
33 |
+
foreach (Mage::getSingleton('heartbeat/testsCollector')->getErrors() as $error) {
|
34 |
+
$errorCodes .= '<error>' . $error . '</error>';
|
35 |
+
}
|
36 |
+
$errorCodes .='</errors>';
|
37 |
+
|
38 |
+
$time = Mage::getSingleton('heartbeat/testsCollector')->getPassingTime();
|
39 |
+
|
40 |
+
$this->getResponse()
|
41 |
+
->setHttpResponseCode($code)
|
42 |
+
->setHeader('Content-type', 'application/xml', true)
|
43 |
+
->setBody('<?xml version="1.0" encoding="UTF-8" ?><pingdom_http_custom_check><status>' . $textCode . '</status><response_time>' . $time . '</response_time>' . $errorCodes . '</pingdom_http_custom_check>')
|
44 |
+
;
|
45 |
+
}
|
46 |
+
|
47 |
+
|
48 |
+
|
49 |
+
}
|
app/code/local/Gorilla/Heartbeat/etc/adminhtml.xml
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
|
4 |
+
<menu>
|
5 |
+
<gorilla module="heartbeat">
|
6 |
+
<title>Gorilla InStore</title>
|
7 |
+
<sort_order>999</sort_order>
|
8 |
+
<children>
|
9 |
+
<heartbeat module="heartbeat">
|
10 |
+
<title>Heart Beat (Pingdom Integration)</title>
|
11 |
+
<sort_order>0</sort_order>
|
12 |
+
<children>
|
13 |
+
<configuration module="adminhtml">
|
14 |
+
<title>Configuration</title>
|
15 |
+
<sort_order>1</sort_order>
|
16 |
+
<action>adminhtml/system_config/edit/section/heartbeat</action>
|
17 |
+
</configuration>
|
18 |
+
</children>
|
19 |
+
</heartbeat>
|
20 |
+
</children>
|
21 |
+
</gorilla>
|
22 |
+
</menu>
|
23 |
+
<acl>
|
24 |
+
<resources>
|
25 |
+
<all>
|
26 |
+
<title>Allow Everything</title>
|
27 |
+
</all>
|
28 |
+
<admin>
|
29 |
+
<children>
|
30 |
+
<Gorilla_Heartbeat>
|
31 |
+
<title>Gorilla InStore - Heart Beat (Pingdom Integration) - Module</title>
|
32 |
+
<sort_order>10</sort_order>
|
33 |
+
</Gorilla_Heartbeat>
|
34 |
+
<system>
|
35 |
+
<children>
|
36 |
+
<config>
|
37 |
+
<children>
|
38 |
+
<heartbeat>
|
39 |
+
<title>Gorilla InStore - Heart Beat (Pingdom Integration) - Config</title>
|
40 |
+
</heartbeat>
|
41 |
+
</children>
|
42 |
+
</config>
|
43 |
+
</children>
|
44 |
+
</system>
|
45 |
+
</children>
|
46 |
+
</admin>
|
47 |
+
</resources>
|
48 |
+
</acl>
|
49 |
+
</config>
|
app/code/local/Gorilla/Heartbeat/etc/config.xml
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Gorilla_Heartbeat>
|
5 |
+
<version>0.0.1</version>
|
6 |
+
</Gorilla_Heartbeat>
|
7 |
+
</modules>
|
8 |
+
<global>
|
9 |
+
<models>
|
10 |
+
<heartbeat>
|
11 |
+
<class>Gorilla_Heartbeat_Model</class>
|
12 |
+
</heartbeat>
|
13 |
+
</models>
|
14 |
+
<helpers>
|
15 |
+
<heartbeat>
|
16 |
+
<class>Gorilla_Heartbeat_Helper</class>
|
17 |
+
</heartbeat>
|
18 |
+
</helpers>
|
19 |
+
</global>
|
20 |
+
<frontend>
|
21 |
+
<routers>
|
22 |
+
<heartbeat>
|
23 |
+
<use>standard</use>
|
24 |
+
<args>
|
25 |
+
<module>Gorilla_Heartbeat</module>
|
26 |
+
<frontName>heartbeat</frontName>
|
27 |
+
</args>
|
28 |
+
</heartbeat>
|
29 |
+
</routers>
|
30 |
+
</frontend>
|
31 |
+
<default>
|
32 |
+
<heartbeat>
|
33 |
+
<general>
|
34 |
+
<enable>1</enable>
|
35 |
+
</general>
|
36 |
+
</heartbeat>
|
37 |
+
</default>
|
38 |
+
</config>
|
app/code/local/Gorilla/Heartbeat/etc/system.xml
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
|
3 |
+
<config>
|
4 |
+
<tabs>
|
5 |
+
<gorilla translate="label" module="heartbeat">
|
6 |
+
<label>Gorilla InStore</label>
|
7 |
+
<sort_order>100</sort_order>
|
8 |
+
</gorilla>
|
9 |
+
</tabs>
|
10 |
+
<sections>
|
11 |
+
<heartbeat translate="label" module="heartbeat">
|
12 |
+
<label>Heart Beat (Pingdom Integration)</label>
|
13 |
+
<tab>gorilla</tab>
|
14 |
+
<frontend_type>text</frontend_type>
|
15 |
+
<sort_order>30</sort_order>
|
16 |
+
<show_in_default>1</show_in_default>
|
17 |
+
<show_in_website>1</show_in_website>
|
18 |
+
<show_in_store>1</show_in_store>
|
19 |
+
<groups>
|
20 |
+
<general translate="label">
|
21 |
+
<label>General</label>
|
22 |
+
<frontend_type>text</frontend_type>
|
23 |
+
<sort_order>1</sort_order>
|
24 |
+
<show_in_default>1</show_in_default>
|
25 |
+
<show_in_website>1</show_in_website>
|
26 |
+
<show_in_store>1</show_in_store>
|
27 |
+
<fields>
|
28 |
+
<enable translate="label">
|
29 |
+
<label>Enable module</label>
|
30 |
+
<frontend_type>select</frontend_type>
|
31 |
+
<sort_order>1</sort_order>
|
32 |
+
<show_in_default>1</show_in_default>
|
33 |
+
<show_in_website>1</show_in_website>
|
34 |
+
<show_in_store>1</show_in_store>
|
35 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
36 |
+
</enable>
|
37 |
+
</fields>
|
38 |
+
</general>
|
39 |
+
</groups>
|
40 |
+
</heartbeat>
|
41 |
+
</sections>
|
42 |
+
</config>
|
app/etc/modules/Gorilla_Heartbeat.xml
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<config>
|
2 |
+
<modules>
|
3 |
+
<Gorilla_Heartbeat>
|
4 |
+
<active>true</active>
|
5 |
+
<codePool>local</codePool>
|
6 |
+
</Gorilla_Heartbeat>
|
7 |
+
</modules>
|
8 |
+
</config>
|
package.xml
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<package>
|
3 |
+
<name>heartbeat-extension-for-magento</name>
|
4 |
+
<version>0.0.1</version>
|
5 |
+
<stability>stable</stability>
|
6 |
+
<license uri="http://instore.gorillagroup.com/license-agreement">Gorilla License</license>
|
7 |
+
<channel>community</channel>
|
8 |
+
<extends/>
|
9 |
+
<summary>The HeartBeat module is designed to provide in-depth monitoring for your Magento site. There are two ways to monitor the status of your site – via an XML report or through Pingdom.</summary>
|
10 |
+
<description>The HeartBeat module is designed to provide in-depth monitoring for your Magento site. There are two ways to monitor the status of your site – via an XML report or through Pingdom.
|
11 |
+
Pingdom is monitoring service that tracks all website & server vitals in one convenient monitoring platform. It helps you spot performance trends, share data with others, and helps with issue resolution. Pingdom also sends users real-time updates via email, SMS (texts), Twitter, or mobile notification via iOS or Android devices.
|
12 |
+

|
13 |
+
The HeartBeat module monitors seven components that are vital for site functionality and performance of any Magento website. These tests include: API availability, database, flat table, logs, catalog, file system, and indexes.</description>
|
14 |
+
<notes>HeartBeat Released</notes>
|
15 |
+
<authors><author><name>Gorilla Team</name><user>briangrady</user><email>grady@gorillagroup.com</email></author></authors>
|
16 |
+
<date>2012-06-13</date>
|
17 |
+
<time>17:14:09</time>
|
18 |
+
<contents><target name="magelocal"><dir name="Gorilla"><dir name="Heartbeat"><dir name="Helper"><file name="Data.php" hash="5b5a72e4bb5a4ce3f1714a774dc7349f"/></dir><dir name="Model"><dir name="Tests"><file name="Api.php" hash="ea91218d8f5b212b132fdc5b86cdb967"/><file name="Catalog.php" hash="a7e19979440ecca0ae650b113227819e"/><file name="Database.php" hash="ebe95c834437faeb988cb3ca8abcaad7"/><file name="Filesystem.php" hash="bbf3f0b4b10fd2ad87640f4dea432fb8"/><file name="Flattable.php" hash="3f6facf4489b9cf590e6ec13ad806f6b"/><file name="Index.php" hash="204709bcdf381f63a3401941a1ddc495"/><file name="Log.php" hash="edc8dee0cb74f718d556ca8548da523e"/></dir><file name="TestsCollector.php" hash="b935e52bed9b908d4c2e702b37cfa42c"/><file name="TestsInterface.php" hash="5ae94e08822da721b45a9b1546a2a4b5"/></dir><dir name="controllers"><file name="IndexController.php" hash="1616d51d85d43a974ff0fdd57fa1b3cb"/></dir><dir name="etc"><file name="adminhtml.xml" hash="818551d3d7ba1962d837eff1f85f0203"/><file name="config.xml" hash="3705efcb09a4c46a0c241c9e532d16a9"/><file name="system.xml" hash="1024c468f92ce8e236e1084b73712d3a"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Gorilla_Heartbeat.xml" hash="73424503c8a3a95a747570ac3e05b4cb"/></dir></target></contents>
|
19 |
+
<compatible/>
|
20 |
+
<dependencies><required><php><min>5.0.0</min><max>5.4.3</max></php><package><name>Mage_Core_Modules</name><channel>community</channel><min>1.6.0</min><max>1.7.0</max></package></required></dependencies>
|
21 |
+
</package>
|