nagios_mklivestatus 0.0.9 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
data/RELEASE.rdoc CHANGED
@@ -17,4 +17,11 @@
17
17
  * include logging management
18
18
  * preparing release v1.0.0
19
19
  * include wait query manager
20
- * include binaries for library
20
+ * include binaries for library
21
+
22
+ == 0.0.10
23
+ * correcting bugs
24
+ * adding logs to verbose mode
25
+
26
+ == 0.0.11
27
+ * correcting bug : limit
data/bin/nagmk-ruby CHANGED
@@ -16,7 +16,7 @@ require 'yaml'
16
16
 
17
17
  #default logging
18
18
  log_opts = {
19
- :name => '/var/logs/nagios_mklivestatus_ruby.log',
19
+ :name => File.join(File.absolute_path(File.dirname(__FILE__)),'..', 'log','nagios_mklivestatus_ruby.log'),
20
20
  :level => Logger::INFO
21
21
  }
22
22
 
@@ -61,7 +61,6 @@ optparser = OptionParser.new do |opts|
61
61
  end
62
62
 
63
63
  opts.on( '-o', '--options NAME=VALUE', "Options to add to make the request.\n\tcolumn_headers : show column header\n\tlimit : limit output lines\n\toutput : \'json\' or \'python\' output formating\n\tlocal_time : local time settings\n\tuser : authenticated user\n ") do |opt|
64
-
65
64
  if opt.match(/^([\w_]+)=(true|false)$/)
66
65
  name,value = opt.split("=")
67
66
  if value == "true"
@@ -69,10 +68,10 @@ optparser = OptionParser.new do |opts|
69
68
  elsif value == "false"
70
69
  mk_opts[name.to_sym] = false
71
70
  end
72
- elsif opt.match(/^([\w_]+)=(\d)$/)
71
+ elsif opt.match(/^([\w_]+)=(\d+)$/)
73
72
  name,value = opt.split("=")
74
73
  mk_opts[name.to_sym] = value.to_i
75
- elsif opt.match(/^([\w_]+)=(\w)$/)
74
+ elsif opt.match(/^([\w_]+)=(\w+)$/)
76
75
  name,value = opt.split("=")
77
76
  mk_opts[name.to_sym] = value
78
77
  end
@@ -88,6 +87,7 @@ optparser.parse!
88
87
 
89
88
  #set logging options
90
89
  Nagios::MkLiveStatus.init(:log=>log_opts)
90
+ include Nagios::MkLiveStatus
91
91
 
92
92
  begin
93
93
 
@@ -142,5 +142,7 @@ begin
142
142
  rescue Exception => ex
143
143
  if log_opts[:name] != STDOUT
144
144
  puts ex.message
145
+ else
146
+ logger.error(ex.message)
145
147
  end
146
148
  end
@@ -55,10 +55,10 @@ optparser = OptionParser.new do |opts|
55
55
  elsif value == "false"
56
56
  mk_opts[:options][name.to_sym] = false
57
57
  end
58
- elsif opt.match(/^([\w_]+)=(\d)$/)
58
+ elsif opt.match(/^([\w_]+)=(\d+)$/)
59
59
  name,value = opt.split("=")
60
60
  mk_opts[:options][name.to_sym] = value.to_i
61
- elsif opt.match(/^([\w_]+)=(\w)$/)
61
+ elsif opt.match(/^([\w_]+)=(\w+)$/)
62
62
  name,value = opt.split("=")
63
63
  mk_opts[:options][name.to_sym] = value
64
64
  end
@@ -107,9 +107,9 @@ module Nagios::MkLiveStatus::Parser
107
107
 
108
108
  wait_dispatching(command, waits)
109
109
 
110
- elsif command.match(/^UserAuth: (.+)$/)
110
+ elsif command.match(/^AuthUser: (.+)$/)
111
111
  query_parsed = true
112
- nagios_opts[:user] = command.match(/^UserAuth: (.+)$/)[1]
112
+ nagios_opts[:user] = command.match(/^AuthUser: (.+)$/)[1]
113
113
 
114
114
  elsif command.match(/^ColumnHeaders: (on|off)$/)
115
115
  query_parsed = true
@@ -67,6 +67,18 @@ class Nagios::MkLiveStatus::Request
67
67
  # * :output : output format like json/python, if none provided set to CSV (OutputFormat: out)
68
68
  def query(query=nil, options={})
69
69
 
70
+
71
+ if logger.debug?
72
+ logger.debug("query recieved :")
73
+ query.to_s.split("\n").each do |line|
74
+ logger.debug(line)
75
+ end
76
+ logger.debug("options recieved : ")
77
+ options.keys.each do |key|
78
+ logger.debug("#{key} : #{options[key]}")
79
+ end
80
+ end
81
+
70
82
  #set column headers
71
83
  column_header = false
72
84
  if options.has_key? :column_headers and options[:column_headers]
@@ -81,7 +93,7 @@ class Nagios::MkLiveStatus::Request
81
93
 
82
94
  #set limit
83
95
  limit = nil
84
- if options.has_key? :limit and options[:limit] != nil and not options[:limit].to_i
96
+ if options.has_key? :limit and options[:limit] != nil and options[:limit].to_i > 0
85
97
  limit = options[:limit].to_i
86
98
  end
87
99
 
@@ -117,7 +129,7 @@ class Nagios::MkLiveStatus::Request
117
129
 
118
130
  #set user if needed
119
131
  if user != nil and not user.empty? and strQuery.match /^GET\s+(hosts|hostgroups|services|servicegroup|log)\s*$/
120
- strQuery << "UserAuth: #{user}\n"
132
+ strQuery << "AuthUser: #{user}\n"
121
133
  end
122
134
 
123
135
  if localtime != nil
@@ -179,8 +191,11 @@ class Nagios::MkLiveStatus::Request
179
191
  response.split("\n").each do |line|
180
192
  logger.info(line)
181
193
  end
194
+ else
195
+ logger.info("No results.")
182
196
  end
183
197
 
198
+
184
199
  return response
185
200
 
186
201
  end
File without changes
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nagios_mklivestatus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.11
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-09 00:00:00.000000000 Z
12
+ date: 2012-07-03 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Querying Nagios MKLiveStatus through TCP or Unix sockets
15
15
  email: team@esco-lan.org
@@ -49,6 +49,7 @@ files:
49
49
  - bin/nagmk-conf.yml
50
50
  - bin/nagmk-ruby-config
51
51
  - bin/nagmk-ruby
52
+ - log/nagios_mklivestatus_ruby.log
52
53
  - README.rdoc
53
54
  - RELEASE.rdoc
54
55
  homepage: https://github.com/RECIA/nagios_mklivestatus
@@ -71,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
72
  version: '0'
72
73
  requirements: []
73
74
  rubyforge_project:
74
- rubygems_version: 1.8.17
75
+ rubygems_version: 1.8.8
75
76
  signing_key:
76
77
  specification_version: 3
77
78
  summary: Querying Nagios MKLiveStatus through sockets TCP or Unix