kurchatov 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/.travis.yml +5 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +111 -0
  7. data/Rakefile +1 -0
  8. data/Vagrantfile +16 -0
  9. data/bin/kurchatov +6 -0
  10. data/examples/check_file_contains.rb +14 -0
  11. data/examples/count_proc.rb +14 -0
  12. data/examples/cpu.rb +29 -0
  13. data/examples/disk.rb +56 -0
  14. data/examples/disk_stat.rb +28 -0
  15. data/examples/dns_check.rb +5 -0
  16. data/examples/exim.rb +12 -0
  17. data/examples/file_age.rb +11 -0
  18. data/examples/find_files.rb +21 -0
  19. data/examples/http.rb +25 -0
  20. data/examples/iptables.rb +27 -0
  21. data/examples/la.rb +10 -0
  22. data/examples/mdadm.rb +43 -0
  23. data/examples/megacli.rb +12 -0
  24. data/examples/memory.rb +28 -0
  25. data/examples/net.rb +25 -0
  26. data/examples/net_stat.rb +25 -0
  27. data/examples/nfs.rb +9 -0
  28. data/examples/nginx.rb +22 -0
  29. data/examples/nginx_500.rb +48 -0
  30. data/examples/ntp.rb +15 -0
  31. data/examples/openfiles.rb +6 -0
  32. data/examples/pgsql.rb +67 -0
  33. data/examples/ping_icmp.rb +12 -0
  34. data/examples/ping_tcp.rb +14 -0
  35. data/examples/proc_mem.rb +24 -0
  36. data/examples/process_usage.rb +15 -0
  37. data/examples/rabbitmq.rb +16 -0
  38. data/examples/runit.rb +47 -0
  39. data/examples/sidekiq.rb +21 -0
  40. data/examples/sidekiq_queue_state.rb +9 -0
  41. data/examples/status_file.rb +14 -0
  42. data/examples/tw_cli.rb +17 -0
  43. data/examples/uptime.rb +14 -0
  44. data/kurchatov.gemspec +28 -0
  45. data/lib/kurchatov/application.rb +154 -0
  46. data/lib/kurchatov/config.rb +14 -0
  47. data/lib/kurchatov/log.rb +9 -0
  48. data/lib/kurchatov/mashie.rb +152 -0
  49. data/lib/kurchatov/mixin/command.rb +31 -0
  50. data/lib/kurchatov/mixin/event.rb +63 -0
  51. data/lib/kurchatov/mixin/http.rb +21 -0
  52. data/lib/kurchatov/mixin/init.rb +6 -0
  53. data/lib/kurchatov/mixin/ohai.rb +22 -0
  54. data/lib/kurchatov/mixin/queue.rb +14 -0
  55. data/lib/kurchatov/monitor.rb +62 -0
  56. data/lib/kurchatov/plugin/config.rb +68 -0
  57. data/lib/kurchatov/plugin/dsl.rb +81 -0
  58. data/lib/kurchatov/plugin/riemann.rb +54 -0
  59. data/lib/kurchatov/plugin.rb +15 -0
  60. data/lib/kurchatov/queue.rb +28 -0
  61. data/lib/kurchatov/responders/http.rb +36 -0
  62. data/lib/kurchatov/responders/init.rb +3 -0
  63. data/lib/kurchatov/responders/riemann.rb +46 -0
  64. data/lib/kurchatov/responders/udp.rb +32 -0
  65. data/lib/kurchatov/riemann/client.rb +49 -0
  66. data/lib/kurchatov/riemann/event.rb +42 -0
  67. data/lib/kurchatov/riemann/message.rb +18 -0
  68. data/lib/kurchatov/version.rb +3 -0
  69. data/lib/kurchatov.rb +3 -0
  70. data/lib/ohai/plugins/darwin/hostname.rb +22 -0
  71. data/lib/ohai/plugins/darwin/platform.rb +38 -0
  72. data/lib/ohai/plugins/hostname.rb +27 -0
  73. data/lib/ohai/plugins/linux/hostname.rb +26 -0
  74. data/lib/ohai/plugins/linux/platform.rb +113 -0
  75. data/lib/ohai/plugins/linux/virtualization.rb +125 -0
  76. data/lib/ohai/plugins/os.rb +53 -0
  77. data/lib/ohai/plugins/platform.rb +28 -0
  78. data/lib/ohai/plugins/virtualization.rb +86 -0
  79. data/lib/ohai/plugins/windows/hostname.rb +33 -0
  80. data/lib/ohai/plugins/windows/platform.rb +27 -0
  81. data/tests/run.sh +55 -0
  82. metadata +209 -0
