collectd_gearman 0.1.0
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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +105 -0
- data/Rakefile +1 -0
- data/bin/collectd_gearman +11 -0
- data/collectd_gearman.gemspec +27 -0
- data/lib/collectd_gearman/application.rb +153 -0
- data/lib/collectd_gearman/version.rb +3 -0
- data/lib/collectd_gearman.rb +5 -0
- metadata +138 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Adrian Lopez
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
# CollectdGearman
|
2
|
+
|
3
|
+
/etc/collectd/collectd.conf.d/notification.conf
|
4
|
+
```
|
5
|
+
LoadPlugin exec
|
6
|
+
# ...
|
7
|
+
<Plugin exec>
|
8
|
+
NotificationExec "user" "/usr/local/bin/collectd_gearman"
|
9
|
+
</Plugin>
|
10
|
+
```
|
11
|
+
|
12
|
+
/etc/collectd/nagios.yaml
|
13
|
+
```
|
14
|
+
gearman_server: localhost
|
15
|
+
gearman_key: should_be_changed
|
16
|
+
```
|
17
|
+
|
18
|
+
|
19
|
+
## Configuration file
|
20
|
+
/etc/collectd/nagios.yaml
|
21
|
+
|
22
|
+
Could be defined in runtime with "-c" parameter.
|
23
|
+
|
24
|
+
Options that could be defined:
|
25
|
+
```
|
26
|
+
gearman_server: localhost
|
27
|
+
gearman_key: should_be_changed
|
28
|
+
send_gearman: /usr/bin/send_gearman
|
29
|
+
```
|
30
|
+
|
31
|
+
## Examples
|
32
|
+
df-threshold.txt
|
33
|
+
```
|
34
|
+
Severity: FAILURE
|
35
|
+
Time: 1403985600.050
|
36
|
+
Host: otro_client1.com
|
37
|
+
Plugin: df
|
38
|
+
PluginInstance: root
|
39
|
+
Type: df_complex
|
40
|
+
TypeInstance: used
|
41
|
+
DataSource: value
|
42
|
+
CurrentValue: 2.116443e+11
|
43
|
+
WarningMin: nan
|
44
|
+
WarningMax: 4.025360e+09
|
45
|
+
FailureMin: 6.025350e+09
|
46
|
+
FailureMax: 6.025360e+09
|
47
|
+
```
|
48
|
+
|
49
|
+
```
|
50
|
+
$ cat df-threshold.txt | ruby -Ilib/ bin/collectd_gearman -s localhost -k KEY -v
|
51
|
+
/usr/bin/send_gearman --server="localhost" --encryption=yes --key="KEY" --host="otro_client1.com" --service="df-root.df_complex-used" --message="Host otro_client1.com, plugin df (instance root) type df_complex (instance used): Data source 'value' is currently 211644297216.000000. That is above the failure threshold of 6025360000.000000." -r=2
|
52
|
+
/usr/bin/send_gearman --server="localhost" --encryption=yes --key="KEY" --host="otro_client1.com" --service="df-root.df_complex" --message="Host otro_client1.com, plugin df (instance root) type df_complex (instance used): Data source 'value' is currently 211644297216.000000. That is above the failure threshold of 6025360000.000000." -r=2
|
53
|
+
/usr/bin/send_gearman --server="localhost" --encryption=yes --key="KEY" --host="otro_client1.com" --service="df.df_complex-used" --message="Host otro_client1.com, plugin df (instance root) type df_complex (instance used): Data source 'value' is currently 211644297216.000000. That is above the failure threshold of 6025360000.000000." -r=2
|
54
|
+
/usr/bin/send_gearman --server="localhost" --encryption=yes --key="KEY" --host="otro_client1.com" --service="df.df_complex" --message="Host otro_client1.com, plugin df (instance root) type df_complex (instance used): Data source 'value' is currently 211644297216.000000. That is above the failure threshold of 6025360000.000000." -r=2
|
55
|
+
```
|
56
|
+
|
57
|
+
|
58
|
+
disk-threshold.txt
|
59
|
+
```
|
60
|
+
Severity: FAILURE
|
61
|
+
Time: 1403986248.700
|
62
|
+
Host: otro_client1.com
|
63
|
+
Plugin: disk
|
64
|
+
PluginInstance: sda5
|
65
|
+
Type: disk_octets
|
66
|
+
DataSource: read
|
67
|
+
CurrentValue: 2.047989e+03
|
68
|
+
WarningMin: nan
|
69
|
+
WarningMax: nan
|
70
|
+
FailureMin: 9.900000e+01
|
71
|
+
FailureMax: 1.000000e+02
|
72
|
+
```
|
73
|
+
|
74
|
+
```
|
75
|
+
$ cat disk-threshold.txt | ruby -Ilib/ bin/collectd_gearman -s localhost -k KEY -v
|
76
|
+
/usr/bin/send_gearman --server="localhost" --encryption=yes --key="KEY" --host="otro_client1.com" --service="disk-sda5.disk_octets.read" --message="Host otro_client1.com, plugin disk (instance sda5) type disk_octets: Data source 'read' is currently 2047.988533. That is above the failure threshold of 100.000000." -r=2
|
77
|
+
/usr/bin/send_gearman --server="localhost" --encryption=yes --key="KEY" --host="otro_client1.com" --service="disk-sda5.disk_octets" --message="Host otro_client1.com, plugin disk (instance sda5) type disk_octets: Data source 'read' is currently 2047.988533. That is above the failure threshold of 100.000000." -r=2
|
78
|
+
/usr/bin/send_gearman --server="localhost" --encryption=yes --key="KEY" --host="otro_client1.com" --service="disk.disk_octets" --message="Host otro_client1.com, plugin disk (instance sda5) type disk_octets: Data source 'read' is currently 2047.988533. That is above the failure threshold of 100.000000." -r=2
|
79
|
+
```
|
80
|
+
|
81
|
+
## Installation
|
82
|
+
|
83
|
+
Add this line to your application's Gemfile:
|
84
|
+
|
85
|
+
gem 'collectd_gearman'
|
86
|
+
|
87
|
+
And then execute:
|
88
|
+
|
89
|
+
$ bundle
|
90
|
+
|
91
|
+
Or install it yourself as:
|
92
|
+
|
93
|
+
$ gem install collectd_gearman
|
94
|
+
|
95
|
+
## Usage
|
96
|
+
|
97
|
+
TODO: Write usage instructions here
|
98
|
+
|
99
|
+
## Contributing
|
100
|
+
|
101
|
+
1. Fork it ( http://github.com/<my-github-username>/collectd_gearman/fork )
|
102
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
103
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
104
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
105
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'collectd_gearman/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "collectd_gearman"
|
8
|
+
spec.version = CollectdGearman::VERSION
|
9
|
+
spec.authors = ["Adrian Lopez"]
|
10
|
+
spec.email = ["adrianlzt@gmail.com"]
|
11
|
+
spec.summary = %q{Convert collectd notifications in passive checks sent via send_gearman}
|
12
|
+
spec.description = %q{Executable to be used with NotificationExec in collectd. It will send several passive checks, from specific to general plugin-type.}
|
13
|
+
spec.homepage = "https://github.com/adrianlzt/collectd_gearman"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
|
24
|
+
spec.add_runtime_dependency 'yaml'
|
25
|
+
spec.add_runtime_dependency 'optparse'
|
26
|
+
spec.add_runtime_dependency 'ostruct'
|
27
|
+
end
|
@@ -0,0 +1,153 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'yaml'
|
3
|
+
require 'ostruct'
|
4
|
+
|
5
|
+
module CollectdGearman
|
6
|
+
|
7
|
+
class Application
|
8
|
+
|
9
|
+
CONF_FILE = "/etc/collectd/nagios.yaml"
|
10
|
+
SEND_GEARMAN_BIN = "/usr/bin/send_gearman"
|
11
|
+
|
12
|
+
def self.run
|
13
|
+
standard_exception_handling do
|
14
|
+
handle_options
|
15
|
+
data = read_stdin
|
16
|
+
send_commands data
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.options
|
21
|
+
@options ||= OpenStruct.new
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.handle_options
|
25
|
+
parse_args
|
26
|
+
read_conf
|
27
|
+
set_defaults
|
28
|
+
check_params
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.parse_args
|
32
|
+
options.config_file = CONF_FILE
|
33
|
+
|
34
|
+
OptionParser.new do |opts|
|
35
|
+
opts.banner = "Usage: collectd_gearman [options]"
|
36
|
+
|
37
|
+
opts.on('-f', '--config FILE', 'Config file') { |v| options.config_file = v }
|
38
|
+
opts.on('-s', '--server SERVER', 'Gearman server') { |v| options.gearman_server = v }
|
39
|
+
opts.on('-k', '--key KEY', 'Gearman key') { |v| options.gearman_key = v }
|
40
|
+
opts.on('-g', '--send_gearman BIN', 'send_gearman binary') { |v| options.send_gearman = v }
|
41
|
+
opts.on('-v', '--verbose', 'verbose') { |v| options.verbose = v }
|
42
|
+
|
43
|
+
opts.on_tail("-h", "--help", "-H", "Display this help message.") do
|
44
|
+
puts opts
|
45
|
+
exit
|
46
|
+
end
|
47
|
+
|
48
|
+
end.parse!
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.read_conf
|
52
|
+
return unless File.exist?(options.config_file)
|
53
|
+
file_config = YAML.load_file(options.config_file)
|
54
|
+
file_config.each do |k,v|
|
55
|
+
options.send("#{k}=",v) unless options.send(k)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.set_defaults
|
60
|
+
options.send_gearman ||= SEND_GEARMAN_BIN
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.check_params
|
64
|
+
raise "Gearman server must be defined" unless options.gearman_server
|
65
|
+
raise "Gearman key must be defined" unless options.gearman_key
|
66
|
+
end
|
67
|
+
|
68
|
+
# Read threshold data from Collectd
|
69
|
+
def self.read_stdin
|
70
|
+
data = {}
|
71
|
+
ARGF.each do |line|
|
72
|
+
if line =~ /^[a-zA-Z]+: .*/
|
73
|
+
data.merge!({line.split(": ").first => line.split(": ").last.strip})
|
74
|
+
else
|
75
|
+
data.merge!(message: line.strip)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# DataSource = value is the same as nothing
|
80
|
+
data.delete("DataSource") if data["DataSource"] == "value"
|
81
|
+
data
|
82
|
+
end
|
83
|
+
|
84
|
+
# Send passive checks to all posible services
|
85
|
+
def self.send_commands(data)
|
86
|
+
# Plugin-Instance.Type-Instance.DataSource
|
87
|
+
# Plugin-Instance.Type-Instance
|
88
|
+
# Plugin-Instance.Type.DataSource
|
89
|
+
# Plugin-Instance.Type
|
90
|
+
# Plugin.Type-Instance.DataSource
|
91
|
+
# Plugin.Type-Instance
|
92
|
+
# Plugin.Type.DataSource
|
93
|
+
# Plugin.Type
|
94
|
+
|
95
|
+
if data["PluginInstance"] and data["TypeInstance"] and data["DataSource"]
|
96
|
+
send_gearman data["Host"],data[:message],data["Severity"],"#{data["Plugin"]}-#{data["PluginInstance"]}.#{data["Type"]}-#{data["TypeInstance"]}.#{data["DataSource"]}"
|
97
|
+
end
|
98
|
+
|
99
|
+
if data["PluginInstance"] and data["TypeInstance"]
|
100
|
+
send_gearman data["Host"],data[:message],data["Severity"],"#{data["Plugin"]}-#{data["PluginInstance"]}.#{data["Type"]}-#{data["TypeInstance"]}"
|
101
|
+
end
|
102
|
+
|
103
|
+
if data["PluginInstance"] and data["DataSource"]
|
104
|
+
send_gearman data["Host"],data[:message],data["Severity"],"#{data["Plugin"]}-#{data["PluginInstance"]}.#{data["Type"]}.#{data["DataSource"]}"
|
105
|
+
end
|
106
|
+
|
107
|
+
if data["PluginInstance"]
|
108
|
+
send_gearman data["Host"],data[:message],data["Severity"],"#{data["Plugin"]}-#{data["PluginInstance"]}.#{data["Type"]}"
|
109
|
+
end
|
110
|
+
|
111
|
+
if data["TypeInstance"] and data["DataSource"]
|
112
|
+
send_gearman data["Host"],data[:message],data["Severity"],"#{data["Plugin"]}.#{data["Type"]}-#{data["TypeInstance"]}.#{data["DataSource"]}"
|
113
|
+
end
|
114
|
+
|
115
|
+
if data["TypeInstance"]
|
116
|
+
send_gearman data["Host"],data[:message],data["Severity"],"#{data["Plugin"]}.#{data["Type"]}-#{data["TypeInstance"]}"
|
117
|
+
end
|
118
|
+
|
119
|
+
send_gearman data["Host"],data[:message],data["Severity"],"#{data["Plugin"]}.#{data["Type"]}"
|
120
|
+
end
|
121
|
+
|
122
|
+
def self.send_gearman(host,message,severity,service)
|
123
|
+
case severity
|
124
|
+
when "FAILURE"
|
125
|
+
return_code = 2
|
126
|
+
when "WARNING"
|
127
|
+
return_code = 1
|
128
|
+
when "OKAY"
|
129
|
+
return_code = 0
|
130
|
+
else
|
131
|
+
return_code = 3
|
132
|
+
end
|
133
|
+
|
134
|
+
cmd = "#{options.send_gearman} --server=\"#{options.gearman_server}\" --encryption=yes --key=\"#{options.gearman_key}\" --host=\"#{host}\" --service=\"#{service}\" --message=\"#{message.gsub('"',"'")}\" -r=#{return_code}"
|
135
|
+
|
136
|
+
raise "Command not found: #{options.send_gearman}" unless File.exist?(options.send_gearman)
|
137
|
+
|
138
|
+
puts cmd if options.verbose
|
139
|
+
|
140
|
+
system cmd
|
141
|
+
end
|
142
|
+
|
143
|
+
def self.standard_exception_handling
|
144
|
+
yield
|
145
|
+
rescue SystemExit
|
146
|
+
# Exit silently with current status
|
147
|
+
raise
|
148
|
+
rescue Exception => ex
|
149
|
+
$stderr.puts ex.message
|
150
|
+
exit(false)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
metadata
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: collectd_gearman
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Adrian Lopez
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-06-30 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.5'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.5'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: yaml
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: optparse
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: ostruct
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: Executable to be used with NotificationExec in collectd. It will send
|
95
|
+
several passive checks, from specific to general plugin-type.
|
96
|
+
email:
|
97
|
+
- adrianlzt@gmail.com
|
98
|
+
executables:
|
99
|
+
- collectd_gearman
|
100
|
+
extensions: []
|
101
|
+
extra_rdoc_files: []
|
102
|
+
files:
|
103
|
+
- .gitignore
|
104
|
+
- Gemfile
|
105
|
+
- LICENSE.txt
|
106
|
+
- README.md
|
107
|
+
- Rakefile
|
108
|
+
- bin/collectd_gearman
|
109
|
+
- collectd_gearman.gemspec
|
110
|
+
- lib/collectd_gearman.rb
|
111
|
+
- lib/collectd_gearman/application.rb
|
112
|
+
- lib/collectd_gearman/version.rb
|
113
|
+
homepage: https://github.com/adrianlzt/collectd_gearman
|
114
|
+
licenses:
|
115
|
+
- MIT
|
116
|
+
post_install_message:
|
117
|
+
rdoc_options: []
|
118
|
+
require_paths:
|
119
|
+
- lib
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
none: false
|
128
|
+
requirements:
|
129
|
+
- - ! '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
requirements: []
|
133
|
+
rubyforge_project:
|
134
|
+
rubygems_version: 1.8.23
|
135
|
+
signing_key:
|
136
|
+
specification_version: 3
|
137
|
+
summary: Convert collectd notifications in passive checks sent via send_gearman
|
138
|
+
test_files: []
|