htmon-icinga 0.1.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9952df5eb685c8cb83f8d80e175e25b003c6f1f5
4
+ data.tar.gz: 0342bdf7363b641578d3df89af853c80af597e02
5
+ SHA512:
6
+ metadata.gz: f8ab6af47d9c15c4a5d0cd34ed562b60b5b29408903af40b296d40879f69860361914c3cd399496232e1cc736492544540b70d4d92b6650db1d602bc0e2ea950
7
+ data.tar.gz: 6f26765b79b1521370cbd6c4bf104cd6376d7db2e570681e29b7c82dd5b9e6b09a7c6d16b50d0428aa890f73b48dce1254a4ab0a9f1dfa20cfdbf6e3a1a09f4e
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'pry'
4
+ # Specify your gem's dependencies in htmon-icinga.gemspec
5
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Tim Foerster
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,45 @@
1
+ # Htmon::Icinga
2
+
3
+ This gem provides a icinga / nagios compatible client for [timmyArch/htmon](https://github.com/timmyArch/htmon).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'htmon-icinga'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install htmon-icinga
20
+
21
+ ## Usage
22
+
23
+ It provides an easy to use interface for creating modules.
24
+
25
+ Normally your module only needs to inherit from Htmon::Icinga::Module.
26
+
27
+ It will provide you multiple callbacks.
28
+ ** The callback should only return a String(*the message*) if condition allows it
29
+
30
+ * callback :on_ok
31
+ * callback :on_warn
32
+ * callback :on_crit
33
+
34
+ Each of these callbacks accept 3 arguments -> ** | value, warn, crit | **
35
+ Please checkout [keepalive](https://github.com/timmyArch/htmon-icinga/blob/master/lib/htmon/icinga/modules/keepalive.rb) module.
36
+
37
+ ## Contributing
38
+
39
+ Bug reports and pull requests are welcome on GitHub at https://github.com/timmyArch/htmon-icinga.
40
+
41
+
42
+ ## License
43
+
44
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
45
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "htmon/icinga"
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/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/check_htmon ADDED
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'htmon/icinga'
4
+
5
+ Conf = Struct.new(:url, :metric,
6
+ :warn, :thresh, :hostname).new
7
+
8
+ ARGV.each.with_index do |argument,i|
9
+ case argument
10
+ when '--url' then Conf.url = ARGV[i+1]
11
+ when '--metric' then Conf.metric = ARGV[i+1]
12
+ when '--hostname' then Conf.hostname = ARGV[i+1]
13
+ when '--warn' then Conf.warn = ARGV[i+1].to_i
14
+ when '--thresh' then Conf.thresh = ARGV[i+1].to_i
15
+ end
16
+ end
17
+
18
+ abort("hostname missing") unless Conf.hostname
19
+ abort("metric missing") unless Conf.metric
20
+ abort("redis url missing") unless Conf.url
21
+
22
+ Htmon::Icinga.new(redis: Redis.new(url: Conf.url),
23
+ metric: Conf.metric,
24
+ hostname: Conf.hostname,
25
+ warn: Conf.warn,
26
+ thresh: Conf.thresh).result.print
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'htmon/icinga/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "htmon-icinga"
8
+ spec.version = Htmon::Icinga::VERSION
9
+ spec.authors = ["Tim Foerster"]
10
+ spec.email = ["github@mailserver.1n3t.de"]
11
+
12
+ spec.summary = %q{Htmon Icinga2 Client}
13
+ spec.homepage = "https://github.com/timmyArch/htmon-icinga"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.11"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.0"
24
+
25
+ spec.add_dependency "redis"
26
+ end
@@ -0,0 +1,117 @@
1
+
2
+ module Htmon
3
+ module Icinga
4
+
5
+ def self.new hostname: nil, metric: nil, thresh: nil, warn: nil, redis: nil
6
+ a = Module.modules.find do |x|
7
+ x.metric_name.to_s == metric.to_s
8
+ end
9
+ if a
10
+ a.new(hostname: hostname, thresh: thresh, warn: warn, redis: redis)
11
+ else
12
+ raise "No module found"
13
+ end
14
+ end
15
+
16
+
17
+ class Module
18
+
19
+ Result ||= Struct.new(:message, :level)
20
+
21
+ Result.class_eval do
22
+
23
+ def print
24
+ send(level, self.message)
25
+ end
26
+
27
+ private
28
+
29
+ def die code, message
30
+ puts message
31
+ exit code
32
+ end
33
+
34
+ def ok message
35
+ die 0, message
36
+ end
37
+
38
+ def warn message
39
+ die 1, message
40
+ end
41
+
42
+ def crit message
43
+ die 2, message
44
+ end
45
+
46
+ def unknown message
47
+ die 2, message
48
+ end
49
+
50
+ end
51
+
52
+ class << self
53
+
54
+ attr_accessor :metric_name
55
+ attr_reader :callbacks, :performance_data
56
+
57
+ def modules
58
+ @modules ||= []
59
+ end
60
+
61
+ def inherited klass
62
+ modules << klass
63
+ end
64
+
65
+ def metric_name
66
+ @metric_name || name.downcase[/::([^:]+)$/,1]
67
+ end
68
+
69
+ def callback method, &block
70
+ @callbacks ||= {}
71
+ if block_given?
72
+ @callbacks[method] = block
73
+ else
74
+ @callbacks[method]
75
+ end
76
+ end
77
+
78
+ end
79
+
80
+ attr_accessor :hostname, :thresh, :warn, :redis
81
+
82
+ def initialize hostname: nil, thresh: nil, warn: nil, redis: nil
83
+ @hostname, @thresh, @warn, @redis = hostname, thresh, warn, redis
84
+ end
85
+
86
+ def redis
87
+ @redis || Icinga.redis
88
+ end
89
+
90
+ def result
91
+ hv = self.class.callbacks[:handle_value]
92
+ post_value = hv ? hv.call(value) : value
93
+ %i{on_ok on_warn on_crit}.map do |type|
94
+ c = self.class.callbacks[type]
95
+ ret = Result.new
96
+ message = c && c.call(post_value, warn, thresh)
97
+ if message
98
+ ret.level = type.to_s.gsub('on_', '')
99
+ ret.message = message
100
+ ret
101
+ else
102
+ nil
103
+ end
104
+ end.find{|x| x.instance_of? Result } or
105
+ Result.new("unexpect situation occured", :unknown)
106
+ end
107
+
108
+ def value
109
+ @value ||= redis.get "metric::#{hostname}::#{self.class.metric_name}"
110
+ end
111
+
112
+ end
113
+ end
114
+ end
115
+
116
+ require_relative 'modules/keepalive'
117
+
@@ -0,0 +1,24 @@
1
+
2
+ module Htmon
3
+ module Icinga
4
+ class Module
5
+ class Keepalive < Module
6
+
7
+ callback :on_ok do |value, warn, thresh|
8
+ if value.to_i > 0
9
+ "Keepalive received #{value} times | signals=#{value}"
10
+ end
11
+ end
12
+
13
+ callback :on_crit do |value, warn, thresh|
14
+ "Keepalive not received" if value.nil?
15
+ end
16
+
17
+ performance_data do |value|
18
+ "signals=#{value}"
19
+ end
20
+
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,5 @@
1
+ module Htmon
2
+ module Icinga
3
+ VERSION = "0.1.1"
4
+ end
5
+ end
@@ -0,0 +1,17 @@
1
+ require 'redis'
2
+ require "htmon/icinga/version"
3
+ require "htmon/icinga/module"
4
+
5
+ module Htmon
6
+ module Icinga
7
+
8
+ def self.redis
9
+ @redis
10
+ end
11
+
12
+ def self.redis= r
13
+ @redis = r
14
+ end
15
+
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: htmon-icinga
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Tim Foerster
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-02-09 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.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
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: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: redis
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email:
71
+ - github@mailserver.1n3t.de
72
+ executables:
73
+ - check_htmon
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - exe/check_htmon
87
+ - htmon-icinga.gemspec
88
+ - lib/htmon/icinga.rb
89
+ - lib/htmon/icinga/module.rb
90
+ - lib/htmon/icinga/modules/keepalive.rb
91
+ - lib/htmon/icinga/version.rb
92
+ homepage: https://github.com/timmyArch/htmon-icinga
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.5.1
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Htmon Icinga2 Client
116
+ test_files: []