cloudwatch_logs_insights_url_builder 0.0.1 → 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
  SHA256:
3
- metadata.gz: 76f321c616c87f935c6698cd13d763fea55e3ded22ceeccc7bf3ce9e4444d644
4
- data.tar.gz: 55a903d5832dae43ec348b7c35df2bf3f9cd4a5a7212fa09db2c0f61e3c245c9
3
+ metadata.gz: 2952989f7eaff60bf2ef7b18c849edb47423e093b25916f3d1ee715bd223f5bb
4
+ data.tar.gz: 0c86fb1d3437e3d6c69f6d7f043e98b598a93f9789d7a9db453b96c83a57929d
5
5
  SHA512:
6
- metadata.gz: 443eebdfe8bf3530385502ae71a20c824ae80237feeb74c8072967cbe2a23e35851a35b3587cecf20ac455c1278c6b2701bff9c4054940bba4e1dcc9beef017e
7
- data.tar.gz: 6faec77bd5a6bed72d28e6a417ad7dfe1495cb9b602f922bdca2abf279b2c1858aa47cb18ee97cdc50fb1b4963e29d11bcda243fc391ef4003e504488b3726b5
6
+ metadata.gz: c36b6c47e31d354c930ba71a7e7e4e311dcdbf6a723c79d1be691b81d247f1746965d16118c07334430f78cc98df359742639129898aaf7c6e11cdb89ef0d9ca
7
+ data.tar.gz: f571b2ff89607d6694aa7dfe1939d804c2587b03df7184cd3714a43a904d2aceac6a8f6a01373376f9b400983cfd5585465f2a66935ba19171ac4a699d4ceeff
@@ -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
- Generate AWS Console URL for Amazon CloudWatch.
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
 
@@ -20,10 +20,11 @@ builder = CloudWatchLogsInsightsUrlBuilder.new
20
20
  builder.time_type = 'ABSOLUTE'
21
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.1'
3
+ spec.version = '0.0.6'
4
4
  spec.authors = ['naomichi-y']
5
5
  spec.email = ['n.yamakita@gmail.com']
6
6
 
7
- spec.summary = 'Generate AWS Console URL for Amazon CloudWatch.'
8
- spec.description = 'Specify log groups and filters to generate URLs accessible to the AWS Console.'
7
+ spec.summary = 'Generate AWS Console URL for Amazon CloudWatch Insights.'
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,7 +2,7 @@ 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
 
@@ -13,9 +13,10 @@ class CloudWatchLogsInsightsUrlBuilder
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.1
4
+ version: 0.0.6
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: []
@@ -128,5 +128,5 @@ requirements: []
128
128
  rubygems_version: 3.0.1
129
129
  signing_key:
130
130
  specification_version: 4
131
- summary: Generate AWS Console URL for Amazon CloudWatch.
131
+ summary: Generate AWS Console URL for Amazon CloudWatch Insights.
132
132
  test_files: []