sensu-plugins-jenkins 1.6.2 → 1.7.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 +4 -4
- data/CHANGELOG.md +7 -1
- data/bin/check-jenkins-build-time.rb +45 -8
- data/bin/check-jenkins.rb +10 -3
- data/lib/sensu-plugins-jenkins/version.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75c39b7e5b5565b722528e10fb11058718cc4a3269c6ed5681addfb89407b9cb
|
4
|
+
data.tar.gz: b3d3ca9c8db98a107638ece7e80ac90619cca58dfe892a403f5c672aa83f4f7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b78f035d9c4665fd24d04396f4747648de3391ff65311e61c85260a798f538676975f51eac261fe0e85c5a2b58f547695355d7c4602efddf0bf80848ab69e7eb
|
7
|
+
data.tar.gz: 0372069eeb99cdc1d30098c4b6d0be30880acd803fa75fd1e008d912e12fe152904793e9b8bdf9b168395a11d3240454440ef878ee7df662556cb8a04fa1c62d
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,11 @@ Which is based on [Keep A Changelog](http://keepachangelog.com/)
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [1.7.0] - 2018-05-14
|
10
|
+
### Added
|
11
|
+
- check-jenkins-build-time.rb: add `--check-build-duration` mode to check duration (@CoRfr)
|
12
|
+
- check-jenkins.rb: add `--timeout` option to specify timeout instead of the hardcoded 5s (@CoRfr)
|
13
|
+
|
9
14
|
## [1.6.2] - 2018-03-01
|
10
15
|
### Fixed
|
11
16
|
- check-jenkins-health.rb: fixed bug introduced by #25 (@majormoses)
|
@@ -95,7 +100,8 @@ Which is based on [Keep A Changelog](http://keepachangelog.com/)
|
|
95
100
|
### Added
|
96
101
|
- initial release
|
97
102
|
|
98
|
-
[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-jenkins/compare/1.
|
103
|
+
[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-jenkins/compare/1.7.0...HEAD
|
104
|
+
[1.7.0]: https://github.com/sensu-plugins/sensu-plugins-jenkins/compare/1.6.2...1.7.0
|
99
105
|
[1.6.2]: https://github.com/sensu-plugins/sensu-plugins-jenkins/compare/1.6.1...1.6.2
|
100
106
|
[1.6.1]: https://github.com/sensu-plugins/sensu-plugins-jenkins/compare/1.6.0...1.6.1
|
101
107
|
[1.6.0]: https://github.com/sensu-plugins/sensu-plugins-jenkins/compare/1.5.0...1.6.0
|
@@ -4,7 +4,9 @@
|
|
4
4
|
#
|
5
5
|
# DESCRIPTION:
|
6
6
|
# Alert if the last successful build timestamp of a jenkins job is older than
|
7
|
-
# a specified time duration
|
7
|
+
# a specified time duration
|
8
|
+
# OR not within a specific daily time window
|
9
|
+
# OR if the total build duration exceeds a specified duration.
|
8
10
|
#
|
9
11
|
# OUTPUT:
|
10
12
|
# plain text
|
@@ -19,6 +21,8 @@
|
|
19
21
|
# where TIME_EXPRESSION is either a relative time duration from now (30m, 1h) or
|
20
22
|
# a daily time window (1am-2am, 1:01am-2:01am), without spaces.
|
21
23
|
#
|
24
|
+
# --check-build-duration to check the last build duration for a job.
|
25
|
+
#
|
22
26
|
# DEPENDENCIES:
|
23
27
|
# gem: sensu-plugin
|
24
28
|
# jenkins_api_client
|
@@ -50,6 +54,11 @@ class JenkinsBuildTime < Sensu::Plugin::Check::CLI
|
|
50
54
|
long: '--jobs JOB_NAME=TIME_EXPRESSION,[JOB_NAME=TIME_EXPRESSION]',
|
51
55
|
required: true
|
52
56
|
|
57
|
+
option :check_build_duration,
|
58
|
+
description: 'Mode to check the build duration instead of the last occurence of a build',
|
59
|
+
short: '-d',
|
60
|
+
long: '--[no-]check-build-duration'
|
61
|
+
|
53
62
|
option :username,
|
54
63
|
description: 'Username for Jenkins instance',
|
55
64
|
short: '-U USERNAME',
|
@@ -68,24 +77,32 @@ class JenkinsBuildTime < Sensu::Plugin::Check::CLI
|
|
68
77
|
critical_jobs = []
|
69
78
|
|
70
79
|
jobs = parse_jobs_param
|
80
|
+
check_build_duration = config[:check_build_duration] || false
|
71
81
|
|
72
82
|
jobs.each do |job_name, time_expression|
|
73
83
|
begin
|
74
|
-
|
84
|
+
build_number = last_successful_build_number(job_name)
|
85
|
+
last_build_time = build_time(job_name, build_number)
|
86
|
+
last_build_duration = build_duration(job_name, build_number)
|
75
87
|
rescue
|
76
88
|
critical "Error looking up Jenkins job: #{job_name}"
|
77
89
|
end
|
78
90
|
|
79
|
-
if
|
91
|
+
if check_build_duration
|
92
|
+
unless time_within_allowed_build_duration?(last_build_duration,
|
93
|
+
parse_duration_seconds(time_expression))
|
94
|
+
critical_jobs << critical_message_build_duration(job_name, last_build_time, last_build_duration, time_expression)
|
95
|
+
end
|
96
|
+
elsif time_expression_is_window?(time_expression)
|
80
97
|
unless time_within_window?(last_build_time,
|
81
98
|
parse_window_start(time_expression),
|
82
99
|
parse_window_end(time_expression))
|
83
|
-
critical_jobs << critical_message(job_name, last_build_time, time_expression)
|
100
|
+
critical_jobs << critical_message(job_name, last_build_time, last_build_duration, time_expression)
|
84
101
|
end
|
85
102
|
else
|
86
103
|
unless time_within_allowed_duration?(last_build_time,
|
87
104
|
parse_duration_seconds(time_expression))
|
88
|
-
critical_jobs << critical_message(job_name, last_build_time, time_expression)
|
105
|
+
critical_jobs << critical_message(job_name, last_build_time, last_build_duration, time_expression)
|
89
106
|
end
|
90
107
|
end
|
91
108
|
end
|
@@ -104,9 +121,21 @@ class JenkinsBuildTime < Sensu::Plugin::Check::CLI
|
|
104
121
|
jenkins.job.list_details(job_name)['lastSuccessfulBuild']['number']
|
105
122
|
end
|
106
123
|
|
124
|
+
def build_details(job_name, build_number)
|
125
|
+
# Cache the results
|
126
|
+
@build_details ||= {}
|
127
|
+
@build_details[job_name] ||= {}
|
128
|
+
@build_details[job_name][build_number] ||= jenkins.job.get_build_details(job_name, build_number)
|
129
|
+
end
|
130
|
+
|
107
131
|
def build_time(job_name, build_number)
|
108
132
|
# Jenkins expresses timestamps in epoch millis
|
109
|
-
Time.at(
|
133
|
+
Time.at(build_details(job_name, build_number)['timestamp'] / 1000)
|
134
|
+
end
|
135
|
+
|
136
|
+
def build_duration(job_name, build_number)
|
137
|
+
# Jenkins expresses timestamps in epoch millis, convert it to seconds
|
138
|
+
build_details(job_name, build_number)['duration'] / 1000
|
110
139
|
end
|
111
140
|
|
112
141
|
def time_expression_is_window?(time_expression)
|
@@ -148,8 +177,16 @@ class JenkinsBuildTime < Sensu::Plugin::Check::CLI
|
|
148
177
|
time > (@now - duration_seconds)
|
149
178
|
end
|
150
179
|
|
151
|
-
def
|
152
|
-
|
180
|
+
def time_within_allowed_build_duration?(build_duration_seconds, duration_seconds)
|
181
|
+
build_duration_seconds <= duration_seconds
|
182
|
+
end
|
183
|
+
|
184
|
+
def critical_message_build_duration(job_name, last_build_time, duration_seconds, time_expression)
|
185
|
+
"#{job_name}: last built at #{last_build_time} (#{ChronicDuration.output(duration_seconds)}) exceeded max duration (#{time_expression})"
|
186
|
+
end
|
187
|
+
|
188
|
+
def critical_message(job_name, last_build_time, duration_seconds, time_expression)
|
189
|
+
"#{job_name}: last built at #{last_build_time} (#{ChronicDuration.output(duration_seconds)}), not within allowed time: #{time_expression}"
|
153
190
|
end
|
154
191
|
|
155
192
|
def parse_jobs_param
|
data/bin/check-jenkins.rb
CHANGED
@@ -65,16 +65,23 @@ class JenkinsMetricsPingPongChecker < Sensu::Plugin::Check::CLI
|
|
65
65
|
description: 'Perform "insecure" SSL connections and transfers.',
|
66
66
|
default: false
|
67
67
|
|
68
|
+
option :timeout,
|
69
|
+
short: '-t SECONDS',
|
70
|
+
long: '--timeout SECONDS',
|
71
|
+
description: 'Timeout for REST request',
|
72
|
+
proc: proc(&:to_i),
|
73
|
+
default: 5
|
74
|
+
|
68
75
|
def run
|
69
76
|
https ||= config[:https] ? 'https' : 'http'
|
70
77
|
testurl = "#{https}://#{config[:server]}:#{config[:port]}#{config[:uri]}"
|
71
78
|
|
72
79
|
r = if config[:https] && config[:insecure]
|
73
|
-
RestClient::Resource.new(testurl, timeout:
|
80
|
+
RestClient::Resource.new(testurl, timeout: config[:timeout], verify_ssl: false).get
|
74
81
|
elsif config[:https]
|
75
|
-
RestClient::Resource.new(testurl, timeout:
|
82
|
+
RestClient::Resource.new(testurl, timeout: config[:timeout], verify_ssl: true).get
|
76
83
|
else
|
77
|
-
RestClient::Resource.new(testurl, timeout:
|
84
|
+
RestClient::Resource.new(testurl, timeout: config[:timeout]).get
|
78
85
|
end
|
79
86
|
|
80
87
|
if r.code == 200 && r.body.include?('pong')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensu-plugins-jenkins
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sensu-Plugins and contributors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sensu-plugin
|