nagios-splunk 0.0.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MDYxNjliNjVmMjI2ZTJhM2RiZTYyNWU1MmNiNTU4NzU2ZjhiNTU4NQ==
5
+ data.tar.gz: !binary |-
6
+ NzhhM2ZjZGE4NjAyYjEwYzczNmY1MzVhMTM5Yjk1ZjkzMmI5ODAxNQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ N2FhMWYxMGY0MjI4M2YzNWRjNzBiNjM4ZmI3NzNjMWEzYTBhMWVjOThmYWNl
10
+ YzEzYjBmM2NlYTAxYWYzMGRkOTBjY2FhOTgzMjM4NWI5ODRlODQwYmI2ZDVi
11
+ Y2MzYWNmZDhiNjViMTUwNDMzZDcwZWQ4YTJiYjcwNDg2NDNkY2U=
12
+ data.tar.gz: !binary |-
13
+ Njk2YzlhMjliOTI1MzQ5NWNmY2ZjZDMyMzM0MTYzMzc4ZGQ4MTU1OTM3ZDE5
14
+ NmJkNDIxZmMwY2ZmMDc1NGEyOWIzMzhkNzUwODZkNzY3ZmE2MzlmMDE5ODQ1
15
+ ZTcwYjg1OTQwZmQwNjIyOThjYzQyZTJjNzg1ZWMxOTBmNjVkYWI=
@@ -7,6 +7,7 @@ module Nagios
7
7
  LOGIN_URL = "/services/auth/login"
8
8
  POOL_LIST_URL = "/services/licenser/pools"
9
9
  LICENSE_LIST_URL = "/services/licenser/licenses"
10
+ LICENSE_LOCALSLAVE_URL = "/services/licenser/localslave"
10
11
 
11
12
  autoload :Check, "nagios/splunk/check"
12
13
  autoload :RestClient, "nagios/splunk/rest_client"
@@ -15,6 +15,21 @@ module Nagios
15
15
  @rest_client = client
16
16
  end
17
17
 
18
+ def localslave(warn, crit)
19
+ response = rest_client.get(LICENSE_LOCALSLAVE_URL)
20
+ result = response.code == "200" ? parse_data(response.body) : {}
21
+ last_success_ago = Time.now - result['license']['last_master_contact_success_time'].to_i
22
+ code = case true
23
+ when last_success_ago.to_i > crit.to_i then 2
24
+ when last_success_ago.to_i > warn.to_i then 1
25
+ else 0
26
+ end
27
+ message = "License slave #{result['license']['slave_label']} #{STATUS[code]}"
28
+ message << " | last_master_contact_attempt_time: #{result['license']['last_master_contact_attempt_time']}; last_master_contact_success_time: #{result['license']['last_master_contact_success_time']}"
29
+ return [code, message]
30
+ end
31
+
32
+
18
33
  # pool usage check
19
34
  # @param [String] name of the pool
20
35
  # @param [Integer] warn license usage threshhold
@@ -58,9 +73,9 @@ module Nagios
58
73
  # @return [Integer] exit code
59
74
  def check_threshold(usage, quota, warn, crit)
60
75
  case true
61
- when usage > quota * crit.to_i / 100:
76
+ when usage > quota * crit.to_i / 100
62
77
  return 2
63
- when usage > quota * warn.to_i / 100:
78
+ when usage > quota * warn.to_i / 100
64
79
  return 1
65
80
  else
66
81
  return 0
@@ -95,29 +110,36 @@ module Nagios
95
110
  # @param [String] stack_id
96
111
  # @return [Array<Hash>]
97
112
  def find_licenses(stack_id)
98
- response = rest_client.get(LICENSE_LIST_URL)
99
- result = response.code == "200" ? parse_data(response.body) : {}
100
- # find all VALID licenses by stack_id
101
- result.reject! {|k,v| v["stack_id"] != stack_id || v["status"] != "VALID" }
102
- raise NoLicensesFound.new("No licenses are found in stack '#{stack_id}'") if result.empty?
103
- result
113
+ @licenses ||= {}
114
+ @licenses[stack_id] ||=
115
+ begin
116
+ response = rest_client.get(LICENSE_LIST_URL)
117
+ result = response.code == "200" ? parse_data(response.body) : {}
118
+ # find all VALID licenses by stack_id
119
+ result.reject! {|k,v| v["stack_id"] != stack_id || v["status"] != "VALID" }
120
+ raise NoLicensesFound.new("No licenses are found in stack '#{stack_id}'") if result.empty?
121
+ result
122
+ end
104
123
  end
105
124
 
106
125
  # list of available pools
107
126
  # @param [String] stack_id
108
127
  # @return [Array<Hash>]
109
128
  def find_pools(stack_id = nil)
110
- response = rest_client.get(POOL_LIST_URL)
111
- result = response.code == "200" ? parse_data(response.body) : {}
112
- # find all license pools by stack_id
113
- result.reject! {|k,v| v["stack_id"] != stack_id } unless stack_id.nil?
114
- raise NoPoolsFound.new("No pools are found in stack '#{stack_id}'") if result.empty?
115
- result
129
+ @license_pools ||= {}
130
+ @license_pools[stack_id || :all] ||=
131
+ begin
132
+ response = rest_client.get(POOL_LIST_URL)
133
+ result = response.code == "200" ? parse_data(response.body) : {}
134
+ # find all license pools by stack_id
135
+ result.reject! {|k,v| v["stack_id"] != stack_id } unless stack_id.nil?
136
+ raise NoPoolsFound.new("No pools are found in stack '#{stack_id}'") if result.empty?
137
+ result
138
+ end
116
139
  end
