zabbix-monitor 0.0.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 +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/tasks/zabbix.rb +20 -0
- data/lib/zabbix.rb +31 -0
- data/lib/zabbix/config.rb +23 -0
- data/lib/zabbix/monitor.rb +55 -0
- data/lib/zabbix/tasks.rb +1 -0
- data/zabbix-monitor.gemspec +24 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 29fc1e1290fbd5398058280ddc8dc5de4747a920
|
4
|
+
data.tar.gz: 3804953826fb8964598e3bf97322d3b74ba0ed67
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a0845431f03d095103e171fa5cbc0a577c1829ba0654d6089a56251814b5ae15cab3b76a2b70835c3462b180fa888a86bfaa9d264d9b42b4dd6d8c82dbeefd2f
|
7
|
+
data.tar.gz: 874c3de57a94eee7b231e850abc9219c7061bd6689b1df1cb5b604febff5cf1032c794e9d916b1ad5192df55080c4e8eb420e3925eafcc3a29d452cf60ecfe75
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Robert Jan de Gelder
|
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,29 @@
|
|
1
|
+
# Monitor
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'zabbix-agent-monitor'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install zabbix-agent-monitor
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
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 new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/lib/tasks/zabbix.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'zabbix'
|
2
|
+
require 'rufus-scheduler'
|
3
|
+
|
4
|
+
namespace :zabbix do
|
5
|
+
desc 'Collect data for Zabbix'
|
6
|
+
task :collect_once => :environment do
|
7
|
+
Zabbix::Monitor.new.collect_data
|
8
|
+
end
|
9
|
+
|
10
|
+
desc 'Collect data for Zabbix every minute'
|
11
|
+
task :collect_data => :environment do
|
12
|
+
Rufus::Scheduler.new.tap do |scheduler|
|
13
|
+
scheduler.every '1m' do
|
14
|
+
ActiveRecord::Base.connection_pool.with_connection do
|
15
|
+
Zabbix::Monitor.new.collect_data
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end.join
|
19
|
+
end
|
20
|
+
end
|
data/lib/zabbix.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'zabbix/config'
|
2
|
+
require 'zabbix/monitor'
|
3
|
+
|
4
|
+
module Zabbix
|
5
|
+
|
6
|
+
class << self
|
7
|
+
|
8
|
+
# Call this method to modify defaults in your initializers.
|
9
|
+
#
|
10
|
+
# example:
|
11
|
+
#
|
12
|
+
# Zabbix.configure do |config|
|
13
|
+
# config.config_file_path = '/etc/zabbix/zabbix_agentd.conf'
|
14
|
+
# config.host_name = 'servername'
|
15
|
+
# config.mode = :push
|
16
|
+
# config.rules = [
|
17
|
+
# {
|
18
|
+
# :command => 'Monitor.new.test',
|
19
|
+
# :zabbix_key => 'zabbix.test'
|
20
|
+
# }
|
21
|
+
# ]
|
22
|
+
# end
|
23
|
+
def configure
|
24
|
+
yield config
|
25
|
+
end
|
26
|
+
|
27
|
+
def config
|
28
|
+
@config ||= Config.new
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Zabbix
|
2
|
+
|
3
|
+
class Config
|
4
|
+
|
5
|
+
attr_accessor :config_file_path, :host_name, :rules, :mode
|
6
|
+
|
7
|
+
# Set the mode to one of :push, :file or :stdout
|
8
|
+
#
|
9
|
+
# Options:
|
10
|
+
#
|
11
|
+
# :push uses the Zabbix agent to push the data to the Zabbix server
|
12
|
+
# :file writes the data to tmp/zabbix/monitor
|
13
|
+
# :stdout writes the data to the stdout
|
14
|
+
def mode= value
|
15
|
+
allowed_modes = [:push, :file, :stdout].freeze
|
16
|
+
if allowed_modes.include?(value)
|
17
|
+
@mode = value
|
18
|
+
else
|
19
|
+
raise "Unsupported mode: #{value}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Zabbix
|
4
|
+
|
5
|
+
class Monitor
|
6
|
+
|
7
|
+
def collect_data
|
8
|
+
config.rules.each do |rule|
|
9
|
+
value = eval rule[:command]
|
10
|
+
process_data rule[:zabbix_key], value
|
11
|
+
end
|
12
|
+
rescue Exception => e
|
13
|
+
puts 'NO GOOD'
|
14
|
+
puts e.message
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def config
|
20
|
+
Zabbix.config
|
21
|
+
end
|
22
|
+
|
23
|
+
def process_data key, value
|
24
|
+
case config.mode
|
25
|
+
when :push
|
26
|
+
to_zabbix key, value
|
27
|
+
when :file
|
28
|
+
to_file key, value
|
29
|
+
when :stdout
|
30
|
+
to_stdout key, value
|
31
|
+
else
|
32
|
+
to_stdout key, value
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Use zabbix_sender command to send each result to the Zabbix server
|
37
|
+
def to_zabbix key, value
|
38
|
+
result = `zabbix_sender -c #{config.config_file_path} -s "#{config.host_name}" -k #{key} -o #{value}`
|
39
|
+
case $?.to_i
|
40
|
+
when 0 # SUCCESS
|
41
|
+
puts 'GREAT'
|
42
|
+
else
|
43
|
+
puts 'BUMMER'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def to_file key, value
|
48
|
+
raise 'Write to file is not implemented yet'
|
49
|
+
end
|
50
|
+
|
51
|
+
def to_stdout key, value
|
52
|
+
puts "#{key}: #{value}"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/zabbix/tasks.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'tasks/zabbix'
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'zabbix-monitor'
|
7
|
+
spec.version = '0.0.1'
|
8
|
+
spec.authors = ['Robert Jan de Gelder']
|
9
|
+
spec.email = ['r.degelder@sping.nl']
|
10
|
+
spec.description = 'Zabbix application monitoring'
|
11
|
+
spec.summary = 'Let the Zabbix agent read your application monitoring'
|
12
|
+
spec.homepage = 'http://rubygems.org/gems/zabbix-monitor'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
# spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
# spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_dependency 'rufus-scheduler'
|
21
|
+
|
22
|
+
spec.add_development_dependency 'rake'
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: zabbix-monitor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Robert Jan de Gelder
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rufus-scheduler
|
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: 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: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
description: Zabbix application monitoring
|
56
|
+
email:
|
57
|
+
- r.degelder@sping.nl
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/tasks/zabbix.rb
|
68
|
+
- lib/zabbix.rb
|
69
|
+
- lib/zabbix/config.rb
|
70
|
+
- lib/zabbix/monitor.rb
|
71
|
+
- lib/zabbix/tasks.rb
|
72
|
+
- zabbix-monitor.gemspec
|
73
|
+
homepage: http://rubygems.org/gems/zabbix-monitor
|
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.1.11
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: Let the Zabbix agent read your application monitoring
|
97
|
+
test_files: []
|