sensu-plugins-jenkins 0.0.3 → 0.0.4
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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/CHANGELOG.md +11 -2
- data/README.md +2 -1
- data/bin/check-jenkins-build-time.rb +147 -0
- data/lib/sensu-plugins-jenkins/version.rb +1 -1
- metadata +22 -6
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: deb1fb9a4cca84c812d40c614d17fc9cd5f701f9
|
4
|
+
data.tar.gz: aed0d9935e51586b5da4d5c935009b6b804a5bb3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 892ae6fc25459aa1ff0be4b815d86c38a9337223a4b24a7186733ff4c10d012da97b489b7b986d7b957e1104c24003814d63095f8d63880fff3d1205fac48343
|
7
|
+
data.tar.gz: c702b9eafc459fd07f8413a62ca31375325e17b3bdf3e1dba877bc562aac36d248297f85e61482b5063c83c0e50367c3c7f87f4145ec9b3d435c2ef0a15a87fb
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/CHANGELOG.md
CHANGED
@@ -3,9 +3,18 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
3
3
|
|
4
4
|
This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/)
|
5
5
|
|
6
|
-
## Unreleased][unreleased]
|
6
|
+
## [Unreleased][unreleased]
|
7
7
|
|
8
|
-
## [0.0.
|
8
|
+
## [0.0.4] - 2015-07-14
|
9
|
+
### Changed
|
10
|
+
- updated sensu-plugin gem to 1.2.0
|
11
|
+
|
12
|
+
## [0.0.3] - 2015-06-4
|
13
|
+
### Added
|
14
|
+
- New check `bin/check-jenkins-build-time.rb` which alerts when Jenkins builds
|
15
|
+
fail to succeed within a certain duration or configurable time window.
|
16
|
+
|
17
|
+
## [0.0.2] - 2015-06-03
|
9
18
|
|
10
19
|
### Added
|
11
20
|
- PR #1
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
## Sensu-Plugins-jenkins
|
2
2
|
|
3
|
-
[](https://travis-ci.org/sensu-plugins/sensu-plugins-jenkins)
|
3
|
+
[ ](https://travis-ci.org/sensu-plugins/sensu-plugins-jenkins)
|
4
4
|
[](http://badge.fury.io/rb/sensu-plugins-jenkins)
|
5
5
|
[](https://codeclimate.com/github/sensu-plugins/sensu-plugins-jenkins)
|
6
6
|
[](https://codeclimate.com/github/sensu-plugins/sensu-plugins-jenkins)
|
@@ -10,6 +10,7 @@
|
|
10
10
|
## Functionality
|
11
11
|
|
12
12
|
## Files
|
13
|
+
* bin/check-jenkins-build-time.rb
|
13
14
|
* bin/check-jenkins-health.rb
|
14
15
|
* bin/check-jenkins-job-status.rb
|
15
16
|
* bin/check-jenkins.rb
|
@@ -0,0 +1,147 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-jenkins-build-time
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# Alert if the last successful build timestamp of a jenkins job is older than
|
7
|
+
# a specified time duration OR not within a specific daily time window.
|
8
|
+
#
|
9
|
+
# OUTPUT:
|
10
|
+
# plain text
|
11
|
+
#
|
12
|
+
# PLATFORMS:
|
13
|
+
# Linux
|
14
|
+
#
|
15
|
+
# USAGE:
|
16
|
+
# check-jenkins-build-time -u JENKINS_URL -j job_1_name=30min,job_2_name=1:30am-2:30am
|
17
|
+
#
|
18
|
+
# -j parameter should be a comma-separated list of JOB_NAME=TIME_EXPRESSION
|
19
|
+
# where TIME_EXPRESSION is either a relative time duration from now (30m, 1h) or
|
20
|
+
# a daily time window (1am-2am, 1:01am-2:01am), without spaces.
|
21
|
+
#
|
22
|
+
# DEPENDENCIES:
|
23
|
+
# gem: sensu-plugin
|
24
|
+
# jenkins_api_client
|
25
|
+
# chronic_duration
|
26
|
+
#
|
27
|
+
#
|
28
|
+
# LICENSE:
|
29
|
+
# Copyright Matt Greensmith mgreensmith@cozy.co matt@mattgreensmith.net
|
30
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
31
|
+
# for details.
|
32
|
+
#
|
33
|
+
|
34
|
+
require 'sensu-plugin/check/cli'
|
35
|
+
require 'jenkins_api_client'
|
36
|
+
require 'chronic_duration'
|
37
|
+
|
38
|
+
class JenkinsBuildTime < Sensu::Plugin::Check::CLI
|
39
|
+
ONE_DAY = 86_400
|
40
|
+
|
41
|
+
option :url,
|
42
|
+
description: 'URL to Jenkins API',
|
43
|
+
short: '-u JENKINS_URL',
|
44
|
+
long: '--url JENKINS_URL',
|
45
|
+
required: true
|
46
|
+
|
47
|
+
option :jobs,
|
48
|
+
description: 'Jobs to check. Comma-separated list of JOB_NAME=TIME_EXPRESSION',
|
49
|
+
short: '-j JOB_NAME=TIME_EXPRESSION,[JOB_NAME=TIME_EXPRESSION]',
|
50
|
+
long: '--jobs JOB_NAME=TIME_EXPRESSION,[JOB_NAME=TIME_EXPRESSION]',
|
51
|
+
required: true
|
52
|
+
|
53
|
+
def run
|
54
|
+
@now = Time.now
|
55
|
+
critical_jobs = []
|
56
|
+
|
57
|
+
jobs = parse_jobs_param
|
58
|
+
|
59
|
+
jobs.each do |job_name, time_expression|
|
60
|
+
last_build_time = build_time(job_name, last_successful_build_number(job_name))
|
61
|
+
if time_expression_is_window?(time_expression)
|
62
|
+
unless time_within_window?(last_build_time,
|
63
|
+
parse_window_start(time_expression),
|
64
|
+
parse_window_end(time_expression))
|
65
|
+
critical_jobs << critical_message(job_name, last_build_time, time_expression)
|
66
|
+
end
|
67
|
+
else
|
68
|
+
unless time_within_allowed_duration?(last_build_time,
|
69
|
+
parse_duration_seconds(time_expression))
|
70
|
+
critical_jobs << critical_message(job_name, last_build_time, time_expression)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
critical "#{critical_jobs.length} failure(s): #{critical_jobs.join(', ')}" unless critical_jobs.empty?
|
76
|
+
ok "#{jobs.keys.length} job(s) had successful builds within allowed times"
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
def jenkins
|
82
|
+
@jenkins ||= JenkinsApi::Client.new(server_ip: config[:url], log_level: 3)
|
83
|
+
end
|
84
|
+
|
85
|
+
def last_successful_build_number(job_name)
|
86
|
+
jenkins.job.list_details(job_name)['lastSuccessfulBuild']['number']
|
87
|
+
end
|
88
|
+
|
89
|
+
def build_time(job_name, build_number)
|
90
|
+
# Jenkins expresses timestamps in epoch millis
|
91
|
+
Time.at(jenkins.job.get_build_details(job_name, build_number)['timestamp'] / 1000)
|
92
|
+
end
|
93
|
+
|
94
|
+
def time_expression_is_window?(time_expression)
|
95
|
+
time_expression.index('-') ? true : false
|
96
|
+
end
|
97
|
+
|
98
|
+
def parse_window_start(time_expression)
|
99
|
+
Time.parse(time_expression.split('-')[0])
|
100
|
+
end
|
101
|
+
|
102
|
+
def parse_window_end(time_expression)
|
103
|
+
Time.parse(time_expression.split('-')[1])
|
104
|
+
end
|
105
|
+
|
106
|
+
def time_within_window?(time, window_start, window_end)
|
107
|
+
time_after_window_start_today = window_start < time
|
108
|
+
time_in_window_today = time_after_window_start_today && window_end > time
|
109
|
+
|
110
|
+
time_after_window_start_yesterday = (window_start - ONE_DAY) < time
|
111
|
+
time_in_window_yesterday = time_after_window_start_yesterday && (window_end - ONE_DAY) > time
|
112
|
+
|
113
|
+
if @now < window_end && @now > window_start # we are in the window, so we will accept today or yesterday
|
114
|
+
time_ok = (time_in_window_today || time_in_window_yesterday)
|
115
|
+
elsif @now < window_end
|
116
|
+
# we are before the window, so we only accept yesterday
|
117
|
+
time_ok = time_in_window_yesterday
|
118
|
+
else
|
119
|
+
# we are after the window, so we only accept today
|
120
|
+
time_ok = time_in_window_today
|
121
|
+
end
|
122
|
+
time_ok
|
123
|
+
end
|
124
|
+
|
125
|
+
def parse_duration_seconds(time_expression)
|
126
|
+
ChronicDuration.parse(time_expression)
|
127
|
+
end
|
128
|
+
|
129
|
+
def time_within_allowed_duration?(time, duration_seconds)
|
130
|
+
time > (@now - duration_seconds)
|
131
|
+
end
|
132
|
+
|
133
|
+
def critical_message(job_name, last_build_time, time_expression)
|
134
|
+
"#{job_name}: last built at #{last_build_time}, not within allowed time: #{time_expression}"
|
135
|
+
end
|
136
|
+
|
137
|
+
def parse_jobs_param
|
138
|
+
jobs = {}
|
139
|
+
job_param = config[:jobs].split(',')
|
140
|
+
job_param.each do |j|
|
141
|
+
name, time_expression = j.split('=')
|
142
|
+
fail "Jobs mut be expressed as JOB_NAME=TIME_EXPRESSION. Invalid parameter: '#{j}'" if time_expression.nil?
|
143
|
+
jobs[name] = time_expression
|
144
|
+
end
|
145
|
+
jobs
|
146
|
+
end
|
147
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensu-plugins-jenkins
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sensu-Plugins and contributors
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
30
30
|
8sHuVruarogxxKPBzlL2is4EUb6oN/RdpGx2l4254+nyR+abg//Ed27Ym0PkB4lk
|
31
31
|
HP0m8WSjZmFr109pE/sVsM5jtOCvogyujQOjNVGN4gz1wwPr
|
32
32
|
-----END CERTIFICATE-----
|
33
|
-
date: 2015-
|
33
|
+
date: 2015-07-14 00:00:00.000000000 Z
|
34
34
|
dependencies:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: sensu-plugin
|
@@ -38,14 +38,14 @@ dependencies:
|
|
38
38
|
requirements:
|
39
39
|
- - '='
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: 1.
|
41
|
+
version: 1.2.0
|
42
42
|
type: :runtime
|
43
43
|
prerelease: false
|
44
44
|
version_requirements: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
46
|
- - '='
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: 1.
|
48
|
+
version: 1.2.0
|
49
49
|
- !ruby/object:Gem::Dependency
|
50
50
|
name: rest-client
|
51
51
|
requirement: !ruby/object:Gem::Requirement
|
@@ -74,6 +74,20 @@ dependencies:
|
|
74
74
|
- - '='
|
75
75
|
- !ruby/object:Gem::Version
|
76
76
|
version: 1.3.0
|
77
|
+
- !ruby/object:Gem::Dependency
|
78
|
+
name: chronic_duration
|
79
|
+
requirement: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - '='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: 0.10.6
|
84
|
+
type: :runtime
|
85
|
+
prerelease: false
|
86
|
+
version_requirements: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - '='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 0.10.6
|
77
91
|
- !ruby/object:Gem::Dependency
|
78
92
|
name: codeclimate-test-reporter
|
79
93
|
requirement: !ruby/object:Gem::Requirement
|
@@ -92,14 +106,14 @@ dependencies:
|
|
92
106
|
name: rubocop
|
93
107
|
requirement: !ruby/object:Gem::Requirement
|
94
108
|
requirements:
|
95
|
-
- -
|
109
|
+
- - '='
|
96
110
|
- !ruby/object:Gem::Version
|
97
111
|
version: '0.30'
|
98
112
|
type: :development
|
99
113
|
prerelease: false
|
100
114
|
version_requirements: !ruby/object:Gem::Requirement
|
101
115
|
requirements:
|
102
|
-
- -
|
116
|
+
- - '='
|
103
117
|
- !ruby/object:Gem::Version
|
104
118
|
version: '0.30'
|
105
119
|
- !ruby/object:Gem::Dependency
|
@@ -208,12 +222,14 @@ executables:
|
|
208
222
|
- check-jenkins.rb
|
209
223
|
- check-jenkins-job-status.rb
|
210
224
|
- check-jenkins-health.rb
|
225
|
+
- check-jenkins-build-time.rb
|
211
226
|
extensions: []
|
212
227
|
extra_rdoc_files: []
|
213
228
|
files:
|
214
229
|
- CHANGELOG.md
|
215
230
|
- LICENSE
|
216
231
|
- README.md
|
232
|
+
- bin/check-jenkins-build-time.rb
|
217
233
|
- bin/check-jenkins-health.rb
|
218
234
|
- bin/check-jenkins-job-status.rb
|
219
235
|
- bin/check-jenkins.rb
|
metadata.gz.sig
CHANGED
Binary file
|