alerty-plugin-amazon_sns 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +2 -1
- data/alerty-plugin-amazon_sns.gemspec +1 -1
- data/lib/alerty/plugin/amazon_sns.rb +18 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b748815b308593963baddf3e99474586b95ad4a7
|
4
|
+
data.tar.gz: 7fab8979be67329acdcbb1e507acf3469e29c1a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d54cb95bc5a4648960ac13b6b11b8694ffc91562c0f0dbadc25c9b9316f58c791f4a86a4846b98c1b3562f95c9b27cdf6e338a9797da49480f61c0a1767e5cee
|
7
|
+
data.tar.gz: bc0dc677367e3646b77436538e526d2ac2d1580409f46d3f6ec207cd57f2cdb990a3aae4cd2b4ddf3452107487399b5512ee7df07187225c420601b6255581f4
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -22,7 +22,8 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
* **type**: must be `amazon_sns`
|
24
24
|
* **topc_arn**: Amazon SNS topic name
|
25
|
-
* **subject**: subject of alert. `${command}` is replaced with a given command, `${hostname}` is replaced with the hostname ran
|
25
|
+
* **subject**: subject of alert. `${command}` is replaced with a given command, `${hostname}` is replaced with the hostname ran the command, `${output}` is replaced with the output.
|
26
|
+
* **message**: message of alert. `${command}` is replaced with a given command, `${hostname}` is replaced with the hostname ran the command, `${output}` is replaced with the output. The default is `${output}`.
|
26
27
|
* **aws_region**: AWS Region. (default: guess from topic_arn, like arn:aws:sns:us-east-1:<account_id>:<topic_name> => us-east-1)
|
27
28
|
* **aws_access_key_id**: Credential key id (default: ENV['AWS_SECRET_KEY_id'] or ~/.aws/credentials or instance profile on EC2)
|
28
29
|
* **aws_secret_access_key**: Credential secret access_key (default: ENV['AWS_SECRET_ACCESS_KEY'] or ~/.aws/credentials or instance profile on EC2)
|
@@ -17,14 +17,14 @@ class Alerty
|
|
17
17
|
params[:secret_access_key] = config.aws_secret_access_key if config.aws_secret_access_key
|
18
18
|
@client = Aws::SNS::Client.new(params)
|
19
19
|
@subject = config.subject
|
20
|
+
@message = config.message
|
20
21
|
@topic_arn = config.topic_arn
|
21
22
|
@num_retries = config.num_retries || 3
|
22
23
|
end
|
23
24
|
|
24
25
|
def alert(record)
|
25
|
-
|
26
|
-
|
27
|
-
subject = subject[0..98] # SNS constraint, must be less than 100 character long
|
26
|
+
subject = get_subject(record)
|
27
|
+
message = get_message(record)
|
28
28
|
retries = 0
|
29
29
|
begin
|
30
30
|
@client.publish(topic_arn: @topic_arn, message: message, subject: subject)
|
@@ -42,13 +42,27 @@ class Alerty
|
|
42
42
|
|
43
43
|
private
|
44
44
|
|
45
|
+
def get_message(record)
|
46
|
+
message = @message.nil? ? record[:output] : expand_placeholder(@message, record)
|
47
|
+
message = ' ' if message.empty? # SNS constraint, SNS errors if message is empty
|
48
|
+
message
|
49
|
+
end
|
50
|
+
|
51
|
+
def get_subject(record)
|
52
|
+
subject = expand_placeholder(@subject, record)
|
53
|
+
subject = subject[0..98] # SNS constraint, must be less than 100 character long
|
54
|
+
end
|
55
|
+
|
45
56
|
def guess_region(topic_arn)
|
46
57
|
# arn:aws:sns:ap-northeast-1:<account_id>:<topic_name>
|
47
58
|
topic_arn.split(':')[3]
|
48
59
|
end
|
49
60
|
|
50
61
|
def expand_placeholder(str, record)
|
51
|
-
str.gsub('${command}', record[:command])
|
62
|
+
replaced = str.gsub('${command}', record[:command])
|
63
|
+
replaced.gsub!('${hostname}', record[:hostname])
|
64
|
+
replaced.gsub!('${output}', record[:output])
|
65
|
+
replaced
|
52
66
|
end
|
53
67
|
end
|
54
68
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alerty-plugin-amazon_sns
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Naotoshi Seo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: alerty
|