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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2952989f7eaff60bf2ef7b18c849edb47423e093b25916f3d1ee715bd223f5bb
|
4
|
+
data.tar.gz: 0c86fb1d3437e3d6c69f6d7f043e98b598a93f9789d7a9db453b96c83a57929d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c36b6c47e31d354c930ba71a7e7e4e311dcdbf6a723c79d1be691b81d247f1746965d16118c07334430f78cc98df359742639129898aaf7c6e11cdb89ef0d9ca
|
7
|
+
data.tar.gz: f571b2ff89607d6694aa7dfe1939d804c2587b03df7184cd3714a43a904d2aceac6a8f6a01373376f9b400983cfd5585465f2a66935ba19171ac4a699d4ceeff
|
data/.github/workflows/rspec.yml
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
# cloudwatch_logs_url_builder
|
2
2
|
|
3
|
-

|
4
4
|
[](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(
|
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.
|
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
|
-
|
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 = +
|
10
|
+
result = +encode("~#{key}~(")
|
11
11
|
|
12
12
|
value.each do |v|
|
13
|
-
result << "#{
|
13
|
+
result << "#{encode("~'")}#{encode_value(v)}"
|
14
14
|
end
|
15
15
|
|
16
|
-
@conditions << result +
|
16
|
+
@conditions << result + encode(')')
|
17
17
|
|
18
18
|
when String
|
19
|
-
@conditions << "#{
|
19
|
+
@conditions << "#{encode("~#{key}~'")}#{encode_value(value)}"
|
20
20
|
else
|
21
|
-
@conditions << "#{
|
21
|
+
@conditions << "#{encode("~#{key}~")}#{encode_value(value)}"
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
def build
|
26
|
-
"#{
|
26
|
+
"#{encode('~(')}#{@conditions.join.delete_prefix(encode('~'))}#{encode(')')}"
|
27
27
|
end
|
28
28
|
|
29
29
|
private
|
30
30
|
|
31
|
-
def
|
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
|
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.
|
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
|
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: []
|