add alertcontact in uptimerobotservice
This commit is contained in:
parent
918584c35b
commit
be836d5956
2
.idea/php.xml
generated
2
.idea/php.xml
generated
@ -35,7 +35,7 @@
|
|||||||
<path value="$PROJECT_DIR$/vendor/symfony/dependency-injection" />
|
<path value="$PROJECT_DIR$/vendor/symfony/dependency-injection" />
|
||||||
</include_path>
|
</include_path>
|
||||||
</component>
|
</component>
|
||||||
<component name="PhpProjectSharedConfiguration" php_language_level="7.1">
|
<component name="PhpProjectSharedConfiguration" php_language_level="7.4">
|
||||||
<option name="suggestChangeDefaultLanguageLevel" value="false" />
|
<option name="suggestChangeDefaultLanguageLevel" value="false" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@ -11,7 +11,7 @@
|
|||||||
],
|
],
|
||||||
"minimum-stability": "stable",
|
"minimum-stability": "stable",
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=7.1",
|
"php": ">=7.4",
|
||||||
"symfony/framework-bundle": ">=4.3",
|
"symfony/framework-bundle": ">=4.3",
|
||||||
"symfony/flex": "^1.2",
|
"symfony/flex": "^1.2",
|
||||||
"symfony/dependency-injection": "^v4.4",
|
"symfony/dependency-injection": "^v4.4",
|
||||||
|
|||||||
@ -11,3 +11,7 @@ services:
|
|||||||
arguments:
|
arguments:
|
||||||
- '%uptime_robot.credentials.api_key%'
|
- '%uptime_robot.credentials.api_key%'
|
||||||
- '@Symfony\Component\Serializer\SerializerInterface'
|
- '@Symfony\Component\Serializer\SerializerInterface'
|
||||||
|
calls:
|
||||||
|
- setInterval: '%uptime_robot.configurations.interval%'
|
||||||
|
- setAlertContactsString: '%uptime_robot.configurations.alert_contacts%'
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Pn\UptimeRobotBundle\Service;
|
namespace Pn\UptimeRobotBundle\Service;
|
||||||
|
|
||||||
|
use Pn\UptimeRobotBundle\Model\AlertContact;
|
||||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
use Symfony\Component\Serializer\SerializerInterface;
|
use Symfony\Component\Serializer\SerializerInterface;
|
||||||
use Vdhicts\UptimeRobot\Client\Client;
|
use Vdhicts\UptimeRobot\Client\Client;
|
||||||
@ -11,6 +12,12 @@ class UptimeRobotApiService
|
|||||||
{
|
{
|
||||||
private $apiKey;
|
private $apiKey;
|
||||||
|
|
||||||
|
private $interval;
|
||||||
|
|
||||||
|
private string $alertContactsString;
|
||||||
|
|
||||||
|
private array $alertContacts;
|
||||||
|
|
||||||
/** @var $client */
|
/** @var $client */
|
||||||
protected $client;
|
protected $client;
|
||||||
|
|
||||||
@ -35,6 +42,7 @@ class UptimeRobotApiService
|
|||||||
|
|
||||||
$this->client = new Client($configuration);
|
$this->client = new Client($configuration);
|
||||||
$this->serializer = $serializer;
|
$this->serializer = $serializer;
|
||||||
|
$this->alertContacts = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -42,7 +50,8 @@ class UptimeRobotApiService
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function isActive(){
|
public function isActive()
|
||||||
|
{
|
||||||
return !empty($this->apiKey);
|
return !empty($this->apiKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,13 +71,64 @@ class UptimeRobotApiService
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getInterval()
|
||||||
|
{
|
||||||
|
return $this->interval;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed $interval
|
||||||
|
*/
|
||||||
|
public function setInterval($interval): void
|
||||||
|
{
|
||||||
|
$this->interval = $interval;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed $alertContactsString
|
||||||
|
*/
|
||||||
|
public function setAlertContactsString(?string $alertContactsString): void
|
||||||
|
{
|
||||||
|
$this->alertContactsString = $alertContactsString;
|
||||||
|
if (!empty($alertContactsString) && $this->isActive()) {
|
||||||
|
$alertContacts = explode(',', $alertContactsString);
|
||||||
|
|
||||||
|
foreach ($alertContacts as $alertContactName) {
|
||||||
|
|
||||||
|
$alertContact = $this->alertContactService->findbyName($alertContactName);
|
||||||
|
if ($alertContact instanceof AlertContact) {
|
||||||
|
$this->alertContacts[] = $alertContact;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getAlertContacts()
|
||||||
|
{
|
||||||
|
return $this->alertContacts;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed $alertContacts
|
||||||
|
*/
|
||||||
|
public function setAlertContacts($alertContacts): void
|
||||||
|
{
|
||||||
|
$this->alertContacts = $alertContacts;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return UptimeRobotMonitorService
|
* @return UptimeRobotMonitorService
|
||||||
*/
|
*/
|
||||||
public function getMonitorService(): UptimeRobotMonitorService
|
public function getMonitorService(): UptimeRobotMonitorService
|
||||||
{
|
{
|
||||||
if (null === $this->monitorService) {
|
if (null === $this->monitorService) {
|
||||||
$this->monitorService = New UptimeRobotMonitorService($this->client);
|
$this->monitorService = new UptimeRobotMonitorService($this->client);
|
||||||
if ($this->io instanceof SymfonyStyle) {
|
if ($this->io instanceof SymfonyStyle) {
|
||||||
$this->monitorService->setIo($this->io);
|
$this->monitorService->setIo($this->io);
|
||||||
}
|
}
|
||||||
@ -82,7 +142,7 @@ class UptimeRobotApiService
|
|||||||
public function getAlertContactService(): UptimeRobotAlertContacsService
|
public function getAlertContactService(): UptimeRobotAlertContacsService
|
||||||
{
|
{
|
||||||
if (null === $this->alertContactService) {
|
if (null === $this->alertContactService) {
|
||||||
$this->alertContactService = New UptimeRobotAlertContacsService($this->client);
|
$this->alertContactService = new UptimeRobotAlertContacsService($this->client);
|
||||||
if ($this->io instanceof SymfonyStyle) {
|
if ($this->io instanceof SymfonyStyle) {
|
||||||
$this->alertContactService->setIo($this->io);
|
$this->alertContactService->setIo($this->io);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user