sensu-plugins-gitlab 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c0f61944b6812d7ad611fcdfd0d089b97112a433
4
+ data.tar.gz: 7b68f6c565d7fc6edc2f78df1cd557ecbac25894
5
+ SHA512:
6
+ metadata.gz: 0cefa69fd900e91b00ecb2f91d92ffccdc7cdc62f523aa9c0a5c015c20054cbb6428174c3f27e4fc5092f372c1d8ca003af07f3a678d9e7b3b78b3ca77e350a4
7
+ data.tar.gz: bf3e2a63950e5355d45515e75ebf808d9850750c2e103c8a0cc51485d67b6736f92f01ede2721291b8f38d8418a3872616d16067465886312bd4983f5352060e
@@ -0,0 +1,27 @@
1
+ # Change Log
2
+ This project adheres to [Semantic Versioning](http://semver.org/).
3
+
4
+ This CHANGELOG follows the format located [here](https://github.com/sensu-plugins/community/blob/master/HOW_WE_CHANGELOG.md)
5
+
6
+ ## [Unreleased]
7
+
8
+ ## [0.0.1] - 2018-04-02
9
+ ### Breaking Changes
10
+ - Dropped `ruby 2.1` support (@yuri-zubov sponsored by Actility, https://www.actility.com)
11
+ - Added `rest-client` as a dependency which requires you to have a local c compiler present to install this plugin (@yuri-zubov sponsored by Actility, https://www.actility.com)
12
+ - bumped dependency of `sensu-plugin` to 2.x you can read about it [here](https://github.com/sensu-plugins/sensu-plugin/blob/master/CHANGELOG.md#v200---2017-03-29) (@majormoses)
13
+ - dropped ruby 2.0 support (@majormoses)
14
+
15
+ ### Security
16
+ - updated `yard` dependency to `~> 0.9.11` per: https://nvd.nist.gov/vuln/detail/CVE-2017-17042 which closes attacks against a yard server loading arbitrary files (@majormoses)
17
+
18
+ ### Added
19
+ - Added health-check for gitlab (@yuri-zubov sponsored by Actility, https://www.actility.com)
20
+ - Added basic metrics from gitlab (@yuri-zubov sponsored by Actility, https://www.actility.com)
21
+ - Basic Skel to be used to make new plugin repo setup easier.
22
+ - PR template
23
+ - Rubocop config
24
+ - basic testing setup
25
+
26
+ [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-skel/compare/0.0.1...HEAD
27
+ [0.0.1]: https://github.com/sensu-plugins/sensu-plugins-skel/compare/0b2d68b64a3d100c10da5e4cfce42206b9f22250...0.0.1
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Sensu Community Plugins
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,21 @@
1
+ ## Sensu-Plugins-gitlab
2
+
3
+ [![Build Status](https://travis-ci.org/sensu-plugins/sensu-plugins-gitlab.svg?branch=master)](https://travis-ci.org/sensu-plugins/sensu-plugins-gitlab)
4
+ [![Gem Version](https://badge.fury.io/rb/sensu-plugins-gitlab.svg)](http://badge.fury.io/rb/sensu-plugins-gitlab)
5
+ [![Dependency Status](https://gemnasium.com/sensu-plugins/sensu-plugins-gitlab.svg)](https://gemnasium.com/sensu-plugins/sensu-plugins-gitlab)
6
+ [![Community Slack](https://slack.sensu.io/badge.svg)](https://slack.sensu.io/badge)
7
+
8
+ ## Functionality
9
+
10
+ ## Files
11
+
12
+ - `bin/check-health-gitlab.rb`
13
+ - `bin/metrics-gitlab.rb`
14
+
15
+ ## Usage
16
+
17
+ ## Installation
18
+
19
+ [Installation and Setup](http://sensu-plugins.io/docs/installation_instructions.html)
20
+
21
+ ## Notes
@@ -0,0 +1,69 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-health-gitlab
4
+ #
5
+ # DESCRIPTION:
6
+ #
7
+ # OUTPUT:
8
+ # plain-text
9
+ #
10
+ # PLATFORMS:
11
+ # Linux, Windows, BSD, Solaris, etc
12
+ #
13
+ # DEPENDENCIES:
14
+ # gem: sensu-plugin
15
+ # gem: rest-client
16
+ #
17
+ # USAGE:
18
+ #
19
+ # NOTES:
20
+ #
21
+ # LICENSE:
22
+ # Yuri Zubov <yury.zubau@gmail.com> sponsored by Actility, https://www.actility.com
23
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
24
+ # for details.
25
+ #
26
+
27
+ require 'sensu-plugin/check/cli'
28
+ require 'rest-client'
29
+ require 'json'
30
+
31
+ class CheckHealthGitlab < Sensu::Plugin::Check::CLI
32
+ option :endpoint,
33
+ description: 'Github ENDPOINT',
34
+ short: '-E ENDPOINT',
35
+ long: '--endpoint ENDPOINT',
36
+ default: 'http://localhost/-/liveness'
37
+
38
+ option :token,
39
+ description: 'TOKEN_API',
40
+ short: '-t TOKEN_API',
41
+ long: '--token TOKEN_API'
42
+
43
+ def request
44
+ RestClient::Request.execute(
45
+ method: :get,
46
+ url: config[:endpoint],
47
+ headers: { params: { token: config[:token] } }
48
+ )
49
+ end
50
+
51
+ def check_health
52
+ response = request
53
+
54
+ JSON.parse(response)
55
+ end
56
+
57
+ def run
58
+ result = check_health
59
+ bad_health = result.reject { |_k, v| v['status'] == 'ok' }.reduce('') { |_result, (k, v)| "#{k}:#{v['status']}" }
60
+
61
+ if bad_health.empty?
62
+ ok 'Gitlab is ok'
63
+ else
64
+ warning "Gitlab is not good #{bad_health}"
65
+ end
66
+ rescue StandardError => e
67
+ critical e.message
68
+ end
69
+ end
@@ -0,0 +1,170 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # metrics-gitlab
4
+ #
5
+ # DESCRIPTION:
6
+ #
7
+ # OUTPUT:
8
+ # plain text, metric data, etc
9
+ #
10
+ # PLATFORMS:
11
+ # Linux, Windows, BSD, Solaris, etc
12
+ #
13
+ # DEPENDENCIES:
14
+ # gem: sensu-plugin
15
+ # gem: gitlab
16
+ #
17
+ # USAGE:
18
+ #
19
+ # NOTES:
20
+ #
21
+ # LICENSE:
22
+ # Yuri Zubov <yury.zubau@gmail.com> sponsored by Actility, https://www.actility.com
23
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
24
+ # for details.
25
+ #
26
+
27
+ require 'sensu-plugin/metric/cli'
28
+ require 'gitlab'
29
+
30
+ class GitlabGraphite < Sensu::Plugin::Metric::CLI::Graphite
31
+ option :endpoint,
32
+ description: 'Github ENDPOINT',
33
+ short: '-E ENDPOINT',
34
+ long: '--endpoint ENDPOINT'
35
+
36
+ option :token,
37
+ description: 'TOKEN_API',
38
+ short: '-t TOKEN_API',
39
+ long: '--token TOKEN_API'
40
+
41
+ option :period,
42
+ description: 'Sampling Period in seconds.',
43
+ short: '-p',
44
+ long: '--period',
45
+ proc: proc(&:to_i),
46
+ default: 3600
47
+
48
+ option :scheme,
49
+ description: 'Metric naming scheme, text to prepend to metric',
50
+ short: '-S SCHEME',
51
+ long: '--scheme SCHEME',
52
+ default: "#{Socket.gethostname}.gitlab"
53
+
54
+ def gitlab_configure
55
+ Gitlab.private_token = config[:token]
56
+ Gitlab.endpoint = config[:endpoint]
57
+ end
58
+
59
+ def commit_count(commits)
60
+ select_by_period(commits).count
61
+ end
62
+
63
+ def commit_count_by_status(project, commits)
64
+ result = { pending: 0, running: 0, success: 0, failed: 0, canceled: 0 }
65
+ select_by_period(commits).each do |commit|
66
+ commit_info = Gitlab.commit(project.id, commit.id)
67
+ unless commit_info.status.nil?
68
+ result[commit_info.status.to_sym] = result[commit_info.status.to_sym].to_i + 1
69
+ end
70
+ end
71
+
72
+ result
73
+ end
74
+
75
+ def project_count(projects)
76
+ projects.count
77
+ end
78
+
79
+ def user_count(users)
80
+ users.count
81
+ end
82
+
83
+ def group_count(groups)
84
+ groups.count
85
+ end
86
+
87
+ def select_by_period(list)
88
+ list.lazy.select { |item| Time.iso8601(item.created_at) >= (Time.now.utc - config[:period]) }
89
+ end
90
+
91
+ def repository_count(repositories)
92
+ select_by_period(repositories).count
93
+ end
94
+
95
+ def print_hash(hash, path = '')
96
+ hash.each do |key, value|
97
+ if value.is_a? Hash
98
+ print_hash(value, "#{path}.#{key}")
99
+ else
100
+ output "#{config[:scheme]}#{path}.#{key}", value
101
+ end
102
+ end
103
+ end
104
+
105
+ def event_count_by_action(events)
106
+ result = {
107
+ created: 0,
108
+ updated: 0,
109
+ closed: 0,
110
+ reopened: 0,
111
+ pushed: 0,
112
+ commented: 0,
113
+ merged: 0,
114
+ joined: 0,
115
+ left: 0,
116
+ destroyed: 0,
117
+ expired: 0
118
+ }
119
+ select_by_period(events).each do |event|
120
+ result[event.action_name.to_sym] = result[event.action_name.to_sym].to_i + 1
121
+ end
122
+
123
+ result
124
+ end
125
+
126
+ def merge_request_count(merge_requests)
127
+ select_by_period(merge_requests).count
128
+ end
129
+
130
+ def run
131
+ gitlab_configure
132
+ metrics = {
133
+ project_count: 0,
134
+ user_count: 0,
135
+ group_count: 0
136
+ }
137
+
138
+ projects = Gitlab.projects
139
+ metrics[:project_count] += project_count(projects)
140
+ metrics[:user_count] += user_count(Gitlab.users)
141
+ metrics[:group_count] += group_count(Gitlab.groups)
142
+
143
+ if Gitlab::VERSION > '4.3.0'
144
+ metrics[:sidekiq] = {}
145
+ sidekiq_job_stats = Gitlab.sidekiq_job_stats.jobs
146
+ metrics[:sidekiq][:processed] = sidekiq_job_stats.processed
147
+ metrics[:sidekiq][:failed] = sidekiq_job_stats.failed
148
+ metrics[:sidekiq][:enqueued] = sidekiq_job_stats.enqueued
149
+ end
150
+
151
+ projects.each do |project|
152
+ metrics[project.name] = { commit_count: 0, commit_count_by_status: {} }
153
+
154
+ metrics[project.name][:branches_count] = Gitlab.branches(project.id).count
155
+
156
+ project_events = Gitlab.project_events(project.id, after: (Time.now.utc - config[:period]))
157
+ metrics[project.name][:events_count_per_hour] = event_count_by_action(project_events)
158
+ merge_requests = Gitlab.merge_requests(project.id, since: (Time.now.utc - config[:period]))
159
+ metrics[project.name][:merge_request_count_per_hour] = merge_request_count(merge_requests)
160
+
161
+ commits = Gitlab.commits(project.id, since: (Time.now.utc - config[:period]))
162
+ metrics[project.name][:commit_count_per_hour] = commit_count(commits)
163
+ metrics[project.name][:commit_count_per_hour_by_status] = commit_count_by_status(project, commits)
164
+ end
165
+
166
+ print_hash(metrics)
167
+
168
+ ok
169
+ end
170
+ end
@@ -0,0 +1 @@
1
+ require 'sensu-plugins-gitlab/version'
@@ -0,0 +1,9 @@
1
+ module SensuPluginsGitlab
2
+ module Version
3
+ MAJOR = 0
4
+ MINOR = 0
5
+ PATCH = 1
6
+
7
+ VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,288 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sensu-plugins-gitlab
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sensu-Plugins and contributors
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-04-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gitlab
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rest-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sensu-plugin
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.15'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.15'
69
+ - !ruby/object:Gem::Dependency
70
+ name: github-markup
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.3'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: kitchen-docker
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.6'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.6'
97
+ - !ruby/object:Gem::Dependency
98
+ name: kitchen-localhost
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.3'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.3'
111
+ - !ruby/object:Gem::Dependency
112
+ name: mixlib-shellout
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "<"
116
+ - !ruby/object:Gem::Version
117
+ version: 2.3.0
118
+ - - "~>"
119
+ - !ruby/object:Gem::Version
120
+ version: '2.2'
121
+ type: :development
122
+ prerelease: false
123
+ version_requirements: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - "<"
126
+ - !ruby/object:Gem::Version
127
+ version: 2.3.0
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: '2.2'
131
+ - !ruby/object:Gem::Dependency
132
+ name: pry
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - "~>"
136
+ - !ruby/object:Gem::Version
137
+ version: '0.10'
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - "~>"
143
+ - !ruby/object:Gem::Version
144
+ version: '0.10'
145
+ - !ruby/object:Gem::Dependency
146
+ name: rake
147
+ requirement: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - "~>"
150
+ - !ruby/object:Gem::Version
151
+ version: '12.0'
152
+ type: :development
153
+ prerelease: false
154
+ version_requirements: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - "~>"
157
+ - !ruby/object:Gem::Version
158
+ version: '12.0'
159
+ - !ruby/object:Gem::Dependency
160
+ name: redcarpet
161
+ requirement: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - "~>"
164
+ - !ruby/object:Gem::Version
165
+ version: '3.2'
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - "~>"
171
+ - !ruby/object:Gem::Version
172
+ version: '3.2'
173
+ - !ruby/object:Gem::Dependency
174
+ name: rspec
175
+ requirement: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - "~>"
178
+ - !ruby/object:Gem::Version
179
+ version: '3.4'
180
+ type: :development
181
+ prerelease: false
182
+ version_requirements: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - "~>"
185
+ - !ruby/object:Gem::Version
186
+ version: '3.4'
187
+ - !ruby/object:Gem::Dependency
188
+ name: rubocop
189
+ requirement: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - "~>"
192
+ - !ruby/object:Gem::Version
193
+ version: 0.51.0
194
+ type: :development
195
+ prerelease: false
196
+ version_requirements: !ruby/object:Gem::Requirement
197
+ requirements:
198
+ - - "~>"
199
+ - !ruby/object:Gem::Version
200
+ version: 0.51.0
201
+ - !ruby/object:Gem::Dependency
202
+ name: serverspec
203
+ requirement: !ruby/object:Gem::Requirement
204
+ requirements:
205
+ - - "~>"
206
+ - !ruby/object:Gem::Version
207
+ version: 2.36.1
208
+ type: :development
209
+ prerelease: false
210
+ version_requirements: !ruby/object:Gem::Requirement
211
+ requirements:
212
+ - - "~>"
213
+ - !ruby/object:Gem::Version
214
+ version: 2.36.1
215
+ - !ruby/object:Gem::Dependency
216
+ name: test-kitchen
217
+ requirement: !ruby/object:Gem::Requirement
218
+ requirements:
219
+ - - "~>"
220
+ - !ruby/object:Gem::Version
221
+ version: '1.6'
222
+ type: :development
223
+ prerelease: false
224
+ version_requirements: !ruby/object:Gem::Requirement
225
+ requirements:
226
+ - - "~>"
227
+ - !ruby/object:Gem::Version
228
+ version: '1.6'
229
+ - !ruby/object:Gem::Dependency
230
+ name: yard
231
+ requirement: !ruby/object:Gem::Requirement
232
+ requirements:
233
+ - - "~>"
234
+ - !ruby/object:Gem::Version
235
+ version: 0.9.11
236
+ type: :development
237
+ prerelease: false
238
+ version_requirements: !ruby/object:Gem::Requirement
239
+ requirements:
240
+ - - "~>"
241
+ - !ruby/object:Gem::Version
242
+ version: 0.9.11
243
+ description: Sensu gitlab plugins
244
+ email: "<sensu-users@googlegroups.com>"
245
+ executables:
246
+ - check-health-gitlab.rb
247
+ - metrics-gitlab.rb
248
+ extensions: []
249
+ extra_rdoc_files: []
250
+ files:
251
+ - CHANGELOG.md
252
+ - LICENSE
253
+ - README.md
254
+ - bin/check-health-gitlab.rb
255
+ - bin/metrics-gitlab.rb
256
+ - lib/sensu-plugins-gitlab.rb
257
+ - lib/sensu-plugins-gitlab/version.rb
258
+ homepage: https://github.com/sensu-plugins/sensu-plugins-gitlab
259
+ licenses:
260
+ - MIT
261
+ metadata:
262
+ maintainer: sensu-plugin
263
+ development_status: active
264
+ production_status: unstable - testing recommended
265
+ release_draft: 'false'
266
+ release_prerelease: 'false'
267
+ post_install_message: You can use the embedded Ruby by setting EMBEDDED_RUBY=true
268
+ in /etc/default/sensu
269
+ rdoc_options: []
270
+ require_paths:
271
+ - lib
272
+ required_ruby_version: !ruby/object:Gem::Requirement
273
+ requirements:
274
+ - - ">="
275
+ - !ruby/object:Gem::Version
276
+ version: 2.1.0
277
+ required_rubygems_version: !ruby/object:Gem::Requirement
278
+ requirements:
279
+ - - ">="
280
+ - !ruby/object:Gem::Version
281
+ version: '0'
282
+ requirements: []
283
+ rubyforge_project:
284
+ rubygems_version: 2.5.2.1
285
+ signing_key:
286
+ specification_version: 4
287
+ summary: Sensu plugins for gitlab
288
+ test_files: []