Skip to content

Commit 40759e7

Browse files
committed
Add script : delete alames created.
1 parent 35c5d30 commit 40759e7

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ Autorize this policy :
2727
"Effect": "Allow",
2828
"Action": [
2929
"cloudwatch:PutMetricAlarm",
30-
"cloudwatch:PutMetricData"
30+
"cloudwatch:PutMetricData",
31+
"cloudwatch:DeleteAlarms"
3132
],
3233
"Resource": [
3334
"*"
@@ -63,6 +64,11 @@ Create alarme in Cloud Watch (Run one time)
6364
php alarmes.php [-f config-file]
6465
```
6566

67+
Delte alarme in Cloud Watch (Run one time)
68+
```
69+
php delete-alarmes.php [-f config-file]
70+
```
71+
6672
## Plugins
6773

6874
| Name | Description |

delete-alarmes.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
define('APPLICATION_PATH', realpath(dirname(__FILE__)));
3+
4+
include APPLICATION_PATH . '/vendor/autoload.php';
5+
require_once 'lib.php';
6+
7+
use Aws\CloudWatch\CloudWatchClient;
8+
9+
// Load config file.
10+
$conf = getConfigFile();
11+
if ($conf === false) {
12+
echo "Conf file is not valid";
13+
die();
14+
}
15+
// Store metric by namespace in order to call "AWS Could Watch" one time per namespace
16+
$metricsToPush = array();
17+
18+
// Get Instance Id
19+
$instanceId = file_get_contents("http://169.254.169.254/latest/meta-data/instance-id");
20+
21+
$client = getCloudWatchClient($conf);
22+
23+
foreach ($conf->metrics as $metrics) {
24+
foreach ($metrics as $metricName => $metric) {
25+
$pluginName = isset($metric->{'plugin'})===true?$metric->{'plugin'}:$metricName;
26+
$className = "CloudWatchScript\\Plugins\\" . $pluginName . "Monitoring";
27+
28+
$metricController = new $className($metric, $metric->name);
29+
30+
foreach ($metricController->getAlarms() as $key => $alarm) {
31+
$client->deleteAlarms(array(
32+
'AlarmNames' => array($alarm["Name"])
33+
));
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)