sys_watchdog 0.0.2 → 0.0.3
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 +4 -4
- data/CNAME +1 -0
- data/README.md +12 -11
- data/_config.yml +1 -0
- data/lib/sys_watchdog/main.rb +28 -20
- data/lib/sys_watchdog/notify.rb +2 -2
- data/lib/sys_watchdog/wd_test.rb +15 -14
- data/sys_watchdog.gemspec +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 32e9ee338613c50e7292a0c82b04cf6259d54aa9
|
4
|
+
data.tar.gz: 11f75ee6a5074a2e461dd683997900f03830491d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9bc8050aa88024ddf1a4aa50a3938b9e85decce244ae02a52f38337eb30eddcbef50ce98388732071bf0616c0dc4132282d078b312e86a8d6a755383ec5a9f3e
|
7
|
+
data.tar.gz: c434713b9e4f43bd271f27fa11814394697d0d872f70e475a13efca29fe4e0f819cdbf53219e035a445c78adc59d891498c5299432d18cc3272a1f17d7a2b74c
|
data/CNAME
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
sys-watchdog.bettercall.io
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@ Sys Watchdog
|
|
4
4
|
|
5
5
|
** perform all steps as root
|
6
6
|
|
7
|
-
##
|
7
|
+
## Install
|
8
8
|
|
9
9
|
```
|
10
10
|
gem install sys_watchdog
|
@@ -14,7 +14,7 @@ If using Rbenv, run ```rbenv rehash``` to make sys_watchdog binary available.
|
|
14
14
|
|
15
15
|
## Setup
|
16
16
|
|
17
|
-
If on Linux with systemd available (eg: Ubuntu 16+, RedHat 7+. Generally distro versions released from 2015):
|
17
|
+
If on Linux with systemd available (eg: Ubuntu 16+, RedHat 7+. Generally distro versions released from 2015 on):
|
18
18
|
|
19
19
|
```
|
20
20
|
sys_watchdog setup_with_systemd
|
@@ -26,29 +26,30 @@ Otherwise:
|
|
26
26
|
sys_watchdog setup_with_cron
|
27
27
|
```
|
28
28
|
|
29
|
-
|
29
|
+
Edit ```/etc/sys_watchdog.yml```. You can see example configurations in [util/sys_watchdog_sample.yml](https://github.com/tomlobato/sys_watchdog/blob/master/util/sys_watchdog_sample.yml) and [test/sys_watchdog_test.yml](https://github.com/tomlobato/sys_watchdog/blob/master/test/sys_watchdog_test.yml).
|
30
30
|
|
31
|
-
|
32
|
-
You can see some examples in this file and in [/test/sys_watchdog_test.yml](https://github.com/tomlobato/sys_watchdog/blob/master/test/sys_watchdog_test.yml).
|
31
|
+
## Test run
|
33
32
|
|
34
|
-
|
33
|
+
Run from command line:
|
35
34
|
|
36
35
|
```
|
37
36
|
sys_watchdog test
|
38
37
|
```
|
39
38
|
|
40
|
-
|
39
|
+
It will execute all system tests defined in ```/etc/sys_watchdog.yml``` and exit. You can use this to adjust your tests and get a grasp of the sys_watchdog operation.
|
41
40
|
|
42
|
-
|
41
|
+
## Start
|
42
|
+
|
43
|
+
Finally, start the periodic run...
|
43
44
|
|
44
45
|
for systemd:
|
45
46
|
```systemctl start sys_watchdog```
|
46
47
|
|
47
|
-
or
|
48
|
+
or, if installed with cron, uncomment the cron job line:
|
48
49
|
```vim /etc/crontab```
|
49
50
|
|
50
51
|
|
51
|
-
|
52
|
+
## Config Settings
|
52
53
|
|
53
54
|
setting | description
|
54
55
|
-------------|-------------------------------------------------------------------------------------------------
|
@@ -61,7 +62,7 @@ smtp_domain | -
|
|
61
62
|
mail_from | -
|
62
63
|
mail_to | -
|
63
64
|
|
64
|
-
|
65
|
+
## Sys Test Settings
|
65
66
|
|
66
67
|
setting | description
|
67
68
|
------------------|-------------------------------------------------------------------------------------------
|
data/_config.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
theme: jekyll-theme-cayman
|
data/lib/sys_watchdog/main.rb
CHANGED
@@ -3,9 +3,14 @@ class SysWatchdog
|
|
3
3
|
DEFAULT_LOG_FILE = '/var/log/sys_watchdog.log'
|
4
4
|
|
5
5
|
def initialize conf_file: nil, log_file: nil
|
6
|
-
|
6
|
+
log_file ||= DEFAULT_LOG_FILE
|
7
|
+
conf_file ||= DEFAULT_CONF_FILE
|
8
|
+
|
7
9
|
@trackers = {}
|
8
|
-
|
10
|
+
|
11
|
+
@logger = WdLogger.new log_file
|
12
|
+
parse_conf conf_file
|
13
|
+
|
9
14
|
setup
|
10
15
|
end
|
11
16
|
|
@@ -49,35 +54,38 @@ class SysWatchdog
|
|
49
54
|
def run_test test, after_restore: false
|
50
55
|
success, exitstatus, output = test.run
|
51
56
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
end
|
56
|
-
@trackers[test.name] = output
|
57
|
-
end
|
57
|
+
notify_change test, output
|
58
|
+
|
59
|
+
return if success == test.fail
|
58
60
|
|
59
61
|
if success
|
60
|
-
|
61
|
-
|
62
|
-
notify "#{test.name} ok"
|
63
|
-
end
|
62
|
+
test.fail = false
|
63
|
+
notify "#{test.name} ok"
|
64
64
|
else
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
fail test, exitstatus, output
|
71
|
-
end
|
65
|
+
if test.restore_cmd and not after_restore
|
66
|
+
test.restore
|
67
|
+
run_test test, after_restore: true
|
68
|
+
else
|
69
|
+
fail test, exitstatus, output
|
72
70
|
end
|
73
71
|
end
|
74
72
|
rescue => e
|
75
73
|
@logger.error e.desc
|
76
74
|
end
|
77
75
|
|
76
|
+
def notify_change test, output
|
77
|
+
if test.notify_on_change
|
78
|
+
if @trackers[test.name] != output
|
79
|
+
notify "#{test.name} changed", "old: #{@trackers[test.name]}\nnew: #{output}"
|
80
|
+
end
|
81
|
+
@trackers[test.name] = output
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
78
85
|
def fail test, exitstatus, output
|
79
86
|
test.fail = true
|
80
|
-
body = "
|
87
|
+
body = "exitstatus: #{exitstatus}"
|
88
|
+
body += "\noutput: #{output}" if output and not output.empty?
|
81
89
|
notify "#{test.name} fail", body
|
82
90
|
end
|
83
91
|
end
|
data/lib/sys_watchdog/notify.rb
CHANGED
@@ -19,10 +19,10 @@ class SysWatchdog
|
|
19
19
|
slack_client.chat_postMessage(channel: @conf[:slack_channel], text: "[#{server_name}] #{msg}", as_user: true)
|
20
20
|
end
|
21
21
|
|
22
|
-
def send_mail sub,
|
22
|
+
def send_mail sub, body
|
23
23
|
@logger.info "Sending email: #{ sub }"
|
24
24
|
|
25
|
-
body
|
25
|
+
body ||= ""
|
26
26
|
body += append_sys_info
|
27
27
|
|
28
28
|
mail = Mail.new do
|
data/lib/sys_watchdog/wd_test.rb
CHANGED
@@ -31,7 +31,7 @@ class WdTest
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
def run
|
34
|
+
def run
|
35
35
|
@logger.info "========== testing #{@name}"
|
36
36
|
|
37
37
|
unless @test_cmd
|
@@ -42,14 +42,14 @@ class WdTest
|
|
42
42
|
exitstatus, output = run_cmd @test_cmd
|
43
43
|
|
44
44
|
success = check_result exitstatus, output
|
45
|
-
@logger.info "success: #{success
|
45
|
+
@logger.info "success: #{success}"
|
46
46
|
|
47
47
|
[success, exitstatus, output]
|
48
48
|
end
|
49
49
|
|
50
50
|
private
|
51
51
|
|
52
|
-
def run_cmd cmd
|
52
|
+
def run_cmd cmd
|
53
53
|
@logger.info "run: #{ cmd }"
|
54
54
|
|
55
55
|
output = IO.popen(cmd, "r") {|pipe| pipe.read}
|
@@ -75,17 +75,18 @@ class WdTest
|
|
75
75
|
end
|
76
76
|
|
77
77
|
def check_result exitstatus, output
|
78
|
-
success =
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
78
|
+
success =
|
79
|
+
if @expected_regex
|
80
|
+
output =~ @expected_regex
|
81
|
+
elsif @expected_string
|
82
|
+
output.index @expected_string
|
83
|
+
elsif @expected_max
|
84
|
+
output.to_f <= @expected_max
|
85
|
+
elsif @expected_min
|
86
|
+
output.to_f <= @expected_min
|
87
|
+
else
|
88
|
+
exitstatus == 0
|
89
|
+
end
|
89
90
|
!!success
|
90
91
|
end
|
91
92
|
end
|
data/sys_watchdog.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sys_watchdog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Lobato
|
@@ -47,8 +47,10 @@ extensions: []
|
|
47
47
|
extra_rdoc_files: []
|
48
48
|
files:
|
49
49
|
- ".gitignore"
|
50
|
+
- CNAME
|
50
51
|
- README.md
|
51
52
|
- Rakefile
|
53
|
+
- _config.yml
|
52
54
|
- bin/sys_watchdog
|
53
55
|
- lib/sys_watchdog.rb
|
54
56
|
- lib/sys_watchdog/core_extensions.rb
|