-
Notifications
You must be signed in to change notification settings - Fork 0
/
Monitoring.php
50 lines (41 loc) · 1.5 KB
/
Monitoring.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
namespace Monitoring;
class Monitoring
{
const HANDLERS = 'handlers';
const STATES = 'states';
/**
* @param array $config
* @param string $handlerConfig
* @param string $stateConfig
*/
public function __construct( $config = array(), $handlerConfig = self::HANDLERS, $stateConfig = self::STATES )
{
$this->_basePath = isset($config['base_path']) ? $config['base_path'] : __DIR__;
$this->_config = $config;
$this->monitoring($handlerConfig, $stateConfig);
}
/**
* @param string $handlerConfig
* @param string $stateConfig
* @throws MonitoringException
*/
public function monitoring( $handlerConfig = self::HANDLERS, $stateConfig = self::STATES )
{
if (!isset($this->_config[$handlerConfig])) {
throw new MonitoringException('Should set `handler` config');
}
if (!isset($this->_config[$stateConfig])) {
throw new MonitoringException('Should set `states` config');
}
$duplicate = null;
if( $this->_config['duplicate'] ) {
$this->_config['duplicate']['base_path'] = $this->_basePath;
$duplicate = new CheckDuplicate($this->_config['duplicate']);
}
$handler = new AlertHandlers( $this->_config[$handlerConfig], $duplicate, $this->_basePath );
$stateList = new AlertStates( $handler, $this->_config[$stateConfig], $this->_basePath );
$stateList->verifyError();
$duplicate->saveFile();
}
}