boppers-uptime 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 +8 -0
- data/.rubocop.yml +116 -0
- data/.travis.yml +19 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/LICENSE.txt +21 -0
- data/README.md +62 -0
- data/Rakefile +12 -0
- data/boppers-uptime.gemspec +33 -0
- data/gems.locked +82 -0
- data/gems.rb +2 -0
- data/lib/boppers-uptime.rb +4 -0
- data/lib/boppers/uptime.rb +111 -0
- data/lib/boppers/uptime/relative_time.rb +29 -0
- data/lib/boppers/uptime/version.rb +7 -0
- metadata +184 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: '08b9f90ec4d9408775ebd4347b1413d0c47e19c9'
|
4
|
+
data.tar.gz: 39a1a32f229f241aa1e840dcd19b76c801729b40
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2e24370726d99636da7b5e7f85daef991627dd632b2482effccda16d7e2b81b581927047c34b76ebb5e96695f4643e1e7e3b190edc80e7673576b2bb0d7c280a
|
7
|
+
data.tar.gz: 8b5f0ba1e1f3ae5cbdd9da2f070ecde12bea7642e2f31e68bd61d88c84a1bbe8b2f20854dceed80ac4f3f0018cadda4e431c8f43e2f4a951d50be094cf492966
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.4
|
3
|
+
|
4
|
+
Style/Alias:
|
5
|
+
EnforcedStyle: prefer_alias_method
|
6
|
+
|
7
|
+
Style/FrozenStringLiteralComment:
|
8
|
+
EnforcedStyle: always
|
9
|
+
|
10
|
+
Style/ClassCheck:
|
11
|
+
EnforcedStyle: kind_of?
|
12
|
+
|
13
|
+
Metrics/LineLength:
|
14
|
+
Max: 80
|
15
|
+
|
16
|
+
Style/BlockDelimiters:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Style/RegexpLiteral:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
Metrics/AbcSize:
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
Style/PerlBackrefs:
|
26
|
+
Enabled: false
|
27
|
+
|
28
|
+
ClassLength:
|
29
|
+
Enabled: false
|
30
|
+
|
31
|
+
CyclomaticComplexity:
|
32
|
+
Enabled: false
|
33
|
+
|
34
|
+
Documentation:
|
35
|
+
Enabled: false
|
36
|
+
|
37
|
+
Encoding:
|
38
|
+
Enabled: false
|
39
|
+
|
40
|
+
FileName:
|
41
|
+
Enabled: false
|
42
|
+
|
43
|
+
IfUnlessModifier:
|
44
|
+
Enabled: false
|
45
|
+
|
46
|
+
MethodLength:
|
47
|
+
Enabled: false
|
48
|
+
|
49
|
+
ModuleFunction:
|
50
|
+
Enabled: false
|
51
|
+
|
52
|
+
OneLineConditional:
|
53
|
+
Enabled: false
|
54
|
+
|
55
|
+
ParameterLists:
|
56
|
+
Enabled: false
|
57
|
+
|
58
|
+
Proc:
|
59
|
+
Enabled: false
|
60
|
+
|
61
|
+
SingleLineBlockParams:
|
62
|
+
Enabled: false
|
63
|
+
|
64
|
+
VariableInterpolation:
|
65
|
+
Enabled: false
|
66
|
+
|
67
|
+
Style/TrailingCommaInLiteral:
|
68
|
+
Enabled: false
|
69
|
+
|
70
|
+
WhileUntilModifier:
|
71
|
+
Enabled: false
|
72
|
+
|
73
|
+
PredicateName:
|
74
|
+
NamePrefixBlacklist:
|
75
|
+
- is_
|
76
|
+
|
77
|
+
StringLiterals:
|
78
|
+
EnforcedStyle: double_quotes
|
79
|
+
|
80
|
+
DotPosition:
|
81
|
+
EnforcedStyle: leading
|
82
|
+
|
83
|
+
SpaceBeforeBlockBraces:
|
84
|
+
EnforcedStyle: space
|
85
|
+
|
86
|
+
SpaceInsideBlockBraces:
|
87
|
+
EnforcedStyle: no_space
|
88
|
+
|
89
|
+
DoubleNegation:
|
90
|
+
Enabled: false
|
91
|
+
|
92
|
+
SpaceInsideBlockBraces:
|
93
|
+
SpaceBeforeBlockParameters: false
|
94
|
+
|
95
|
+
SpaceInsideHashLiteralBraces:
|
96
|
+
Enabled: false
|
97
|
+
|
98
|
+
PercentLiteralDelimiters:
|
99
|
+
PreferredDelimiters:
|
100
|
+
'%': '{}'
|
101
|
+
'%i': '{}'
|
102
|
+
'%q': '{}'
|
103
|
+
'%Q': '{}'
|
104
|
+
'%r': '{}'
|
105
|
+
'%s': '{}'
|
106
|
+
'%w': '{}'
|
107
|
+
'%W': '{}'
|
108
|
+
'%x': '{}'
|
109
|
+
|
110
|
+
Style/CollectionMethods:
|
111
|
+
PreferredMethods:
|
112
|
+
collect: 'map'
|
113
|
+
collect!: 'map!'
|
114
|
+
inject: 'reduce'
|
115
|
+
detect: 'find'
|
116
|
+
find_all: 'select'
|
data/.travis.yml
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
sudo: false
|
2
|
+
language: ruby
|
3
|
+
cache: bundler
|
4
|
+
rvm:
|
5
|
+
- 2.4.2
|
6
|
+
before_install:
|
7
|
+
- gem install bundler
|
8
|
+
- bundle install
|
9
|
+
before_script:
|
10
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
11
|
+
- chmod +x ./cc-test-reporter
|
12
|
+
- "./cc-test-reporter before-build"
|
13
|
+
after_script:
|
14
|
+
- "./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT"
|
15
|
+
notifications:
|
16
|
+
email: false
|
17
|
+
env:
|
18
|
+
global:
|
19
|
+
secure: CBI+2WSAlg+MijEc5o3hKW6svE659sM2LiuC9LqtXOH17iRNS0uENBZyuzcI+sCYtHzb+wJuTYtQX8RsUsaB2tl3CWOJBtazDWwNUUyhS4PgRCK36nRXdaXSA1tQ24zK6Z9/MbgJ+YYReW/9zNSvwFjy1sxLCHTAtKTzbBTmaAWHgoG/bLzw8Rl4tPFdI3UZwQGzEvbJLjE/9F6kS0X8Hm49UmmzvkQ6FI7kS16WT1cW3Kybnnx1Nd+HbzQe40cFz6vjjEuVwCcS0hNmpVyzU/PGXO8Y0am/BhdHcpiV4CCDzdARkwwjYMSM2MBSt8XzuPn75sFvmQjawChcD2zwbKXYpjo74XWhqoKwfzJrZTJiPGcTcA3acEhgr80RURdgCG4bzmhrOHYZdZ42KDDJAVNLPnICeHe5fXtAe5/AJUIFdEmRkQZLhNc8MWB9gFvaXFglm/D9shuQABM1zODNNr03AU0Hnw1hgy/WKyO0tAKlZsqWaanBV9QLbSgDzWUWYjXoNN3WT8ESLjMrebUlkA9xhNzURbsOKEgS9RJW3D6KZ249IaPojxay3o3kAbSV7G87isnQnBU411Z5N2jLveB+/+PE/jHYN2NuZ+xoUIMv/eoeUTH9rGS0lWhZ+CjK+U83jYLad9Fm0a0A7KiKjpML4sslufyCjaG4W/wATtQ=
|
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 fnando.vieira@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/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Nando Vieira
|
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,62 @@
|
|
1
|
+
# Boppers::Uptime
|
2
|
+
|
3
|
+
A [bopper](https://github.com/fnando/boppers) to check if your sites are online.
|
4
|
+
|
5
|
+
[![Travis-CI](https://travis-ci.org/fnando/boppers-uptime.png)](https://travis-ci.org/fnando/boppers-uptime)
|
6
|
+
[![GPA](https://codeclimate.com/github/fnando/boppers-uptime/badges/gpa.svg)](https://codeclimate.com/github/fnando/boppers-uptime)
|
7
|
+
[![Test Coverage](https://codeclimate.com/github/fnando/boppers-uptime/badges/coverage.svg)](https://codeclimate.com/github/fnando/boppers-uptime)
|
8
|
+
[![Gem](https://img.shields.io/gem/v/boppers-uptime.svg)](https://rubygems.org/gems/boppers-uptime)
|
9
|
+
[![Gem](https://img.shields.io/gem/dt/boppers-uptime.svg)](https://rubygems.org/gems/boppers-uptime)
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem "boppers-uptime"
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install boppers-uptime
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
Boppers.configure do |config|
|
31
|
+
config.boppers << Boppers::Uptime.new(name: "Portfolio", url: "https://portfolionow.co/")
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
Available options:
|
36
|
+
|
37
|
+
- `name:` The target monitoring's name. Required.
|
38
|
+
- `url`: The url that will be monitored. Required.
|
39
|
+
- `status`: The expected HTTP status (can be an array of numbers). Default to `200`.
|
40
|
+
- `contain`: The returned URL must include that given text (may also be a regular expression).
|
41
|
+
- `min_failures`: Only notify after reaching this threadshold. Defaults to `2`.
|
42
|
+
- `interval`: The polling interval. Defaults to `30` (seconds).
|
43
|
+
- `timezone:` The timezone for displaying dates. Defaults to `Etc/UTC`.
|
44
|
+
- `format`: How the time will be formatted. Defaults to `%Y-%m-%dT%H:%M:%S%:z` (e.g. `2017-10-18T19:31:29-02:00`).
|
45
|
+
|
46
|
+
## Development
|
47
|
+
|
48
|
+
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.
|
49
|
+
|
50
|
+
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).
|
51
|
+
|
52
|
+
## Contributing
|
53
|
+
|
54
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/fnando/boppers-uptime. 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.
|
55
|
+
|
56
|
+
## License
|
57
|
+
|
58
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
59
|
+
|
60
|
+
## Code of Conduct
|
61
|
+
|
62
|
+
Everyone interacting in the Boppers project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/fnando/boppers-uptime/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "./lib/boppers/uptime/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "boppers-uptime"
|
7
|
+
spec.version = Boppers::Uptime::VERSION
|
8
|
+
spec.authors = ["Nando Vieira"]
|
9
|
+
spec.email = ["fnando.vieira@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "A bopper to check if your sites are online."
|
12
|
+
spec.description = spec.summary
|
13
|
+
spec.homepage = "https://rubygems.org/gems/boppers-uptime"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_dependency "boppers"
|
24
|
+
spec.add_dependency "tzinfo"
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler"
|
27
|
+
spec.add_development_dependency "rake"
|
28
|
+
spec.add_development_dependency "minitest-utils"
|
29
|
+
spec.add_development_dependency "simplecov"
|
30
|
+
spec.add_development_dependency "pry-meta"
|
31
|
+
spec.add_development_dependency "webmock"
|
32
|
+
spec.add_development_dependency "mocha"
|
33
|
+
end
|
data/gems.locked
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
boppers-uptime (0.1.0)
|
5
|
+
boppers
|
6
|
+
tzinfo
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
addressable (2.5.2)
|
12
|
+
public_suffix (>= 2.0.2, < 4.0)
|
13
|
+
aitch (1.0.2)
|
14
|
+
nokogiri (>= 1.6.0)
|
15
|
+
awesome_print (1.8.0)
|
16
|
+
boppers (0.0.2)
|
17
|
+
aitch
|
18
|
+
thor
|
19
|
+
byebug (9.1.0)
|
20
|
+
coderay (1.1.2)
|
21
|
+
crack (0.4.3)
|
22
|
+
safe_yaml (~> 1.0.0)
|
23
|
+
docile (1.1.5)
|
24
|
+
hashdiff (0.3.7)
|
25
|
+
json (2.1.0)
|
26
|
+
metaclass (0.0.4)
|
27
|
+
method_source (0.9.0)
|
28
|
+
mini_portile2 (2.3.0)
|
29
|
+
minitest (5.10.3)
|
30
|
+
minitest-utils (0.4.0)
|
31
|
+
minitest
|
32
|
+
mocha (1.3.0)
|
33
|
+
metaclass (~> 0.0.1)
|
34
|
+
nokogiri (1.8.1)
|
35
|
+
mini_portile2 (~> 2.3.0)
|
36
|
+
pry (0.11.2)
|
37
|
+
coderay (~> 1.1.0)
|
38
|
+
method_source (~> 0.9.0)
|
39
|
+
pry-byebug (3.5.0)
|
40
|
+
byebug (~> 9.1)
|
41
|
+
pry (~> 0.10)
|
42
|
+
pry-meta (0.0.10)
|
43
|
+
awesome_print
|
44
|
+
pry
|
45
|
+
pry-byebug
|
46
|
+
pry-remote
|
47
|
+
pry-remote (0.1.8)
|
48
|
+
pry (~> 0.9)
|
49
|
+
slop (~> 3.0)
|
50
|
+
public_suffix (3.0.0)
|
51
|
+
rake (12.2.1)
|
52
|
+
safe_yaml (1.0.4)
|
53
|
+
simplecov (0.15.1)
|
54
|
+
docile (~> 1.1.0)
|
55
|
+
json (>= 1.8, < 3)
|
56
|
+
simplecov-html (~> 0.10.0)
|
57
|
+
simplecov-html (0.10.2)
|
58
|
+
slop (3.6.0)
|
59
|
+
thor (0.20.0)
|
60
|
+
thread_safe (0.3.6)
|
61
|
+
tzinfo (1.2.4)
|
62
|
+
thread_safe (~> 0.1)
|
63
|
+
webmock (3.1.0)
|
64
|
+
addressable (>= 2.3.6)
|
65
|
+
crack (>= 0.3.2)
|
66
|
+
hashdiff
|
67
|
+
|
68
|
+
PLATFORMS
|
69
|
+
ruby
|
70
|
+
|
71
|
+
DEPENDENCIES
|
72
|
+
boppers-uptime!
|
73
|
+
bundler
|
74
|
+
minitest-utils
|
75
|
+
mocha
|
76
|
+
pry-meta
|
77
|
+
rake
|
78
|
+
simplecov
|
79
|
+
webmock
|
80
|
+
|
81
|
+
BUNDLED WITH
|
82
|
+
1.16.0
|
data/gems.rb
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "tzinfo"
|
4
|
+
|
5
|
+
require "boppers/uptime/version"
|
6
|
+
require "boppers/uptime/relative_time"
|
7
|
+
|
8
|
+
module Boppers
|
9
|
+
class Uptime
|
10
|
+
FORMAT = "%Y-%m-%dT%H:%M:%S%:z"
|
11
|
+
|
12
|
+
attr_reader :name, :url, :interval, :status, :contain, :min_failures,
|
13
|
+
:timezone, :format, :failures, :failed_at
|
14
|
+
|
15
|
+
def initialize(name:, url:, interval: 30, status: 200, contain: nil,
|
16
|
+
min_failures: 1, timezone: Time.now.getlocal.zone,
|
17
|
+
format: FORMAT)
|
18
|
+
@name = name
|
19
|
+
@url = url
|
20
|
+
@interval = interval
|
21
|
+
@status = [status].flatten.map(&:to_i)
|
22
|
+
@contain = contain
|
23
|
+
@min_failures = min_failures
|
24
|
+
@timezone = find_timezone(timezone)
|
25
|
+
@format = format
|
26
|
+
@failures = []
|
27
|
+
end
|
28
|
+
|
29
|
+
def call
|
30
|
+
response = HttpClient.get(url)
|
31
|
+
|
32
|
+
succeed = valid_response?(response)
|
33
|
+
|
34
|
+
return succeed! if succeed
|
35
|
+
|
36
|
+
# Check failed, so track the failure and check
|
37
|
+
# if we need to send any notification (only sends a notification
|
38
|
+
# when threadshold is reached for the first time).
|
39
|
+
failures << now
|
40
|
+
reached_threshold = failures.size == min_failures
|
41
|
+
went_offline! if reached_threshold
|
42
|
+
end
|
43
|
+
|
44
|
+
def succeed!
|
45
|
+
offline_at = failures.first
|
46
|
+
online_at = now
|
47
|
+
failure_threshold_exceeded = failures.size >= min_failures
|
48
|
+
failures.clear
|
49
|
+
back_online!(offline_at, online_at) if failure_threshold_exceeded
|
50
|
+
end
|
51
|
+
|
52
|
+
def valid_response?(response)
|
53
|
+
validations = []
|
54
|
+
|
55
|
+
validations << status.include?(response.code)
|
56
|
+
validations << response.body.include?(contain) if contain.kind_of?(String)
|
57
|
+
validations << response.body.match?(contain) if contain.kind_of?(Regexp)
|
58
|
+
|
59
|
+
validations.all?
|
60
|
+
end
|
61
|
+
|
62
|
+
def back_online!(offline_at, online_at)
|
63
|
+
duration = RelativeTime.call(offline_at, online_at)
|
64
|
+
|
65
|
+
title = "#{name} is up"
|
66
|
+
message = [
|
67
|
+
"#{name} is back online at #{format_time(online_at)}, after #{duration} of downtime.",
|
68
|
+
"You can check it at #{url}."
|
69
|
+
].join("\n")
|
70
|
+
|
71
|
+
Boppers.notify(:uptime,
|
72
|
+
title: title,
|
73
|
+
message: message,
|
74
|
+
options: {color: :green})
|
75
|
+
end
|
76
|
+
|
77
|
+
def went_offline!
|
78
|
+
failed_at = failures.first
|
79
|
+
title = "#{name} is down"
|
80
|
+
message = [
|
81
|
+
"#{name} is offline since #{format_time(failed_at)}.",
|
82
|
+
"You can check it at #{url}."
|
83
|
+
].join("\n")
|
84
|
+
|
85
|
+
Boppers.notify(:uptime,
|
86
|
+
title: title,
|
87
|
+
message: message,
|
88
|
+
options: {color: :red})
|
89
|
+
end
|
90
|
+
|
91
|
+
def now
|
92
|
+
period = timezone.current_period
|
93
|
+
utc_offset = period.offset.utc_total_offset
|
94
|
+
Time.now.getlocal(utc_offset)
|
95
|
+
end
|
96
|
+
|
97
|
+
def format_time(time)
|
98
|
+
time.strftime(format)
|
99
|
+
end
|
100
|
+
|
101
|
+
def find_timezone(name)
|
102
|
+
TZInfo::Timezone.get(name)
|
103
|
+
rescue TZInfo::InvalidTimezoneIdentifier
|
104
|
+
name = name.to_sym
|
105
|
+
|
106
|
+
TZInfo::Timezone.all.find do |zone|
|
107
|
+
zone.current_period.abbreviation == name
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Boppers
|
4
|
+
class Uptime
|
5
|
+
module RelativeTime
|
6
|
+
def self.call(from_time, to_time)
|
7
|
+
seconds = (to_time - from_time).to_i
|
8
|
+
return plural(seconds, "second") if seconds < 60
|
9
|
+
|
10
|
+
minutes = (seconds / 60).to_i
|
11
|
+
return plural(minutes, "minute") if minutes < 60
|
12
|
+
|
13
|
+
hours = (minutes / 60).to_i
|
14
|
+
return plural(hours, "hour") if hours < 24
|
15
|
+
|
16
|
+
days = (hours / 24).to_i
|
17
|
+
plural(days, "day")
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.plural(count, one, many = "#{one}s")
|
21
|
+
if count == 1
|
22
|
+
"#{count} #{one}"
|
23
|
+
else
|
24
|
+
"#{count} #{many}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,184 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: boppers-uptime
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nando Vieira
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-11-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: boppers
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: tzinfo
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest-utils
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry-meta
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: webmock
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: mocha
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
description: A bopper to check if your sites are online.
|
140
|
+
email:
|
141
|
+
- fnando.vieira@gmail.com
|
142
|
+
executables: []
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- ".gitignore"
|
147
|
+
- ".rubocop.yml"
|
148
|
+
- ".travis.yml"
|
149
|
+
- CODE_OF_CONDUCT.md
|
150
|
+
- LICENSE.txt
|
151
|
+
- README.md
|
152
|
+
- Rakefile
|
153
|
+
- boppers-uptime.gemspec
|
154
|
+
- gems.locked
|
155
|
+
- gems.rb
|
156
|
+
- lib/boppers-uptime.rb
|
157
|
+
- lib/boppers/uptime.rb
|
158
|
+
- lib/boppers/uptime/relative_time.rb
|
159
|
+
- lib/boppers/uptime/version.rb
|
160
|
+
homepage: https://rubygems.org/gems/boppers-uptime
|
161
|
+
licenses:
|
162
|
+
- MIT
|
163
|
+
metadata: {}
|
164
|
+
post_install_message:
|
165
|
+
rdoc_options: []
|
166
|
+
require_paths:
|
167
|
+
- lib
|
168
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
169
|
+
requirements:
|
170
|
+
- - ">="
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: '0'
|
173
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
174
|
+
requirements:
|
175
|
+
- - ">="
|
176
|
+
- !ruby/object:Gem::Version
|
177
|
+
version: '0'
|
178
|
+
requirements: []
|
179
|
+
rubyforge_project:
|
180
|
+
rubygems_version: 2.6.13
|
181
|
+
signing_key:
|
182
|
+
specification_version: 4
|
183
|
+
summary: A bopper to check if your sites are online.
|
184
|
+
test_files: []
|