umarcts-sensu-plugins-slurm 1.0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fb62ab0e44447f05e9b4548260848d90d8ae99cf
4
+ data.tar.gz: 7ea2317f65d86b37862e088dd18fb4b561986226
5
+ SHA512:
6
+ metadata.gz: 124734be05696da92fa76752b9a0bad46f9e3a55dd16ecd7cee5ea01adaf86e14937e402ec0155070b963269b0d6366d204767e657cc1ce9b122c1f94cac7ba1
7
+ data.tar.gz: 1789e06e0b878a594e8a3ab3d3e0ba3dae52e5e43f9d1bb094ef18af69df0e4181464dd53794b2c17d4c9654e801d7bda2313110091091aab54aeaf6ad46d3c5
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ # Change Log
2
+ ## 1.0.0 - 2018-02-27
3
+ - initial release
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Sensu-Plugins
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,38 @@
1
+ ## umarcts-sensu-plugins-slurm
2
+
3
+ ### To build gem
4
+ - Clone this repo
5
+ - cd into this repo's dir
6
+ - `gem build umarcts-sensu-plugins-slurm.gemspec`
7
+
8
+ ### To use handler-scontrol in Sensu
9
+ ### Define handler
10
+
11
+ ```
12
+ {
13
+ "handlers": {
14
+ "slurm": {
15
+ "command": "/opt/sensu/embedded/bin/handler-scontrol.rb",
16
+ "type": "pipe",
17
+ "severities": [ "critical" ]
18
+ }
19
+ }
20
+ }
21
+ ```
22
+
23
+ ### Set `handled_by_scontrol: true` in check definition(s)
24
+
25
+ ```
26
+ {
27
+ "checks": {
28
+ "check_slurmd_process": {
29
+ "command": "check-process.rb -p slurmd",
30
+ "interval": 30,
31
+ "occurrences": 2,
32
+ "handled_by_scontrol": true,
33
+ "subscribers": [ "compute" ],
34
+ "handlers": [ "slurm" ]
35
+ }
36
+ }
37
+ }
38
+ ```
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "sensu-handler"
4
+ require "net/http"
5
+
6
+ class Scontrol < Sensu::Handler
7
+
8
+ option :short_hostname,
9
+ description: 'tell scontrol to use short hostnames instead of fqdn',
10
+ short: '-s',
11
+ long: '--short-hostname',
12
+ default: ''
13
+
14
+ option :binary_path,
15
+ description: 'provide the path to the scontrol binary',
16
+ short: '-p',
17
+ long: '--path /opt/slurm/bin/scontrol',
18
+ default: '/bin/scontrol'
19
+
20
+ # this method will get events listed for the client that triggered this handler
21
+ # it uses the settings from the api.json file configured in sensu to get credentials
22
+ # it then gets a request from the api of all events, if any, and returns them as a string
23
+ def event_exists?(client)
24
+ api = @settings['api'] || {}
25
+ path = "/events/#{client}"
26
+ request = Net::HTTP::Get.new(path)
27
+ if api['user']
28
+ request.basic_auth(api['user'], api['password'])
29
+ end
30
+ Net::HTTP.new(api['host'] || '127.0.0.1', api['port'] || 4567).start do |http|
31
+ response = http.request(request)
32
+ response.body
33
+ end
34
+ end
35
+
36
+ # search the event data for references to our variable from the check
37
+ # definition called handled_by_scontrol.
38
+ # this will return the number of occurences of "handled_by_scontrol"
39
+ def handled_by_scontrol_count(client)
40
+ event_exists?(client).scan(/handled_by_scontrol/).count
41
+ end
42
+
43
+ def handle
44
+
45
+ # these variables are pulled from the @event data that this handler received:
46
+ client = @event['client']['name']
47
+ hostname= client.split('.')
48
+ check = @event['check']['name']
49
+ check_status = @event['check']['status']
50
+ action = @event['action']
51
+
52
+ if config[:short_hostname]
53
+ if check_status != 0 && action == "create" && handled_by_scontrol_count(client) == 1
54
+ system("sudo #{config[:binary_path]} update nodename=#{hostname.first} state=drain reason=\"sensu #{check}\"")
55
+ puts "running: #{config[:binary_path]} update nodename=#{hostname.first} state=drain reason=\"sensu #{check}\""
56
+ elsif check_status == 0 && action == "resolve" && handled_by_scontrol_count(client) == 0
57
+ system("sudo #{config[:binary_path]} update nodename=#{hostname.first} state=undrain")
58
+ puts "running: #{config[:binary_path]} update nodename=#{hostname.first} state=undrain"
59
+ end
60
+ else
61
+ if check_status != 0 && action == "create" && handled_by_scontrol_count(client) == 1
62
+ system("sudo #{config[:binary_path]} update nodename=#{hostname} state=drain reason=\"sensu #{check}\"")
63
+ puts "running: #{config[:binary_path]} update nodename=#{hostname} state=drain reason=\"sensu #{check}\""
64
+ elsif check_status == 0 && action == "resolve" && handled_by_scontrol_count(client) == 0
65
+ system("sudo #{config[:binary_path]} update nodename=#{hostname} state=undrain")
66
+ puts "running: #{config[:binary_path]} update nodename=#{hostname} state=undrain"
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,10 @@
1
+ module UMARCTSSensuPluginsSlurm
2
+ # This defines the version of the gem
3
+ module Version
4
+ MAJOR = 1
5
+ MINOR = 0
6
+ PATCH = 0
7
+
8
+ VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
9
+ end
10
+ end
@@ -0,0 +1 @@
1
+ require 'umarcts-sensu-plugins-slurm/version'
metadata ADDED
@@ -0,0 +1,225 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: umarcts-sensu-plugins-slurm
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - David Rhey
8
+ - Daniel Barker
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2018-02-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: sensu-plugin
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.2'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.2'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rest-client
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '='
33
+ - !ruby/object:Gem::Version
34
+ version: 1.8.0
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '='
40
+ - !ruby/object:Gem::Version
41
+ version: 1.8.0
42
+ - !ruby/object:Gem::Dependency
43
+ name: chronic_duration
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '='
47
+ - !ruby/object:Gem::Version
48
+ version: 0.10.6
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '='
54
+ - !ruby/object:Gem::Version
55
+ version: 0.10.6
56
+ - !ruby/object:Gem::Dependency
57
+ name: bundler
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '1.7'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '1.7'
70
+ - !ruby/object:Gem::Dependency
71
+ name: codeclimate-test-reporter
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '0.4'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '0.4'
84
+ - !ruby/object:Gem::Dependency
85
+ name: github-markup
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '1.3'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '1.3'
98
+ - !ruby/object:Gem::Dependency
99
+ name: pry
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: '0.10'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '0.10'
112
+ - !ruby/object:Gem::Dependency
113
+ name: rubocop
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - "~>"
117
+ - !ruby/object:Gem::Version
118
+ version: 0.40.0
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: 0.40.0
126
+ - !ruby/object:Gem::Dependency
127
+ name: rspec
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - "~>"
131
+ - !ruby/object:Gem::Version
132
+ version: '3.1'
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: '3.1'
140
+ - !ruby/object:Gem::Dependency
141
+ name: rake
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - "~>"
145
+ - !ruby/object:Gem::Version
146
+ version: '10.0'
147
+ type: :development
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - "~>"
152
+ - !ruby/object:Gem::Version
153
+ version: '10.0'
154
+ - !ruby/object:Gem::Dependency
155
+ name: redcarpet
156
+ requirement: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - "~>"
159
+ - !ruby/object:Gem::Version
160
+ version: '3.2'
161
+ type: :development
162
+ prerelease: false
163
+ version_requirements: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - "~>"
166
+ - !ruby/object:Gem::Version
167
+ version: '3.2'
168
+ - !ruby/object:Gem::Dependency
169
+ name: yard
170
+ requirement: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - "~>"
173
+ - !ruby/object:Gem::Version
174
+ version: '0.8'
175
+ type: :development
176
+ prerelease: false
177
+ version_requirements: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - "~>"
180
+ - !ruby/object:Gem::Version
181
+ version: '0.8'
182
+ description: Sensu + Slurm/SchedMD
183
+ email: drhey@umich.edu
184
+ executables:
185
+ - handler-scontrol.rb
186
+ extensions: []
187
+ extra_rdoc_files: []
188
+ files:
189
+ - CHANGELOG.md
190
+ - LICENSE
191
+ - README.md
192
+ - bin/handler-scontrol.rb
193
+ - lib/umarcts-sensu-plugins-slurm.rb
194
+ - lib/umarcts-sensu-plugins-slurm/version.rb
195
+ homepage: https://github.com/drhey/umarcts-sensu-plugins-slurm
196
+ licenses:
197
+ - MIT
198
+ metadata:
199
+ maintainer: sensu-plugin
200
+ development_status: active
201
+ production_status: stable
202
+ release_draft: 'false'
203
+ release_prerelease: 'false'
204
+ post_install_message: You can use the embedded Ruby by setting EMBEDDED_RUBY=true
205
+ in /etc/default/sensu
206
+ rdoc_options: []
207
+ require_paths:
208
+ - lib
209
+ required_ruby_version: !ruby/object:Gem::Requirement
210
+ requirements:
211
+ - - ">="
212
+ - !ruby/object:Gem::Version
213
+ version: 2.0.0
214
+ required_rubygems_version: !ruby/object:Gem::Requirement
215
+ requirements:
216
+ - - ">="
217
+ - !ruby/object:Gem::Version
218
+ version: '0'
219
+ requirements: []
220
+ rubyforge_project:
221
+ rubygems_version: 2.6.11
222
+ signing_key:
223
+ specification_version: 4
224
+ summary: Sensu + Slurm/SchedMD
225
+ test_files: []