cloudwatch_logs_insights_url_builder 0.0.5 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e3d56725a23f6ab73a39e5506520875674cb18cbc65fa06899fb4912ded43924
4
- data.tar.gz: ccc7edc00aab56148028d9054cda2d57692ab0fef323d12c3e4d10cffa12594d
3
+ metadata.gz: 34d2f31f3aa8e5546cd5f16090a7614c290070dad11699a3fa0869a2302d2dc9
4
+ data.tar.gz: 5c00488c30674c89a5693bd8eeda4ee634ed9ee9197ead8504a30f268dc36a0f
5
5
  SHA512:
6
- metadata.gz: d686059bbef57f8ca87cb2df54d2cc7e3d13f915b4efb985d32c4b643e99d09729a2bf17b94e41ea08c833af9eee72c8ceac8bb3dc5220fe1a99beb05ddb1360
7
- data.tar.gz: eae567ce0e58e2c7f46327100a13674ce3e6280192f9d34b13f27a257c88e7d95490005ec44e6facceebe0e6686853a1d6c9bc98ec57be965e837485e922e584
6
+ metadata.gz: a1abedef52813b617fffb9689d40d919b1fc37447406fdbee838a55e535199e5962658b0b391dba505be66bbfe86358350fff73071bd0ed5a5fed2b23dc3fc80
7
+ data.tar.gz: 2570eebd4aa8aa5e3005aba36eb840cb0978b1d9a2c7a567a852b48e2aa0a8b31b9d0637cecc51f2284135b52f9e3f61ce8685e73456b8928a6b53625dd4330b
@@ -15,6 +15,7 @@ jobs:
15
15
  uses: ruby/setup-ruby@v1
16
16
  with:
17
17
  bundler-cache: true
18
+ ruby-version: '2.7'
18
19
 
19
20
  - name: Bundler and gem install
20
21
  run: |
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cloudwatch_logs_insights_url_builder (0.0.4)
4
+ cloudwatch_logs_insights_url_builder (0.0.6)
5
5
  url
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,13 +1,13 @@
1
1
  # cloudwatch_logs_url_builder
2
2
 
