sensu-plugins-mongodb-mrtrotl 1.4.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 +7 -0
- data/CHANGELOG.md +1 -0
- data/LICENSE +22 -0
- data/README.md +27 -0
- data/bin/check-mongodb-metric.rb +144 -0
- data/bin/check-mongodb-query-count.rb +267 -0
- data/bin/check-mongodb.py +1644 -0
- data/bin/check-mongodb.rb +5 -0
- data/bin/metrics-mongodb-replication.rb +254 -0
- data/bin/metrics-mongodb.rb +133 -0
- data/lib/bson/__init__.py +1347 -0
- data/lib/bson/__pycache__/__init__.cpython-310.pyc +0 -0
- data/lib/bson/__pycache__/_helpers.cpython-310.pyc +0 -0
- data/lib/bson/__pycache__/binary.cpython-310.pyc +0 -0
- data/lib/bson/__pycache__/code.cpython-310.pyc +0 -0
- data/lib/bson/__pycache__/codec_options.cpython-310.pyc +0 -0
- data/lib/bson/__pycache__/dbref.cpython-310.pyc +0 -0
- data/lib/bson/__pycache__/decimal128.cpython-310.pyc +0 -0
- data/lib/bson/__pycache__/errors.cpython-310.pyc +0 -0
- data/lib/bson/__pycache__/int64.cpython-310.pyc +0 -0
- data/lib/bson/__pycache__/json_util.cpython-310.pyc +0 -0
- data/lib/bson/__pycache__/max_key.cpython-310.pyc +0 -0
- data/lib/bson/__pycache__/min_key.cpython-310.pyc +0 -0
- data/lib/bson/__pycache__/objectid.cpython-310.pyc +0 -0
- data/lib/bson/__pycache__/raw_bson.cpython-310.pyc +0 -0
- data/lib/bson/__pycache__/regex.cpython-310.pyc +0 -0
- data/lib/bson/__pycache__/son.cpython-310.pyc +0 -0
- data/lib/bson/__pycache__/timestamp.cpython-310.pyc +0 -0
- data/lib/bson/__pycache__/tz_util.cpython-310.pyc +0 -0
- data/lib/bson/_cbson.cpython-310-x86_64-linux-gnu.so +0 -0
- data/lib/bson/_helpers.py +41 -0
- data/lib/bson/binary.py +364 -0
- data/lib/bson/code.py +101 -0
- data/lib/bson/codec_options.py +414 -0
- data/lib/bson/codec_options.pyi +100 -0
- data/lib/bson/dbref.py +133 -0
- data/lib/bson/decimal128.py +314 -0
- data/lib/bson/errors.py +35 -0
- data/lib/bson/int64.py +39 -0
- data/lib/bson/json_util.py +874 -0
- data/lib/bson/max_key.py +55 -0
- data/lib/bson/min_key.py +55 -0
- data/lib/bson/objectid.py +286 -0
- data/lib/bson/py.typed +2 -0
- data/lib/bson/raw_bson.py +175 -0
- data/lib/bson/regex.py +135 -0
- data/lib/bson/son.py +208 -0
- data/lib/bson/timestamp.py +124 -0
- data/lib/bson/tz_util.py +52 -0
- data/lib/gridfs/__init__.py +1015 -0
- data/lib/gridfs/__pycache__/__init__.cpython-310.pyc +0 -0
- data/lib/gridfs/__pycache__/errors.cpython-310.pyc +0 -0
- data/lib/gridfs/__pycache__/grid_file.cpython-310.pyc +0 -0
- data/lib/gridfs/errors.py +33 -0
- data/lib/gridfs/grid_file.py +907 -0
- data/lib/gridfs/py.typed +2 -0
- data/lib/pymongo/__init__.py +185 -0
- data/lib/pymongo/__pycache__/__init__.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/_csot.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/aggregation.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/auth.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/auth_aws.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/bulk.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/change_stream.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/client_options.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/client_session.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/collation.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/collection.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/command_cursor.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/common.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/compression_support.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/cursor.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/daemon.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/database.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/driver_info.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/encryption.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/encryption_options.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/errors.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/event_loggers.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/hello.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/helpers.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/max_staleness_selectors.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/message.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/mongo_client.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/monitor.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/monitoring.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/network.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/ocsp_cache.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/ocsp_support.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/operations.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/periodic_executor.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/pool.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/pyopenssl_context.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/read_concern.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/read_preferences.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/response.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/results.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/saslprep.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/server.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/server_api.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/server_description.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/server_selectors.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/server_type.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/settings.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/socket_checker.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/srv_resolver.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/ssl_context.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/ssl_support.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/topology.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/topology_description.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/typings.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/uri_parser.cpython-310.pyc +0 -0
- data/lib/pymongo/__pycache__/write_concern.cpython-310.pyc +0 -0
- data/lib/pymongo/_cmessage.cpython-310-x86_64-linux-gnu.so +0 -0
- data/lib/pymongo/_csot.py +118 -0
- data/lib/pymongo/aggregation.py +229 -0
- data/lib/pymongo/auth.py +549 -0
- data/lib/pymongo/auth_aws.py +94 -0
- data/lib/pymongo/bulk.py +513 -0
- data/lib/pymongo/change_stream.py +457 -0
- data/lib/pymongo/client_options.py +302 -0
- data/lib/pymongo/client_session.py +1112 -0
- data/lib/pymongo/collation.py +224 -0
- data/lib/pymongo/collection.py +3204 -0
- data/lib/pymongo/command_cursor.py +353 -0
- data/lib/pymongo/common.py +984 -0
- data/lib/pymongo/compression_support.py +149 -0
- data/lib/pymongo/cursor.py +1345 -0
- data/lib/pymongo/daemon.py +141 -0
- data/lib/pymongo/database.py +1202 -0
- data/lib/pymongo/driver_info.py +42 -0
- data/lib/pymongo/encryption.py +884 -0
- data/lib/pymongo/encryption_options.py +221 -0
- data/lib/pymongo/errors.py +365 -0
- data/lib/pymongo/event_loggers.py +221 -0
- data/lib/pymongo/hello.py +219 -0
- data/lib/pymongo/helpers.py +259 -0
- data/lib/pymongo/max_staleness_selectors.py +114 -0
- data/lib/pymongo/message.py +1440 -0
- data/lib/pymongo/mongo_client.py +2144 -0
- data/lib/pymongo/monitor.py +440 -0
- data/lib/pymongo/monitoring.py +1801 -0
- data/lib/pymongo/network.py +311 -0
- data/lib/pymongo/ocsp_cache.py +87 -0
- data/lib/pymongo/ocsp_support.py +372 -0
- data/lib/pymongo/operations.py +507 -0
- data/lib/pymongo/periodic_executor.py +183 -0
- data/lib/pymongo/pool.py +1660 -0
- data/lib/pymongo/py.typed +2 -0
- data/lib/pymongo/pyopenssl_context.py +383 -0
- data/lib/pymongo/read_concern.py +75 -0
- data/lib/pymongo/read_preferences.py +609 -0
- data/lib/pymongo/response.py +109 -0
- data/lib/pymongo/results.py +217 -0
- data/lib/pymongo/saslprep.py +113 -0
- data/lib/pymongo/server.py +247 -0
- data/lib/pymongo/server_api.py +170 -0
- data/lib/pymongo/server_description.py +285 -0
- data/lib/pymongo/server_selectors.py +153 -0
- data/lib/pymongo/server_type.py +32 -0
- data/lib/pymongo/settings.py +159 -0
- data/lib/pymongo/socket_checker.py +104 -0
- data/lib/pymongo/srv_resolver.py +126 -0
- data/lib/pymongo/ssl_context.py +39 -0
- data/lib/pymongo/ssl_support.py +99 -0
- data/lib/pymongo/topology.py +890 -0
- data/lib/pymongo/topology_description.py +639 -0
- data/lib/pymongo/typings.py +39 -0
- data/lib/pymongo/uri_parser.py +624 -0
- data/lib/pymongo/write_concern.py +129 -0
- data/lib/pymongo-4.2.0.dist-info/INSTALLER +1 -0
- data/lib/pymongo-4.2.0.dist-info/LICENSE +201 -0
- data/lib/pymongo-4.2.0.dist-info/METADATA +250 -0
- data/lib/pymongo-4.2.0.dist-info/RECORD +167 -0
- data/lib/pymongo-4.2.0.dist-info/REQUESTED +0 -0
- data/lib/pymongo-4.2.0.dist-info/WHEEL +6 -0
- data/lib/pymongo-4.2.0.dist-info/top_level.txt +3 -0
- data/lib/sensu-plugins-mongodb/metrics.rb +391 -0
- data/lib/sensu-plugins-mongodb/version.rb +9 -0
- data/lib/sensu-plugins-mongodb.rb +1 -0
- metadata +407 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 4bf92415bc202c93667c938be921e397412b5581
|
|
4
|
+
data.tar.gz: bdeb2ad885fddfecf96f4c8eb3752d4227e1d069
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 3cb5d08f107811a2bb47c2fcf3a4b64e6eb6a77011b33b9011fbdb4321713bcc7b2b890d102751ae4214e94dcdb5b61a16a381f49990ec3acbfab54e10e73bba
|
|
7
|
+
data.tar.gz: 56bc629f8ee1401818ba34c448a75848e6b849c8e50a7661d2beff75360f846b7914839fd414f09544bd7fadc21a6987737d4cfab3d02679e51c203058c83a37
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Can be found at [https://github.com/boutetnico/sensu-plugins-mongodb/releases](https://github.com/boutetnico/sensu-plugins-mongodb/releases).
|
data/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2015 Sensu-Plugins
|
|
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.
|
data/README.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
## Sensu-Plugins-mongodb
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/rb/sensu-plugins-mongodb-boutetnico.svg)
|
|
4
|
+
[](https://bonsai.sensu.io/assets/boutetnico/sensu-plugins-mongodb)
|
|
5
|
+
|
|
6
|
+
## This is an unofficial fork
|
|
7
|
+
|
|
8
|
+
This fork is automatically tested, built and published to [RubyGems](https://rubygems.org/gems/sensu-plugins-mongodb-boutetnico/) and [Bonsai](https://bonsai.sensu.io/assets/boutetnico/sensu-plugins-mongodb).
|
|
9
|
+
|
|
10
|
+
## Files
|
|
11
|
+
|
|
12
|
+
* bin/check-mongodb.py
|
|
13
|
+
* bin/check-mongodb.rb - wrapper for check-mongodb.py
|
|
14
|
+
* bin/check-mongodb-metric.rb
|
|
15
|
+
* bin/check-mongodb-query-count.rb
|
|
16
|
+
* bin/metrics-mongodb.rb
|
|
17
|
+
* bin/metrics-mongodb-replication.rb
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
[Installation and Setup](http://sensu-plugins.io/docs/installation_instructions.html)
|
|
24
|
+
|
|
25
|
+
## Notes
|
|
26
|
+
|
|
27
|
+
The `pymongo` python package needs to be installed to use `check-mongodb`
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
#! /usr/bin/env ruby
|
|
2
|
+
#
|
|
3
|
+
# check-mongodb-metric.rb
|
|
4
|
+
#
|
|
5
|
+
# DESCRIPTION:
|
|
6
|
+
#
|
|
7
|
+
# OUTPUT:
|
|
8
|
+
# plain text
|
|
9
|
+
#
|
|
10
|
+
# PLATFORMS:
|
|
11
|
+
# Linux
|
|
12
|
+
#
|
|
13
|
+
# DEPENDENCIES:
|
|
14
|
+
# gem: sensu-plugin
|
|
15
|
+
# gem: mongo
|
|
16
|
+
# gem: bson
|
|
17
|
+
# gem: bson_ext
|
|
18
|
+
#
|
|
19
|
+
# USAGE:
|
|
20
|
+
# #YELLOW
|
|
21
|
+
#
|
|
22
|
+
# NOTES:
|
|
23
|
+
#
|
|
24
|
+
# LICENSE:
|
|
25
|
+
# Copyright 2016 Conversocial https://github.com/conversocial
|
|
26
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
|
27
|
+
# for details.
|
|
28
|
+
#
|
|
29
|
+
|
|
30
|
+
require 'sensu-plugin/check/cli'
|
|
31
|
+
require 'sensu-plugins-mongodb/metrics'
|
|
32
|
+
require 'mongo'
|
|
33
|
+
include Mongo
|
|
34
|
+
|
|
35
|
+
#
|
|
36
|
+
# Mongodb
|
|
37
|
+
#
|
|
38
|
+
|
|
39
|
+
class CheckMongodbMetric < Sensu::Plugin::Check::CLI
|
|
40
|
+
option :host,
|
|
41
|
+
description: 'MongoDB host',
|
|
42
|
+
long: '--host HOST',
|
|
43
|
+
default: 'localhost'
|
|
44
|
+
|
|
45
|
+
option :port,
|
|
46
|
+
description: 'MongoDB port',
|
|
47
|
+
long: '--port PORT',
|
|
48
|
+
default: 27_017
|
|
49
|
+
|
|
50
|
+
option :user,
|
|
51
|
+
description: 'MongoDB user',
|
|
52
|
+
long: '--user USER',
|
|
53
|
+
default: nil
|
|
54
|
+
|
|
55
|
+
option :password,
|
|
56
|
+
description: 'MongoDB password',
|
|
57
|
+
long: '--password PASSWORD',
|
|
58
|
+
default: nil
|
|
59
|
+
|
|
60
|
+
option :ssl,
|
|
61
|
+
description: 'Connect using SSL',
|
|
62
|
+
long: '--ssl',
|
|
63
|
+
default: false
|
|
64
|
+
|
|
65
|
+
option :ssl_cert,
|
|
66
|
+
description: 'The certificate file used to identify the local connection against mongod',
|
|
67
|
+
long: '--ssl-cert SSL_CERT',
|
|
68
|
+
default: ''
|
|
69
|
+
|
|
70
|
+
option :ssl_key,
|
|
71
|
+
description: 'The private key used to identify the local connection against mongod',
|
|
72
|
+
long: '--ssl-key SSL_KEY',
|
|
73
|
+
default: ''
|
|
74
|
+
|
|
75
|
+
option :ssl_ca_cert,
|
|
76
|
+
description: 'The set of concatenated CA certificates, which are used to validate certificates passed from the other end of the connection',
|
|
77
|
+
long: '--ssl-ca-cert SSL_CA_CERT',
|
|
78
|
+
default: ''
|
|
79
|
+
|
|
80
|
+
option :ssl_verify,
|
|
81
|
+
description: 'Whether or not to do peer certification validation',
|
|
82
|
+
long: '--ssl-verify',
|
|
83
|
+
default: false
|
|
84
|
+
|
|
85
|
+
option :debug,
|
|
86
|
+
description: 'Enable debug',
|
|
87
|
+
long: '--debug',
|
|
88
|
+
default: false
|
|
89
|
+
|
|
90
|
+
option :require_master,
|
|
91
|
+
description: 'Require the node to be a master node',
|
|
92
|
+
long: '--require-master',
|
|
93
|
+
default: false
|
|
94
|
+
|
|
95
|
+
option :metric,
|
|
96
|
+
description: 'Name of the metric to check',
|
|
97
|
+
long: '--metric METRIC',
|
|
98
|
+
short: '-m METRIC',
|
|
99
|
+
required: true
|
|
100
|
+
|
|
101
|
+
option :warn,
|
|
102
|
+
description: 'Warn if values are above this threshold',
|
|
103
|
+
short: '-w WARN',
|
|
104
|
+
proc: proc(&:to_i),
|
|
105
|
+
default: 0
|
|
106
|
+
|
|
107
|
+
option :crit,
|
|
108
|
+
description: 'Fail if values are above this threshold',
|
|
109
|
+
short: '-c CRIT',
|
|
110
|
+
proc: proc(&:to_i),
|
|
111
|
+
default: 0
|
|
112
|
+
|
|
113
|
+
def run
|
|
114
|
+
Mongo::Logger.logger.level = Logger::FATAL
|
|
115
|
+
@debug = config[:debug]
|
|
116
|
+
if @debug
|
|
117
|
+
Mongo::Logger.logger.level = Logger::DEBUG
|
|
118
|
+
config_debug = config.clone
|
|
119
|
+
config_debug[:password] = '***'
|
|
120
|
+
puts 'Arguments: ' + config_debug.inspect
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
# Get the metrics.
|
|
124
|
+
collector = SensuPluginsMongoDB::Metrics.new(config)
|
|
125
|
+
collector.connect_mongo_db('admin')
|
|
126
|
+
exit(1) if config[:require_master] && !collector.master?
|
|
127
|
+
metrics = collector.server_metrics
|
|
128
|
+
|
|
129
|
+
# Make sure the requested value is available.
|
|
130
|
+
unless metrics.key?(config[:metric])
|
|
131
|
+
unknown "Unable to find a value for metric '#{config[:metric]}'"
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
# Check the requested value against the thresholds.
|
|
135
|
+
value = metrics[config[:metric]]
|
|
136
|
+
if value >= config[:crit]
|
|
137
|
+
critical "The value of '#{config[:metric]}' exceeds #{config[:crit]}."
|
|
138
|
+
end
|
|
139
|
+
if value >= config[:warn]
|
|
140
|
+
warning "The value of '#{config[:metric]}' exceeds #{config[:warn]}."
|
|
141
|
+
end
|
|
142
|
+
ok "The value of '#{config[:metric]}' is below all threshold."
|
|
143
|
+
end
|
|
144
|
+
end
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
#! /usr/bin/env ruby
|
|
2
|
+
#
|
|
3
|
+
# check-mongodb-query-count.rb
|
|
4
|
+
#
|
|
5
|
+
# DESCRIPTION:
|
|
6
|
+
# Check how many documents are returned by a MongoDB query.
|
|
7
|
+
#
|
|
8
|
+
# OUTPUT:
|
|
9
|
+
# Plain text
|
|
10
|
+
#
|
|
11
|
+
# PLATFORMS:
|
|
12
|
+
# Linux
|
|
13
|
+
#
|
|
14
|
+
# DEPENDENCIES:
|
|
15
|
+
# gem: sensu-plugin
|
|
16
|
+
# gem: mongo
|
|
17
|
+
# gem: bson
|
|
18
|
+
# gem: bson_ext
|
|
19
|
+
# gem: json
|
|
20
|
+
#
|
|
21
|
+
# USAGE:
|
|
22
|
+
# # Check MongoDB collection "logs" for critical events
|
|
23
|
+
# ./check-mongodb-query-count.rb --user sensu --pass sensu --database test --collection logs
|
|
24
|
+
# --query '{"level":"CRITICAL"}'
|
|
25
|
+
# --minutes-previous 5
|
|
26
|
+
# -w 0 -c 10 --include-results
|
|
27
|
+
#
|
|
28
|
+
# NOTES:
|
|
29
|
+
# Ruby is shit.
|
|
30
|
+
#
|
|
31
|
+
# LICENSE:
|
|
32
|
+
# Copyright 2019 github.com/boutetnico
|
|
33
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
|
34
|
+
# for details.
|
|
35
|
+
#
|
|
36
|
+
|
|
37
|
+
require 'sensu-plugin/check/cli'
|
|
38
|
+
require 'mongo'
|
|
39
|
+
require 'json'
|
|
40
|
+
include Mongo
|
|
41
|
+
|
|
42
|
+
#
|
|
43
|
+
# Mongodb
|
|
44
|
+
#
|
|
45
|
+
|
|
46
|
+
class MongoDBQueryCount < Sensu::Plugin::Check::CLI
|
|
47
|
+
option :host,
|
|
48
|
+
description: 'MongoDB host',
|
|
49
|
+
long: '--host HOST',
|
|
50
|
+
default: 'localhost'
|
|
51
|
+
|
|
52
|
+
option :port,
|
|
53
|
+
description: 'MongoDB port',
|
|
54
|
+
long: '--port PORT',
|
|
55
|
+
default: 27_017
|
|
56
|
+
|
|
57
|
+
option :user,
|
|
58
|
+
description: 'MongoDB user',
|
|
59
|
+
long: '--user USER',
|
|
60
|
+
default: nil
|
|
61
|
+
|
|
62
|
+
option :password,
|
|
63
|
+
description: 'MongoDB password',
|
|
64
|
+
long: '--password PASSWORD',
|
|
65
|
+
default: nil
|
|
66
|
+
|
|
67
|
+
option :ssl,
|
|
68
|
+
description: 'Connect using SSL',
|
|
69
|
+
long: '--ssl',
|
|
70
|
+
default: false
|
|
71
|
+
|
|
72
|
+
option :ssl_cert,
|
|
73
|
+
description: 'The certificate file used to identify the local connection against mongod',
|
|
74
|
+
long: '--ssl-cert SSL_CERT',
|
|
75
|
+
default: ''
|
|
76
|
+
|
|
77
|
+
option :ssl_key,
|
|
78
|
+
description: 'The private key used to identify the local connection against mongod',
|
|
79
|
+
long: '--ssl-key SSL_KEY',
|
|
80
|
+
default: ''
|
|
81
|
+
|
|
82
|
+
option :ssl_ca_cert,
|
|
83
|
+
description: 'The set of concatenated CA certificates, which are used to validate certificates passed from the other end of the connection',
|
|
84
|
+
long: '--ssl-ca-cert SSL_CA_CERT',
|
|
85
|
+
default: ''
|
|
86
|
+
|
|
87
|
+
option :ssl_verify,
|
|
88
|
+
description: 'Whether or not to do peer certification validation',
|
|
89
|
+
long: '--ssl-verify',
|
|
90
|
+
default: false
|
|
91
|
+
|
|
92
|
+
option :debug,
|
|
93
|
+
description: 'Enable debug',
|
|
94
|
+
long: '--debug',
|
|
95
|
+
default: false
|
|
96
|
+
|
|
97
|
+
option :database,
|
|
98
|
+
description: 'Database to perform query on',
|
|
99
|
+
short: '-d DATABASE',
|
|
100
|
+
long: '--database DATABASE',
|
|
101
|
+
required: true
|
|
102
|
+
|
|
103
|
+
option :collection,
|
|
104
|
+
description: 'Collection to perform query on',
|
|
105
|
+
short: '-C COLLECTION',
|
|
106
|
+
long: '--collection COLLECTION',
|
|
107
|
+
required: true
|
|
108
|
+
|
|
109
|
+
option :query,
|
|
110
|
+
description: 'Query to perform',
|
|
111
|
+
short: '-q QUERY',
|
|
112
|
+
long: '--query QUERY',
|
|
113
|
+
required: true
|
|
114
|
+
|
|
115
|
+
option :warn,
|
|
116
|
+
short: '-w N',
|
|
117
|
+
long: '--warn N',
|
|
118
|
+
description: 'Result count WARNING threshold',
|
|
119
|
+
proc: proc(&:to_i),
|
|
120
|
+
default: 0
|
|
121
|
+
|
|
122
|
+
option :crit,
|
|
123
|
+
short: '-c N',
|
|
124
|
+
long: '--crit N',
|
|
125
|
+
description: 'Result count CRITICAL threshold',
|
|
126
|
+
proc: proc(&:to_i),
|
|
127
|
+
default: 0
|
|
128
|
+
|
|
129
|
+
option :invert,
|
|
130
|
+
long: '--invert',
|
|
131
|
+
description: 'Invert thresholds',
|
|
132
|
+
boolean: true
|
|
133
|
+
|
|
134
|
+
option :date_field,
|
|
135
|
+
description: 'Field to use instead of "date" for query.',
|
|
136
|
+
long: '--date-field FIELD_NAME',
|
|
137
|
+
default: 'date'
|
|
138
|
+
|
|
139
|
+
option :minutes_previous,
|
|
140
|
+
description: 'Minutes before offset to check date field against query.',
|
|
141
|
+
long: '--minutes-previous MINUTES_PREVIOUS',
|
|
142
|
+
proc: proc(&:to_i),
|
|
143
|
+
default: 0
|
|
144
|
+
|
|
145
|
+
option :hours_previous,
|
|
146
|
+
description: 'Hours before offset to check date field against query.',
|
|
147
|
+
long: '--hours-previous HOURS_PREVIOUS',
|
|
148
|
+
proc: proc(&:to_i),
|
|
149
|
+
default: 0
|
|
150
|
+
|
|
151
|
+
option :days_previous,
|
|
152
|
+
description: 'Days before offset to check date field against query.',
|
|
153
|
+
long: '--days-previous DAYS_PREVIOUS',
|
|
154
|
+
proc: proc(&:to_i),
|
|
155
|
+
default: 0
|
|
156
|
+
|
|
157
|
+
option :weeks_previous,
|
|
158
|
+
description: 'Weeks before offset to check date field against query.',
|
|
159
|
+
long: '--weeks-previous WEEKS_PREVIOUS',
|
|
160
|
+
proc: proc(&:to_i),
|
|
161
|
+
default: 0
|
|
162
|
+
|
|
163
|
+
option :months_previous,
|
|
164
|
+
description: 'Months before offset to check date field against query.',
|
|
165
|
+
long: '--months-previous MONTHS_PREVIOUS',
|
|
166
|
+
proc: proc(&:to_i),
|
|
167
|
+
default: 0
|
|
168
|
+
|
|
169
|
+
option :include_results,
|
|
170
|
+
long: '--include-results',
|
|
171
|
+
description: 'Include results in response',
|
|
172
|
+
boolean: false
|
|
173
|
+
|
|
174
|
+
def connect_mongo_db
|
|
175
|
+
address_str = "#{config[:host]}:#{config[:port]}"
|
|
176
|
+
client_opts = {}
|
|
177
|
+
client_opts[:database] = config[:database]
|
|
178
|
+
unless config[:user].nil?
|
|
179
|
+
client_opts[:user] = config[:user]
|
|
180
|
+
client_opts[:password] = config[:password]
|
|
181
|
+
end
|
|
182
|
+
if config[:ssl]
|
|
183
|
+
client_opts[:ssl] = true
|
|
184
|
+
client_opts[:ssl_cert] = config[:ssl_cert]
|
|
185
|
+
client_opts[:ssl_key] = config[:ssl_key]
|
|
186
|
+
client_opts[:ssl_ca_cert] = config[:ssl_ca_cert]
|
|
187
|
+
client_opts[:ssl_verify] = config[:ssl_verify]
|
|
188
|
+
end
|
|
189
|
+
mongo_client = Mongo::Client.new([address_str], client_opts)
|
|
190
|
+
@db = mongo_client.database
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
def query_mongo
|
|
194
|
+
collection = @db[config[:collection]]
|
|
195
|
+
begin
|
|
196
|
+
query = JSON.parse(config[:query])
|
|
197
|
+
rescue JSON::ParserError
|
|
198
|
+
unknown 'Failed to parse query. Provide a valid JSON array.'
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
start_time = Time.now.utc.to_i
|
|
202
|
+
if config[:minutes_previous] != 0
|
|
203
|
+
start_time -= (config[:minutes_previous] * 60)
|
|
204
|
+
end
|
|
205
|
+
if config[:hours_previous] != 0
|
|
206
|
+
start_time -= (config[:hours_previous] * 60 * 60)
|
|
207
|
+
end
|
|
208
|
+
if config[:days_previous] != 0
|
|
209
|
+
start_time -= (config[:days_previous] * 60 * 60 * 24)
|
|
210
|
+
end
|
|
211
|
+
if config[:weeks_previous] != 0
|
|
212
|
+
start_time -= (config[:weeks_previous] * 60 * 60 * 24 * 7)
|
|
213
|
+
end
|
|
214
|
+
if config[:months_previous] != 0
|
|
215
|
+
start_time -= (config[:months_previous] * 60 * 60 * 24 * 31)
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
query[config[:date_field]] = { '$gte' => Time.at(start_time).to_datetime }
|
|
219
|
+
|
|
220
|
+
if config[:debug]
|
|
221
|
+
puts 'Query: ' + query.inspect
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
collection.find(query)
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
def print_results(results)
|
|
228
|
+
count = results.count
|
|
229
|
+
|
|
230
|
+
if config[:include_results]
|
|
231
|
+
results.each { |document| puts document.inspect }
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
if config[:invert]
|
|
235
|
+
if count < config[:crit]
|
|
236
|
+
critical "Query count (#{count}) was below critical threshold."
|
|
237
|
+
elsif count < config[:warn]
|
|
238
|
+
warning "Query count (#{count}) was below warning threshold."
|
|
239
|
+
else
|
|
240
|
+
ok "Query count (#{count}) was ok"
|
|
241
|
+
end
|
|
242
|
+
elsif count > config[:crit]
|
|
243
|
+
critical "Query count (#{count}) was above critical threshold."
|
|
244
|
+
elsif count > config[:warn]
|
|
245
|
+
warning "Query count (#{count}) was above warning threshold."
|
|
246
|
+
else
|
|
247
|
+
ok "Query count (#{count}) was ok"
|
|
248
|
+
end
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
def run
|
|
252
|
+
Mongo::Logger.logger.level = Logger::FATAL
|
|
253
|
+
@debug = config[:debug]
|
|
254
|
+
if @debug
|
|
255
|
+
Mongo::Logger.logger.level = Logger::DEBUG
|
|
256
|
+
config_debug = config.clone
|
|
257
|
+
config_debug[:password] = '***'
|
|
258
|
+
puts 'Arguments: ' + config_debug.inspect
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
connect_mongo_db
|
|
262
|
+
|
|
263
|
+
results = query_mongo
|
|
264
|
+
|
|
265
|
+
print_results(results)
|
|
266
|
+
end
|
|
267
|
+
end
|