117
140
 
118
141
  # Find pool by name
119
142
  # param [String] name of the pool
120
- # param [String] stack_id which pool is assigned to
121
143
  # @return [Hash] pool
122
144
  def find_pool_by_name(name)
123
145
  pools = find_pools
@@ -30,6 +30,11 @@ module Nagios
30
30
  :long => "--pool-name POOL",
31
31
  :description => "Pool name wich usage is being checked.")
32
32
 
33
+ option(:localslave,
34
+ :short => "-L",
35
+ :long => "--localslave-check",
36
+ :description => "Run localslave check.")
37
+
33
38
  option(:stack_id,
34
39
  :short => "-s STACK_ID",
35
40
  :long => "--stack-id STACK_ID",
@@ -43,7 +48,9 @@ module Nagios
43
48
  splunk = Check.new(client)
44
49
 
45
50
  begin
46
- if config[:pool]
51
+ if config[:localslave]
52
+ status, message = splunk.localslave(config[:warn], config[:crit])
53
+ elsif config[:pool]
47
54
  status, message = splunk.pool_usage(config[:pool], config[:warn], config[:crit])
48
55
  else
49
56
  status, message = splunk.license_usage(config[:warn], config[:crit], config[:stack_id])
@@ -2,7 +2,7 @@ $:.push File.expand_path("../lib", __FILE__)
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "nagios-splunk"
5
- s.version = "0.0.3"
5
+ s.version = "1.0.0"
6
6
  s.authors = 'Max Horbul'
7
7
  s.email = ["max@gorbul.net"]
8
8
  s.homepage = "https://github.com/mhorbul/nagios-splunk"
metadata CHANGED
@@ -1,130 +1,110 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: nagios-splunk
3
- version: !ruby/object:Gem::Version
4
- hash: 25
5
- prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 3
10
- version: 0.0.3
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Max Horbul
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2012-07-26 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
11
+ date: 2014-01-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
21
14
  name: nokogiri
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
- version: "0"
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
32
20
  type: :runtime
33
- version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
35
- name: mixlib-cli
36
21
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
38
- none: false
39
- requirements:
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- hash: 3
43
- segments:
44
- - 0
45
- version: "0"
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: mixlib-cli
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
46
34
  type: :runtime
47
- version_requirements: *id002
48
- - !ruby/object:Gem::Dependency
49
- name: minitest
50
35
  prerelease: false
51
- requirement: &id003 !ruby/object:Gem::Requirement
52
- none: false
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- hash: 3
57
- segments:
58
- - 0
59
- version: "0"
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: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
60
48
  type: :development
61
- version_requirements: *id003
62
- - !ruby/object:Gem::Dependency
63
- name: rake
64
49
  prerelease: false
65
- requirement: &id004 !ruby/object:Gem::Requirement
66
- none: false
67
- requirements:
68
- - - ">="
69
- - !ruby/object:Gem::Version
70
- hash: 3
71
- segments:
72
- - 0
73
- version: "0"
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
74
62
  type: :development
75
- version_requirements: *id004
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
76
69
  description: Splunk monitoring in Nagios
77
- email:
70
+ email:
78
71
  - max@gorbul.net
79
- executables:
72
+ executables:
80
73
  - check_splunk
81
74
  extensions: []
82
-
83
75
  extra_rdoc_files: []
84
-
85
- files:
76
+ files:
77
+ - README
78
+ - Rakefile
86
79
  - bin/check_splunk
80
+ - lib/nagios/splunk.rb
87
81
  - lib/nagios/splunk/check.rb
88
82
  - lib/nagios/splunk/cli.rb
89
83
  - lib/nagios/splunk/exception.rb
90
84
  - lib/nagios/splunk/rest_client.rb
91
- - lib/nagios/splunk.rb
92
- - test/test_helper.rb
93
- - README
94
- - Rakefile
95
85
  - nagios-splunk.gemspec
86
+ - test/test_helper.rb
96
87
  homepage: https://github.com/mhorbul/nagios-splunk
97
88
  licenses: []
98
-
89
+ metadata: {}
99
90
  post_install_message:
100
91
  rdoc_options: []
101
-
102
- require_paths:
92
+ require_paths:
103
93
  - lib
104
- required_ruby_version: !ruby/object:Gem::Requirement
105
- none: false
106
- requirements:
107
- - - ">="
108
- - !ruby/object:Gem::Version
109
- hash: 3
110
- segments:
111
- - 0
112
- version: "0"
113
- required_rubygems_version: !ruby/object:Gem::Requirement
114
- none: false
115
- requirements:
116
- - - ">="
117
- - !ruby/object:Gem::Version
118
- hash: 3
119
- segments:
120
- - 0
121
- version: "0"
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
122
104
  requirements: []
123
-
124
105
  rubyforge_project: nagios-splunk
125
- rubygems_version: 1.8.24
106
+ rubygems_version: 2.2.1
126
107
  signing_key:
127
- specification_version: 3
108
+ specification_version: 4
128
109
  summary: Nagios Splunk plugin
129
110
  test_files: []
130
-