deadman_check 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.travis.yml +16 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +144 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/deadman-check +47 -0
- data/bin/setup +8 -0
- data/deadman_check.gemspec +40 -0
- data/lib/deadman_check.rb +7 -0
- data/lib/deadman_check/version.rb +3 -0
- data/lib/deadman_check_global.rb +10 -0
- data/lib/deadman_check_keyset.rb +27 -0
- data/lib/deadman_check_switch.rb +50 -0
- metadata +164 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5565e27402b5edcb2d0855fe059041567b436779
|
4
|
+
data.tar.gz: ea378921db36b476b9e862f8af00adf572ba14cf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ba534945a247ab3ca5fce9940d7864ff5a7c83e953f51d802a6d52eb42ee2ad62fbb9d7401d8bfbc3eba11db84234d60f1e922f29677f3bc00aed598e7fccd32
|
7
|
+
data.tar.gz: 9e7aebf3624cf27cf0993023343abe7d52111b4ed4be943b5c899db70c7697f1561756c725c798ba633cb52788f3e319b5c4a96b0d3b4d4ebc2c8d412fcee9a5
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
sudo: required
|
2
|
+
language: ruby
|
3
|
+
rvm:
|
4
|
+
- 2.4.0
|
5
|
+
before_install: gem install bundler -v 1.13.7
|
6
|
+
script:
|
7
|
+
- bundle exec rake test
|
8
|
+
deploy:
|
9
|
+
provider: rubygems
|
10
|
+
api_key:
|
11
|
+
secure: "rcQ8I4cBn+UpROxhBUsldKbpiiZ9QNUEep8fLGbmcU6QqN5NA2VrdW/DDzXrgXPPLoTDxRF32K2clIjT6WHYopVOvCeAA0+kNjACtGEV8DKL5VlBz0yWvLqM5L7y6ZhmiL/XUibmN7jcvqqI96h2QRr3qeO4a3XUlAIBqotjMopkqqBcHfq9+19p8CS3yS9Y85c1mM5EDcP7E/3Sa3umK7vvoMh+ulz1mic/CNKSnJOdhicqspvpPLUP0vOZ4Jlnn8I41clkBA0FcbOvEmEU2GNtMR8xDS9e0t+aVBAD92AiKYlHNzWp/84r3ZNjMURmltSLRHOQKYQhFdNJUNxZj9f44mPZcMIqD1kkKFkrdzjRzqpGxldrlUwgGkdiFev9d3x8XYMybDI3SmFDPNfa8d7DeW/AYIwkW6j7rdaFQQLzG4AZnoaW6FOmldePk0hPDT47wdpVy5nItH8ZQax8qJmDOX46IRr4fZ6piXiWZlSIfdwUtdBD47fmZS9xxi+mKTggZYiy+th3txqaXORJCCaaJVo5Yg1hbMN73+yKtLtzmsw/nKr1yVVX3KhYQkNix3ZskNhuOJ2aN2stnVsYKbL0Y924sVp7OrSyg5cWqXEXYcWGpXOKlaABa593QFGwQGl6wo7JiFO7giMQw0n6B4xkRv910BBXSVzafHk+jwk="
|
12
|
+
on:
|
13
|
+
tags: true
|
14
|
+
env:
|
15
|
+
global:
|
16
|
+
secure: "rcQ8I4cBn+UpROxhBUsldKbpiiZ9QNUEep8fLGbmcU6QqN5NA2VrdW/DDzXrgXPPLoTDxRF32K2clIjT6WHYopVOvCeAA0+kNjACtGEV8DKL5VlBz0yWvLqM5L7y6ZhmiL/XUibmN7jcvqqI96h2QRr3qeO4a3XUlAIBqotjMopkqqBcHfq9+19p8CS3yS9Y85c1mM5EDcP7E/3Sa3umK7vvoMh+ulz1mic/CNKSnJOdhicqspvpPLUP0vOZ4Jlnn8I41clkBA0FcbOvEmEU2GNtMR8xDS9e0t+aVBAD92AiKYlHNzWp/84r3ZNjMURmltSLRHOQKYQhFdNJUNxZj9f44mPZcMIqD1kkKFkrdzjRzqpGxldrlUwgGkdiFev9d3x8XYMybDI3SmFDPNfa8d7DeW/AYIwkW6j7rdaFQQLzG4AZnoaW6FOmldePk0hPDT47wdpVy5nItH8ZQax8qJmDOX46IRr4fZ6piXiWZlSIfdwUtdBD47fmZS9xxi+mKTggZYiy+th3txqaXORJCCaaJVo5Yg1hbMN73+yKtLtzmsw/nKr1yVVX3KhYQkNix3ZskNhuOJ2aN2stnVsYKbL0Y924sVp7OrSyg5cWqXEXYcWGpXOKlaABa593QFGwQGl6wo7JiFO7giMQw0n6B4xkRv910BBXSVzafHk+jwk="
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at zane.williamson@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 zane
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
# DeadmanCheck
|
2
|
+
|
3
|
+
Monitor a Redis key that contains an EPOCH time entry. Send email if EPOCH age hits given threshold
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
And then execute:
|
8
|
+
|
9
|
+
$ bundle
|
10
|
+
|
11
|
+
Or install it yourself as:
|
12
|
+
|
13
|
+
$ gem install deadman_check
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
```bash
|
18
|
+
$ deadman-check -h
|
19
|
+
NAME:
|
20
|
+
|
21
|
+
deadman-check
|
22
|
+
|
23
|
+
DESCRIPTION:
|
24
|
+
|
25
|
+
Monitor a Redis key that contains an EPOCH time entry.
|
26
|
+
Send email if EPOCH age hits given threshold
|
27
|
+
|
28
|
+
COMMANDS:
|
29
|
+
|
30
|
+
help Display global or [command] help documentation
|
31
|
+
key_set Update a given Redis key with current EPOCH
|
32
|
+
switch_monitor Target a Redis key to monitor
|
33
|
+
|
34
|
+
GLOBAL OPTIONS:
|
35
|
+
|
36
|
+
-h, --help
|
37
|
+
Display help documentation
|
38
|
+
|
39
|
+
-v, --version
|
40
|
+
Display version information
|
41
|
+
|
42
|
+
-t, --trace
|
43
|
+
Display backtrace when an error occurs
|
44
|
+
```
|
45
|
+
|
46
|
+
### Usage for key_set command
|
47
|
+
|
48
|
+
```bash
|
49
|
+
$ deadman-check key_set -h
|
50
|
+
|
51
|
+
NAME:
|
52
|
+
|
53
|
+
key_set
|
54
|
+
|
55
|
+
SYNOPSIS:
|
56
|
+
|
57
|
+
deadman-check key_set [options]
|
58
|
+
|
59
|
+
DESCRIPTION:
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
EXAMPLES:
|
64
|
+
|
65
|
+
# Update a Redis key deadman/myservice, with current EPOCH time
|
66
|
+
deadman-check key_set --host 127.0.0.1 --port 6379 --key deadman/myservice
|
67
|
+
|
68
|
+
OPTIONS:
|
69
|
+
|
70
|
+
--host HOST
|
71
|
+
IP address or hostname of Redis system
|
72
|
+
|
73
|
+
--port PORT
|
74
|
+
port Redis is listening on
|
75
|
+
|
76
|
+
--key KEY
|
77
|
+
Redis key to monitor
|
78
|
+
```
|
79
|
+
|
80
|
+
### Usage for switch_monitor command
|
81
|
+
|
82
|
+
```bash
|
83
|
+
$ deadman-check switch_monitor -h
|
84
|
+
|
85
|
+
NAME:
|
86
|
+
|
87
|
+
switch_monitor
|
88
|
+
|
89
|
+
SYNOPSIS:
|
90
|
+
|
91
|
+
deadman-check switch_monitor [options]
|
92
|
+
|
93
|
+
DESCRIPTION:
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
EXAMPLES:
|
98
|
+
|
99
|
+
# Target a Redis key deadman/myservice, and this key has an EPOCH
|
100
|
+
value to check looking to alert on 500 second or greater freshness
|
101
|
+
deadman-check switch_monitor \
|
102
|
+
--host 127.0.0.1 \
|
103
|
+
--port 6379 \
|
104
|
+
--key deadman/myservice \
|
105
|
+
--freshness 500 \
|
106
|
+
--alert-to ops@mycomany.tld \
|
107
|
+
--alert-from ops-no-reply-email@mycomany.tld
|
108
|
+
|
109
|
+
OPTIONS:
|
110
|
+
|
111
|
+
--host HOST
|
112
|
+
IP address or hostname of Redis system
|
113
|
+
|
114
|
+
--port PORT
|
115
|
+
port Redis is listening on
|
116
|
+
|
117
|
+
--key KEY
|
118
|
+
Redis key to monitor
|
119
|
+
|
120
|
+
--freshness SECONDS
|
121
|
+
The value in seconds to alert on when the recorded
|
122
|
+
EPOCH value exceeds current EPOCH
|
123
|
+
|
124
|
+
--alert-to EMAIL
|
125
|
+
Email address to send alert to
|
126
|
+
|
127
|
+
--alert-from EMAIL
|
128
|
+
Email address to send from
|
129
|
+
```
|
130
|
+
|
131
|
+
## Development
|
132
|
+
|
133
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
134
|
+
|
135
|
+
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).
|
136
|
+
|
137
|
+
## Contributing
|
138
|
+
|
139
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/deadman_check. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
140
|
+
|
141
|
+
|
142
|
+
## License
|
143
|
+
|
144
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "deadman_check"
|
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
|
data/bin/deadman-check
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'commander/import'
|
5
|
+
require 'deadman_check'
|
6
|
+
|
7
|
+
program :name, 'deadman-check'
|
8
|
+
program :version, DeadmanCheck::VERSION
|
9
|
+
program :description, %q{Monitor a Redis key that contains an EPOCH time entry.
|
10
|
+
Send email if EPOCH age hits given threshold}
|
11
|
+
|
12
|
+
command :switch_monitor do |c|
|
13
|
+
c.syntax = 'deadman-check switch_monitor [options]'
|
14
|
+
c.summary = 'Target a Redis key to monitor'
|
15
|
+
c.description = ''
|
16
|
+
c.example %q{Target a Redis key deadman/myservice, and this key has an EPOCH
|
17
|
+
value to check looking to alert on 500 second or greater freshness},
|
18
|
+
%q{deadman-check switch_monitor --host 127.0.0.1 --port 6379 --key deadman/myservice --freshness 500 --alert-to ops@mycomany.tld --alert-from ops-no-reply-email@mycomany.tld}
|
19
|
+
c.option '--host HOST', String, 'IP address or hostname of Redis system'
|
20
|
+
c.option '--port PORT', String, 'port Redis is listening on'
|
21
|
+
c.option '--key KEY', String, 'Redis key to monitor'
|
22
|
+
c.option '--freshness SECONDS', String, %q{The value in seconds to alert on when the recorded
|
23
|
+
EPOCH value exceeds current EPOCH}
|
24
|
+
c.option '--alert-to EMAIL', String, 'Email address to send alert to'
|
25
|
+
c.option '--alert-from EMAIL', String, 'Email address to send from'
|
26
|
+
c.action do |args, options|
|
27
|
+
switch_monitor = DeadmanCheck::SwitchMonitor.new(options.host, options.port,
|
28
|
+
options.key, options.freshness, options.alert_to, options.alert_from)
|
29
|
+
switch_monitor.run_check
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
command :key_set do |c|
|
34
|
+
c.syntax = 'deadman-check key_set [options]'
|
35
|
+
c.summary = 'Update a given Redis key with current EPOCH'
|
36
|
+
c.description = ''
|
37
|
+
c.example %q{Update a Redis key deadman/myservice, with current EPOCH time},
|
38
|
+
%q{deadman-check key_set --host 127.0.0.1 --port 6379 --key deadman/myservice}
|
39
|
+
c.option '--host HOST', String, 'IP address or hostname of Redis system'
|
40
|
+
c.option '--port PORT', String, 'port Redis is listening on'
|
41
|
+
c.option '--key KEY', String, 'Redis key to monitor'
|
42
|
+
c.action do |args, options|
|
43
|
+
key_set = DeadmanCheck::KeySet.new(options.host, options.port,
|
44
|
+
options.key)
|
45
|
+
key_set.run_redis_key_update
|
46
|
+
end
|
47
|
+
end
|
data/bin/setup
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'deadman_check/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "deadman_check"
|
8
|
+
spec.version = DeadmanCheck::VERSION
|
9
|
+
spec.authors = ["zane"]
|
10
|
+
spec.email = ["zane.williamson@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Monitor a Redis key that contains an EPOCH time entry.
|
13
|
+
Send email if EPOCH age hits given threshold}
|
14
|
+
spec.description = %q{A script to check a given Redis key EPOCH for
|
15
|
+
freshness. Good for monitoring cron jobs or batch jobs. Have the last step
|
16
|
+
of the job post the EPOCH time to target Redis key. This script will monitor
|
17
|
+
it for a given freshness value (difference in time now to posted EPOCH)}
|
18
|
+
spec.homepage = "https://github.com/sepulworld/deadman-check"
|
19
|
+
spec.license = "MIT"
|
20
|
+
|
21
|
+
if spec.respond_to?(:metadata)
|
22
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
23
|
+
spec.metadata['optional_gems'] = "keyring"
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "bin"
|
30
|
+
spec.executables = "deadman-check"
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
36
|
+
|
37
|
+
spec.add_dependency 'commander', '~> 4.4', '>= 4.4.3'
|
38
|
+
spec.add_dependency 'redis', '~> 3.3', '>= 3.3.3'
|
39
|
+
spec.add_dependency 'pony', '~> 1.1'
|
40
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'deadman_check/version'
|
2
|
+
require 'deadman_check_global'
|
3
|
+
require 'redis'
|
4
|
+
|
5
|
+
module DeadmanCheck
|
6
|
+
# KeySet Class
|
7
|
+
class KeySet
|
8
|
+
attr_accessor :host, :port, :key
|
9
|
+
|
10
|
+
def initialize(host, port, key)
|
11
|
+
@host = host
|
12
|
+
@port = port
|
13
|
+
@key = key
|
14
|
+
end
|
15
|
+
|
16
|
+
def _update_redis_key(host, port, key)
|
17
|
+
epoch_time_now = DeadmanCheck::DeadmanCheckGlobal.new.get_epoch_time
|
18
|
+
redis = Redis.new(:host => host, :port => port)
|
19
|
+
redis.set(key, epoch_time_now)
|
20
|
+
puts "Redis key #{key} updated EPOCH to #{epoch_time_now}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def run_redis_key_update
|
24
|
+
_update_redis_key(@host, @port, @key)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'deadman_check/version'
|
2
|
+
require 'deadman_check_global'
|
3
|
+
require 'redis'
|
4
|
+
require 'pony'
|
5
|
+
|
6
|
+
module DeadmanCheck
|
7
|
+
# Switch class
|
8
|
+
class SwitchMonitor
|
9
|
+
attr_accessor :host, :port, :key, :freshness, :alert_to, :alert_from
|
10
|
+
|
11
|
+
def initialize(host, port, key, freshness, alert_to, alert_from)
|
12
|
+
@host = host
|
13
|
+
@port = port
|
14
|
+
@key = key
|
15
|
+
@freshness = freshness.to_i
|
16
|
+
@alert_to = alert_to
|
17
|
+
@alert_from = alert_from
|
18
|
+
end
|
19
|
+
|
20
|
+
def _diff_epoc(current_epoch, recorded_epoch)
|
21
|
+
epoch_difference = current_epoch - recorded_epoch
|
22
|
+
return epoch_difference
|
23
|
+
end
|
24
|
+
|
25
|
+
def _get_recorded_epoch(host, port, key)
|
26
|
+
redis = Redis.new(:host => host, :port => port)
|
27
|
+
recorded_epoch = redis.get(key)
|
28
|
+
return recorded_epoch
|
29
|
+
end
|
30
|
+
|
31
|
+
def email_alert(alert_to, alert_from, key, recorded_epoch, current_epoch,
|
32
|
+
epoch_diff)
|
33
|
+
Pony.mail(:to => alert_to, :from => alert_from,
|
34
|
+
:subject => "Alert: Deadman Switch Triggered for #{key}",
|
35
|
+
:body => "Alert: Deadman Switch Triggered for #{key}, with
|
36
|
+
#{epoch_diff} seconds since last run")
|
37
|
+
end
|
38
|
+
|
39
|
+
def run_check
|
40
|
+
recorded_epoch = _get_recorded_epoch(@host, @port, @key).to_i
|
41
|
+
current_epoch = DeadmanCheck::DeadmanCheckGlobal.new.get_epoch_time.to_i
|
42
|
+
epoch_diff = _diff_epoc(current_epoch, recorded_epoch)
|
43
|
+
if epoch_diff > @freshness
|
44
|
+
email_alert(@alert_to, @alert_from, @key,
|
45
|
+
recorded_epoch, current_epoch, epoch_diff)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
metadata
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: deadman_check
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- zane
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: commander
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '4.4'
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 4.4.3
|
65
|
+
type: :runtime
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - "~>"
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '4.4'
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 4.4.3
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: redis
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '3.3'
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: 3.3.3
|
85
|
+
type: :runtime
|
86
|
+
prerelease: false
|
87
|
+
version_requirements: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - "~>"
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '3.3'
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 3.3.3
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: pony
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - "~>"
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '1.1'
|
102
|
+
type: :runtime
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - "~>"
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '1.1'
|
109
|
+
description: |-
|
110
|
+
A script to check a given Redis key EPOCH for
|
111
|
+
freshness. Good for monitoring cron jobs or batch jobs. Have the last step
|
112
|
+
of the job post the EPOCH time to target Redis key. This script will monitor
|
113
|
+
it for a given freshness value (difference in time now to posted EPOCH)
|
114
|
+
email:
|
115
|
+
- zane.williamson@gmail.com
|
116
|
+
executables:
|
117
|
+
- deadman-check
|
118
|
+
extensions: []
|
119
|
+
extra_rdoc_files: []
|
120
|
+
files:
|
121
|
+
- ".gitignore"
|
122
|
+
- ".travis.yml"
|
123
|
+
- CODE_OF_CONDUCT.md
|
124
|
+
- Gemfile
|
125
|
+
- LICENSE.txt
|
126
|
+
- README.md
|
127
|
+
- Rakefile
|
128
|
+
- bin/console
|
129
|
+
- bin/deadman-check
|
130
|
+
- bin/setup
|
131
|
+
- deadman_check.gemspec
|
132
|
+
- lib/deadman_check.rb
|
133
|
+
- lib/deadman_check/version.rb
|
134
|
+
- lib/deadman_check_global.rb
|
135
|
+
- lib/deadman_check_keyset.rb
|
136
|
+
- lib/deadman_check_switch.rb
|
137
|
+
homepage: https://github.com/sepulworld/deadman-check
|
138
|
+
licenses:
|
139
|
+
- MIT
|
140
|
+
metadata:
|
141
|
+
allowed_push_host: https://rubygems.org
|
142
|
+
optional_gems: keyring
|
143
|
+
post_install_message:
|
144
|
+
rdoc_options: []
|
145
|
+
require_paths:
|
146
|
+
- lib
|
147
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
|
+
requirements:
|
154
|
+
- - ">="
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: '0'
|
157
|
+
requirements: []
|
158
|
+
rubyforge_project:
|
159
|
+
rubygems_version: 2.6.8
|
160
|
+
signing_key:
|
161
|
+
specification_version: 4
|
162
|
+
summary: Monitor a Redis key that contains an EPOCH time entry. Send email if EPOCH
|
163
|
+
age hits given threshold
|
164
|
+
test_files: []
|