sensu-plugins-kubernetes 0.1.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e7891019bcd4d1ee4a9ee93933dfe027e4059a3b
4
- data.tar.gz: 6a530b4917597e3b2aede0e3deeb709a25a9a5bd
3
+ metadata.gz: da62b54a627d8cb692fc340e5e004d31f4c836cf
4
+ data.tar.gz: ffa06f5b83a3e6539a9934929354dc2658873ae3
5
5
  SHA512:
6
- metadata.gz: 6bfc0e8b53232cbc19061ad115964f8592a1e05be418281ff18e340d74635353a1692f8f2a2c625b17296531d7be4a87271ed98292e9957bef8641e7e0e4484e
7
- data.tar.gz: 4a526bc45fcae03e58dd26def4c88dca48331286a87f10836a08aee5f6bfbb6d02959bb241f0945bda4b0e6348b6bfe32808c45aab3fed761af9dac65f0a192b
6
+ metadata.gz: d1652721603c4ca51d28f1fdb4248b189c0535722902f8355480cfd1f91f2d7e6761a31c278e5d39db1fff78b42e9ccd183eeb164744d371331bb1fb59df825d
7
+ data.tar.gz: 26b2e69ce1a96ccff4f9bb053e65476d7fe1984e48e83d79b53022d83679c7af14a36ead9aec3194311420f891dc0b35c3880ead9c7ad95a1d35e7cb7548869a
@@ -1,10 +1,20 @@
1
- #Change Log
1
+ # Change Log
2
2
  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
6
  ## [Unreleased]
7
7
 
8
+ ## [1.0.0] - 2017-03-21
9
+ ### Added
10
+ - Add `metrics-pods.rb` that will output the number of running pods per service (@mickfeech)
11
+ - Add `check-kube-pods-running` check (@nyxcharon)
12
+
13
+ ### Changed
14
+ - Update `kubeclient` to 2.3.0 (@jackfengji)
15
+ - Split `check-kube-pods-pending` into two checks; the original still checks for
16
+ pending pods, the restart count portion has been split into it's own check, `check-kube-pods-restarting`. (@nyxcharon)
17
+
8
18
  ## [0.1.2] - 2016-08-07
9
19
  ### Fixed
10
20
  - check-kube-service-available.rb: fixed error caused by misspelling of true boolean (@justinhammar)
@@ -39,7 +49,8 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
39
49
  ### Added
40
50
  - initial release
41
51
 
