-
Notifications
You must be signed in to change notification settings - Fork 105
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 #69 from 0x46616c6b/reporter-mail
added reporter to send mail when check fails
- Loading branch information
Showing
6 changed files
with
201 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?php | ||
|
||
namespace Liip\MonitorBundle\Helper; | ||
|
||
use ArrayObject; | ||
use Swift_Mailer; | ||
use Swift_Message; | ||
use ZendDiagnostics\Check\CheckInterface; | ||
use ZendDiagnostics\Result\Collection as ResultsCollection; | ||
use ZendDiagnostics\Result\ResultInterface; | ||
use ZendDiagnostics\Runner\Reporter\ReporterInterface; | ||
|
||
/** | ||
* @author louis <louis@systemli.org> | ||
*/ | ||
class SwiftMailerReporter implements ReporterInterface | ||
{ | ||
/** | ||
* @var Swift_Mailer | ||
*/ | ||
private $mailer; | ||
/** | ||
* @var string | ||
*/ | ||
private $recipient; | ||
/** | ||
* @var string | ||
*/ | ||
private $subject; | ||
/** | ||
* @var | ||
*/ | ||
private $sender; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param Swift_Mailer $mailer | ||
* @param string $recipient | ||
* @param $sender | ||
* @param string $subject | ||
*/ | ||
public function __construct(Swift_Mailer $mailer, $recipient, $sender, $subject) | ||
{ | ||
$this->mailer = $mailer; | ||
$this->recipient = $recipient; | ||
$this->sender = $sender; | ||
$this->subject = $subject; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function onStart(ArrayObject $checks, $runnerConfig) | ||
{ | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function onBeforeRun(CheckInterface $check, $checkAlias = null) | ||
{ | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function onAfterRun(CheckInterface $check, ResultInterface $result, $checkAlias = null) | ||
{ | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function onStop(ResultsCollection $results) | ||
{ | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function onFinish(ResultsCollection $results) | ||
{ | ||
if ($results->getFailureCount() > 0 | ||
|| $results->getWarningCount() > 0 | ||
|| $results->getUnknownCount() > 0 | ||
) { | ||
$body = ''; | ||
|
||
foreach ($results as $check) { | ||
/* @var $check CheckInterface */ | ||
/* @var $result ResultInterface */ | ||
$result = isset($results[$check]) ? $results[$check] : null; | ||
|
||
if ($result instanceof ResultInterface) { | ||
$body .= sprintf("Check: %s\n", $check->getLabel()); | ||
$body .= sprintf("Message: %s\n\n", $result->getMessage()); | ||
} | ||
} | ||
|
||
$message = Swift_Message::newInstance() | ||
->setSubject($this->subject) | ||
->setFrom($this->sender) | ||
->setTo($this->recipient) | ||
->setBody($body); | ||
|
||
$this->mailer->send($message); | ||
} | ||
} | ||
} |
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,20 @@ | ||
<?xml version="1.0" ?> | ||
|
||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
|
||
<parameters> | ||
<parameter key="liip_monitor.reporter.swift_mailer.class">Liip\MonitorBundle\Helper\SwiftMailerReporter</parameter> | ||
</parameters> | ||
|
||
<services> | ||
<service id="liip_monitor.reporter.swift_mailer" class="%liip_monitor.reporter.swift_mailer.class%"> | ||
<tag name="liip_monitor.additional_reporter" alias="swift_mailer" /> | ||
<argument type="service" id="mailer" /> | ||
<argument>%liip_monitor.mailer.recipient%</argument> | ||
<argument>%liip_monitor.mailer.sender%</argument> | ||
<argument>%liip_monitor.mailer.subject%</argument> | ||
</service> | ||
</services> | ||
</container> |
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