sensu-plugins-chrony 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1ffc7eafe93835b54dd148f675fb486fb4dc7cf1
4
+ data.tar.gz: 182bb25005fe8a9fa3e8f11b85f86268f8371112
5
+ SHA512:
6
+ metadata.gz: 80f61920c6e981c550480157c82b4403445ac57efd3a44820e484a71b769bf42413e77c1c1024bfd50bd55615ab3dc09cd6131dc671a4dfd1586ba7583aca189
7
+ data.tar.gz: 381c2829395b818b369dec89c8ea05146b4d5f53c25b08e3c11f328cb097e03812daabe5414e0e9277bd163e306665edc514f37258b243966e15da32c5b10d30
data/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ # Change Log
2
+ This project adheres to [Semantic Versioning](http://semver.org/).
3
+
4
+ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/)
5
+
6
+ ## Unreleased
7
+
8
+ ## [0.0.1] - 2015-12-28
9
+ ### Added
10
+ - Initial release
data/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ Copyright (c) 2015 Matteo Cerutti
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
data/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # Sensu plugin for monitoring Chrony NTP
2
+
3
+ A sensu plugin to monitor Chrony NTP.
4
+
5
+ The plugin generates multiple OK/WARN/CRIT/UNKNOWN events via the sensu client socket (https://sensuapp.org/docs/latest/clients#client-socket-input)
6
+ so that you do not miss state changes when monitoring offset, stratum and status.
7
+
8
+ ## Usage
9
+
10
+ The plugin accepts the following command line options:
11
+
12
+ ```
13
+ Usage: check-chrony.rb (options)
14
+ -c, --chronyc-cmd <PATH> Path to chronyc executable (default: /usr/bin/chronyc)
15
+ --crit-offset <OFFSET> Critical if OFFSET exceeds current offset (ms)
16
+ --crit-stratum <STRATUM> Critical if STRATUM exceeds current stratum
17
+ --dryrun Do not send events to sensu client socket
18
+ --warn-offset <OFFSET> Warn if OFFSET exceeds current offset (ms)
19
+ --warn-stratum <STRATUM> Warn if STRATUM exceeds current stratum
20
+ ```
21
+
22
+ ## Author
23
+ Matteo Cerutti - <matteo.cerutti@hotmail.co.uk>
@@ -0,0 +1,142 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # check-chrony.rb
4
+ #
5
+ # Author: Matteo Cerutti <matteo.cerutti@hotmail.co.uk>
6
+ #
7
+
8
+ require 'sensu-plugin/check/cli'
9
+ require 'socket'
10
+ require 'json'
11
+
12
+ class CheckChrony < Sensu::Plugin::Check::CLI
13
+ option :chronyc_cmd,
14
+ :description => "Path to chronyc executable (default: /usr/bin/chronyc)",
15
+ :short => "-c <PATH>",
16
+ :long => "--chronyc-cmd <PATH>",
17
+ :default => "/usr/bin/chronyc"
18
+
19
+ option :warn_offset,
20
+ :description => "Warn if OFFSET exceeds current offset (ms)",
21
+ :long => "--warn-offset <OFFSET>",
22
+ :default => 50
23
+
24
+ option :crit_offset,
25
+ :description => "Critical if OFFSET exceeds current offset (ms)",
26
+ :long => "--crit-offset <OFFSET>",
27
+ :default => 100
28
+
29
+ option :warn_stratum,
30
+ :description => "Warn if STRATUM exceeds current stratum",
31
+ :long => "--warn-stratum <STRATUM>",
32
+ :default => 10
33
+
34
+ option :crit_stratum,
35
+ :description => "Critical if STRATUM exceeds current stratum",
36
+ :long => "--crit-stratum <STRATUM>",
37
+ :default => 16
38
+
39
+ option :dryrun,
40
+ :description => "Do not send events to sensu client socket",
41
+ :long => "--dryrun",
42
+ :boolean => true,
43
+ :default => false
44
+
45
+ def initialize()
46
+ super
47
+ end
48
+
49
+ def send_client_socket(data)
50
+ if config[:dryrun]
51
+ puts data.inspect
52
+ else
53
+ sock = UDPSocket.new
54
+ sock.send(data + "\n", 0, "127.0.0.1", 3030)
55
+ end
56
+ end
57
+
58
+ def send_ok(check_name, msg)
59
+ event = {"name" => check_name, "status" => 0, "output" => "OK: #{msg}", "handler" => config[:handler]}
60
+ send_client_socket(event.to_json)
61
+ end
62
+
63
+ def send_warning(check_name, msg)
64
+ event = {"name" => check_name, "status" => 1, "output" => "WARNING: #{msg}", "handler" => config[:handler]}
65
+ send_client_socket(event.to_json)
66
+ end
67
+
68
+ def send_critical(check_name, msg)
69
+ event = {"name" => check_name, "status" => 2, "output" => "CRITICAL: #{msg}", "handler" => config[:handler]}
70
+ send_client_socket(event.to_json)
71
+ end
72
+
73
+ def send_unknown(check_name, msg)
74
+ event = {"name" => check_name, "status" => 3, "output" => "UNKNOWN: #{msg}", "handler" => config[:handler]}
75
+ send_client_socket(event.to_json)
76
+ end
77
+
78
+ def run
79
+ stratum = nil
80
+ offset = nil
81
+ status = nil
82
+
83
+ %x[#{config[:chronyc_cmd]} tracking].each_line do |line|
84
+ case line.downcase
85
+ when /^stratum\s*:\s*(\d+)$/
86
+ stratum = $1.to_i
87
+ when /^last offset\s*:\s*(-?[.\d]+)\s*seconds$/
88
+ # convert from seconds to milliseconds
89
+ offset = $1.to_f * 1000
90
+ when /^leap status\s*:\s*(.*?)$/
91
+ status = $1
92
+ end
93
+ end
94
+
95
+ if stratum
96
+ check_name = "chrony-stratum"
97
+ msg = "NTP stratum is #{stratum}"
98
+
99
+ if stratum >= config[:crit_stratum]
100
+ msg += ", expected < #{config[:crit_stratum]}"
101
+ send_critical(check_name, msg)
102
+ elsif stratum >= config[:warn_stratum]
103
+ msg += ", expected < #{config[:warn_stratum]}"
104
+ send_critical(check_name, msg)
105
+ else
106
+ send_ok(check_name, msg)
107
+ end
108
+ else
109
+ send_unknown(check_name, "Failed to look up NTP stratum")
110
+ end
111
+
112
+ if offset
113
+ check_name = "chrony-offset"
114
+ msg = "NTP offset is #{offset}ms"
115
+
116
+ if offset >= config[:crit_offset] or offset <= -config[:crit_offset]
117
+ msg += ", expected > -#{config[:crit_offset]} and < #{config[:crit_offset]}"
118
+ send_critical(check_name, msg)
119
+ elsif offset >= config[:warn_offset] or offset < -config[:warn_offset]
120
+ msg += ", expected > -#{config[:crit_offset]} and < #{config[:warn_offset]}"
121
+ send_critical(check_name, msg)
122
+ else
123
+ send_ok(check_name, msg)
124
+ end
125
+ else
126
+ send_unknown(check_name, "Failed to look up NTP offset")
127
+ end
128
+
129
+ if status
130
+ msg = "NTP status is '#{status}'"
131
+
132
+ if status != "normal"
133
+ msg += ", expected 'Normal'"
134
+ critical(msg)
135
+ else
136
+ ok(msg)
137
+ end
138
+ else
139
+ unknown("Failed to look up NTP status")
140
+ end
141
+ end
142
+ end
@@ -0,0 +1,9 @@
1
+ module SensuPluginsChrony
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
@@ -0,0 +1 @@
1
+ require 'sensu-plugins-chrony/version'
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sensu-plugins-chrony
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Matteo Cerutti
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sensu-plugin
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.2.0
27
+ description: This plugin provides facilities for monitoring Chrony NTP
28
+ email: "<matteo.cerutti@hotmail.co.uk>"
29
+ executables:
30
+ - check-chrony.rb
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - CHANGELOG.md
35
+ - LICENSE
36
+ - README.md
37
+ - bin/check-chrony.rb
38
+ - lib/sensu-plugins-chrony.rb
39
+ - lib/sensu-plugins-chrony/version.rb
40
+ homepage: https://github.com/m4ce/sensu-plugins-chrony
41
+ licenses:
42
+ - MIT
43
+ metadata:
44
+ maintainer: "@m4ce"
45
+ development_status: active
46
+ production_status: stable
47
+ release_draft: 'false'
48
+ release_prerelease: 'false'
49
+ post_install_message: You can use the embedded Ruby by setting EMBEDDED_RUBY=true
50
+ in /etc/default/sensu
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: 1.9.3
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubyforge_project:
66
+ rubygems_version: 2.4.5.1
67
+ signing_key:
68
+ specification_version: 4
69
+ summary: Sensu plugins for monitoring Chrony NTP
70
+ test_files: []