cloud_watch_logs_poller 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 527dec092ed98ff28cfa44f2cff0dc7f225a5dd232e8721b669b3cac615d0e44
4
+ data.tar.gz: 54f4d32fe73c65249494b7b1444c1a8900c89b7dfc1c1599b36aa296aea8990e
5
+ SHA512:
6
+ metadata.gz: 8092cac6c07d2b048ff85230938d1beb99178d26d69726b60ff1cbf8389bffe85aedfd2c35d779269fef69e251d7a60849f2cf8ffa4e93049fbfb2539a003c9f
7
+ data.tar.gz: f3fa6a8b8b2377efee81c0f4af257c081ae222be8471d27f457d1ed2565b7381dd267c99708f076c768e8bdf39703537439b35ecc26dfd0f08d77e6f6b81e630
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ vendor
14
+
15
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.3
7
+ before_install: gem install bundler -v 2.0.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in cloud_watch_logs_poller.gemspec
4
+ gemspec
@@ -0,0 +1,45 @@
1
+ # CloudWatchLogsPoller
2
+
3
+ Polling Cloud Watch Logs.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'cloud_watch_logs_poller'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install cloud_watch_logs_poller
20
+
21
+ ## Usage
22
+
23
+ - Set Aws credentials
24
+ - AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY / AWS_REGION
25
+
26
+ ```
27
+ interval = 10 # seconds
28
+ log_group_name = 'logs'
29
+ filter_pattern = 'ERROR'
30
+
31
+ poller_process = CloudWatchLogsPoller::Process.new(interval)
32
+ poller_process.execute(log_group_name: log_group_name, filter_pattern: filter_pattern) do |event|
33
+ puts event
34
+ end
35
+ ```
36
+
37
+ ## Development
38
+
39
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
40
+
41
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
42
+
43
+ ## Contributing
44
+
45
+ Bug reports and pull requests are welcome on GitHub at https://github.com/taka0125/cloud_watch_logs_poller.
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "cloud_watch_logs_poller"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,30 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "cloud_watch_logs_poller/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cloud_watch_logs_poller"
8
+ spec.version = CloudWatchLogsPoller::VERSION
9
+ spec.authors = ["Takahiro Ooishi"]
10
+ spec.email = ["taka0125@gmail.com"]
11
+
12
+ spec.summary = %q{Polling Cloud Watch Logs}
13
+ spec.description = %q{Polling Cloud Watch Logs}
14
+ spec.homepage = "https://github.com/taka0125/cloud_watch_logs_poller"
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_dependency "aws-sdk-cloudwatchlogs", "~> 1.0"
26
+
27
+ spec.add_development_dependency "bundler", "~> 2.0"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "rspec", "~> 3.0"
30
+ end
@@ -0,0 +1,9 @@
1
+ require "aws-sdk-cloudwatchlogs"
2
+ require "cloud_watch_logs_poller/version"
3
+ require "cloud_watch_logs_poller/event"
4
+ require "cloud_watch_logs_poller/process"
5
+
6
+ module CloudWatchLogsPoller
7
+ class Error < StandardError; end
8
+ # Your code goes here...
9
+ end
@@ -0,0 +1,27 @@
1
+ module CloudWatchLogsPoller
2
+ class Event
3
+ attr_reader :log_stream_name
4
+ attr_reader :timestamp
5
+ attr_reader :message
6
+ attr_reader :ingestion_time
7
+ attr_reader :event_id
8
+
9
+ def initialize(log_stream_name, timestamp, message, ingestion_time, event_id)
10
+ @log_stream_name = log_stream_name
11
+ @timestamp = timestamp
12
+ @message = message
13
+ @ingestion_time = ingestion_time
14
+ @event_id = event_id
15
+ end
16
+
17
+ def self.convert_from_filtered_log_event(event)
18
+ new(
19
+ event.log_stream_name,
20
+ event.timestamp,
21
+ event.message,
22
+ event.ingestion_time,
23
+ event.event_id
24
+ )
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,47 @@
1
+ module CloudWatchLogsPoller
2
+ class Process
3
+ def initialize(interval, debug: false)
4
+ @client = Aws::CloudWatchLogs::Client.new
5
+ @interval = interval
6
+ @debug = debug
7
+ end
8
+
9
+ def execute(log_group_name:, log_stream_name_prefix: nil, filter_pattern: nil, start_time: Time.now, &block)
10
+ params = {
11
+ log_group_name: log_group_name,
12
+ log_stream_name_prefix: log_stream_name_prefix,
13
+ start_time: start_time.is_a?(Time) ? start_time.to_i * 1000 : start_time,
14
+ filter_pattern: filter_pattern,
15
+ interleaved: true
16
+ }
17
+
18
+ loop do
19
+ loop do
20
+ result = @client.filter_log_events(params)
21
+ result.events.each do |event|
22
+ block.call(Event.convert_from_filtered_log_event(event))
23
+ end
24
+
25
+ debug_log(params)
26
+ debug_log(result)
27
+
28
+ break unless result.next_token
29
+
30
+ params[:next_token] = result.next_token
31
+ end
32
+
33
+ sleep(@interval)
34
+ end
35
+ rescue Interrupt
36
+ puts "Polling stopped."
37
+ end
38
+
39
+ private
40
+
41
+ def debug_log(message)
42
+ return unless @debug
43
+
44
+ puts "[#{Time.now}] #{message}"
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,3 @@
1
+ module CloudWatchLogsPoller
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cloud_watch_logs_poller
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Takahiro Ooishi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-12-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aws-sdk-cloudwatchlogs
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: Polling Cloud Watch Logs
70
+ email:
71
+ - taka0125@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - README.md
81
+ - Rakefile
82
+ - bin/console
83
+ - bin/setup
84
+ - cloud_watch_logs_poller.gemspec
85
+ - lib/cloud_watch_logs_poller.rb
86
+ - lib/cloud_watch_logs_poller/event.rb
87
+ - lib/cloud_watch_logs_poller/process.rb
88
+ - lib/cloud_watch_logs_poller/version.rb
89
+ homepage: https://github.com/taka0125/cloud_watch_logs_poller
90
+ licenses: []
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubygems_version: 3.0.3
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Polling Cloud Watch Logs
111
+ test_files: []