LogMailer - Version 0.1.0

Version Notes

Zur Installation des Moduls

07.12.2012 - Erstes Release

Download this release

Release Info

Developer Benjamin Wunderlich
Extension LogMailer
Version 0.1.0
Comparing to
See all releases


Version 0.1.0

app/code/community/Shopwerft/LogMailer/Helper/Data.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Shopwerft
5
+ * @package Shopwerft_LogMailer
6
+ * @authors Shopwerft GmbH <info@shopwerft.com>
7
+ * @developer Benjamin Wunderlich <b.wunderlich@shopwerft.com, http://www.shopwerft.com/>
8
+ * @version 0.1.0
9
+ * @copyright Shopwerft GmbH
10
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
+ */
12
+
13
+ class Shopwerft_LogMailer_Helper_Data extends Mage_Core_Helper_Abstract
14
+ {
15
+
16
+ const CONFIG_PATH_ACTIVE = 'dev/log/logmailingactive';
17
+ const CONFIG_PATH_LOGFILES = 'dev/log/logfiles';
18
+ const CONFIG_PATH_RECEIVERS = 'dev/log/receivers';
19
+
20
+ /**
21
+ * Check if sending out of log files is enabled.
22
+ *
23
+ * @param Mage_Core_Model_Store $store
24
+ * @return bool
25
+ */
26
+ public function isActive(Mage_Core_Model_Store $store = null)
27
+ {
28
+ return (bool) Mage::getStoreConfig(self::CONFIG_PATH_ACTIVE, $store);
29
+ }
30
+
31
+ /**
32
+ * Get the configured log files to observe.
33
+ *
34
+ * @param Mage_Core_Model_Store $store
35
+ * @return array The log files configured in backend
36
+ */
37
+ public function getLogFiles(Mage_Core_Model_Store $store = null)
38
+ {
39
+ $config = Mage::getStoreConfig(self::CONFIG_PATH_LOGFILES, $store);
40
+ return array_map('trim', explode("\n", $config));
41
+ }
42
+
43
+ /**
44
+ * Get the notification receivers (email-addresses).
45
+ *
46
+ * @param Mage_Core_Model_Store $store
47
+ * @return array
48
+ */
49
+ public function getReceivers(Mage_Core_Model_Store $store = null)
50
+ {
51
+ $config = Mage::getStoreConfig(self::CONFIG_PATH_RECEIVERS, $store);
52
+ return array_map('trim', explode("\n", $config));
53
+ }
54
+ }
app/code/community/Shopwerft/LogMailer/Model/Cron.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Shopwerft
5
+ * @package Shopwerft_LogMailer
6
+ * @authors Shopwerft GmbH <info@shopwerft.com>
7
+ * @developer Benjamin Wunderlich <b.wunderlich@shopwerft.com, http://www.shopwerft.com/>
8
+ * @version 0.1.0
9
+ * @copyright Shopwerft GmbH
10
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
+ */
12
+
13
+ class Shopwerft_LogMailer_Model_Cron extends Mage_Core_Model_Abstract {
14
+
15
+
16
+ public function sendLog($event)
17
+ {
18
+ /** @var $helper Shopwerft_LogMailer_Helper_Data */
19
+ $helper = Mage::helper('swlogmailer');
20
+ /** @var $logFilter Shopwerft_LogMailer_Model_Filter */
21
+ $logFilter = Mage::getModel('swlogmailer/filter');
22
+ $logFilter->setDate(date('Y-m-d', time() - 24*60*60)) // yesterday (all my troubles ...)
23
+ ->addLogfile($helper->getLogFiles());
24
+ foreach($helper->getReceivers() as $receiver) {
25
+ /** @var $email Mage_Core_Model_Email */
26
+ $email = Mage::getModel('core/email');
27
+ $email->setSubject('Log from ' . $logFilter->getDate())
28
+ ->setBody($logFilter->getLines())
29
+ ->setToEmail($receiver)
30
+ ->setToName($receiver)
31
+ ->setFromEmail($receiver)
32
+ ->setFromName($receiver)
33
+ ->send();
34
+ }
35
+ }
36
+
37
+ }
app/code/community/Shopwerft/LogMailer/Model/Filter.php ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Shopwerft
5
+ * @package Shopwerft_LogMailer
6
+ * @authors Shopwerft GmbH <info@shopwerft.com>
7
+ * @developer Benjamin Wunderlich <b.wunderlich@shopwerft.com, http://www.shopwerft.com/>
8
+ * @version 0.1.0
9
+ * @copyright Shopwerft GmbH
10
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
+ */
12
+
13
+ class Shopwerft_LogMailer_Model_Filter extends Mage_Core_Model_Abstract
14
+ {
15
+
16
+ protected $_files = array();
17
+
18
+ /**
19
+ * Add a single (string) or multiple log filenames (array) to filter.
20
+ * @param string|array $filename
21
+ * @return Shopwerft_LogMailer_Model_Filter
22
+ */
23
+ public function addLogfile($filename)
24
+ {
25
+ if(is_array($filename)) {
26
+ $this->_files = array_merge($this->_files, $filename);
27
+ } elseif(is_string($filename)) {
28
+ $this->_files[] = $filename;
29
+ }
30
+ return $this;
31
+ }
32
+
33
+ /**
34
+ * Get the log file lines as a report.
35
+ *
36
+ * @return string
37
+ */
38
+ public function getLines()
39
+ {
40
+ $resultLines = "Log Messages from ". $this->getDate();
41
+ $logDir = Mage::getBaseDir('var').DS.'log'.DS;
42
+ foreach($this->_files as $filename) {
43
+ $file = $logDir . $filename;
44
+ if(!file_exists($file)) {
45
+ $resultLines .= "\n\nFile $filename does not exist!";
46
+ continue;
47
+ }
48
+
49
+ $lines = file($file);
50
+
51
+ $resultLines .= "\n\nFile $filename:\n\n";
52
+
53
+ $matches = false;
54
+ $linesCount = 0;
55
+ foreach ($lines as $line_num => $line) {
56
+ if(preg_match('#\A\d\d\d\d-\d\d-\d\d#', $line)) {
57
+ if(substr($line, 0, 10) == $this->getDate()) {
58
+ $matches = true;
59
+ } else {
60
+ $matches = false;
61
+ }
62
+ }
63
+ if($matches) {
64
+ $linesCount++;
65
+ $resultLines .= $line;
66
+ }
67
+ }
68
+
69
+ if($linesCount == 0) {
70
+ $resultLines .= "---";
71
+ }
72
+
73
+ }
74
+
75
+ return $resultLines;
76
+ }
77
+
78
+
79
+ }
app/code/community/Shopwerft/LogMailer/etc/adminhtml.xml ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" ?>
2
+
3
+ <!--
4
+ /**
5
+ * @category Shopwerft
6
+ * @package Shopwerft_LogMailer
7
+ * @authors Shopwerft GmbH <info@shopwerft.com>
8
+ * @developer Benjamin Wunderlich <b.wunderlich@shopwerft.com, http://www.shopwerft.com/>
9
+ * @version 0.1.0
10
+ * @copyright Shopwerft GmbH
11
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
12
+ */
13
+ -->
14
+
15
+ <config>
16
+
17
+ <acl>
18
+ <resources>
19
+ <admin>
20
+ <children>
21
+ <system>
22
+ <children>
23
+ <config>
24
+ <children>
25
+ <swlogmailer translate="title" module="swlogmailer">
26
+ <title>Log Mailer</title>
27
+ </swlogmailer>
28
+ </children>
29
+ </config>
30
+ </children>
31
+ </system>
32
+ </children>
33
+ </admin>
34
+ </resources>
35
+ </acl>
36
+
37
+ </config>
app/code/community/Shopwerft/LogMailer/etc/config.xml ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Shopwerft_LogMailer>
5
+ <version>0.1.0</version>
6
+ </Shopwerft_LogMailer>
7
+ </modules>
8
+ <global>
9
+ <models>
10
+ <swlogmailer>
11
+ <class>Shopwerft_LogMailer_Model</class>
12
+ </swlogmailer>
13
+ </models>
14
+ <helpers>
15
+ <swlogmailer>
16
+ <class>Shopwerft_LogMailer_Helper</class>
17
+ </swlogmailer>
18
+ </helpers>
19
+ </global>
20
+
21
+ <adminhtml>
22
+ <translate>
23
+ <modules>
24
+ <Shopwerft_LogMailer>
25
+ <files>
26
+ <default>Shopwerft_LogMailer.csv</default>
27
+ </files>
28
+ </Shopwerft_LogMailer>
29
+ </modules>
30
+ </translate>
31
+ </adminhtml>
32
+
33
+ <crontab>
34
+ <jobs>
35
+ <logmailer_send_log>
36
+ <schedule><cron_expr>0 6 * * *</cron_expr></schedule>
37
+ <run><model>swlogmailer/cron::sendLog</model></run>
38
+ </logmailer_send_log>
39
+ </jobs>
40
+ </crontab>
41
+
42
+ </config>
app/code/community/Shopwerft/LogMailer/etc/system.xml ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+
3
+ <!--
4
+ /**
5
+ * @category Shopwerft
6
+ * @package Shopwerft_${Modulname}
7
+ * @authors Shopwerft GmbH <info@shopwerft.com>
8
+ * @developer Benjamin Wunderlich <b.wunderlich@shopwerft.com, http://www.shopwerft.com/>
9
+ * @version 0.1.0
10
+ * @copyright Shopwerft GmbH
11
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
12
+ */
13
+ -->
14
+ <config>
15
+ <sections>
16
+ <dev translate="label" module="swLogMailer">
17
+ <groups>
18
+ <log translate="label" module="swLogMailer">
19
+ <fields>
20
+ <header translate="label">
21
+ <label>Log Mailer</label>
22
+ <comment></comment>
23
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
24
+ <sort_order>100</sort_order>
25
+ <show_in_default>1</show_in_default>
26
+ <show_in_website>1</show_in_website>
27
+ <show_in_store>1</show_in_store>
28
+ </header>
29
+ <logmailingactive translate="label">
30
+ <label>Activated</label>
31
+ <comment>Set this to "yes" to activate the modules functionality.</comment>
32
+ <frontend_type>select</frontend_type>
33
+ <source_model>adminhtml/system_config_source_yesno</source_model>
34
+ <sort_order>110</sort_order>
35
+ <show_in_default>1</show_in_default>
36
+ <show_in_website>1</show_in_website>
37
+ <show_in_store>1</show_in_store>
38
+ </logmailingactive>
39
+ <logfiles translate="label">
40
+ <label>Observed logfiles</label>
41
+ <comment>Enter here only the names of the log files to observe (one per line).</comment>
42
+ <frontend_type>textarea</frontend_type>
43
+ <sort_order>120</sort_order>
44
+ <depends>
45
+ <logmailingactive>1</logmailingactive>
46
+ </depends>
47
+ <show_in_default>1</show_in_default>
48
+ <show_in_website>1</show_in_website>
49
+ <show_in_store>1</show_in_store>
50
+ </logfiles>
51
+ <receivers translate="label">
52
+ <label>Notification receivers</label>
53
+ <comment>Enter here the email addresses of the receivers of the log files (one per line).</comment>
54
+ <frontend_type>textarea</frontend_type>
55
+ <sort_order>130</sort_order>
56
+ <depends>
57
+ <logmailingactive>1</logmailingactive>
58
+ </depends>
59
+ <show_in_default>1</show_in_default>
60
+ <show_in_website>1</show_in_website>
61
+ <show_in_store>1</show_in_store>
62
+ </receivers>
63
+ </fields>
64
+ </log>
65
+ </groups>
66
+ </dev>
67
+ </sections>
68
+
69
+ </config>
app/etc/modules/Shopwerft_LogMailer.xml ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+
3
+ <!--
4
+ /**
5
+ * @category Shopwerft
6
+ * @package Shopwerft_LogMailer
7
+ * @authors Shopwerft GmbH <info@shopwerft.com>
8
+ * @developer Benjamin Wunderlich <b.wunderlich@shopwerft.com, http://www.shopwerft.com/>
9
+ * @version 0.1.0
10
+ * @copyright Shopwerft GmbH
11
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
12
+ */
13
+ -->
14
+
15
+ <config>
16
+ <modules>
17
+ <Shopwerft_LogMailer>
18
+ <active>true</active>
19
+ <codePool>community</codePool>
20
+ </Shopwerft_LogMailer>
21
+ </modules>
22
+ </config>
package.xml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>LogMailer</name>
4
+ <version>0.1.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/OSL-3.0">Open Software License v. 3.0 (OSL-3.0)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Sendet einmal am Tag neue Log-Meldungen aus festgelegten Log-Dateien an definierte E-Mail-Adressen.</summary>
10
+ <description>Kleines Magento-Modul, das einmal am Tag aktuelle Log-Meldungen aus ausgew&#xE4;hlte Log-Dateien an festgelegte E-Mail-Adressen schickt. Besonders n&#xFC;tzlich, wenn man auf Meldungen im Exception-Log zeitnah reagieren m&#xF6;chte.</description>
11
+ <notes>Zur Installation des Moduls&#xD;
12
+ &#xD;
13
+ 07.12.2012 - Erstes Release</notes>
14
+ <authors><author><name>Benjamin Wunderlich</name><user>Shopwerft</user><email>module@shopwerft.com</email></author></authors>
15
+ <date>2012-12-07</date>
16
+ <time>15:02:12</time>
17
+ <contents><target name="magecommunity"><dir name="Shopwerft"><dir name="LogMailer"><dir name="Helper"><file name="Data.php" hash="1a2de7cbc83784ffc34acd9fc7b12fe2"/></dir><dir name="Model"><file name="Cron.php" hash="228bf1cae5c4e642d297bcd26acc1c83"/><file name="Filter.php" hash="1898e3ea99b4d2a14821cfa89f940d32"/></dir><dir name="etc"><file name="adminhtml.xml" hash="00b77c17dadba855e65cf1baac2cbbc1"/><file name="config.xml" hash="bccccd69f4f4138f7e68d7cf5bd128e8"/><file name="system.xml" hash="d5640b3bfd4f13d3a3bdbe42ef06712f"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Shopwerft_LogMailer.xml" hash="3ac9747b5277575fea34eac0d6c84a30"/></dir></target></contents>
18
+ <compatible/>
19
+ <dependencies><required><php><min>5.2.0</min><max>5.4.9</max></php></required></dependencies>
20
+ </package>