systemd_service_check 0.0.0 → 1.0.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 +1 -0
- data/README.md +110 -65
- data/lib/systemd_service_check/CHANGELOG.md +27 -0
- data/lib/systemd_service_check/base.rb +41 -30
- data/lib/systemd_service_check/cli.rb +45 -39
- data/lib/systemd_service_check/version.rb +1 -1
- data/lib/systemd_service_check.rb +2 -3
- data/lib/table_print-patch-pr70/column.rb +27 -0
- data/lib/table_print-patch-pr70/formatter.rb +33 -0
- data/systemd_service_check.gemspec +4 -4
- data/systemd_service_check.sample.yml +32 -0
- metadata +11 -34
- data/LICENSE +0 -21
- data/lib/systemd_service_check.yml +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14d00810a361024a249ae6211e3805e1383badf662431804174abfc4b86e842e
|
4
|
+
data.tar.gz: d68c217324a1a19a507e97cfa1c790f3e2ad18981d2496dba23a4be437220f30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c0f87e7ee79969bad99bf4f77f8be010217b0e75c9fc6b7a93541eaec69b6ed1bd5de78d9ebfc0c248add2f421151730fee9519c83b15869679733cef730995
|
7
|
+
data.tar.gz: c215f24bb497793765217e66e58df8c711d7218a40584ebce380cf0983f43289b3b36a5cb75b2b44d893feefc906a9cfedd576d295dee4c468f405e0dcea6fd4
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
# SystemdServiceCheck
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/systemd_service_check.svg)](https://badge.fury.io/rb/systemd_service_check)
|
3
4
|
[![Build Status](https://travis-ci.org/k-ta-yamada/systemd_service_check.svg?branch=master)](https://travis-ci.org/k-ta-yamada/systemd_service_check)
|
4
5
|
|
5
|
-
|
6
|
+
This gem provide `ssc` command to check multiple `systemd service`
|
7
|
+
etc on multiple remote servers using net-ssh.
|
6
8
|
|
7
9
|
## Installation
|
8
10
|
|
@@ -14,17 +16,21 @@ gem 'systemd_service_check'
|
|
14
16
|
|
15
17
|
And then execute:
|
16
18
|
|
17
|
-
|
19
|
+
```sh
|
20
|
+
$ bundle
|
21
|
+
```
|
18
22
|
|
19
23
|
Or install it yourself as:
|
20
24
|
|
21
|
-
|
25
|
+
```sh
|
26
|
+
$ gem install systemd_service_check
|
27
|
+
```
|
22
28
|
|
23
29
|
## Usage
|
24
30
|
|
25
31
|
### configure yaml
|
26
32
|
|
27
|
-
sample file
|
33
|
+
sample file: [./systemd_service_check.sample.yml](https://github.com/k-ta-yamada/systemd_service_check/blob/master/systemd_service_check.sample.yml)
|
28
34
|
|
29
35
|
usage at require: `SystemdServiceCheck::Base.new(yaml: './path/to/setting.yml')`
|
30
36
|
|
@@ -36,7 +42,7 @@ usage as CLI: `ssc check -y ./path/to/setting.yml`
|
|
36
42
|
require 'systemd_service_check'
|
37
43
|
|
38
44
|
ssc = SystemdServiceCheck::Base.new
|
39
|
-
|
45
|
+
|
40
46
|
puts ssc.to_json
|
41
47
|
```
|
42
48
|
|
@@ -45,7 +51,7 @@ puts ssc.to_json
|
|
45
51
|
```sh
|
46
52
|
$ ssc help
|
47
53
|
Commands:
|
48
|
-
ssc check ENV [ENV...] options # check target ENV Servers.
|
54
|
+
ssc check ENV [ENV...] options # check target ENV Servers.
|
49
55
|
ssc help [COMMAND] # Describe available commands or one specific command
|
50
56
|
ssc version # return SystemdServiceCheck::VERSION
|
51
57
|
```
|
@@ -56,43 +62,50 @@ Usage:
|
|
56
62
|
ssc check ENV [ENV...] options
|
57
63
|
|
58
64
|
Options:
|
59
|
-
-
|
60
|
-
|
61
|
-
-
|
62
|
-
|
65
|
+
-f, [--format=table] # [t]able, [j]son, [a]wesome_print
|
66
|
+
# Default: table
|
67
|
+
-y, [--yaml=./systemd_service_check.sample.yml] # setting yaml file
|
68
|
+
# Default: ./systemd_service_check.sample.yml
|
63
69
|
|
64
70
|
check target ENV Servers.
|
65
|
-
default option is `-t, [--table]`
|
66
71
|
```
|
67
72
|
|
68
73
|
```sh
|
69
74
|
$ ssc check
|
70
|
-
ENV | IP | HOSTNAME | USER | SERVICE_NAME
|
71
|
-
|
72
|
-
dev | 192.168.1.101 | centos7 | root | sshd.service
|
73
|
-
dev | 192.168.1.101 | centos7 | root | firewalld.service
|
74
|
-
dev | 192.168.1.101 | centos7 | root |
|
75
|
-
dev | 192.168.1.101 | centos7 | root |
|
76
|
-
dev | 192.168.1.101 | centos7 | root |
|
77
|
-
dev | 192.168.1.101 | centos7 | root |
|
75
|
+
ENV | IP | HOSTNAME | USER | SERVICE_NAME | LOAD_STATE | ACTIVE_STATE | SUB_STATE | UNIT_FILE_STATE | TYPE
|
76
|
+
----|---------------|----------|------|--------------------------------|------------|--------------|-----------|-----------------|--------
|
77
|
+
dev | 192.168.1.101 | centos7 | root | sshd.service | loaded | active | running | enabled | notify
|
78
|
+
dev | 192.168.1.101 | centos7 | root | firewalld.service | loaded | inactive | dead | disabled | dbus
|
79
|
+
dev | 192.168.1.101 | centos7 | root | rsyslog.service | loaded | active | running | enabled | notify
|
80
|
+
dev | 192.168.1.101 | centos7 | root | network.service | loaded | active | exited | bad | forking
|
81
|
+
dev | 192.168.1.101 | centos7 | root | systemd-tmpfiles-clean.timer | loaded | active | waiting | static | n/a
|
82
|
+
dev | 192.168.1.101 | centos7 | root | dummy_long_name_size_30_______ | not-found | inactive | dead | n/a | n/a
|
78
83
|
```
|
79
84
|
|
80
85
|
```sh
|
81
|
-
$ ssc check
|
86
|
+
$ ssc check --format=json | jq
|
82
87
|
[
|
83
88
|
{
|
84
89
|
"server": {
|
85
90
|
"env": "dev",
|
86
91
|
"ip": "192.168.1.101",
|
87
92
|
"user": "root",
|
88
|
-
"
|
93
|
+
"options": {
|
94
|
+
"password": "vagrant",
|
95
|
+
"keys": [
|
96
|
+
""
|
97
|
+
],
|
98
|
+
"logger": "#<Logger:0x00007fa52293b0b0>",
|
99
|
+
"password_prompt": "#<Net::SSH::Prompt:0x00007fa52293aa70>",
|
100
|
+
"user": "root"
|
101
|
+
},
|
89
102
|
"services": [
|
90
103
|
"sshd.service",
|
91
104
|
"firewalld.service",
|
92
|
-
"dummy.service",
|
93
105
|
"rsyslog.service",
|
94
|
-
"
|
95
|
-
"systemd-tmpfiles-clean.timer"
|
106
|
+
"network.service",
|
107
|
+
"systemd-tmpfiles-clean.timer",
|
108
|
+
"dummy_long_name_size_30_______"
|
96
109
|
],
|
97
110
|
"hostname": "centos7"
|
98
111
|
},
|
@@ -101,37 +114,49 @@ $ ssc check -j | jq
|
|
101
114
|
"service_name": "sshd.service",
|
102
115
|
"load_state": "loaded",
|
103
116
|
"active_state": "active",
|
104
|
-
"sub_state": "running"
|
117
|
+
"sub_state": "running",
|
118
|
+
"unit_file_state": "enabled",
|
119
|
+
"type": "notify"
|
105
120
|
},
|
106
121
|
{
|
107
122
|
"service_name": "firewalld.service",
|
108
123
|
"load_state": "loaded",
|
109
124
|
"active_state": "inactive",
|
110
|
-
"sub_state": "dead"
|
111
|
-
|
112
|
-
|
113
|
-
"service_name": "dummy.service",
|
114
|
-
"load_state": "not-found",
|
115
|
-
"active_state": "inactive",
|
116
|
-
"sub_state": "dead"
|
125
|
+
"sub_state": "dead",
|
126
|
+
"unit_file_state": "disabled",
|
127
|
+
"type": "dbus"
|
117
128
|
},
|
118
129
|
{
|
119
130
|
"service_name": "rsyslog.service",
|
120
131
|
"load_state": "loaded",
|
121
132
|
"active_state": "active",
|
122
|
-
"sub_state": "running"
|
133
|
+
"sub_state": "running",
|
134
|
+
"unit_file_state": "enabled",
|
135
|
+
"type": "notify"
|
123
136
|
},
|
124
137
|
{
|
125
|
-
"service_name": "
|
126
|
-
"load_state": "
|
127
|
-
"active_state": "
|
128
|
-
"sub_state": "
|
138
|
+
"service_name": "network.service",
|
139
|
+
"load_state": "loaded",
|
140
|
+
"active_state": "active",
|
141
|
+
"sub_state": "exited",
|
142
|
+
"unit_file_state": "bad",
|
143
|
+
"type": "forking"
|
129
144
|
},
|
130
145
|
{
|
131
146
|
"service_name": "systemd-tmpfiles-clean.timer",
|
132
147
|
"load_state": "loaded",
|
133
148
|
"active_state": "active",
|
134
|
-
"sub_state": "waiting"
|
149
|
+
"sub_state": "waiting",
|
150
|
+
"unit_file_state": "static",
|
151
|
+
"type": "n/a"
|
152
|
+
},
|
153
|
+
{
|
154
|
+
"service_name": "dummy_long_name_size_30_______",
|
155
|
+
"load_state": "not-found",
|
156
|
+
"active_state": "inactive",
|
157
|
+
"sub_state": "dead",
|
158
|
+
"unit_file_state": "n/a",
|
159
|
+
"type": "n/a"
|
135
160
|
}
|
136
161
|
]
|
137
162
|
}
|
@@ -139,60 +164,80 @@ $ ssc check -j | jq
|
|
139
164
|
```
|
140
165
|
|
141
166
|
```sh
|
142
|
-
$ ssc check
|
167
|
+
$ ssc check --format=awesome_print
|
143
168
|
[
|
144
|
-
[0] #<Struct:SystemdServiceCheck::Base::Result:
|
145
|
-
server = #<Struct:SystemdServiceCheck::Base::Server:
|
169
|
+
[0] #<Struct:SystemdServiceCheck::Base::Result:0x7fabeca9ad40
|
170
|
+
server = #<Struct:SystemdServiceCheck::Base::Server:0x7fabec9c6ea0
|
146
171
|
env = "dev",
|
147
172
|
hostname = "centos7",
|
148
173
|
ip = "192.168.1.101",
|
149
|
-
|
174
|
+
options = {
|
175
|
+
:password => "vagrant",
|
176
|
+
:keys => [
|
177
|
+
[0] ""
|
178
|
+
],
|
179
|
+
:logger => #<Logger:0x00007fabec9c6478 @level=4, @progname=nil, @default_formatter=#<Logger::Formatter:0x00007fabec9c63d8 @datetime_format=nil>, @formatter=nil, @logdev=#<Logger::LogDevice:0x00007fabec9c6360 @shift_period_suffix=nil, @shift_size=nil, @shift_age=nil, @filename=nil, @dev=#<IO:<STDERR>>, @mon_owner=nil, @mon_count=0, @mon_mutex=#<Thread::Mutex:0x00007fabec9c6248>>>,
|
180
|
+
:password_prompt => #<Net::SSH::Prompt:0x00007fabec9c61d0>,
|
181
|
+
:user => "root"
|
182
|
+
},
|
150
183
|
services = [
|
151
184
|
[0] "sshd.service",
|
152
185
|
[1] "firewalld.service",
|
153
|
-
[2] "
|
154
|
-
[3] "
|
155
|
-
[4] "
|
156
|
-
[5] "
|
186
|
+
[2] "rsyslog.service",
|
187
|
+
[3] "network.service",
|
188
|
+
[4] "systemd-tmpfiles-clean.timer",
|
189
|
+
[5] "dummy_long_name_size_30_______"
|
157
190
|
],
|
158
191
|
user = "root"
|
159
192
|
>,
|
160
193
|
services = [
|
161
|
-
[0] #<Struct:SystemdServiceCheck::Base::Service:
|
194
|
+
[0] #<Struct:SystemdServiceCheck::Base::Service:0x7fabed259798
|
162
195
|
active_state = "active",
|
163
196
|
load_state = "loaded",
|
164
197
|
service_name = "sshd.service",
|
165
|
-
sub_state = "running"
|
198
|
+
sub_state = "running",
|
199
|
+
type = "notify",
|
200
|
+
unit_file_state = "enabled"
|
166
201
|
>,
|
167
|
-
[1] #<Struct:SystemdServiceCheck::Base::Service:
|
202
|
+
[1] #<Struct:SystemdServiceCheck::Base::Service:0x7fabecabaeb0
|
168
203
|
active_state = "inactive",
|
169
204
|
load_state = "loaded",
|
170
205
|
service_name = "firewalld.service",
|
171
|
-
sub_state = "dead"
|
172
|
-
|
173
|
-
|
174
|
-
active_state = "inactive",
|
175
|
-
load_state = "not-found",
|
176
|
-
service_name = "dummy.service",
|
177
|
-
sub_state = "dead"
|
206
|
+
sub_state = "dead",
|
207
|
+
type = "dbus",
|
208
|
+
unit_file_state = "disabled"
|
178
209
|
>,
|
179
|
-
[
|
210
|
+
[2] #<Struct:SystemdServiceCheck::Base::Service:0x7fabecab7648
|
180
211
|
active_state = "active",
|
181
212
|
load_state = "loaded",
|
182
213
|
service_name = "rsyslog.service",
|
183
|
-
sub_state = "running"
|
214
|
+
sub_state = "running",
|
215
|
+
type = "notify",
|
216
|
+
unit_file_state = "enabled"
|
184
217
|
>,
|
185
|
-
[
|
186
|
-
active_state = "
|
187
|
-
load_state = "
|
188
|
-
service_name = "
|
189
|
-
sub_state = "
|
218
|
+
[3] #<Struct:SystemdServiceCheck::Base::Service:0x7fabeca9e3f0
|
219
|
+
active_state = "active",
|
220
|
+
load_state = "loaded",
|
221
|
+
service_name = "network.service",
|
222
|
+
sub_state = "exited",
|
223
|
+
type = "forking",
|
224
|
+
unit_file_state = "bad"
|
190
225
|
>,
|
191
|
-
[
|
226
|
+
[4] #<Struct:SystemdServiceCheck::Base::Service:0x7fabed8c6db0
|
192
227
|
active_state = "active",
|
193
228
|
load_state = "loaded",
|
194
229
|
service_name = "systemd-tmpfiles-clean.timer",
|
195
|
-
sub_state = "waiting"
|
230
|
+
sub_state = "waiting",
|
231
|
+
type = "n/a",
|
232
|
+
unit_file_state = "static"
|
233
|
+
>,
|
234
|
+
[5] #<Struct:SystemdServiceCheck::Base::Service:0x7fabeca9b1f0
|
235
|
+
active_state = "inactive",
|
236
|
+
load_state = "not-found",
|
237
|
+
service_name = "dummy_long_name_size_30_______",
|
238
|
+
sub_state = "dead",
|
239
|
+
type = "n/a",
|
240
|
+
unit_file_state = "n/a"
|
196
241
|
>
|
197
242
|
]
|
198
243
|
>
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# CHANGELOG
|
2
|
+
|
3
|
+
Please confirm details from the following.
|
4
|
+
|
5
|
+
https://github.com/k-ta-yamada/systemd_service_check/releases
|
6
|
+
|
7
|
+
## v1.0.0
|
8
|
+
|
9
|
+
2018-01-28 JST
|
10
|
+
|
11
|
+
- issues: https://github.com/k-ta-yamada/systemd_service_check/milestone/1?closed=1
|
12
|
+
- release: https://github.com/k-ta-yamada/systemd_service_check/releases/tag/v1.0.0
|
13
|
+
- commits: https://github.com/k-ta-yamada/systemd_service_check/compare/v0.0.0...v1.0.0
|
14
|
+
|
15
|
+
## v0.0.0
|
16
|
+
|
17
|
+
2018-01-25 JST
|
18
|
+
|
19
|
+
- release: https://github.com/k-ta-yamada/systemd_service_check/releases/tag/v0.0.0
|
20
|
+
- commits: https://github.com/k-ta-yamada/systemd_service_check/compare/v0.0.0-alpha...v0.0.0
|
21
|
+
|
22
|
+
## v0.0.0-alpha
|
23
|
+
|
24
|
+
2018-01-23 JST
|
25
|
+
|
26
|
+
- release: https://github.com/k-ta-yamada/systemd_service_check/releases/tag/v0.0.0-alpha
|
27
|
+
- commits: https://github.com/k-ta-yamada/systemd_service_check/compare/4e4adbd...v0.0.0-alpha
|
@@ -1,34 +1,43 @@
|
|
1
1
|
require 'net/ssh'
|
2
|
+
require 'thor'
|
2
3
|
require 'yaml'
|
3
4
|
require 'json'
|
4
|
-
require 'active_support'
|
5
|
-
require 'active_support/core_ext/string'
|
6
5
|
require 'pry' # forDebug
|
7
6
|
|
8
7
|
# SystemdServiceCheck
|
9
8
|
module SystemdServiceCheck
|
10
9
|
# Base
|
11
10
|
class Base
|
12
|
-
|
13
|
-
|
11
|
+
class InvalidOption < StandardError; end
|
12
|
+
|
13
|
+
Server = Struct.new(:env, :ip, :user, :options, :services, :hostname)
|
14
|
+
Service = Struct.new(:service_name, :load_state, :active_state, :sub_state, :unit_file_state, :type)
|
14
15
|
Result = Struct.new(:server, :services)
|
15
16
|
|
16
|
-
ENVS = %w[dev stg prd].freeze
|
17
17
|
# TODO: systemctl show -p
|
18
|
-
STATES = %w[LoadState ActiveState SubState].freeze
|
18
|
+
STATES = %w[LoadState ActiveState SubState UnitFileState Type].freeze
|
19
19
|
# TODO: setting by yaml
|
20
20
|
SHOW_GREP = /env/i
|
21
21
|
|
22
|
-
attr_reader :argv, :servers, :target_env, :target_servers, :results
|
22
|
+
attr_reader :argv, :env_names, :servers, :target_env, :target_servers, :results
|
23
23
|
|
24
|
-
def initialize(argv
|
25
|
-
@argv
|
26
|
-
@
|
24
|
+
def initialize(argv, yaml)
|
25
|
+
@argv = argv || []
|
26
|
+
@env_names = []
|
27
|
+
@servers = []
|
27
28
|
@target_env = []
|
28
29
|
@target_servers = []
|
29
|
-
@results
|
30
|
+
@results = []
|
31
|
+
|
32
|
+
raise InvalidOption if yaml.nil? || yaml.empty?
|
30
33
|
load_settings(yaml)
|
31
34
|
configure_target_servers
|
35
|
+
run
|
36
|
+
rescue InvalidOption => e
|
37
|
+
puts "<#{e}>",
|
38
|
+
" Argument yaml must not be nil or empty.",
|
39
|
+
" yaml.class: [#{yaml.class}]"
|
40
|
+
puts " #{e.backtrace_locations.first}"
|
32
41
|
end
|
33
42
|
|
34
43
|
def run
|
@@ -44,16 +53,14 @@ module SystemdServiceCheck
|
|
44
53
|
|
45
54
|
private
|
46
55
|
|
47
|
-
def load_settings(
|
48
|
-
yaml = YAML.load_file(
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
else
|
56
|
-
File.expand_path(filename)
|
56
|
+
def load_settings(file) # rubocop:disable Metrics/AbcSize
|
57
|
+
yaml = JSON.parse(YAML.load_file(File.expand_path(file)).to_json,
|
58
|
+
symbolize_names: true)
|
59
|
+
@env_names = yaml[:servers].map { |s| s[:env] }.uniq
|
60
|
+
@servers = yaml[:servers].map do |s|
|
61
|
+
raise InvalidOption, "ENV: #{s[:env]}" if [s[:password], s[:key]].all?(nil)
|
62
|
+
options = { password: s[:password], keys: [s[:key] || ""] }
|
63
|
+
Server.new(s[:env], s[:ip], s[:user], options, s[:services])
|
57
64
|
end
|
58
65
|
end
|
59
66
|
|
@@ -63,19 +70,20 @@ module SystemdServiceCheck
|
|
63
70
|
end
|
64
71
|
|
65
72
|
def configure_target_env
|
66
|
-
@target_env =
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
73
|
+
@target_env = @env_names & @argv
|
74
|
+
|
75
|
+
# If there is no argument.
|
76
|
+
@target_env = @env_names.first if @target_env.empty? && @argv.empty?
|
77
|
+
|
78
|
+
# If there is only one argument and it is `all`.
|
79
|
+
@target_env = @env_names if @argv.size == 1 && argv.first == 'all'
|
71
80
|
end
|
72
81
|
|
73
82
|
def ssh(server)
|
74
83
|
services = []
|
75
|
-
Net::SSH.start(server[:ip], server[:user],
|
84
|
+
Net::SSH.start(server[:ip], server[:user], server[:options]) do |ssh|
|
76
85
|
server[:hostname] = ssh.exec!('hostname').chop
|
77
86
|
services = server[:services].map { |service_name| systemd(ssh, service_name) }
|
78
|
-
|
79
87
|
# TODO: store in Result object
|
80
88
|
# puts ssh.exec!("systemctl list-timers")
|
81
89
|
end
|
@@ -86,13 +94,16 @@ module SystemdServiceCheck
|
|
86
94
|
states = ssh.exec!("systemctl show #{service_name} -p #{STATES.join(",")}")
|
87
95
|
.split("\n")
|
88
96
|
.map { |v| v.split("=") }
|
89
|
-
.
|
97
|
+
.map { |v| [Thor::Util.snake_case(v[0]).to_sym, v[1]] }
|
98
|
+
.each_with_object({}) { |(k, v), memo| memo[k] = v }
|
90
99
|
|
91
100
|
Service.new(
|
92
101
|
service_name,
|
93
102
|
states[:load_state],
|
94
103
|
states[:active_state],
|
95
|
-
states[:sub_state]
|
104
|
+
states[:sub_state],
|
105
|
+
states[:unit_file_state] || "n/a",
|
106
|
+
states[:type] || "n/a"
|
96
107
|
)
|
97
108
|
end
|
98
109
|
end
|
@@ -2,48 +2,40 @@ require 'systemd_service_check'
|
|
2
2
|
require 'thor'
|
3
3
|
require 'awesome_print'
|
4
4
|
require 'table_print'
|
5
|
-
require 'highline'
|
6
5
|
require 'pry' # forDebug
|
7
6
|
|
7
|
+
# ###############################################################################
|
8
|
+
# MEMO: This patch is a copy of https://github.com/arches/table_print/pull/70
|
9
|
+
# ###############################################################################
|
10
|
+
require 'table_print-patch-pr70/column'
|
11
|
+
require 'table_print-patch-pr70/formatter'
|
12
|
+
|
8
13
|
module SystemdServiceCheck
|
9
14
|
# CLI
|
10
15
|
class CLI < Thor
|
11
|
-
class
|
12
|
-
|
13
|
-
option :
|
14
|
-
type: :
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
type: :boolean,
|
20
|
-
default: false,
|
21
|
-
aliases: '-j',
|
22
|
-
desc: 'Result display in json format'
|
23
|
-
option :awesome,
|
24
|
-
type: :boolean,
|
25
|
-
default: false,
|
26
|
-
aliases: '-a',
|
27
|
-
desc: 'Displaying results using awesome_print'
|
16
|
+
class InvalidFormatOption < StandardError; end
|
17
|
+
|
18
|
+
option :format,
|
19
|
+
type: :string,
|
20
|
+
aliases: '-f',
|
21
|
+
desc: "[t]able, [j]son, [a]wesome_print",
|
22
|
+
banner: 'table',
|
23
|
+
default: 'table'
|
28
24
|
option :yaml,
|
29
25
|
type: :string,
|
30
26
|
aliases: '-y',
|
31
27
|
desc: 'setting yaml file',
|
32
|
-
banner: './systemd_service_check.yml'
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
check target ENV Servers.
|
37
|
-
default option is `-t, [--table]`
|
38
|
-
STRING
|
39
|
-
desc "check ENV [ENV...] options", description
|
28
|
+
banner: './systemd_service_check.sample.yml',
|
29
|
+
default: './systemd_service_check.sample.yml'
|
30
|
+
|
31
|
+
desc "check ENV [ENV...] options", "check target ENV Servers."
|
40
32
|
def check(*env)
|
41
|
-
raise
|
42
|
-
@ssc = Base.new(
|
43
|
-
@ssc.run
|
33
|
+
raise InvalidFormatOption unless format_option_validate
|
34
|
+
@ssc = Base.new(env, options[:yaml])
|
44
35
|
disp
|
45
|
-
rescue
|
46
|
-
puts "<#{e}
|
36
|
+
rescue InvalidFormatOption => e
|
37
|
+
puts "<#{e}>",
|
38
|
+
" [#{options[:format]}] is invalid value."
|
47
39
|
puts " #{e.backtrace_locations.first}"
|
48
40
|
end
|
49
41
|
|
@@ -54,10 +46,15 @@ module SystemdServiceCheck
|
|
54
46
|
|
55
47
|
private
|
56
48
|
|
49
|
+
def format_option_validate
|
50
|
+
%w[t table j json a awesome_print].include? options[:format]
|
51
|
+
end
|
52
|
+
|
57
53
|
def disp
|
58
|
-
|
59
|
-
|
60
|
-
|
54
|
+
case options[:format]
|
55
|
+
when 't', 'table' then disp_table
|
56
|
+
when 'j', 'json' then disp_json
|
57
|
+
when 'a', 'awesome_print' then disp_ap
|
61
58
|
end
|
62
59
|
end
|
63
60
|
|
@@ -69,7 +66,7 @@ module SystemdServiceCheck
|
|
69
66
|
ap @ssc.results
|
70
67
|
end
|
71
68
|
|
72
|
-
COLS = %i[env ip hostname user service_name load_state active_state sub_state].freeze
|
69
|
+
COLS = %i[env ip hostname user service_name load_state active_state sub_state unit_file_state type].freeze
|
73
70
|
def disp_table # rubocop:disable Metrics/AbcSize
|
74
71
|
service_name_width =
|
75
72
|
@ssc.results.map(&:services).flatten.map(&:service_name).map(&:size).max
|
@@ -79,6 +76,13 @@ module SystemdServiceCheck
|
|
79
76
|
data = services.map { |s| result.server.to_h.merge(s.to_h) }
|
80
77
|
|
81
78
|
tp(data, COLS, service_name: { width: service_name_width })
|
79
|
+
puts
|
80
|
+
end
|
81
|
+
|
82
|
+
# ref: https://github.com/erikhuda/thor/blob/master/lib/thor/shell.rb#L14
|
83
|
+
if RbConfig::CONFIG["host_os"] =~ /mswin|mingw/ && !ENV["ANSICON"]
|
84
|
+
puts "-- For colors on windows, please setup `ANSICON`.",
|
85
|
+
"-- ANSICON: https://github.com/adoxa/ansicon"
|
82
86
|
end
|
83
87
|
end
|
84
88
|
|
@@ -86,16 +90,18 @@ module SystemdServiceCheck
|
|
86
90
|
services.map do |s|
|
87
91
|
s.class.new(
|
88
92
|
s.service_name,
|
89
|
-
color_state(s.load_state,
|
90
|
-
color_state(s.active_state,
|
91
|
-
color_state(s.sub_state,
|
93
|
+
color_state(s.load_state, :==, "loaded"),
|
94
|
+
color_state(s.active_state, :==, "active"),
|
95
|
+
color_state(s.sub_state, :!=, "dead"),
|
96
|
+
color_state(s.unit_file_state, :==, "enabled"),
|
97
|
+
s.type
|
92
98
|
)
|
93
99
|
end
|
94
100
|
end
|
95
101
|
|
96
102
|
def color_state(obj, method, arg)
|
97
103
|
green_or_red = obj.send(method, arg) ? :green : :red
|
98
|
-
|
104
|
+
set_color(obj, green_or_red)
|
99
105
|
end
|
100
106
|
end
|
101
107
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# ###############################################################################
|
2
|
+
# MEMO: This patch is a copy of https://github.com/arches/table_print/pull/70
|
3
|
+
# ###############################################################################
|
4
|
+
module TablePrint
|
5
|
+
class Column
|
6
|
+
def data_width
|
7
|
+
if multibyte_count
|
8
|
+
[
|
9
|
+
name.each_char.collect { |c| c.bytesize == 1 ? 1 : 2 }.inject(0, &:+),
|
10
|
+
Array(data).compact.collect { |s| escape_strip(s.to_s) }.collect { |m| m.each_char.collect { |n| n.bytesize == 1 ? 1 : 2 }.inject(0, &:+) }.max
|
11
|
+
].compact.max || 0
|
12
|
+
else
|
13
|
+
[
|
14
|
+
name.length,
|
15
|
+
Array(data).compact.collect { |s| escape_strip(s.to_s) }.collect(&:length).max
|
16
|
+
].compact.max || 0
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def escape_strip(string)
|
23
|
+
return string unless string.class == String
|
24
|
+
string.gsub(/\e\[([0-9]{1,2};){0,2}[0-9]{1,2}m/, '')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# ###############################################################################
|
2
|
+
# MEMO: This patch is a copy of https://github.com/arches/table_print/pull/70
|
3
|
+
# ###############################################################################
|
4
|
+
module TablePrint
|
5
|
+
class FixedWidthFormatter
|
6
|
+
def format(value)
|
7
|
+
padding = width - length(escape_strip(value).to_s)
|
8
|
+
truncate(value) + (padding < 0 ? '' : " " * padding)
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def truncate(value)
|
14
|
+
return "" unless value
|
15
|
+
|
16
|
+
value = value.to_s
|
17
|
+
value_stripped, stripped_stuff = escape_strip(value, true)
|
18
|
+
return value unless value_stripped.length > width
|
19
|
+
"#{value[0..(width + stripped_stuff.length) - 4]}..."
|
20
|
+
end
|
21
|
+
|
22
|
+
def escape_strip(string, return_stripped_stuff = false)
|
23
|
+
return string unless string.class == String
|
24
|
+
stripped_stuff = ''
|
25
|
+
string_stripped = string.gsub(/\e\[([0-9]{1,2};){0,2}[0-9]{1,2}m/) do |s|
|
26
|
+
stripped_stuff << s
|
27
|
+
s = ''
|
28
|
+
end
|
29
|
+
return string_stripped, stripped_stuff if return_stripped_stuff == true
|
30
|
+
string_stripped
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -10,9 +10,11 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["key.luvless@gmail.com"]
|
11
11
|
|
12
12
|
spec.summary =
|
13
|
-
'
|
13
|
+
'This gem provide `ssc` command to check multiple `systemd service` \
|
14
|
+
etc on multiple remote servers using net-ssh.'
|
14
15
|
spec.description =
|
15
|
-
'
|
16
|
+
'This gem provide `ssc` command to check multiple `systemd service` \
|
17
|
+
etc on multiple remote servers using net-ssh.'
|
16
18
|
spec.homepage = "https://github.com/k-ta-yamada/systemd_service_check"
|
17
19
|
spec.license = "MIT"
|
18
20
|
|
@@ -42,9 +44,7 @@ Gem::Specification.new do |spec|
|
|
42
44
|
spec.add_development_dependency 'pry-theme'
|
43
45
|
spec.add_development_dependency 'rubocop'
|
44
46
|
|
45
|
-
spec.add_dependency 'activesupport'
|
46
47
|
spec.add_dependency 'awesome_print'
|
47
|
-
spec.add_dependency 'highline'
|
48
48
|
spec.add_dependency 'net-ssh'
|
49
49
|
spec.add_dependency 'pry'
|
50
50
|
spec.add_dependency 'table_print'
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# SERVICES TO BE CHECKED [Array]
|
2
|
+
services: &default_services
|
3
|
+
- sshd.service
|
4
|
+
- firewalld.service
|
5
|
+
- rsyslog.service
|
6
|
+
- network.service
|
7
|
+
- systemd-tmpfiles-clean.timer
|
8
|
+
- dummy_long_name_size_30_______
|
9
|
+
|
10
|
+
# SERVERS TO BE CHECKED [Array of Hash]
|
11
|
+
servers:
|
12
|
+
# only password
|
13
|
+
- env: dev
|
14
|
+
ip: 192.168.1.101
|
15
|
+
user: root
|
16
|
+
password: vagrant
|
17
|
+
# key: ./.vagrant/machines/centos7/virtualbox/private_key
|
18
|
+
services: *default_services
|
19
|
+
# only private key
|
20
|
+
- env: stg
|
21
|
+
ip: 192.168.1.101
|
22
|
+
user: root
|
23
|
+
# password: vagrant
|
24
|
+
key: ./.vagrant/machines/centos7/virtualbox/private_key
|
25
|
+
services: *default_services
|
26
|
+
# password and private key (private key will be used preferentially)
|
27
|
+
- env: prd
|
28
|
+
ip: 192.168.1.101
|
29
|
+
user: root
|
30
|
+
password: invalid-dummy-password
|
31
|
+
key: ./.vagrant/machines/centos7/virtualbox/private_key
|
32
|
+
services: *default_services
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: systemd_service_check
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- k-ta-yamada
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-01-
|
11
|
+
date: 2018-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,20 +94,6 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: activesupport
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
type: :runtime
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - ">="
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
111
97
|
- !ruby/object:Gem::Dependency
|
112
98
|
name: awesome_print
|
113
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,20 +108,6 @@ dependencies:
|
|
122
108
|
- - ">="
|
123
109
|
- !ruby/object:Gem::Version
|
124
110
|
version: '0'
|
125
|
-
- !ruby/object:Gem::Dependency
|
126
|
-
name: highline
|
127
|
-
requirement: !ruby/object:Gem::Requirement
|
128
|
-
requirements:
|
129
|
-
- - ">="
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: '0'
|
132
|
-
type: :runtime
|
133
|
-
prerelease: false
|
134
|
-
version_requirements: !ruby/object:Gem::Requirement
|
135
|
-
requirements:
|
136
|
-
- - ">="
|
137
|
-
- !ruby/object:Gem::Version
|
138
|
-
version: '0'
|
139
111
|
- !ruby/object:Gem::Dependency
|
140
112
|
name: net-ssh
|
141
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -192,7 +164,9 @@ dependencies:
|
|
192
164
|
- - ">="
|
193
165
|
- !ruby/object:Gem::Version
|
194
166
|
version: '0'
|
195
|
-
description:
|
167
|
+
description: |-
|
168
|
+
This gem provide `ssc` command to check multiple `systemd service` \
|
169
|
+
etc on multiple remote servers using net-ssh.
|
196
170
|
email:
|
197
171
|
- key.luvless@gmail.com
|
198
172
|
executables:
|
@@ -206,7 +180,6 @@ files:
|
|
206
180
|
- ".travis.yml"
|
207
181
|
- CODE_OF_CONDUCT.md
|
208
182
|
- Gemfile
|
209
|
-
- LICENSE
|
210
183
|
- LICENSE.txt
|
211
184
|
- README.md
|
212
185
|
- Rakefile
|
@@ -215,11 +188,14 @@ files:
|
|
215
188
|
- bin/setup
|
216
189
|
- bin/ssc
|
217
190
|
- lib/systemd_service_check.rb
|
218
|
-
- lib/systemd_service_check.
|
191
|
+
- lib/systemd_service_check/CHANGELOG.md
|
219
192
|
- lib/systemd_service_check/base.rb
|
220
193
|
- lib/systemd_service_check/cli.rb
|
221
194
|
- lib/systemd_service_check/version.rb
|
195
|
+
- lib/table_print-patch-pr70/column.rb
|
196
|
+
- lib/table_print-patch-pr70/formatter.rb
|
222
197
|
- systemd_service_check.gemspec
|
198
|
+
- systemd_service_check.sample.yml
|
223
199
|
homepage: https://github.com/k-ta-yamada/systemd_service_check
|
224
200
|
licenses:
|
225
201
|
- MIT
|
@@ -243,5 +219,6 @@ rubyforge_project:
|
|
243
219
|
rubygems_version: 2.7.3
|
244
220
|
signing_key:
|
245
221
|
specification_version: 4
|
246
|
-
summary:
|
222
|
+
summary: This gem provide `ssc` command to check multiple `systemd service` \ etc
|
223
|
+
on multiple remote servers using net-ssh.
|
247
224
|
test_files: []
|
data/LICENSE
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
MIT License
|
2
|
-
|
3
|
-
Copyright (c) 2018 k-ta yamada
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
13
|
-
copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
SOFTWARE.
|
@@ -1,26 +0,0 @@
|
|
1
|
-
# SERVICE TO BE CHECKED
|
2
|
-
:services: &default_services
|
3
|
-
- sshd.service
|
4
|
-
- firewalld.service
|
5
|
-
- dummy.service
|
6
|
-
- rsyslog.service
|
7
|
-
- "12345678901234567890123456789012345678901234567890"
|
8
|
-
- systemd-tmpfiles-clean.timer
|
9
|
-
|
10
|
-
# SERVERS TO BE CHECKED
|
11
|
-
:servers:
|
12
|
-
- :env: dev
|
13
|
-
:ip: 192.168.1.101
|
14
|
-
:user: root
|
15
|
-
:pass: vagrant
|
16
|
-
:services: *default_services
|
17
|
-
- :env: stg
|
18
|
-
:ip: centos7
|
19
|
-
:user: root
|
20
|
-
:pass: vagrant
|
21
|
-
:services: *default_services
|
22
|
-
- :env: prd
|
23
|
-
:ip: centos7
|
24
|
-
:user: root
|
25
|
-
:pass: vagrant
|
26
|
-
:services: *default_services
|