42
- [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-kubernetes/compare/0.1.2...HEAD
52
+ [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-kubernetes/compare/1.0.0...HEAD
53
+ [1.0.0]: https://github.com/sensu-plugins/sensu-plugins-kubernetes/compare/0.1.2...1.0.0
43
54
  [0.1.2]: https://github.com/sensu-plugins/sensu-plugins-kubernetes/compare/0.1.1...0.1.2
44
55
  [0.1.1]: https://github.com/sensu-plugins/sensu-plugins-kubernetes/compare/0.1.0...0.1.1
45
56
  [0.1.0]: https://github.com/sensu-plugins/sensu-plugins-kubernetes/compare/0.0.1...0.1.0
data/README.md CHANGED
@@ -15,7 +15,10 @@ This provides functionality to check node and pod status as well as api and serv
15
15
  - bin/check-kube-pods-pending.rb
16
16
  - bin/check-kube-service-available.rb
17
17
  - bin/check-kube-pods-runtime.rb
18
+ - bin/check-kube-pods-running.rb
19
+ - bin/check-kube-pods-restarting.rb
18
20
  - bin/handler-kube-pod.rb
21
+ - bin/metrics-pods.rb
19
22
 
20
23
  ## Usage
21
24
 
@@ -105,6 +108,46 @@ Usage: check-kube-pods-runtime.rb (options)
105
108
  -w, --warn TIMEOUT Threshold for pods to be in the pending state
106
109
  ```
107
110
 
111
+ **check-kube-pods-running.rb**
112
+ ```
113
+ Usage: ./check-kube-pods-running.rb (options)
114
+ --ca-file CA-FILE CA file to verify API server cert
115
+ --cert CERT-FILE Client cert to present
116
+ --key KEY-FILE Client key for the client cert
117
+ --in-cluster Use service account authentication
118
+ --password PASSWORD If user is passed, also pass a password
119
+ -s, --api-server URL URL to API server
120
+ -t, --token TOKEN Bearer token for authorization
121
+ --token-file TOKEN-FILE File containing bearer token for authorization
122
+ -u, --user USER User with access to API
123
+ -v, --api-version VERSION API version
124
+ -n NAMESPACES, Exclude the specified list of namespaces
125
+ --exclude-namespace
126
+ -f, --filter FILTER Selector filter for pods to be checked
127
+ -p, --pods PODS List of pods to check
128
+ ```
129
+
130
+ **check-kube-pods-restarting.rb**
131
+
132
+ ```
133
+ Usage: ./check-kube-pods-restarting.rb (options)
134
+ --ca-file CA-FILE CA file to verify API server cert
135
+ --cert CERT-FILE Client cert to present
136
+ --key KEY-FILE Client key for the client cert
137
+ --in-cluster Use service account authentication
138
+ --password PASSWORD If user is passed, also pass a password
139
+ -s, --api-server URL URL to API server
140
+ -t, --token TOKEN Bearer token for authorization
141
+ --token-file TOKEN-FILE File containing bearer token for authorization
142
+ -u, --user USER User with access to API
143
+ -v, --api-version VERSION API version
144
+ -n NAMESPACES, Exclude the specified list of namespaces
145
+ --exclude-namespace
146
+ -f, --filter FILTER Selector filter for pods to be checked
147
+ -p, --pods PODS List of pods to check
148
+ -r, --restart COUNT Threshold for number of restarts allowed
149
+ ```
150
+
108
151
  **handler-kube-pod.rb**
109
152
  ```
110
153
  Usage: handler-kube-pod.rb (options)
@@ -130,6 +173,21 @@ Usage: handler-kube-pod.rb (options)
130
173
  }
131
174
  ```
132
175
 
176
+ **metrics-pods**
177
+ ```
178
+ Usage: metrics-pods.rb (options)
179
+ --ca-file CA-FILE CA file to verify API server cert
180
+ --cert CERT-FILE Client cert to present
181
+ --key KEY-FILE Client key for the client cert
182
+ --in-cluster Use service account authentication
183
+ --password PASSWORD If user is passed, also pass a password
184
+ -s, --api-server URL URL to API server
185
+ -t, --token TOKEN Bearer token for authorization
186
+ --token-file TOKEN-FILE File containing bearer token for authorization
187
+ -u, --user USER User with access to API
188
+ -v, --api-version VERSION API version
189
+ ```
190
+
133
191
  `api_server` and `api_version` can still be used for backwards compatibility,
134
192
  but `server` and `version` will take precedence.
135
193
 
@@ -32,7 +32,6 @@
32
32
  # -f, --filter FILTER Selector filter for pods to be checked
33
33
  # -p, --pods PODS Optional list of pods to check.
34
34
  # Defaults to 'all'
35
- # -r, --restart COUNT Threshold for number of restarts allowed
36
35
  #
37
36
  # NOTES:
38
37
  # => The filter used for the -f flag is in the form key=value. If multiple
@@ -62,13 +61,6 @@ class AllPodsAreReady < Sensu::Plugins::Kubernetes::CLI
62
61
  proc: proc(&:to_i),
63
62
  default: 300
64
63
 
65
- option :restart_count,
66
- description: 'Threshold for number of restarts allowed',
67
- short: '-r COUNT',
68
- long: '--restart',
69
- proc: proc(&:to_i),
70
- default: 10
71
-
72
64
  option :pod_filter,
73
65
  description: 'Selector filter for pods to be checked',
74
66
  short: '-f FILTER',
@@ -84,7 +76,6 @@ class AllPodsAreReady < Sensu::Plugins::Kubernetes::CLI
84
76
  def run
85
77
  pods_list = []
86
78
  failed_pods = []
87
- restarted_pods = []
88
79
  pods = []
89
80
  if config[:pod_filter].nil?
90
81
  pods_list = parse_list(config[:pod_list])
@@ -101,29 +92,17 @@ class AllPodsAreReady < Sensu::Plugins::Kubernetes::CLI
101
92
  next if config[:exclude_namespace].include?(pod.metadata.namespace)
102
93
  next unless pods_list.include?(pod.metadata.name) || pods_list.include?('all')
103
94
  # Check for pending state
104
- if pod.status.phase == 'Pending'
105
- pod_stamp = Time.parse(pod.metadata.creationTimestamp)
106
- if (Time.now.utc - pod_stamp.utc).to_i > config[:pending_timeout]
107
- failed_pods << "#{pod.metadata.namespace}.#{pod.metadata.name}"
108
- end
109
- end
110
- # Check restarts
111
- next if pod.status.containerStatuses.nil?
112
- pod.status.containerStatuses.each do |container|
113
- if container.restartCount.to_i > config[:restart_count]
114
- restarted_pods << "#{pod.metadata.namespace}.#{container.name}"
115
- end
95
+ next unless pod.status.phase == 'Pending'
96
+ pod_stamp = Time.parse(pod.metadata.creationTimestamp)
97
+ puts pod.metadata.name
98
+ if (Time.now.utc - pod_stamp.utc).to_i > config[:pending_timeout]
99
+ failed_pods << "#{pod.metadata.namespace}.#{pod.metadata.name}"
116
100
  end
117
101
  end
118
-
119
- if failed_pods.empty? && restarted_pods.empty?
102
+ if failed_pods.empty?
120
103
  ok 'All pods are reporting as ready'
121
- elsif failed_pods.empty?
122
- critical "Pods exceeded restart threshold: #{restarted_pods.join(' ')}"
123
- elsif restarted_pods.empty?
124
- critical "Pods exceeded pending threshold: #{failed_pods.join(' ')}"
125
104
  else
126
- critical "Pod restart and pending thresholds exceeded, pending: #{failed_pods.join(' ')} restarting: #{restarted_pods.join(' ')}"
105
+ critical "Pods exceeded pending threshold: #{failed_pods.join(' ')}"
127
106
  end
128
107
  rescue KubeException => e
129
108
  critical 'API error: ' << e.message
@@ -0,0 +1,116 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-kube-pods-restarting
4
+ #
5
+ # DESCRIPTION:
6
+ # => Check if pods are constantly restarting
7
+ #
8
+ # OUTPUT:
9
+ # plain text
10
+ #
11
+ # PLATFORMS:
12
+ # Linux
13
+ #
14
+ # DEPENDENCIES:
15
+ # gem: sensu-plugin
16
+ # gem: kube-client
17
+ #
18
+ # USAGE:
19
+ # --ca-file CA-FILE CA file to verify API server cert
20
+ # --cert CERT-FILE Client cert to present
21
+ # --key KEY-FILE Client key for the client cert
22
+ # --in-cluster Use service account authentication
23
+ # --password PASSWORD If user is passed, also pass a password
24
+ # -s, --api-server URL URL to API server
25
+ # -t, --token TOKEN Bearer token for authorization
26
+ # --token-file TOKEN-FILE File containing bearer token for authorization
27
+ # -u, --user USER User with access to API
28
+ # -v, --api-version VERSION API version
29
+ # -n NAMESPACES, Exclude the specified list of namespaces
30
+ # --exclude-namespace
31
+ # -f, --filter FILTER Selector filter for pods to be checked
32
+ # -p, --pods PODS List of pods to check
33
+ # -r, --restart COUNT Threshold for number of restarts allowed
34
+ #
35
+ # NOTES:
36
+ # => The filter used for the -f flag is in the form key=value. If multiple
37
+ # filters need to be specfied, use a comma. ex. foo=bar,red=color
38
+ #
39
+ # LICENSE:
40
+ # Barry Martin <nyxcharon@gmail.com>
41
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
42
+ # for details.
43
+ #
44
+
45
+ require 'sensu-plugins-kubernetes/cli'
46
+
47
+ class PodsRestarting < Sensu::Plugins::Kubernetes::CLI
48
+ @options = Sensu::Plugins::Kubernetes::CLI.options.dup
49
+
50
+ option :pod_list,
51
+ description: 'List of pods to check',
52
+ short: '-p PODS',
53
+ long: '--pods',
54
+ default: 'all'
55
+
56
+ option :restart_count,
57
+ description: 'Threshold for number of restarts allowed',
58
+ short: '-r COUNT',
59
+ long: '--restart',
60
+ proc: proc(&:to_i),
61
+ default: 10
62
+
63
+ option :pod_filter,
64
+ description: 'Selector filter for pods to be checked',
65
+ short: '-f FILTER',
66
+ long: '--filter'
67
+
68
+ option :exclude_namespace,
69
+ description: 'Exclude the specified list of namespaces',
70
+ short: '-n NAMESPACES',
71
+ long: '--exclude-namespace',
72
+ proc: proc { |a| a.split(',') },
73
+ default: ''
74
+
75
+ def run
76
+ pods_list = []
77
+ restarted_pods = []
78
+ pods = []
79
+ if config[:pod_filter].nil?
80
+ pods_list = parse_list(config[:pod_list])
81
+ pods = client.get_pods
82
+ else
83
+ pods = client.get_pods(label_selector: config[:pod_filter].to_s)
84
+ if pods.empty?
85
+ unknown 'The filter specified resulted in 0 pods'
86
+ end
87
+ pods_list = ['all']
88
+ end
89
+ pods.each do |pod|
90
+ next if pod.nil?
91
+ next if config[:exclude_namespace].include?(pod.metadata.namespace)
92
+ next unless pods_list.include?(pod.metadata.name) || pods_list.include?('all')
93
+ # Check restarts
94
+ next if pod.status.containerStatuses.nil?
95
+ pod.status.containerStatuses.each do |container|
96
+ if container.restartCount.to_i > config[:restart_count]
97
+ restarted_pods << "#{pod.metadata.namespace}.#{container.name}"
98
+ end
99
+ end
100
+ end
101
+
102
+ if restarted_pods.empty?
103
+ ok 'All pods are under restart threshold'
104
+ else
105
+ critical "Pods exceeded restart threshold: #{restarted_pods.join(' ')}"
106
+ end
107
+ rescue KubeException => e
108
+ critical 'API error: ' << e.message
109
+ end
110
+
111
+ def parse_list(list)
112
+ return list.split(',') if list && list.include?(',')
113
+ return [list] if list
114
+ ['']
115
+ end
116
+ end
@@ -0,0 +1,104 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-kube-pods-running
4
+ #
5
+ # DESCRIPTION:
6
+ # => Check if pods are in a running state
7
+ #
8
+ # OUTPUT:
9
+ # plain text
10
+ #
11
+ # PLATFORMS:
12
+ # Linux
13
+ #
14
+ # DEPENDENCIES:
15
+ # gem: sensu-plugin
16
+ # gem: kube-client
17
+ #
18
+ # Usage: ./check-kube-pods-running.rb (options)
19
+ # --ca-file CA-FILE CA file to verify API server cert
20
+ # --cert CERT-FILE Client cert to present
21
+ # --key KEY-FILE Client key for the client cert
22
+ # --in-cluster Use service account authentication
23
+ # --password PASSWORD If user is passed, also pass a password
24
+ # -s, --api-server URL URL to API server
25
+ # -t, --token TOKEN Bearer token for authorization
26
+ # --token-file TOKEN-FILE File containing bearer token for authorization
27
+ # -u, --user USER User with access to API
28
+ # -v, --api-version VERSION API version
29
+ # -n NAMESPACES, Exclude the specified list of namespaces
30
+ # --exclude-namespace
31
+ # -f, --filter FILTER Selector filter for pods to be checked
32
+ # -p, --pods PODS List of pods to check
33
+ # NOTES:
34
+ # => The filter used for the -f flag is in the form key=value. If multiple
35
+ # filters need to be specfied, use a comma. ex. foo=bar,red=color
36
+ #
37
+ # LICENSE:
38
+ # Barry Martin <nyxcharon@gmail.com>
39
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
40
+ # for details.
41
+ #
42
+
43
+ require 'sensu-plugins-kubernetes/cli'
44
+
45
+ class AllPodsAreRunning < Sensu::Plugins::Kubernetes::CLI
46
+ @options = Sensu::Plugins::Kubernetes::CLI.options.dup
47
+
48
+ option :pod_list,
49
+ description: 'List of pods to check',
50
+ short: '-p PODS',
51
+ long: '--pods',
52
+ default: 'all'
53
+
54
+ option :pod_filter,
55
+ description: 'Selector filter for pods to be checked',
56
+ short: '-f FILTER',
57
+ long: '--filter'
58
+
59
+ option :exclude_namespace,
60
+ description: 'Exclude the specified list of namespaces',
61
+ short: '-n NAMESPACES',
62
+ long: '--exclude-namespace',
63
+ proc: proc { |a| a.split(',') },
64
+ default: ''
65
+
66
+ def run
67
+ pods_list = []
68
+ failed_pods = []
69
+ pods = []
70
+ if config[:pod_filter].nil?
71
+ pods_list = parse_list(config[:pod_list])
72
+ pods = client.get_pods
73
+ else
74
+ pods = client.get_pods(label_selector: config[:pod_filter].to_s)
75
+ if pods.empty?
76
+ unknown 'The filter specified resulted in 0 pods'
77
+ end
78
+ pods_list = ['all']
79
+ end
80
+ pods.each do |pod|
81
+ next if pod.nil?
82
+ next if config[:exclude_namespace].include?(pod.metadata.namespace)
83
+ next unless pods_list.include?(pod.metadata.name) || pods_list.include?('all')
84
+ next unless pod.status.phase != 'Succeeded' && !pod.status.conditions.nil?
85
+ if pod.status.conditions[1].status == 'False' # This is the Ready state
86
+ failed_pods << pod.metadata.name
87
+ end
88
+ end
89
+
90
+ if failed_pods.empty?
91
+ ok 'All pods are reporting as ready'
92
+ else
93
+ critical "Pods found in a non-ready state: #{failed_pods.join(' ')}"
94
+ end
95
+ rescue KubeException => e
96
+ critical 'API error: ' << e.message
97
+ end
98
+
99
+ def parse_list(list)
100
+ return list.split(',') if list && list.include?(',')
101
+ return [list] if list
102
+ ['']
103
+ end
104
+ end
@@ -0,0 +1,59 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # pod-metrics
4
+ #
5
+ # DESCRIPTION:
6
+ # Will give pod counts from all the exposed services
7
+ #
8
+ # OUTPUT:
9
+ # metric data
10
+ #
11
+ # PLATFORMS:
12
+ # Linux
13
+ #
14
+ # DEPENDENCIES:
15
+ # gem: sensu-plugin
16
+ # gem: kube-client
17
+ #
18
+ # USAGE:
19
+ #
20
+ # NOTES:
21
+ #
22
+ # LICENSE:
23
+ # Copyright 2016 Chris McFee <cmcfee@kent.edu>
24
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
25
+ # for details.
26
+ require 'sensu-plugins-kubernetes/cli'
27
+ require 'sensu-plugin/metric/cli'
28
+ require 'uri'
29
+
30
+ class PodsMetrics < Sensu::Plugin::Metric::CLI::Graphite
31
+ @options = Sensu::Plugins::Kubernetes::CLI.options.dup
32
+
33
+ def run
34
+ config[:scheme] = "#{URI(config[:api_server]).host}.pods"
35
+ count = {}
36
+ client = Sensu::Plugins::Kubernetes::CLI.new.client
37
+ services = client.get_services
38
+ services.each do |s|
39
+ selector_key = []
40
+ count[s.metadata.name] = 0
41
+ services.delete(s.metadata.name)
42
+ s.spec.selector.to_h.each do |k, v|
43
+ selector_key << "#{k}=#{v}"
44
+ end
45
+ pod = nil
46
+ begin
47
+ pod = client.get_pods(label_selector: selector_key.join(',').to_s)
48
+ rescue KubeException => e
49
+ critical 'API error: ' << e.message
50
+ end
51
+ next if pod.nil?
52
+ pod.each do
53
+ count[s.metadata.name] += 1
54
+ end
55
+ end
56
+ count.each { |k, v| output "#{config[:scheme]}.#{k}", v }
57
+ ok
58
+ end
59
+ end
@@ -1,8 +1,8 @@
1
1
  module SensuPluginsKubernetes
2
2
  module Version
3
- MAJOR = 0
4
- MINOR = 1
5
- PATCH = 2
3
+ MAJOR = 1
4
+ MINOR = 0
5
+ PATCH = 0
6
6
 
7
7
  VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugins-kubernetes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 1.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: 2016-08-07 00:00:00.000000000 Z
11
+ date: 2017-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sensu-plugin
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: kubeclient
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '='
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.1.3
33
+ version: '2.3'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '='
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 1.1.3
40
+ version: '2.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: activesupport
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -184,9 +184,12 @@ executables:
184
184
  - check-kube-apiserver-available.rb
185
185
  - check-kube-nodes-ready.rb
186
186
  - check-kube-pods-pending.rb
187
+ - check-kube-pods-restarting.rb
188
+ - check-kube-pods-running.rb
187
189
  - check-kube-pods-runtime.rb
188
190
  - check-kube-service-available.rb
189
191
  - handler-kube-pod.rb
192
+ - metrics-pods.rb
190
193
  extensions: []
191
194
  extra_rdoc_files: []
192
195
  files:
@@ -196,9 +199,12 @@ files:
196
199
  - bin/check-kube-apiserver-available.rb
197
200
  - bin/check-kube-nodes-ready.rb
198
201
  - bin/check-kube-pods-pending.rb
202
+ - bin/check-kube-pods-restarting.rb
203
+ - bin/check-kube-pods-running.rb
199
204
  - bin/check-kube-pods-runtime.rb
200
205
  - bin/check-kube-service-available.rb
201
206
  - bin/handler-kube-pod.rb
207
+ - bin/metrics-pods.rb
202
208
  - lib/sensu-plugins-kubernetes.rb
203
209
  - lib/sensu-plugins-kubernetes/cli.rb
204
210
  - lib/sensu-plugins-kubernetes/client.rb
@@ -229,7 +235,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
229
235
  version: '0'
230
236
  requirements: []
231
237
  rubyforge_project:
232
- rubygems_version: 2.5.1
238
+ rubygems_version: 2.4.5
233
239
  signing_key:
234
240
  specification_version: 4
235
241
  summary: Sensu plugins for kubernetes