-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloudwatch.php
79 lines (59 loc) · 1.61 KB
/
cloudwatch.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<!DOCTYPE html>
<html>
<head>
<title>Cloudwatch Status</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
</head>
<body>
<?php
// Include local configuration
if (file_exists(dirname(__FILE__) . '/local-config.php')) {
include(dirname(__FILE__) . '/local-config.php');
}
if (getenv('access_key')) {
define('ACCESS_KEY', getenv('access_key'));
}
if (getenv('secret_key')) {
define('SECRET_KEY', getenv('secret_key'));
}
if (getenv('slack_token')) {
define('SLACK_TOKEN', getenv('slack_token'));
}
// Include the SDK using the Composer autoloader
require 'vendor/autoload.php';
use Aws\CloudWatch\CloudWatchClient;
use Aws\Common\Credentials\Credentials;
$credentials = new Credentials(ACCESS_KEY, SECRET_KEY);
$client = CloudWatchClient::factory(array(
'credentials' => $credentials,
'region' => 'us-east-1'
));
$alarmsResult = $client->describeAlarms();
$alarms = $alarmsResult->get('MetricAlarms');
?>
<div class="container">
<div class="page-header">
<h1>CloudWatch Alarm Status</h1>
</div>
<table class="table table-condensed">
<tbody>
<?php foreach ($alarms as $alarm) : ?>
<?php
if ($alarm['StateValue'] == "OK") {
$textClass = "text-success";
} else {
$rowClass = "danger";
$textClass = "text-danger";
}
?>
<tr class="<?php echo $rowClass ?>">
<td><strong class="<?php echo $textClass ?>"><?php echo $alarm['StateValue'] ?></strong></td>
<td><?php echo $alarm['AlarmName'] ?></td>
</tr>
<?php endforeach;?>
</tbody>
</table>
<pre><?php print_r($alarms);?></pre>
</div>
</body>
</html>