3
- ![rspec](https://github.com/naomichi-y/cloudwatch_logs_url_builder/actions/workflows/rspec.yml/badge.svg)
3
+ ![rspec](https://github.com/naomichi-y/cloudwatch_logs_insights_url_builder/actions/workflows/rspec.yml/badge.svg)
4
4
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
5
 
6
6
  Generate AWS Console URL for Amazon CloudWatch Insights.
7
7
 
8
8
  ## Installation
9
9
 
10
- ```
10
+ ```ruby
11
11
  gem 'cloudwatch_logs_insights_url_builder'
12
12
  ```
13
13
 
@@ -18,12 +18,13 @@ require 'cloudwatch_logs_insights_url_builder'
18
18
 
19
19
  builder = CloudWatchLogsInsightsUrlBuilder.new
20
20
  builder.time_type = 'ABSOLUTE'
21
- builder.start_time = 24 * 3600
21
+ builder.start_time = - (24 * 3600)
22
22
  builder.end_time = 0
23
-
24
- query = 'fields @timestamp, @message, @logStream, @log\n| sort @timestamp desc\n| limit 2'
25
- log_groups = ['/aws/cloudtrail']
23
+ builder.log_groups = ['/aws/cloudtrail']
26
24
 
27
25
  # https://us-east-1.console.aws.amazon.com/cloudwatch/home?...
28
- builder.log_insights_url(query, log_groups)
26
+ builder.log_insights_url("fields @timestamp, @message, @logStream, @log\n| sort @timestamp desc\n| limit 2")
29
27
  ```
28
+ The generated URL can be used to open the CloudWatch Insights page from a browser.
29
+
30
+ <img width="80%" alt="Screen Shot 2023-01-28 at 12 45 11" src="https://user-images.githubusercontent.com/1632478/215240546-417c523e-692f-47eb-8d01-ccca215d348b.png">
@@ -1,11 +1,14 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'cloudwatch_logs_insights_url_builder'
3
- spec.version = '0.0.5'
3
+ spec.version = '0.0.7'
4
4
  spec.authors = ['naomichi-y']
5
5
  spec.email = ['n.yamakita@gmail.com']
6
6
 
7
7
  spec.summary = 'Generate AWS Console URL for Amazon CloudWatch Insights.'
8
- spec.description = 'Specify log groups and filters to generate URLs accessible to the AWS Console.'
8
+
9
+ spec.description = +'Specify log groups and filters to generate CloudWatch Logs Insights URL '
10
+ spec.description << 'accessible to AWS Console.'
11
+
9
12
  spec.homepage = 'https://github.com/naomichi-y/cloudwatch_logs_insights_url_builder'
10
13
  spec.required_ruby_version = Gem::Requirement.new('>= 2.6.0')
11
14
 
@@ -7,28 +7,28 @@ class CloudWatchLogsInsightsUrlBuilder
7
7
  def add(key, value)
8
8
  case value
9
9
  when Array
10
- result = +encode_key("~#{key}~(")
10
+ result = +encode("~#{key}~(")
11
11
 
12
12
  value.each do |v|
13
- result << "#{encode_key("~'")}#{encode_value(v)}"
13
+ result << "#{encode("~'")}#{encode_value(v)}"
14
14
  end
15
15
 
16
- @conditions << result + encode_key(')')
16
+ @conditions << result + encode(')')
17
17
 
18
18
  when String
19
- @conditions << "#{encode_key("~#{key}~'")}#{encode_value(value)}"
19
+ @conditions << "#{encode("~#{key}~'")}#{encode_value(value)}"
20
20
  else
21
- @conditions << "#{encode_key("~#{key}~")}#{encode_value(value)}"
21
+ @conditions << "#{encode("~#{key}~")}#{encode_value(value)}"
22
22
  end
23
23
  end
24
24
 
25
25
  def build
26
- "#{encode_key('~(')}#{@conditions.join.delete_prefix(encode_key('~'))}#{encode_key(')')}"
26
+ "#{encode('~(')}#{@conditions.join.delete_prefix(encode('~'))}#{encode(')')}"
27
27
  end
28
28
 
29
29
  private
30
30
 
31
- def encode_key(key)
31
+ def encode(key)
32
32
  URI.encode_www_form_component(URI.encode_www_form_component(key)).gsub('%', '$')
33
33
  end
34
34
 
@@ -2,20 +2,21 @@ require 'url'
2
2
  require 'cloudwatch_logs_insights_url_builder/criteria'
3
3
 
4
4
  class CloudWatchLogsInsightsUrlBuilder
5
- attr_accessor :time_type, :timezone, :start_time, :end_time
5
+ attr_accessor :time_type, :timezone, :start_time, :end_time, :log_groups
6
6
 
7
7
  STRING_TIME_FORMAT = '%Y-%m-%dT%T.000Z'.freeze
8
8
 
9
- def initialize(region)
9
+ def initialize(region = 'us-east-1')
10
10
  @region = region
11
11
  @time_type = 'RELATIVE'
12
12
  @timezone = 'Local'
13
13
  @unit = 'minutes'
14
14
  @start_time = -86_400
15
15
  @end_time = 0
16
+ @log_groups = []
16
17
  end
17
18
 
18
- def log_insights_url(query, log_groups = [])
19
+ def log_insights_url(query)
19
20
  url = +"https://#{@region}.console.aws.amazon.com/cloudwatch/home?region=#{@region}#logsV2:logs-insights"
20
21
  url << URI.encode_www_form_component('?queryDetail=').gsub('%', '$')
21
22
 
@@ -30,7 +31,7 @@ class CloudWatchLogsInsightsUrlBuilder
30
31
  builder.add('tz', @timezone)
31
32
  builder.add('editorString', query)
32
33
  builder.add('isLiveTail', false)
33
- builder.add('source', log_groups) if log_groups.size.positive?
34
+ builder.add('source', @log_groups) if @log_groups.size.positive?
34
35
 
35
36
  url << builder.build
36
37
  url
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudwatch_logs_insights_url_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - naomichi-y
@@ -80,8 +80,8 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- description: Specify log groups and filters to generate URLs accessible to the AWS
84
- Console.
83
+ description: Specify log groups and filters to generate CloudWatch Logs Insights URL
84
+ accessible to AWS Console.
85
85
  email:
86
86
  - n.yamakita@gmail.com
87
87
  executables: []