sys_watchdog 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9a8c520ccb449f03c4e01c9dbfc6c5aa0e97b9be
4
- data.tar.gz: cbb848cf690845b14b1a8d2e510d25ec8f88e047
3
+ metadata.gz: 32e9ee338613c50e7292a0c82b04cf6259d54aa9
4
+ data.tar.gz: 11f75ee6a5074a2e461dd683997900f03830491d
5
5
  SHA512:
6
- metadata.gz: e2ddc3711f3f821c1a39e6a873144bf4ddf8a4b8a9acee7ec6f9338a5b2438eecb76bd018bd118aa9042056c166cbca68089e8a4240bf0aa73e443b3cadbebb1
7
- data.tar.gz: 12d037642d2917c77786a6ec97c2b341128e55ac353561870982f9208ac97ff366d2be9d10f143ec50a7797480eadcd96fec31e1420d37c927a1a00bd2243f83
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
- ## Installation
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
- ### Configuration
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
- After install, edit ```/etc/sys_watchdog.yml```.
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
- Now you can test from the command line.
33
+ Run from command line:
35
34
 
36
35
  ```
37
36
  sys_watchdog test
38
37
  ```
39
38
 
40
- ### Start
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
- Finally, after installed and configured, enable periodic run...
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 uncommenting the added cron line:
48
+ or, if installed with cron, uncomment the cron job line:
48
49
  ```vim /etc/crontab```
49
50
 
50
51
 
51
- ### Config Settings
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
- #### Sys Test Settings
65
+ ## Sys Test Settings
65
66
 
66
67
  setting | description
67
68
  ------------------|-------------------------------------------------------------------------------------------
data/_config.yml ADDED
@@ -0,0 +1 @@
1
+ theme: jekyll-theme-cayman
@@ -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
- @logger = WdLogger.new (log_file || DEFAULT_LOG_FILE)
6
+ log_file ||= DEFAULT_LOG_FILE
7
+ conf_file ||= DEFAULT_CONF_FILE
8
+
7
9
  @trackers = {}
8
- parse_conf (conf_file || DEFAULT_CONF_FILE)
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
- if test.notify_on_change
53
- if @trackers[test.name] != output
54
- notify "#{test.name} changed", "old: #{@trackers[test.name]}\nnew: #{output}"
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
- if test.fail
61
- test.fail = false
62
- notify "#{test.name} ok"
63
- end
62
+ test.fail = false
63
+ notify "#{test.name} ok"
64
64
  else
65
- unless test.fail
66
- if test.restore_cmd and not after_restore
67
- test.restore
68
- run_test test, after_restore: true
69
- else
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 = "output: #{output}" if body and not body.empty?
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
@@ -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, _body
22
+ def send_mail sub, body
23
23
  @logger.info "Sending email: #{ sub }"
24
24
 
25
- body = _body || ""
25
+ body ||= ""
26
26
  body += append_sys_info
27
27
 
28
28
  mail = Mail.new do
@@ -31,7 +31,7 @@ class WdTest
31
31
  end
32
32
  end
33
33
 
34
- def run after_restore: false
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.to_s}"
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, allow_raise = false
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 = if @expected_regex
79
- output =~ @expected_regex
80
- elsif @expected_string
81
- output.index @expected_string
82
- elsif @expected_max
83
- output.to_f <= @expected_max
84
- elsif @expected_min
85
- output.to_f <= @expected_min
86
- else
87
- exitstatus == 0
88
- end
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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "sys_watchdog"
3
- s.version = "0.0.2"
3
+ s.version = "0.0.3"
4
4
  s.authors = ["Tom Lobato"]
5
5
  s.email = "lobato@bettercall.io"
6
6
  s.homepage = "http://sys-watchdog.bettercall.io/"
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.2
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