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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 32c4497d480d72360d5e2a067c84aad969ee380b
4
- data.tar.gz: 8b06a6b6281e2320694b52d194557be217950b78
3
+ metadata.gz: b748815b308593963baddf3e99474586b95ad4a7
4
+ data.tar.gz: 7fab8979be67329acdcbb1e507acf3469e29c1a1
5
5
  SHA512:
6
- metadata.gz: 73bc346ad396a0302c745fb993281b5451cf68b2ad2357b7ba2086ffbf991426a4607adc31c732f11e0a12caaf88177caeec7402c9fa9f5c7aace8e3f7e10a7d
7
- data.tar.gz: e12390631701edd434f4608ac7a4b54a426e89d005266e1880119e450b9bba33780d2aa516f0efe725a6f84260dc5e2c8eea36e1db3e5abef6accf8ad005ead8
6
+ metadata.gz: d54cb95bc5a4648960ac13b6b11b8694ffc91562c0f0dbadc25c9b9316f58c791f4a86a4846b98c1b3562f95c9b27cdf6e338a9797da49480f61c0a1767e5cee
7
+ data.tar.gz: bc0dc677367e3646b77436538e526d2ac2d1580409f46d3f6ec207cd57f2cdb990a3aae4cd2b4ddf3452107487399b5512ee7df07187225c420601b6255581f4
@@ -1,3 +1,10 @@
1
+ # 0.0.6 (2017/01/31)
2
+
3
+ Changes:
4
+
5
+ * Replace message with a white space if empty to avoid SNS empty message errors
6
+ * Add message config
7
+
1
8
  # 0.0.5 (2016/12/08)
2
9
 
3
10
  Changes:
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 a command
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)
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "alerty-plugin-amazon_sns"
5
- spec.version = "0.0.5"
5
+ spec.version = "0.0.6"
6
6
  spec.authors = ["Naotoshi Seo"]
7
7
  spec.email = ["sonots@gmail.com"]
8
8
 
@@ -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
- message = record[:output]
26
- subject = expand_placeholder(@subject, record)
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]).gsub('${hostname}', record[:hostname])
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.5
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: 2016-12-08 00:00:00.000000000 Z
11
+ date: 2017-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: alerty