@@ -0,0 +1,48 @@
1
+ require 'file-tail'
2
+
3
+ interval 60
4
+ warning 10
5
+ critical 60
6
+ default[:check_interval] = 300
7
+ default[:check_last_lines] = 300
8
+ default[:file] = '/var/log/nginx/app-500.log'
9
+ default[:nginx_time_local] = "[^\\x20]+\\x20\\+\\d{4}\\]"
10
+
11
+ collect do
12
+
13
+ def get_unix_time_from_line(text)
14
+ match = text.match(plugin.nginx_time_local)
15
+ return nil unless match
16
+ time = parse_local_time(match[0]) rescue nil
17
+ time
18
+ end
19
+
20
+ def parse_local_time(token)
21
+ day, month, year, hour, minute, second, _ = token.split(/[\/: ]/) # работаем с local_time
22
+ Time.local(year, month, day.gsub('[', ''), hour, minute, second).to_i
23
+ end
24
+
25
+ count_all = 0
26
+ count_interval = 0
27
+ file = File::Tail::Logfile.new(plugin.file)
28
+ file.backward(plugin.check_last_lines)
29
+ file.readlines.each do |line|
30
+ line.force_encoding("UTF-8")
31
+ next unless line.valid_encoding?
32
+ time = get_unix_time_from_line(line)
33
+ count_interval += 1 if time > (unixnow - plugin.interval)
34
+ count_all += 1 if time > (unixnow - plugin.check_interval)
35
+ end
36
+
37
+ event(
38
+ :service => "nginx log parse #{plugin.file} interval errors",
39
+ :metric => count_all,
40
+ :desc => "Count errors in file #{plugin.file}, last #{plugin.check_interval} sec"
41
+ )
42
+ event(
43
+ :service => "nginx log parse #{plugin.file} realtime errors",
44
+ :metric => count_interval,
45
+ :state => 'ok',
46
+ :desc => "Count errors in file #{plugin.file}, last #{plugin.interval} sec"
47
+ )
48
+ end
data/examples/ntp.rb ADDED
@@ -0,0 +1,15 @@
1
+ require 'net/ntp'
2
+
3
+ interval 60
4
+ default[:host] = 'pool.ntp.org'
5
+ default[:timeout] = 30
6
+
7
+ collect do
8
+ event(
9
+ :service => "ntp #{plugin.host}",
10
+ :desc => "Ntp lag with host #{plugin.host}",
11
+ :metric => (::Net::NTP.get(plugin.host, 'ntp', plugin.timeout).time.to_f - Time.now.to_f).abs,
12
+ :critical => 0.5,
13
+ :warning => 0.1
14
+ )
15
+ end
@@ -0,0 +1,6 @@
1
+ collect do
2
+ event(
3
+ :metric => File.read('/proc/sys/fs/file-nr').split(' ').first.to_i,
4
+ :description => "Number of allocated file handles"
5
+ )
6
+ end
data/examples/pgsql.rb ADDED
@@ -0,0 +1,67 @@
1
+ default[:host] = '127.0.0.1'
2
+ default[:user] = 'postgres'
3
+ default[:pgsql] = '/usr/bin/psql'
4
+ default[:db4monit] = 'riemann_monit'
5
+ default[:conn_warn] = 5 # reserved pool connections
6
+ default[:conn_crit] = 3 # reserved pool connections
7
+
8
+ run_if do
9
+ File.exists? plugin.pgsql
10
+ end
11
+
12
+ collect do
13
+
14
+ # helpers
15
+ def run_sql(sql, db='postgres')
16
+ shell_out!("#{plugin.psql} -h #{plugin.host} -U #{plugin.user} -tnc \"#{sql}\" #{db}").stdout
17
+ end
18
+
19
+ def in_recovery?
20
+ run_sql('select pg_is_in_recovery()') == 't'
21
+ end
22
+
23
+ def db4monit_exists?
24
+ run_sql("select 1 from pg_database where datname = '#{plugin.db4monit}'") == '1'
25
+ end
26
+
27
+ def run_master_sql
28
+ run_sql("create database #{plugin.db4monit}") unless db4monit_exists?
29
+ run_sql(
30
+ "drop table if exists timestamp; \
31
+ create table timestamp ( id int primary key, value timestamp default now() ); \
32
+ insert into timestamp (id) values (1); \
33
+ ", plugin.db4monit)
34
+ end
35
+
36
+ def repl_lag
37
+ unixnow - run_sql("select extract(epoch from value::timestamp) from timestamp where id = 1;", plugin.db4monit).to_i
38
+ end
39
+
40
+ def connections
41
+ max_conn = run_sql('show max_connections').to_i
42
+ res_conn = run_sql('show superuser_reserved_connections').to_i
43
+ cur_conn = run_sql('select count(1) from pg_stat_activity;').to_i
44
+ [cur_conn, (max_conn - res_conn - cur_conn)]
45
+ end
46
+
47
+ # check status
48
+
49
+ cur_conn, res_conn = connections
50
+ if in_recovery?
51
+ event(:service => 'pgsql replication lag', :desc => 'Postgresql replication lag', :metric => repl_lag, :warning => 120, :critical => 500)
52
+ else
53
+ run_master_sql
54
+ end
55
+
56
+ event(:service => 'pgsql connections', :desc => 'Postgresql current connections', :state => 'ok', :metric => cur_conn)
57
+
58
+ # check reserved pool size
59
+ if res_conn < plugin.conn_warn
60
+ if res_conn > plugin.conn_crit
61
+ event(:service => 'pgsql reserved connections', :desc => 'Postgresql reserved connections state', :state => 'warning', :metric => res_conn)
62
+ else
63
+ event(:service => 'pgsql reserved connections', :desc => 'Postgresql reserved connections state', :state => 'critical', :metric => res_conn)
64
+ end
65
+ end
66
+
67
+ end
@@ -0,0 +1,12 @@
1
+ require 'net/ping'
2
+
3
+ interval 60
4
+ default[:host] = "localhost"
5
+
6
+ collect do
7
+ event(
8
+ :service => "ping icmp #{plugin.host}",
9
+ :state => ::Net::Ping::External.new(ip).ping,
10
+ :description => "ping icmp host: #{plugin.host}"
11
+ )
12
+ end
@@ -0,0 +1,14 @@
1
+ require 'net/ping'
2
+
3
+ default[:host] = "localhost"
4
+ default[:port] = 22
5
+ default[:timeout] = 5
6
+
7
+ collect do
8
+ ::Net::Ping::TCP.econnrefused = true
9
+ event(
10
+ :service => "ping tcp #{plugin.host}:#{plugin.port}",
11
+ :state => ::Net::Ping::TCP.new(plugin.host, plugin.port, plugin.timeout).ping,
12
+ :description => "Ping tcp #{plugin.host}:#{plugin.port}"
13
+ )
14
+ end
@@ -0,0 +1,24 @@
1
+ require 'sys/proctable'
2
+
3
+ default[:pidfile] = '/var/run/service.pid'
4
+
5
+ collect do
6
+
7
+ @pagesize ||= shell('/usr/bin/getconf PAGESIZE').to_i
8
+ master_pid = File.read(plugin.pidfile).to_i
9
+ mem_total = 0
10
+ ::Sys::ProcTable.ps do |p|
11
+ next unless p.pid == master_pid || p.ppid == master_pid
12
+ mem_total += (p.rss * @pagesize).to_f / 1024
13
+ end
14
+
15
+ event(
16
+ :diff => true,
17
+ :description => "RSS usage delta #{plugin.pidfile}",
18
+ :metric => mem_total,
19
+ :service => "procmem #{plugin.pidfile}",
20
+ :warning => 30*1024, #kibibytes
21
+ :critical => 90*1024
22
+ ) if File.stat(plugin.pidfile).mtime > interval
23
+
24
+ end
@@ -0,0 +1,15 @@
1
+ interval 60
2
+
3
+ default[:pid_file] = '/etc/service/name/supervise/pid'
4
+
5
+ collect do
6
+ if File.exists? plugin.pid_file
7
+ pid = File.read(plugin.pid_file).chomp
8
+ cpu_usage = shell("ps -p #{pid} S -o pcpu h").to_i
9
+ mem_usage = shell("ps -p #{pid} S -o rss h").to_i
10
+ event(:service => "process pid cpu #{plugin.pid_file}", :metric => cpu_usage, :description => "Cpu usage for process pid: #{plugin.pid_file}", :warning => 70, :critical => 90)
11
+ event(:service => "process pid mem #{plugin.pid_file}", :metric => mem_usage.to_f / 1024, :description => "Mem (Mb) usage for process pid: #{plugin.pid_file}", :state => 'ok')
12
+ else
13
+ event(:service => "process pid #{plugin.pid_file}", :state => 'critical', :description => "File #{plugin.pid_file} not found")
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ default[:api_url] = 'http://admin:admin@127.0.0.1:55672/api'
2
+ default[:vhost] = ['notexists']
3
+
4
+ collect do
5
+ plugin.vhosts.each do |vhost|
6
+ vhost_uri = "#{plugin.api_url}/queues/#{CGI.escape(vhost)}"
7
+ JSON.parse(rest_get(vhost_uri)).each do |queue|
8
+ event(
9
+ :service => "rabbitmq queue #{queue['name'].gsub('.', '_')} messages count",
10
+ :metric => queue['messages'].to_i,
11
+ :desc => "Rabbitmq queue count in #{queue['name']}",
12
+ :critical => 1000
13
+ )
14
+ end
15
+ end
16
+ end
data/examples/runit.rb ADDED
@@ -0,0 +1,47 @@
1
+ always_start true
2
+
3
+ run_if do
4
+ Dir.exists? '/etc/service'
5
+ end
6
+
7
+ collect do
8
+
9
+ @status_history ||= Array.new
10
+
11
+ def uptime(service)
12
+ pid_file = File.join(service, 'supervise', 'pid')
13
+ return 0 unless File.exist?(pid_file)
14
+ unixnow - File.mtime(pid_file).to_i
15
+ end
16
+
17
+ def runned?(service)
18
+ stat_file = File.join(service, 'supervise', 'stat')
19
+ return false unless File.exists?(stat_file)
20
+ File.read(stat_file).strip == 'run'
21
+ end
22
+
23
+ def human_srv(service)
24
+ service.gsub(/\/etc\/service\//, '')
25
+ end
26
+
27
+ Dir.glob('/etc/service/*').each do |srv|
28
+ srv_uptime = uptime(srv)
29
+ srv_runned = runned?(srv)
30
+ srv_name = human_srv(srv)
31
+
32
+ # сервис запущен и работает дольше чем мы приходили к нему в прошлый раз
33
+ if srv_runned && srv_uptime > interval
34
+ @status_history.delete(srv_name)
35
+ event(:service => "runit #{srv_name}", :state => 'ok', :description => "runit service #{srv_name} running")
36
+ else
37
+ # сервис запущен но работает подозрительно мало, но последний раз замечен не был
38
+ if srv_uptime < interval && srv_runned && !@status_history.include?(srv_name)
39
+ @status_history << srv_name
40
+ else
41
+ # во всех остальных случаях сообщаем о проблеме
42
+ event(:service => "runit #{srv_name}", :state => 'critical', :description => "runit service #{srv_name} not running", :metric => srv_uptime)
43
+ end
44
+ end
45
+ end
46
+
47
+ end
@@ -0,0 +1,21 @@
1
+ default[:url] = 'http://localhost/admin/sidekiq/dashboard/stats'
2
+
3
+ collect do
4
+ stats = JSON.parse(rest_get(plugin.url))
5
+ stats = stats["sidekiq"] ? stats["sidekiq"] : stats
6
+ event(
7
+ :service => "#{name} #{plugin.url}",
8
+ :metric => stats["enqueued"].to_i,
9
+ :description => "sidekiq queue from #{plugin.url}",
10
+ :warning => 10,
11
+ :critical => 60
12
+ )
13
+ event(
14
+ :service => "#{name} #{plugin.url}",
15
+ :metric => stats["failed"].to_i,
16
+ :diff => true,
17
+ :description => "sidekiq failed from #{plugin.url}",
18
+ :warning => 10,
19
+ :critical => 60
20
+ )
21
+ end
@@ -0,0 +1,9 @@
1
+ default[:url] = 'http://localhost/sidekiq/queue-state'
2
+
3
+ collect do
4
+ event(
5
+ :service => "#{name} #{plugin.url}",
6
+ :metric => rest_get(plugin.url).strip == "OK",
7
+ :description => "sidekiq queue status #{plugin.url}"
8
+ )
9
+ end
@@ -0,0 +1,14 @@
1
+ default[:file] = '/var/tmp/error.txt'
2
+ default[:max_lines] = 100
3
+ default[:report_lines] = 5
4
+ default[:service] = 'check state file'
5
+
6
+ collect do
7
+ content = File.read(plugin.file).split("\n").delete_if { |x| x.strip.empty? }
8
+ event(
9
+ :service => "#{plugin.service} #{plugin.file}",
10
+ :description => content.last(plugin.report_lines).join("\n"),
11
+ :metric => content.count,
12
+ :critical => 1
13
+ )
14
+ end
@@ -0,0 +1,17 @@
1
+ interval 180
2
+ always_start true
3
+
4
+ default[:cmd] = "/usr/sbin/tw_cli show | awk '/^c/{print $1}' | xargs -rI{} /usr/sbin/tw_cli /{} show | awk '/^[upb]/&&!/[ \t](OK|VERIFYING|VERIFY-PAUSED)/' |wc -l"
5
+
6
+ run_if do
7
+ File.exists? '/usr/sbin/tw_cli'
8
+ end
9
+
10
+ collect do
11
+ event(
12
+ :service => 'twcli',
13
+ :metric => shell(plugin.cmd).to_i,
14
+ :description => 'Hardware raid tw_cli status',
15
+ :critical => 1
16
+ )
17
+ end
@@ -0,0 +1,14 @@
1
+ interval 60
2
+ always_start true
3
+
4
+ collect :os => "linux" do
5
+ event(
6
+ :metric => File.read('/proc/uptime').split(' ').first.to_f
7
+ )
8
+ end
9
+
10
+ collect :os => "darwin" do
11
+ event(
12
+ :metric => shell('uptime | cut -d":" -f4- | sed s/,//g').to_f
13
+ )
14
+ end
data/kurchatov.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'kurchatov/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "kurchatov"
8
+ spec.version = Kurchatov::VERSION
9
+ spec.authors = ["Vasiliev Dmitry"]
10
+ spec.email = ["vadv.mkn@gmail.com"]
11
+ spec.summary = %q{Gem for monitoring with riemann.}
12
+ spec.description = %q{Gem for monitoring with riemann.}
13
+ spec.homepage = "https://github.com/vadv/kurchatov"
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_dependency "beefcake", ">= 0.3.5"
22
+ spec.add_dependency "ohai", ">= 6.20.0"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.5"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "pry"
27
+ spec.add_development_dependency "ruby-prof"
28
+ end
@@ -0,0 +1,154 @@
1
+ # encoding: utf-8
2
+
3
+ require "mixlib/cli"
4
+ require "kurchatov/version"
5
+ require "kurchatov/config"
6
+ require "kurchatov/mixin/init"
7
+ require "kurchatov/log"
8
+ require "kurchatov/plugin/config"
9
+ require "kurchatov/monitor"
10
+ require "kurchatov/responders/init"
11
+
12
+ module Kurchatov
13
+ class Aplication
14
+ include Mixlib::CLI
15
+ include Kurchatov::Mixin::Ohai
16
+
17
+ option :help,
18
+ :short => "-h",
19
+ :long => "--help",
20
+ :description => "Show this message",
21
+ :on => :tail,
22
+ :boolean => true,
23
+ :show_options => true,
24
+ :exit => 1
25
+
26
+ option :version,
27
+ :short => "-v",
28
+ :long => "--version",
29
+ :description => "Show version",
30
+ :boolean => true,
31
+ :proc => lambda {|v| puts "Kurchatov: #{Kurchatov::VERSION}"},
32
+ :exit => 0
33
+
34
+ option :log_level,
35
+ :short => "-l LEVEL",
36
+ :long => "--log_level LEVEL",
37
+ :description => "Set the log level (debug, info, warn, error, fatal)",
38
+ :proc => lambda {|l| l.to_sym}
39
+
40
+ option :log_location,
41
+ :short => "-L LOGLOCATION",
42
+ :long => "--logfile LOGLOCATION",
43
+ :description => "Set the log file location"
44
+
45
+ option :test_plugin,
46
+ :short => "-T FILE",
47
+ :long => "--test-plugin FILE",
48
+ :description => "Test plugin"
49
+
50
+ option :config_file,
51
+ :short => "-c FILE",
52
+ :long => "--config FILE",
53
+ :description => "Config file"
54
+
55
+ option :plugin_paths,
56
+ :short => "-d DIR1,DIR2",
57
+ :long => "--plugins DIR1,DIR2",
58
+ :description => "Plugin directories",
59
+ :proc => lambda {|l| l.split(',') }
60
+
61
+ option :ohai_plugins_paths,
62
+ :short => "-o DIR1,DIR2",
63
+ :long => "--ohai--plugins DIR1,DIR2",
64
+ :description => "Plugin directories",
65
+ :proc => lambda {|l| l.split(',') }
66
+
67
+ option :host,
68
+ :long => "--host HOSTNAME",
69
+ :description => "Set hostname for events",
70
+ :proc => lambda {|l| l.split(',') }
71
+
72
+ option :tags,
73
+ :short => "-t tag1,tag2,tag3",
74
+ :long => "--tags tag1,tag2,tag3",
75
+ :description => "Set tags for events",
76
+ :proc => lambda {|l| l.split(',') }
77
+
78
+ option :riemann_responder,
79
+ :short => "-H HOST1,HOST2:55655",
80
+ :long => "--hosts HOST1,HOST2:55655",
81
+ :description => "Set riemann hosts for send events",
82
+ :proc => lambda {|l| l.split(',') }
83
+
84
+ option :http_responder,
85
+ :long => "--http 0.0.0.0:55755",
86
+ :description => "Set http responder for information"
87
+
88
+ option :udp_responder,
89
+ :long => "--udp 0.0.0.0:55955",
90
+ :description => "Set udp responder for information"
91
+
92
+ option :stop_on_error,
93
+ :long => "--stop-on-error",
94
+ :description => "Stop on plugin or connection problem",
95
+ :boolean => true,
96
+ :proc => lambda {|l| !!l }
97
+
98
+ def configure_opts
99
+ @attributes = parse_options
100
+ @attributes = nil if @attributes.empty?
101
+ Config.merge!(config)
102
+ end
103
+
104
+ def configure_logging
105
+ Log.init(Config[:log_location])
106
+ Log.level = Config[:log_level]
107
+ end
108
+
109
+ def configure_defaults
110
+ ::Ohai::Config[:plugin_path] = [ File.expand_path(File.join('..', 'ohai', 'plugins'), File.dirname(__FILE__)) ]
111
+ if Config[:ohai_plugins_paths]
112
+ ::Ohai::Config[:plugin_path] += Config[:ohai_plugins_paths]
113
+ end
114
+ Config[:host] ||= ohai[:fqdn] || ohai[:hostname]
115
+ end
116
+
117
+ def configure_responders
118
+ return if Config[:test_plugin]
119
+ Log.error("Please set riemann host") and exit Config[:ERROR_CONFIG] unless
120
+ Config[:riemann_responder]
121
+ if Config[:udp_responder]
122
+ @monitor << Responders::Udp.new( Config[:udp_responder] )
123
+ end
124
+ if Config[:http_responder]
125
+ @monitor << Responders::Http.new( Config[:http_responder] )
126
+ end
127
+ @monitor << Responders::Riemann.new( Config[:riemann_responder] )
128
+ end
129
+
130
+ def configure_plugins
131
+ return if Config[:test_plugin]
132
+ plugins = Kurchatov::Plugins::Config.load_plugins(Config[:plugin_paths],
133
+ Config[:config_file])
134
+ plugins.each {|p| @monitor << p }
135
+ end
136
+
137
+ def configure_test_plugin
138
+ return if !Config[:test_plugin]
139
+ @monitor << Kurchatov::Plugins::DSL.load_riemann_plugin(Config[:test_plugin])
140
+ end
141
+
142
+ def run
143
+ configure_opts
144
+ configure_logging
145
+ configure_defaults
146
+ @monitor = Monitor.new(Config[:stop_on_error] || !!Config[:test_plugin])
147
+ configure_responders
148
+ configure_plugins
149
+ configure_test_plugin
150
+ @monitor.run
151
+ end
152
+
153
+ end
154
+ end
@@ -0,0 +1,14 @@
1
+ require "mixlib/config"
2
+
3
+ module Kurchatov
4
+ class Config
5
+ extend Mixlib::Config
6
+ default :log_level, :info
7
+ default :log_location, STDERR
8
+ default :plugin_paths, ['/usr/share/kurchatov/plugins']
9
+ default :config_file, '/etc/kurchatov/config.yml'
10
+ # errors
11
+ default :ERROR_CONFIG, 2
12
+ default :ERROR_PLUGIN_REQ, 3
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ require "mixlib/log"
2
+
3
+ module Kurchatov
4
+ class Log
5
+ extend Mixlib::Log
6
+ init(Config[:log_location])
7
+ level = Config[:log_level]
8
+ end
9
+ end