sensu-plugins-gpg 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -1
- data/LICENSE +17 -17
- data/README.md +18 -7
- data/bin/check-all-gpg-keys-for-expiry.rb +263 -0
- data/lib/sensu-plugins-gpg.rb +2 -0
- data/lib/sensu-plugins-gpg/integer.rb +26 -0
- data/lib/sensu-plugins-gpg/key.rb +68 -0
- data/lib/sensu-plugins-gpg/version.rb +8 -2
- metadata +23 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d594885aab80d8b32b1ec588e3d7f987cd827877
|
4
|
+
data.tar.gz: 4637fe51fb38b00a4ef90269c553d4ca596f2398
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4086313ec0258c21cac7a6166ac2ac76b96c999d8aee81da8aefb09f71cd1c1e3d28ba2df9e6fcb7e62f686e7bc97aa6b3aa84de6c55126d7c1ad76438698b5
|
7
|
+
data.tar.gz: aa21be0217563fa2cc56592258ec75e117a768a33ef45590a13e1b5ae91acd8dae0ebcba54be9ccf4aa1337115a49270d862d77b03090453d08fb20d071aed63
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,20 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
|
|
5
5
|
|
6
6
|
## [Unreleased]
|
7
7
|
|
8
|
+
## [2.0.0]
|
9
|
+
### Breaking Change
|
10
|
+
- bumped requirement of `sensu-plugin` to [2.0](https://github.com/sensu-plugins/sensu-plugin/blob/master/CHANGELOG.md#v200---2017-03-29) (@majormoses)
|
11
|
+
|
12
|
+
### Added
|
13
|
+
- added scripts `check-all-gpg-keys-for-expiry.rb` and its spec script `check_all_gpg_keys_for_expiry_spec.rb`. (@adityapahuja)
|
14
|
+
|
15
|
+
### Changed
|
16
|
+
- moved spec_helper.rb from test to spec folder for consistency. (@adityapahuja)
|
17
|
+
- updated spec_helper.rb to provide classes and tools for testing check-all-gpg-keys-for-expiry. (@adityapahuja)
|
18
|
+
- updated license to include Crown Copyright. (@adityapahuja)
|
19
|
+
- updated readme to provide details on newly added scripts. (@adityapahuja)
|
20
|
+
- updated version.rb to include comments. (@adityapahuja)
|
21
|
+
|
8
22
|
## [1.0.0] - 2017-07-15
|
9
23
|
### Added
|
10
24
|
- Ruby 2.3.0 support
|
@@ -37,7 +51,8 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
|
|
37
51
|
### Added
|
38
52
|
- initial release
|
39
53
|
|
40
|
-
[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-gpg/compare/
|
54
|
+
[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-gpg/compare/2.0.0...HEAD
|
55
|
+
[2.0.0]: https://github.com/sensu-plugins/sensu-plugins-gpg/compare/1.0.0...2.0.0
|
41
56
|
[1.0.0]: https://github.com/sensu-plugins/sensu-plugins-gpg/compare/0.0.4...1.0.0
|
42
57
|
[0.0.4]: https://github.com/sensu-plugins/sensu-plugins-gpg/compare/0.0.3...0.0.4
|
43
58
|
[0.0.3]: https://github.com/sensu-plugins/sensu-plugins-gpg/compare/0.0.2...0.0.3
|
data/LICENSE
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
Copyright (c) 2015 Sensu-Plugins
|
2
|
+
Copyright (c) 2016 Crown Copyright
|
2
3
|
|
3
|
-
MIT License
|
4
|
+
The MIT License (MIT)
|
4
5
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
the following conditions:
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
8
|
+
in the Software without restriction, including without limitation the rights
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
11
|
+
furnished to do so, subject to the following conditions:
|
12
12
|
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
14
|
+
copies or substantial portions of the Software.
|
15
15
|
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
OF
|
22
|
-
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
22
|
+
SOFTWARE.
|
data/README.md
CHANGED
@@ -1,21 +1,32 @@
|
|
1
|
-
Sensu
|
1
|
+
# Sensu Plugins GPG
|
2
2
|
|
3
|
-
[
|
3
|
+
[![Build Status](https://travis-ci.org/sensu-plugins/sensu-plugins-gpg.svg?branch=master)](https://travis-ci.org/sensu-plugins/sensu-plugins-gpg)
|
4
4
|
[![Gem Version](https://badge.fury.io/rb/sensu-plugins-gpg.svg)](http://badge.fury.io/rb/sensu-plugins-gpg)
|
5
5
|
[![Code Climate](https://codeclimate.com/github/sensu-plugins/sensu-plugins-gpg/badges/gpa.svg)](https://codeclimate.com/github/sensu-plugins/sensu-plugins-gpg)
|
6
6
|
[![Test Coverage](https://codeclimate.com/github/sensu-plugins/sensu-plugins-gpg/badges/coverage.svg)](https://codeclimate.com/github/sensu-plugins/sensu-plugins-gpg)
|
7
7
|
[![Dependency Status](https://gemnasium.com/sensu-plugins/sensu-plugins-gpg.svg)](https://gemnasium.com/sensu-plugins/sensu-plugins-gpg)
|
8
8
|
|
9
|
-
|
9
|
+
This plugin is used for monitoring GPG keys.
|
10
10
|
|
11
11
|
## Files
|
12
|
-
|
12
|
+
|
13
|
+
* bin/check-gpg-expiration.rb
|
14
|
+
* bin/check-all-gpg-keys-for-expiry.rb
|
13
15
|
|
14
16
|
## Usage
|
15
17
|
|
16
|
-
|
18
|
+
In a proper gem environment, plugins can be executed directly from the command line. If you want to check GPG keys' expiry dates, you can use the 'check-all-gpg-keys-for-expiry' plugin. This will only work for Ruby scripts. Scripts in other languages will still need to be called directly due to binstubs not being automatically created.
|
19
|
+
|
20
|
+
```
|
21
|
+
check-all-gpg-keys-for-expiry.rb -w 7 -c 2 -h ~/.gnupg --do-not-display-json-message
|
22
|
+
```
|
23
|
+
|
24
|
+
Depending on Ruby environment, you may need to call Ruby directly.
|
17
25
|
|
18
|
-
|
26
|
+
```
|
27
|
+
/opt/sensu/embedded/bin/ruby check-all-gpg-keys-for-expiry.rb -w 7 -c 2 -h ~/.gnupg --do-not-display-json-message
|
28
|
+
```
|
19
29
|
|
20
|
-
##
|
30
|
+
## Contributing
|
21
31
|
|
32
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/sensu-plugins/sensu-plugins-gpg.
|
@@ -0,0 +1,263 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-all-gpg-keys-for-expiry
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# This script will check all keys' expiry dates and generate JSON message or output
|
7
|
+
# the string "CheckAllGpgKeysForExpiry OK: ..." (like a Nagios plugin). JSON message can be
|
8
|
+
# sent to Sensu client.
|
9
|
+
#
|
10
|
+
# OUTPUT:
|
11
|
+
# plain text
|
12
|
+
# Defaults: CRITICAL if a key is about to expire in 5 days
|
13
|
+
# WARNING if a key is about expire in 14 days
|
14
|
+
# GPG home directory is /root/.gnupg
|
15
|
+
# GPG executable binary is located under /usr/bin/gpg
|
16
|
+
# It checks secret keys
|
17
|
+
# It displays JSON message
|
18
|
+
#
|
19
|
+
# PLATFORMS:
|
20
|
+
# Linux, Mac OS X
|
21
|
+
#
|
22
|
+
# DEPENDENCIES:
|
23
|
+
# gem: sensu-plugin, csv, open3, date, time
|
24
|
+
# GPG package
|
25
|
+
#
|
26
|
+
# USAGE:
|
27
|
+
# check-all-gpg-keys-for-expiry.rb -w 7 -c 2 -h ~/.gnupg -e /usr/local/bin/gpg
|
28
|
+
# --do-not-display-json-message --use-secret-key
|
29
|
+
#
|
30
|
+
# LICENSE:
|
31
|
+
# Aditya Pahuja aditya.s.pahuja@gmail.com
|
32
|
+
# Copyright (c) 2016 Crown Copyright
|
33
|
+
# Released under the same terms as Crown (the MIT license); see LICENSE
|
34
|
+
# for details.
|
35
|
+
#
|
36
|
+
|
37
|
+
require 'sensu-plugins-gpg'
|
38
|
+
require 'sensu-plugin/check/cli'
|
39
|
+
require 'csv'
|
40
|
+
require 'open3'
|
41
|
+
require 'date'
|
42
|
+
require 'time'
|
43
|
+
|
44
|
+
# == Description
|
45
|
+
#
|
46
|
+
# The CheckAllGpgKeysForExpiry class fetches all GPG keys, check their expiry dates and send
|
47
|
+
# appropriate alerts to Sensu
|
48
|
+
class CheckAllGpgKeysForExpiry < Sensu::Plugin::Check::CLI
|
49
|
+
option :warning,
|
50
|
+
short: '-w NUMBER_OF_DAYS_LEFT_TO_TRIGGER_ALERT',
|
51
|
+
long: '--warning NUMBER_OF_DAYS_LEFT_TO_TRIGGER_ALERT',
|
52
|
+
proc: proc(&:to_i),
|
53
|
+
default: 14,
|
54
|
+
description: 'The minimum number of days left to trigger a warning alert'
|
55
|
+
|
56
|
+
option :critical,
|
57
|
+
short: '-c NUMBER_OF_DAYS_LEFT_TO_TRIGGER_ALERT',
|
58
|
+
long: '--critical NUMBER_OF_DAYS_LEFT_TO_TRIGGER_ALERT',
|
59
|
+
proc: proc(&:to_i),
|
60
|
+
default: 5,
|
61
|
+
description: 'Minimum number of days left to trigger a critical alert'
|
62
|
+
|
63
|
+
option :home_directory,
|
64
|
+
short: '-h GPG_HOME_DIR',
|
65
|
+
long: '--home-directory GPG_HOME_DIR',
|
66
|
+
default: '/root/.gnupg',
|
67
|
+
description: 'Location of GPG home directory',
|
68
|
+
required: true
|
69
|
+
|
70
|
+
option :gpg,
|
71
|
+
short: '-e GPG_EXECUTABLE_PATH',
|
72
|
+
long: '--execute GPG_EXECUTABLE_PATH',
|
73
|
+
default: '/usr/bin/gpg',
|
74
|
+
description: 'Location of binary executable file (gpg)'
|
75
|
+
|
76
|
+
option :use_secret_key,
|
77
|
+
short: '-s',
|
78
|
+
long: '--use-secret-key',
|
79
|
+
description: 'Check secret key instead of public key',
|
80
|
+
boolean: true
|
81
|
+
|
82
|
+
option :do_not_display_json_message,
|
83
|
+
short: '-d',
|
84
|
+
long: '--do-not-display-json-message',
|
85
|
+
description: 'Display JSON message instead of sending it to Sensu',
|
86
|
+
boolean: true
|
87
|
+
|
88
|
+
def initialize
|
89
|
+
super
|
90
|
+
end
|
91
|
+
|
92
|
+
# Return the number of days since epoch from a given epoch
|
93
|
+
def self.days_since_epoch(e)
|
94
|
+
epoch = Date.new(1970, 1, 1)
|
95
|
+
d = Time.at(e).to_date
|
96
|
+
(d - epoch).to_i
|
97
|
+
end
|
98
|
+
|
99
|
+
# Return --list-key if 'use_secret_key' is false otherwise
|
100
|
+
# return --list-secret-key
|
101
|
+
def key_type_option
|
102
|
+
if !config[:use_secret_key]
|
103
|
+
'--list-key'
|
104
|
+
else
|
105
|
+
'--list-secret-key'
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# Return all GPG keys' details by executing the GPG command
|
110
|
+
def fetch_all_gpg_keys
|
111
|
+
args = ['--with-colons', '--fixed-list-mode', '--lock-never', key_type_option]
|
112
|
+
gpg_cmd = [config[:gpg] + " --homedir #{config[:home_directory]}"] + args
|
113
|
+
|
114
|
+
_cmd_out, _cmd_err, _status = Open3.capture3 gpg_cmd.join(' ')
|
115
|
+
end
|
116
|
+
|
117
|
+
# Set the key's level to the appropriate level by checking its number of days left
|
118
|
+
def update_key_level(key)
|
119
|
+
num_of_days_left = key.num_of_days_left
|
120
|
+
case num_of_days_left.to_s
|
121
|
+
when /^-\d+$/
|
122
|
+
key.level = 2
|
123
|
+
when /^\d+$/
|
124
|
+
return key.level = 0 if num_of_days_left > config[:warning]
|
125
|
+
return key.level = 2 if num_of_days_left <= config[:critical]
|
126
|
+
return key.level = 1
|
127
|
+
else
|
128
|
+
return key.level = 3
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
# Return the number of days left using key's expiry date and today date
|
133
|
+
def calculate_num_of_days_left(key, today_epoch)
|
134
|
+
CheckAllGpgKeysForExpiry.days_since_epoch(key.expiry.to_i) - CheckAllGpgKeysForExpiry.days_since_epoch(today_epoch)
|
135
|
+
end
|
136
|
+
|
137
|
+
# Populate key's num of days left and its level
|
138
|
+
def populate_key_num_of_days_left_and_level(key, today_epoch)
|
139
|
+
if !key.expiry.nil?
|
140
|
+
key.num_of_days_left = calculate_num_of_days_left(key, today_epoch)
|
141
|
+
update_key_level(key)
|
142
|
+
else
|
143
|
+
key.num_of_days_left = Integer::MAX
|
144
|
+
key.level = 0
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
# Return pub if 'use_secret_key' is false otherwise
|
149
|
+
# return sec
|
150
|
+
def choose_key_type
|
151
|
+
if !config[:use_secret_key]
|
152
|
+
'pub'
|
153
|
+
else
|
154
|
+
'sec'
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
# Return a collection of keys
|
159
|
+
def create_a_collection_of_keys(keys_details)
|
160
|
+
today_epoch = Date.today.to_time.to_i
|
161
|
+
keys = []
|
162
|
+
found_key = false
|
163
|
+
key = nil
|
164
|
+
key_type = choose_key_type
|
165
|
+
CSV.parse(keys_details, col_sep: ':') do |row|
|
166
|
+
current_key_type = row[0]
|
167
|
+
if current_key_type == key_type
|
168
|
+
key = Key.new(row[4], row[6])
|
169
|
+
populate_key_num_of_days_left_and_level(key, today_epoch)
|
170
|
+
found_key = true
|
171
|
+
elsif found_key && current_key_type == 'uid'
|
172
|
+
key.description = row[9]
|
173
|
+
keys.push key
|
174
|
+
found_key = false
|
175
|
+
end
|
176
|
+
end
|
177
|
+
keys
|
178
|
+
end
|
179
|
+
|
180
|
+
# Run the GPG command to fetch all keys
|
181
|
+
def fetch_collection_of_keys
|
182
|
+
cmd_out, cmd_err, status = fetch_all_gpg_keys
|
183
|
+
if status.success?
|
184
|
+
[true, create_a_collection_of_keys(cmd_out)]
|
185
|
+
else
|
186
|
+
[false, cmd_err]
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
# Return a generated JSON message using note and status
|
191
|
+
def generate_json_message(note, status)
|
192
|
+
hash = {
|
193
|
+
name: self.class.name,
|
194
|
+
output: (note.nil? ? 'Unknown, Empty Message?' : note),
|
195
|
+
status: status
|
196
|
+
}
|
197
|
+
JSON.generate(hash)
|
198
|
+
end
|
199
|
+
|
200
|
+
# Return a note and an appropriate alert level after sorting keys using
|
201
|
+
# their number of days left in ascending order
|
202
|
+
def sort_keys
|
203
|
+
success, output = fetch_collection_of_keys
|
204
|
+
if success && output.count > 0
|
205
|
+
note = ''
|
206
|
+
output.sort! { |key1, key2| key1.num_of_days_left <=> key2.num_of_days_left }
|
207
|
+
output.each do |key|
|
208
|
+
note += key.to_s + "\n"
|
209
|
+
end
|
210
|
+
return note, output[0].level
|
211
|
+
elsif success && output.count == 0
|
212
|
+
return 'There are no keys.', 0
|
213
|
+
elsif output.nil?
|
214
|
+
return 'There are no keys.', 0
|
215
|
+
else
|
216
|
+
return output, 3
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
# Return false with error message and its level if GPG executable binary file or its
|
221
|
+
# home directory does not exist otherwise return true
|
222
|
+
def validate_gpg_and_home_directory
|
223
|
+
unless File.exist?(config[:gpg])
|
224
|
+
return false, 'GPG executable binary file [' + config[:gpg] + '] does not exist.', 2
|
225
|
+
end
|
226
|
+
unless File.exist?(config[:home_directory])
|
227
|
+
return false, 'GPG home directory [' + config[:home_directory] + '] does not exist.', 2
|
228
|
+
end
|
229
|
+
[true, '', 0]
|
230
|
+
end
|
231
|
+
|
232
|
+
# Send an appropriate alert level to Sensu using a specified level
|
233
|
+
def select_appropriate_alert_level(level)
|
234
|
+
if level == 0
|
235
|
+
ok
|
236
|
+
elsif level == 1
|
237
|
+
warning
|
238
|
+
elsif level == 2
|
239
|
+
critical
|
240
|
+
else
|
241
|
+
unknown
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
# Get all keys, sort them using their number of days left in ascending order
|
246
|
+
# and then display JSON message or send the message to Sensu
|
247
|
+
def run
|
248
|
+
success, note, level = validate_gpg_and_home_directory
|
249
|
+
note, level = sort_keys if success
|
250
|
+
if !config[:do_not_display_json_message]
|
251
|
+
puts generate_json_message(note, level)
|
252
|
+
else
|
253
|
+
message note
|
254
|
+
select_appropriate_alert_level(level)
|
255
|
+
end
|
256
|
+
exit
|
257
|
+
end
|
258
|
+
|
259
|
+
# Provide an option to disable autorun
|
260
|
+
def self.disable_autorun
|
261
|
+
@@autorun = false
|
262
|
+
end
|
263
|
+
end
|
data/lib/sensu-plugins-gpg.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-all-gpg-keys-for-expiry
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# The Integer class provides maximum and minimum integer.
|
7
|
+
#
|
8
|
+
# LICENSE:
|
9
|
+
# Aditya Pahuja aditya.s.pahuja@gmail.com
|
10
|
+
# Copyright (c) 2016 Crown Copyright
|
11
|
+
# Released under the same terms as Crown (the MIT license); see LICENSE
|
12
|
+
# for details.
|
13
|
+
#
|
14
|
+
class Integer
|
15
|
+
# Number of bytes
|
16
|
+
N_BYTES = [42].pack('i').size
|
17
|
+
|
18
|
+
# Number of bits
|
19
|
+
N_BITS = N_BYTES * 8
|
20
|
+
|
21
|
+
# Maximum number for integer
|
22
|
+
MAX = 2**(N_BITS - 2) - 1
|
23
|
+
|
24
|
+
# Minimum number for integer
|
25
|
+
MIN = -MAX - 1
|
26
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-all-gpg-keys-for-expiry
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# The Key class stores information about the key. It has id, expiry date,
|
7
|
+
# description, level and number of days left
|
8
|
+
#
|
9
|
+
# LICENSE:
|
10
|
+
# Aditya Pahuja aditya.s.pahuja@gmail.com
|
11
|
+
# Copyright (c) 2016 Crown Copyright
|
12
|
+
# Released under the same terms as Crown (the MIT license); see LICENSE
|
13
|
+
# for details.
|
14
|
+
#
|
15
|
+
class Key
|
16
|
+
attr_accessor :id, :expiry, :description, :level, :num_of_days_left
|
17
|
+
|
18
|
+
def initialize(id, expiry)
|
19
|
+
@id = id
|
20
|
+
@expiry = expiry
|
21
|
+
end
|
22
|
+
|
23
|
+
# Return the expiry date if @expiry is specified otherwise return
|
24
|
+
# 'N/A'
|
25
|
+
def display_expiry_date
|
26
|
+
@expiry.nil? ? 'N/A' : Time.at(@expiry.to_i).to_datetime.to_s
|
27
|
+
end
|
28
|
+
|
29
|
+
# Return the number of days left if @num_of_days_left is specified
|
30
|
+
# otherwise return 'N/A'
|
31
|
+
def display_num_of_days_left
|
32
|
+
@num_of_days_left == Integer::MAX ? 'N/A' : @num_of_days_left.to_s
|
33
|
+
end
|
34
|
+
|
35
|
+
# Return the meaningful information about the instance of Key
|
36
|
+
def inspect
|
37
|
+
'Id: ' + @id.to_s +
|
38
|
+
', Expires on: ' + display_expiry_date +
|
39
|
+
', Level: ' + map_number_to_word_level(@level) +
|
40
|
+
', Number of days left to expire: ' + display_num_of_days_left +
|
41
|
+
', Description: ' + @description % self
|
42
|
+
end
|
43
|
+
|
44
|
+
# Print the instance of Key's details in a nice format
|
45
|
+
def to_s
|
46
|
+
'Id: ' + @id.to_s +
|
47
|
+
', Expires on: ' + display_expiry_date +
|
48
|
+
', Level: ' + map_number_to_word_level(@level) +
|
49
|
+
', Number of days left to expire: ' + display_num_of_days_left +
|
50
|
+
', Description: ' + @description % self
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
# Return the meaningful word for a specified level
|
56
|
+
def map_number_to_word_level(level)
|
57
|
+
case level
|
58
|
+
when 0
|
59
|
+
'OK'
|
60
|
+
when 1
|
61
|
+
'WARNING'
|
62
|
+
when 2
|
63
|
+
'CRITICAL'
|
64
|
+
when 3
|
65
|
+
'UNKNOWN'
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -1,9 +1,15 @@
|
|
1
|
+
# SensuPluginsGpg is the main module
|
1
2
|
module SensuPluginsGpg
|
3
|
+
# Version holds details about version number. It consists of
|
4
|
+
# three elements which are major, minor and patch number.
|
2
5
|
module Version
|
3
|
-
|
6
|
+
# Major version number (X.0.0)
|
7
|
+
MAJOR = 2
|
8
|
+
# Minor version number (0.X.0)
|
4
9
|
MINOR = 0
|
10
|
+
# Patch version number (0.0.X)
|
5
11
|
PATCH = 0
|
6
|
-
|
12
|
+
# Version number (X.X.X)
|
7
13
|
VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
|
8
14
|
end
|
9
15
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensu-plugins-gpg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.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: 2017-
|
11
|
+
date: 2017-10-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sensu-plugin
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,6 +122,20 @@ dependencies:
|
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '3.1'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: ruby-enum
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0.5'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0.5'
|
125
139
|
- !ruby/object:Gem::Dependency
|
126
140
|
name: rubocop
|
127
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -153,6 +167,7 @@ dependencies:
|
|
153
167
|
description: Sensu plugins for gpg
|
154
168
|
email: "<sensu-users@googlegroups.com>"
|
155
169
|
executables:
|
170
|
+
- check-all-gpg-keys-for-expiry.rb
|
156
171
|
- check-gpg-expiration.rb
|
157
172
|
extensions: []
|
158
173
|
extra_rdoc_files: []
|
@@ -160,8 +175,11 @@ files:
|
|
160
175
|
- CHANGELOG.md
|
161
176
|
- LICENSE
|
162
177
|
- README.md
|
178
|
+
- bin/check-all-gpg-keys-for-expiry.rb
|
163
179
|
- bin/check-gpg-expiration.rb
|
164
180
|
- lib/sensu-plugins-gpg.rb
|
181
|
+
- lib/sensu-plugins-gpg/integer.rb
|
182
|
+
- lib/sensu-plugins-gpg/key.rb
|
165
183
|
- lib/sensu-plugins-gpg/version.rb
|
166
184
|
homepage: https://github.com/sensu-plugins/sensu-plugins-gpg
|
167
185
|
licenses:
|
@@ -189,7 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
189
207
|
version: '0'
|
190
208
|
requirements: []
|
191
209
|
rubyforge_project:
|
192
|
-
rubygems_version: 2.
|
210
|
+
rubygems_version: 2.6.14
|
193
211
|
signing_key:
|
194
212
|
specification_version: 4
|
195
213
|
summary: Sensu plugins for gpg
|