sensu-check-helpers 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +38 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/sensu-check-helpers/alerts.rb +33 -0
- data/lib/sensu-check-helpers/request.rb +12 -0
- data/lib/sensu-check-helpers/time.rb +19 -0
- data/lib/sensu-check-helpers/version.rb +3 -0
- data/lib/sensu-check-helpers.rb +16 -0
- data/sensu-check-helpers.gemspec +23 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5d4395ddb356a5c3bdc1faed83cf69aa603e5fc1
|
4
|
+
data.tar.gz: 545e81a3bc21b5b5bb2c6a47aa41dc0931fcf6f3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 756bdcf634fc8c0a242aa2b82b1c0551b50c0315f0bacf7effe9c741818026f0f852dd7ca7176d5529eaac129c7b70eaf12f6e7bb450bbae02d9cb52284410bc
|
7
|
+
data.tar.gz: 8384471cd9ace897b64accd0e8cb306026c5ae907979241e4f5e81a7b1033abc8857ba8bc4cab66dd4480d1ea2e66b4bfa44673a19054a4e95f08096d135c726
|
data/.gitignore
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/vendor/bundle
|
26
|
+
/lib/bundler/man/
|
27
|
+
|
28
|
+
# for a library or gem, you might want to ignore these files since the code is
|
29
|
+
# intended to run in multiple environments; otherwise, check them in:
|
30
|
+
# Gemfile.lock
|
31
|
+
# .ruby-version
|
32
|
+
# .ruby-gemset
|
33
|
+
|
34
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
35
|
+
.rvmrc
|
36
|
+
|
37
|
+
.idea
|
38
|
+
Gemfile.lock
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 ITV
|
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.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Sensu::Check::Helpers
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'sensu-check-helpers'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install sensu-check-helpers
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( https://github.com/[my-github-username]/sensu-check-helpers/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module SensuCheckHelpers
|
2
|
+
|
3
|
+
module Alerts
|
4
|
+
|
5
|
+
OK = 0
|
6
|
+
WARNING = 1
|
7
|
+
CRITICAL = 2
|
8
|
+
|
9
|
+
def sensu_client_socket(message)
|
10
|
+
UDPSocket.new.send(message + "\n", 0, '127.0.0.1', 3030)
|
11
|
+
end
|
12
|
+
|
13
|
+
def send_ok(alert_name, alert_message)
|
14
|
+
handlers = config[:handlers].split(',').map(&:strip)
|
15
|
+
check_result = { name: alert_name, status: OK, output: "OK: #{alert_message}", handlers: handlers }
|
16
|
+
sensu_client_socket check_result.to_json
|
17
|
+
end
|
18
|
+
|
19
|
+
def send_warning(alert_name, alert_message)
|
20
|
+
handlers = config[:handlers].split(',').map(&:strip)
|
21
|
+
check_result = { name: alert_name, status: WARNING, output: "WARNING: #{alert_message}", handlers: handlers }
|
22
|
+
sensu_client_socket check_result.to_json
|
23
|
+
end
|
24
|
+
|
25
|
+
def send_critical(alert_name, alert_message)
|
26
|
+
handlers = config[:handlers].split(',').map(&:strip)
|
27
|
+
check_result = { name: alert_name, status: CRITICAL, output: "CRITICAL: #{alert_message}", handlers: handlers }
|
28
|
+
sensu_client_socket check_result.to_json
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module SensuCheckHelpers
|
2
|
+
|
3
|
+
module Time
|
4
|
+
|
5
|
+
def time_period_in_seconds(end_time, start_time)
|
6
|
+
end_time - start_time
|
7
|
+
end
|
8
|
+
|
9
|
+
def as_seconds(duration)
|
10
|
+
ChronicDuration.parse(duration.to_s, keep_zero: true)
|
11
|
+
end
|
12
|
+
|
13
|
+
def pretty_time(duration)
|
14
|
+
ChronicDuration.output(duration, format: :long)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'sensu-check-helpers/version'
|
2
|
+
require 'sensu-check-helpers/alerts'
|
3
|
+
require 'sensu-check-helpers/time'
|
4
|
+
require 'sensu-check-helpers/request'
|
5
|
+
|
6
|
+
require 'socket'
|
7
|
+
require 'chronic_duration'
|
8
|
+
require 'open-uri'
|
9
|
+
require 'json'
|
10
|
+
require 'net/https'
|
11
|
+
|
12
|
+
include OpenURI
|
13
|
+
|
14
|
+
include SensuCheckHelpers::Alerts
|
15
|
+
include SensuCheckHelpers::Time
|
16
|
+
include SensuCheckHelpers::Request
|
@@ -0,0 +1,23 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'sensu-check-helpers/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'sensu-check-helpers'
|
7
|
+
spec.version = SensuCheckHelpers::VERSION
|
8
|
+
spec.authors = ['Ben Snape']
|
9
|
+
spec.email = ['ben.snape@itv.com']
|
10
|
+
spec.summary = %q{Shared code used across custom Sensu checks}
|
11
|
+
spec.homepage = 'http://www.bensnape.com'
|
12
|
+
spec.license = 'MIT'
|
13
|
+
|
14
|
+
spec.files = `git ls-files -z`.split("\x0")
|
15
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.require_paths = ['lib']
|
18
|
+
|
19
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
20
|
+
spec.add_development_dependency 'rake'
|
21
|
+
|
22
|
+
spec.add_dependency 'chronic_duration', '~> 0.10'
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sensu-check-helpers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ben Snape
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-06-17 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.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
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: chronic_duration
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.10'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.10'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- ben.snape@itv.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/sensu-check-helpers.rb
|
68
|
+
- lib/sensu-check-helpers/alerts.rb
|
69
|
+
- lib/sensu-check-helpers/request.rb
|
70
|
+
- lib/sensu-check-helpers/time.rb
|
71
|
+
- lib/sensu-check-helpers/version.rb
|
72
|
+
- sensu-check-helpers.gemspec
|
73
|
+
homepage: http://www.bensnape.com
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.4.6
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: Shared code used across custom Sensu checks
|
97
|
+
test_files: []
|