1
|
|
|
<?php |
2
|
|
|
namespace CloudWatchScript\Plugins; |
3
|
|
|
|
4
|
|
|
use CloudWatchScript\AbstractMonitoring; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Check Solr using ping URL. |
8
|
|
|
* Add and configure the folliwong lines to the config file |
9
|
|
|
* "Sftp" : { |
10
|
|
|
* "name" : "Name of metric and alarm", |
11
|
|
|
* "addr": "127.0.0.1", |
12
|
|
|
* "port": "22", |
13
|
|
|
* "login": "login", |
14
|
|
|
* "password": "password", |
15
|
|
|
* "namespace": "Metric/Namespace", |
16
|
|
|
* "description": "Descrption" |
17
|
|
|
* } |
18
|
|
|
*/ |
19
|
|
|
class SftpMonitoring extends AbstractMonitoring |
20
|
|
|
{ |
21
|
|
|
private $addr; |
22
|
|
|
private $port; |
23
|
|
|
private $login; |
24
|
|
|
private $password; |
25
|
|
|
/** |
26
|
|
|
* @param array $config |
27
|
|
|
* @param String $name |
28
|
|
|
*/ |
29
|
|
|
public function __construct($config, $name) |
30
|
|
|
{ |
31
|
|
|
parent::__construct($config, $name); |
32
|
|
|
$this->addr = $this->config->addr; |
33
|
|
|
$this->port = $this->config->port; |
34
|
|
|
$this->login = $this->config->login; |
35
|
|
|
$this->password = $this->config->password; |
36
|
|
|
} |
37
|
|
|
/** |
38
|
|
|
* Check solr ping url. |
39
|
|
|
* @return metric 0 KO, 1 OK |
40
|
|
|
*/ |
41
|
|
|
public function getMetric() |
42
|
|
|
{ |
43
|
|
|
$connection = ssh2_connect($this->addr, $this->port); |
44
|
|
|
if ($connection === false) { |
45
|
|
|
return 0; |
46
|
|
|
} |
47
|
|
|
if (ssh2_auth_password($connection, $this->login, $this->password) == false) { |
|
|
|
|
48
|
|
|
return 0; |
49
|
|
|
} |
50
|
|
|
$sftp = ssh2_sftp($connection); |
51
|
|
|
if ($sftp === false) { |
52
|
|
|
return 0; |
53
|
|
|
} |
54
|
|
|
return 1; |
55
|
|
|
} |
56
|
|
|
/** |
57
|
|
|
* @return string "None" |
58
|
|
|
*/ |
59
|
|
|
public function getUnit() |
60
|
|
|
{ |
61
|
|
|
return "None"; |
62
|
|
|
} |
63
|
|
|
/** |
64
|
|
|
* @return integer 1 |
65
|
|
|
*/ |
66
|
|
|
public function getAlarms() |
67
|
|
|
{ |
68
|
|
|
return array( |
69
|
|
|
array("ComparisonOperator" => "LessThanThreshold", |
70
|
|
|
"Threshold" => 1, |
71
|
|
|
"Name" => $this->name) |
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
When comparing two booleans, it is generally considered safer to use the strict comparison operator.