heart_top 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +26 -0
- data/Gemfile +4 -2
- data/Rakefile +5 -3
- data/bin/console +4 -3
- data/bin/hearttop +4 -3
- data/heart_top.gemspec +19 -16
- data/lib/heart_top/agent.rb +20 -16
- data/lib/heart_top/cli.rb +101 -101
- data/lib/heart_top/plugin/base.rb +11 -5
- data/lib/heart_top/plugin/slack.rb +26 -6
- data/lib/heart_top/plugin.rb +2 -0
- data/lib/heart_top/schedule.rb +3 -1
- data/lib/heart_top/version.rb +3 -1
- data/lib/heart_top.rb +2 -0
- metadata +23 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3323458320eb456251621f2133e26371244e472
|
4
|
+
data.tar.gz: 445a18599febd626d1cae53215f807c1794f3a66
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4dc44252dfe86817e04797ab4f1964cb63c2b5e278f6b21e9bb56835b52d9cb1c6f5aac43ee873f57dcd94baf7ec00513b15967f46d4d39fcbbd44777c1b3995
|
7
|
+
data.tar.gz: 35af02250311501ac9538739c7aa63b5375a91a4d6ffcf0e773fbbb7fc17ce21eb5e2dc87d6a3a3261c00bf2ab19b6c12fdb59472d1987df9c9ccb4daf141c24
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude: []
|
3
|
+
TargetRubyVersion: 2.3
|
4
|
+
|
5
|
+
Bundler/OrderedGems:
|
6
|
+
Enabled: false
|
7
|
+
|
8
|
+
Metrics/BlockLength:
|
9
|
+
Exclude:
|
10
|
+
- '*.gemspec'
|
11
|
+
- 'spec/**/*'
|
12
|
+
|
13
|
+
Metrics/LineLength:
|
14
|
+
Max: 130
|
15
|
+
Exclude:
|
16
|
+
- '*.gemspec'
|
17
|
+
- 'spec/**/*'
|
18
|
+
|
19
|
+
Metrics/MethodLength:
|
20
|
+
Max: 120
|
21
|
+
|
22
|
+
Metrics/AbcSize:
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
Style/Documentation:
|
26
|
+
Enabled: false
|
data/Gemfile
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
4
6
|
|
5
7
|
# Specify your gem's dependencies in heart_top.gemspec
|
6
8
|
gemspec
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require
|
4
|
-
require
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'heart_top'
|
5
6
|
|
6
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
8
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +11,5 @@ require "heart_top"
|
|
10
11
|
# require "pry"
|
11
12
|
# Pry.start
|
12
13
|
|
13
|
-
require
|
14
|
+
require 'irb'
|
14
15
|
IRB.start(__FILE__)
|
data/bin/hearttop
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
3
4
|
|
4
5
|
# resolve bin path, ignoring symlinks
|
5
|
-
require
|
6
|
+
require 'pathname'
|
6
7
|
bin_file = Pathname.new(__FILE__).realpath
|
7
8
|
|
8
9
|
# add self to libpath
|
9
|
-
|
10
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', bin_file)
|
10
11
|
|
11
12
|
require 'heart_top'
|
12
|
-
HeartTop::CLI.run
|
13
|
+
HeartTop::CLI.run
|
data/heart_top.gemspec
CHANGED
@@ -1,32 +1,35 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
5
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
6
|
+
require 'heart_top/version'
|
5
7
|
|
6
8
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
9
|
+
spec.name = 'heart_top'
|
8
10
|
spec.version = HeartTop::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
11
|
+
spec.authors = ['Faizal Zakaria']
|
12
|
+
spec.email = ['fzakaria@codegarage.co']
|
11
13
|
|
12
|
-
spec.summary =
|
14
|
+
spec.summary = 'HeartTop pings the heartbeat of your laptop every N seconds'
|
13
15
|
spec.description = "Have you ever go to free space, coffee shops or some random place to work, \
|
14
16
|
and you need to to toilet for pee, or big business? Then worried what would happen to your laptop? \
|
15
17
|
This tool could be the solution"
|
16
|
-
spec.homepage =
|
17
|
-
spec.license =
|
18
|
+
spec.homepage = 'https://github.com/faizalzakaria/heart_top'
|
19
|
+
spec.license = 'MIT'
|
18
20
|
|
19
21
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
20
22
|
f.match(%r{^(test|spec|features)/})
|
21
23
|
end
|
22
|
-
spec.bindir =
|
24
|
+
spec.bindir = 'bin'
|
23
25
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
24
|
-
spec.require_paths = [
|
26
|
+
spec.require_paths = ['lib']
|
25
27
|
|
26
|
-
spec.add_development_dependency
|
27
|
-
spec.add_development_dependency
|
28
|
-
spec.add_development_dependency
|
29
|
-
spec.
|
30
|
-
spec.add_dependency
|
31
|
-
spec.add_dependency
|
28
|
+
spec.add_development_dependency 'bundler', '~> 1.15'
|
29
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
30
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
31
|
+
spec.add_development_dependency 'rubocop', '~> 0.49'
|
32
|
+
spec.add_dependency 'terminal-table', '~> 1.8'
|
33
|
+
spec.add_dependency 'rainbow', '~> 2.2'
|
34
|
+
spec.add_dependency 'dante', '~> 0.2'
|
32
35
|
end
|
data/lib/heart_top/agent.rb
CHANGED
@@ -1,26 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'heart_top/plugin'
|
2
4
|
|
3
|
-
|
4
|
-
|
5
|
+
module HeartTop
|
6
|
+
class Agent
|
7
|
+
PLUGINS = %i[slack].freeze
|
5
8
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
9
|
+
def initialize(interval:, verbose:)
|
10
|
+
@interval = interval
|
11
|
+
@verbose = verbose
|
12
|
+
end
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
14
|
+
def run
|
15
|
+
loop do
|
16
|
+
execute_plugins
|
17
|
+
sleep @interval
|
18
|
+
end
|
15
19
|
end
|
16
|
-
end
|
17
20
|
|
18
|
-
|
21
|
+
private
|
19
22
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
23
|
+
def execute_plugins
|
24
|
+
puts 'executing ...' if @verbose
|
25
|
+
PLUGINS.each do |plugin|
|
26
|
+
Object.const_get("HeartTop::Plugin::#{plugin.capitalize}").instance.send('ping')
|
27
|
+
end
|
24
28
|
end
|
25
29
|
end
|
26
30
|
end
|
data/lib/heart_top/cli.rb
CHANGED
@@ -1,116 +1,116 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'heart_top/agent'
|
2
4
|
require 'getoptlong'
|
3
5
|
require 'terminal-table'
|
4
6
|
require 'rainbow'
|
5
7
|
require 'dante'
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
end
|
51
|
-
|
52
|
-
def stop!
|
53
|
-
Dante::Runner
|
54
|
-
.new('hearttop')
|
55
|
-
.execute(:kill => true, :pid_path => pid_path)
|
56
|
-
end
|
57
|
-
|
58
|
-
def set_defaults
|
59
|
-
@interval ||= 10
|
60
|
-
@verbose ||= false
|
61
|
-
end
|
62
|
-
|
63
|
-
def parse_args!(args)
|
64
|
-
opts = GetoptLong.new([ '--help', '-h', GetoptLong::NO_ARGUMENT ],
|
65
|
-
[ '--interval', '-i', GetoptLong::REQUIRED_ARGUMENT ],
|
66
|
-
[ '--verbose', '-v', GetoptLong::NO_ARGUMENT ])
|
67
|
-
@interval = nil
|
68
|
-
@verboes = nil
|
69
|
-
opts.each do |opt, arg|
|
70
|
-
case opt
|
71
|
-
when '--help'
|
72
|
-
print_help
|
73
|
-
when '--interval'
|
74
|
-
@interval = arg
|
75
|
-
when '--verbose'
|
76
|
-
@verbose = true
|
77
|
-
end
|
78
|
-
end
|
79
|
-
@command = args.last
|
80
|
-
unless supported_commands?(@command)
|
81
|
-
raise UnsupportedCommand.new(Rainbow("Unsupported command detected, ").red + Rainbow(@command).green)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
def supported_commands?(cmd)
|
86
|
-
%w(stop start).include?(cmd)
|
87
|
-
end
|
88
|
-
|
89
|
-
def print_details
|
90
|
-
return unless @verbose
|
91
|
-
table = Terminal::Table.new do |t|
|
92
|
-
t << [Rainbow('verbose').green, Rainbow(@verbose).green]
|
93
|
-
t.add_row [Rainbow('interval').green, Rainbow(@interval).green]
|
94
|
-
t.add_row [Rainbow('command').green, Rainbow(@command).green]
|
9
|
+
module HeartTop
|
10
|
+
class CLI
|
11
|
+
attr_accessor :verbose, :interval
|
12
|
+
|
13
|
+
class UnsupportedCommand < StandardError; end
|
14
|
+
|
15
|
+
class << self
|
16
|
+
def run
|
17
|
+
begin
|
18
|
+
parse_args!
|
19
|
+
rescue UnsupportedCommand => e
|
20
|
+
print_error(e.message)
|
21
|
+
exit
|
22
|
+
end
|
23
|
+
set_defaults
|
24
|
+
print_details
|
25
|
+
execute
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def execute!
|
31
|
+
send("#{@command}!")
|
32
|
+
end
|
33
|
+
|
34
|
+
def pid_path
|
35
|
+
'/tmp/heartop.pid'
|
36
|
+
end
|
37
|
+
|
38
|
+
def log_path
|
39
|
+
'/tmp/hearttop.log'
|
40
|
+
end
|
41
|
+
|
42
|
+
def start
|
43
|
+
options = {
|
44
|
+
interval: @interval,
|
45
|
+
verbose: @verbose
|
46
|
+
}
|
47
|
+
Dante::Runner
|
48
|
+
.new('hearttop')
|
49
|
+
.execute(daemonize: true, pid_path: pid_path, log_path: log_path) do |_opts|
|
50
|
+
HeartTop::Agent.new(options).run
|
51
|
+
end
|
95
52
|
end
|
96
|
-
puts table
|
97
|
-
end
|
98
53
|
|
99
|
-
|
100
|
-
|
101
|
-
|
54
|
+
def stop
|
55
|
+
Dante::Runner
|
56
|
+
.new('hearttop')
|
57
|
+
.execute(kill: true, pid_path: pid_path)
|
58
|
+
end
|
59
|
+
|
60
|
+
def set_defaults
|
61
|
+
@interval ||= 10
|
62
|
+
@verbose ||= false
|
63
|
+
end
|
102
64
|
|
103
|
-
|
104
|
-
|
105
|
-
|
65
|
+
def parse_args!
|
66
|
+
opts = GetoptLong.new(['--help', '-h', GetoptLong::NO_ARGUMENT],
|
67
|
+
['--interval', '-i', GetoptLong::REQUIRED_ARGUMENT],
|
68
|
+
['--verbose', '-v', GetoptLong::NO_ARGUMENT])
|
69
|
+
@interval = nil
|
70
|
+
@verboes = nil
|
71
|
+
opts.each do |opt, arg|
|
72
|
+
case opt
|
73
|
+
when '--help'
|
74
|
+
print_help
|
75
|
+
when '--interval'
|
76
|
+
@interval = arg
|
77
|
+
when '--verbose'
|
78
|
+
@verbose = true
|
79
|
+
end
|
80
|
+
end
|
81
|
+
@command = ARGV.shift
|
82
|
+
return if supported_commands?(@command)
|
83
|
+
raise UnsupportedCommand, Rainbow('Unsupported command detected, ').red + Rainbow(@command).green
|
84
|
+
end
|
106
85
|
|
107
|
-
|
108
|
-
|
86
|
+
def supported_commands?(cmd)
|
87
|
+
cmd.nil? || %w[stop start].include?(cmd)
|
88
|
+
end
|
109
89
|
|
110
|
-
|
111
|
-
|
90
|
+
def print_details
|
91
|
+
return unless @verbose
|
92
|
+
table = Terminal::Table.new do |t|
|
93
|
+
t << [Rainbow('verbose').green, Rainbow(@verbose).green]
|
94
|
+
t.add_row [Rainbow('interval').green, Rainbow(@interval).green]
|
95
|
+
t.add_row [Rainbow('command').green, Rainbow(@command).green]
|
96
|
+
end
|
97
|
+
puts table
|
98
|
+
end
|
99
|
+
|
100
|
+
def print_error(msg)
|
101
|
+
puts Rainbow(msg).red
|
102
|
+
end
|
103
|
+
|
104
|
+
def print_help
|
105
|
+
puts <<~EOF
|
106
|
+
heartbeat [OPTION]
|
107
|
+
--help, -h:
|
108
|
+
show help
|
109
|
+
--interval [interval], -i [interval]:
|
110
|
+
interval, e.g: 10 (in seconds)
|
112
111
|
|
113
112
|
EOF
|
114
|
-
|
113
|
+
end
|
114
|
+
end
|
115
115
|
end
|
116
116
|
end
|
@@ -1,9 +1,15 @@
|
|
1
|
-
|
2
|
-
class NotImplementedError < StandardError; end
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
# Base Plugin class
|
4
|
+
# Inherit this class if you adding a new plugin
|
5
|
+
module HeartTop
|
6
|
+
module Plugin
|
7
|
+
class Base
|
8
|
+
class NotImplementedError < StandardError; end
|
9
|
+
|
10
|
+
def ping
|
11
|
+
raise NotImplementedError, "`##{__method__}` must be implemented in subclass"
|
12
|
+
end
|
7
13
|
end
|
8
14
|
end
|
9
15
|
end
|
@@ -1,11 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'heart_top/plugin/base'
|
4
|
+
require 'singleton'
|
5
|
+
require 'json'
|
6
|
+
|
1
7
|
module HeartTop
|
2
8
|
module Plugin
|
3
|
-
class Slack
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
+
class Slack < Base
|
10
|
+
include Singleton
|
11
|
+
|
12
|
+
def ping
|
13
|
+
`curl -X POST --data-urlencode 'payload=#{payload}' #{webhook_url}`
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def payload
|
19
|
+
{
|
20
|
+
channel: '#hearttop',
|
21
|
+
username: 'hearttop',
|
22
|
+
text: 'This is posted to #hearttop and comes from a bot named hearttop.',
|
23
|
+
icon_emoji: ':ghost:'
|
24
|
+
}.to_json.to_s
|
25
|
+
end
|
26
|
+
|
27
|
+
def webhook_url
|
28
|
+
ENV['SLACK_WEBHOOK_URL']
|
9
29
|
end
|
10
30
|
end
|
11
31
|
end
|
data/lib/heart_top/plugin.rb
CHANGED
data/lib/heart_top/schedule.rb
CHANGED
data/lib/heart_top/version.rb
CHANGED
data/lib/heart_top.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: heart_top
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Faizal Zakaria
|
@@ -52,48 +52,62 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.49'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.49'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: terminal-table
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - "~>"
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version: 1.8
|
75
|
+
version: '1.8'
|
62
76
|
type: :runtime
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
80
|
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
|
-
version: 1.8
|
82
|
+
version: '1.8'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rainbow
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
87
|
- - "~>"
|
74
88
|
- !ruby/object:Gem::Version
|
75
|
-
version: 2.2
|
89
|
+
version: '2.2'
|
76
90
|
type: :runtime
|
77
91
|
prerelease: false
|
78
92
|
version_requirements: !ruby/object:Gem::Requirement
|
79
93
|
requirements:
|
80
94
|
- - "~>"
|
81
95
|
- !ruby/object:Gem::Version
|
82
|
-
version: 2.2
|
96
|
+
version: '2.2'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: dante
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
86
100
|
requirements:
|
87
101
|
- - "~>"
|
88
102
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0.2
|
103
|
+
version: '0.2'
|
90
104
|
type: :runtime
|
91
105
|
prerelease: false
|
92
106
|
version_requirements: !ruby/object:Gem::Requirement
|
93
107
|
requirements:
|
94
108
|
- - "~>"
|
95
109
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0.2
|
110
|
+
version: '0.2'
|
97
111
|
description: Have you ever go to free space, coffee shops or some random place to
|
98
112
|
work, and you need to to toilet for pee, or big business? Then worried what would
|
99
113
|
happen to your laptop? This tool could be the solution
|
@@ -108,6 +122,7 @@ extra_rdoc_files: []
|
|
108
122
|
files:
|
109
123
|
- ".gitignore"
|
110
124
|
- ".rspec"
|
125
|
+
- ".rubocop.yml"
|
111
126
|
- ".travis.yml"
|
112
127
|
- Gemfile
|
113
128
|
- LICENSE.txt
|
@@ -146,7 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
146
161
|
version: '0'
|
147
162
|
requirements: []
|
148
163
|
rubyforge_project:
|
149
|
-
rubygems_version: 2.
|
164
|
+
rubygems_version: 2.6.11
|
150
165
|
signing_key:
|
151
166
|
specification_version: 4
|
152
167
|
summary: HeartTop pings the heartbeat of your laptop every N seconds
|