sensu-plugins-barman-checks 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +14 -0
- data/LICENSE +22 -0
- data/README.md +25 -0
- data/bin/check-barman-backup-status-class.rb +121 -0
- data/bin/check-barman-backup-status.rb +35 -0
- data/lib/sensu-plugins-barman-checks/version.rb +9 -0
- data/lib/sensu-plugins-barman-checks.rb +1 -0
- metadata +230 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4df5e979e193f81bfb4ac5a5dd83cd705a18cf33
|
4
|
+
data.tar.gz: 947aa108e79831daca10d7c47ea7a5305c00bdb4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f72757bd3332be66d4208fb49375044b714f08fafd3971d69d8d4f06a3295817149c7526881ae9876058d561cc7a5c5bd43bae3907d1f28e964d7908c80fc6e4
|
7
|
+
data.tar.gz: 238230be8b3f1c022be0c855f472074877f231c8e899b34d032d952d56558d1c90ce8172eaf391ff99fcf86e90071a2c8daec0e2ec3754bb74c3f7cef43a0e0e
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,14 @@
|
|
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 - 2016-11-29
|
9
|
+
### Added
|
10
|
+
- Added barman backup age check
|
11
|
+
- Added barman backup minimum check
|
12
|
+
- Added barman backup status check
|
13
|
+
|
14
|
+
[Unreleased]: https://github.com/sbrimhall/sensu-plugins-barman-checks/compare/0.1.0...HEAD
|
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,25 @@
|
|
1
|
+
## Sensu-Plugins-barman-checks
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/sbrimhall/sensu-plugins-barman-checks.svg?branch=master)](https://travis-ci.org/sbrimhall/sensu-plugins-barman-checks)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/sensu-plugins-barman-checks.svg)](http://badge.fury.io/rb/sensu-plugins-barman-checks)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/sbrimhall/sensu-plugins-barman-checks/badges/gpa.svg)](https://codeclimate.com/github/sbrimhall/sensu-plugins-barman-checks)
|
6
|
+
[![Test Coverage](https://codeclimate.com/github/sensu-plugins/sensu-plugins-barman-checks/badges/coverage.svg)](https://codeclimate.com/github/sbrimhall/sensu-plugins-barman-checks)
|
7
|
+
[![Dependency Status](https://gemnasium.com/sbrimhall/sensu-plugins-barman-checks.svg)](https://gemnasium.com/sbrimhall/sensu-plugins-barman-checks)
|
8
|
+
|
9
|
+
## Functionality
|
10
|
+
|
11
|
+
This plugin is for monitoring Barman PostgreSQL backups. Each configured server on the barman instance is
|
12
|
+
checked to ensure it has backups, that backup status is successful, and that the age of backups is not too old.
|
13
|
+
|
14
|
+
## Files
|
15
|
+
* bin/check-barman-backup-status.rb
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
/path_to_sensu/embedded/bin/ruby /path_to_sensu/embedded/bin/check-barman-backup-status.rb [-m MIN_NUMBER_BACKUPS] [--max-age MAX_AGE_IN_HOURS_OF_LATEST_BACKUP] [--warn WARN_AGE_IN_HOURS_OF_LATEST_BACKUP]
|
20
|
+
|
21
|
+
## Installation
|
22
|
+
|
23
|
+
[Installation and Setup](http://sensu-plugins.io/docs/installation_instructions.html)
|
24
|
+
|
25
|
+
## Notes
|
@@ -0,0 +1,121 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
#
|
4
|
+
# Check Barman Backup Status
|
5
|
+
# ===
|
6
|
+
#
|
7
|
+
# DESCRIPTION:
|
8
|
+
# This plugin checks the status and age of Barman backups for each configured server
|
9
|
+
# Do not run this script directly. It needs to be called via check-barman-backup-status.rb
|
10
|
+
# because the barman gem requires sudo access to work properly and we have to run as
|
11
|
+
# the sensu user, so we use a sudo wrapper in check-barman-backup-status.rb
|
12
|
+
#
|
13
|
+
# PLATFORMS:
|
14
|
+
# Linux, BSD, Solaris
|
15
|
+
#
|
16
|
+
# DEPENDENCIES:
|
17
|
+
# Sensu Plugins run as the sensu user and barman needs to run with sudo or barman user
|
18
|
+
# gem: sensu-plugin
|
19
|
+
# gem: sudo
|
20
|
+
# gem: rbarman
|
21
|
+
#
|
22
|
+
# LICENSE:
|
23
|
+
# Copyright 2016 Scott Brimhall <scottbrimhall@gmail.com>
|
24
|
+
#
|
25
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
26
|
+
# for details.
|
27
|
+
|
28
|
+
require 'sensu-plugin/check/cli'
|
29
|
+
require 'rbarman'
|
30
|
+
require 'time'
|
31
|
+
|
32
|
+
# main plugin class
|
33
|
+
class CheckBarmanBackupStatus < Sensu::Plugin::Check::CLI
|
34
|
+
option :min_backups,
|
35
|
+
description: 'Minimum number of backups that should exist before alerting',
|
36
|
+
short: '-m',
|
37
|
+
long: '--min-backups',
|
38
|
+
required: true,
|
39
|
+
default: 1
|
40
|
+
|
41
|
+
option :warn_age,
|
42
|
+
description: 'The maximum age of backup before warning (in hours)',
|
43
|
+
short: '-w',
|
44
|
+
long: '--warn-age',
|
45
|
+
required: true,
|
46
|
+
default: 24
|
47
|
+
|
48
|
+
option :max_age,
|
49
|
+
description: 'The maximum age of backup before critical alert (in hours)',
|
50
|
+
long: '--max-age',
|
51
|
+
required: true,
|
52
|
+
default: 25
|
53
|
+
|
54
|
+
option :homedir,
|
55
|
+
description: 'The home directory path for barman',
|
56
|
+
long: '--homedir PATH',
|
57
|
+
required: true,
|
58
|
+
default: '/var/lib/barman'
|
59
|
+
|
60
|
+
def time_diff(start_time, end_time)
|
61
|
+
diff = end_time.to_i - start_time.to_i
|
62
|
+
hours = (diff / 60 / 60)
|
63
|
+
hours
|
64
|
+
end
|
65
|
+
|
66
|
+
def run
|
67
|
+
# The rbarman gem defaults to ENV['HOME'] for things. Need to set this to barman's homedir
|
68
|
+
ENV['HOME'] = config[:homedir]
|
69
|
+
start_time = Time.now
|
70
|
+
@crit = []
|
71
|
+
@warn = []
|
72
|
+
|
73
|
+
servers = Rbarman::Servers.all(opts = {})
|
74
|
+
|
75
|
+
servers.each do |server|
|
76
|
+
puts "Name: #{server.name}"
|
77
|
+
backups = RBarman::Backups.all(server.name, opts = {})
|
78
|
+
|
79
|
+
if backups.count < config[:min_backups].to_i
|
80
|
+
@crit << "Minimum backups not met for server #{server.name}. Count is #{backups.count}"
|
81
|
+
else
|
82
|
+
puts "Number of backups for server #{server.name}: #{backups.count}"
|
83
|
+
end
|
84
|
+
|
85
|
+
latest_backup = backups.latest.backup_end
|
86
|
+
backup_time = Time.parse(latest_backup)
|
87
|
+
backup_age = time_diff(backup_time, start_time)
|
88
|
+
|
89
|
+
if backup_age < config[:warn_age].to_i
|
90
|
+
@warn << "Warning threshold for backup age exceeded for latest backup on server #{server.name}. Age is #{backup_age} hour(s)"
|
91
|
+
end
|
92
|
+
|
93
|
+
if backup_age < config[:max_age].to_i
|
94
|
+
@crit << "Maximum age exceeded for latest backup on server #{server.name}. Age is: #{backup_age} hour(s)"
|
95
|
+
else
|
96
|
+
puts "Age of latest backup for server #{server.name}: #{backup_age} hour(s)"
|
97
|
+
end
|
98
|
+
|
99
|
+
backups.each do |b|
|
100
|
+
puts "Backup ID: #{b.id}"
|
101
|
+
if b.status != 'done'
|
102
|
+
@crit << "Backup ID #{b.id} is in error state (#{b.status}) for server #{server.name}"
|
103
|
+
else
|
104
|
+
puts "Backup Status: #{b.status}"
|
105
|
+
end
|
106
|
+
|
107
|
+
puts "Backup Size: #{b.size} bytes"
|
108
|
+
puts "Backup Wal file size: #{b.wal_file_size} bytes"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
# Assuming we got this far, exit cleanly
|
113
|
+
if @crit.empty? && @warn.empty?
|
114
|
+
ok
|
115
|
+
elsif !@crit.empty?
|
116
|
+
critical "critical: #{@crit}"
|
117
|
+
elsif !@warn.empty?
|
118
|
+
warning "warning: #{@warn}"
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
#
|
4
|
+
# Sudo wrapper for running barman backup status check
|
5
|
+
# ===
|
6
|
+
#
|
7
|
+
# DESCRIPTION:
|
8
|
+
# This plugin checks the status and age of Barman backups for each configured server
|
9
|
+
# The sensu user must be configured as NOPASSWD in sudoers for this script in order to work.
|
10
|
+
#
|
11
|
+
# PLATFORMS:
|
12
|
+
# Linux, BSD, Solaris
|
13
|
+
#
|
14
|
+
# DEPENDENCIES:
|
15
|
+
# Sensu Plugins run as the sensu user and barman needs to run with sudo or barman user
|
16
|
+
# gem: sensu-plugin
|
17
|
+
# gem: sudo
|
18
|
+
# gem: rbarman
|
19
|
+
#
|
20
|
+
# LICENSE:
|
21
|
+
# Copyright 2016 Scott Brimhall <scottbrimhall@gmail.com>
|
22
|
+
#
|
23
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
24
|
+
# for details.
|
25
|
+
|
26
|
+
require './check-barman-backup-status-class'
|
27
|
+
require 'sudo'
|
28
|
+
|
29
|
+
# Wrapper around the actual check class since barman requires root or the barman user
|
30
|
+
# and we have to run as the sensu user to run the plugin
|
31
|
+
CheckBarmanBackupStatus.new
|
32
|
+
sudo = Sudo::Wrapper.new
|
33
|
+
sudo.start!
|
34
|
+
sudo[CheckBarmanBackupStatus].run
|
35
|
+
sudo.stop!
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'sensu-plugins-barman-checks/version'
|
metadata
ADDED
@@ -0,0 +1,230 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sensu-plugins-barman-checks
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Scott Brimhall
|
8
|
+
- Sensu-Plugins and contributors
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2016-11-29 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: sensu-plugin
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.2'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.2'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rbarman
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 0.0.15
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 0.0.15
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: sudo
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0.1'
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0.1'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: bundler
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '1.7'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '1.7'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: codeclimate-test-reporter
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0.4'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0.4'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: github-markup
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '1.3'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '1.3'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: pry
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - "~>"
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0.10'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - "~>"
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0.10'
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: rake
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - "~>"
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '10.5'
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - "~>"
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '10.5'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: redcarpet
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - "~>"
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '3.2'
|
133
|
+
type: :development
|
134
|
+
prerelease: false
|
135
|
+
version_requirements: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - "~>"
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '3.2'
|
140
|
+
- !ruby/object:Gem::Dependency
|
141
|
+
name: rubocop
|
142
|
+
requirement: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - "~>"
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: 0.40.0
|
147
|
+
type: :development
|
148
|
+
prerelease: false
|
149
|
+
version_requirements: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - "~>"
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: 0.40.0
|
154
|
+
- !ruby/object:Gem::Dependency
|
155
|
+
name: rspec
|
156
|
+
requirement: !ruby/object:Gem::Requirement
|
157
|
+
requirements:
|
158
|
+
- - "~>"
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: '3.4'
|
161
|
+
type: :development
|
162
|
+
prerelease: false
|
163
|
+
version_requirements: !ruby/object:Gem::Requirement
|
164
|
+
requirements:
|
165
|
+
- - "~>"
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
version: '3.4'
|
168
|
+
- !ruby/object:Gem::Dependency
|
169
|
+
name: yard
|
170
|
+
requirement: !ruby/object:Gem::Requirement
|
171
|
+
requirements:
|
172
|
+
- - "~>"
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: '0.8'
|
175
|
+
type: :development
|
176
|
+
prerelease: false
|
177
|
+
version_requirements: !ruby/object:Gem::Requirement
|
178
|
+
requirements:
|
179
|
+
- - "~>"
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: '0.8'
|
182
|
+
description: |-
|
183
|
+
This plugin provides checking of Barman
|
184
|
+
PostgreSQL backups to ensure they are being
|
185
|
+
properly generated.
|
186
|
+
email: "<scottbrimhall@gmail.com>"
|
187
|
+
executables:
|
188
|
+
- check-barman-backup-status-class.rb
|
189
|
+
- check-barman-backup-status.rb
|
190
|
+
extensions: []
|
191
|
+
extra_rdoc_files: []
|
192
|
+
files:
|
193
|
+
- CHANGELOG.md
|
194
|
+
- LICENSE
|
195
|
+
- README.md
|
196
|
+
- bin/check-barman-backup-status-class.rb
|
197
|
+
- bin/check-barman-backup-status.rb
|
198
|
+
- lib/sensu-plugins-barman-checks.rb
|
199
|
+
- lib/sensu-plugins-barman-checks/version.rb
|
200
|
+
homepage: https://github.com/sbrimhall/sensu-plugins-barman-checks
|
201
|
+
licenses:
|
202
|
+
- MIT
|
203
|
+
metadata:
|
204
|
+
maintainer: sbrimhall
|
205
|
+
development_status: active
|
206
|
+
production_status: unstable - testing recommended
|
207
|
+
release_draft: 'false'
|
208
|
+
release_prerelease: 'false'
|
209
|
+
post_install_message: You can use the embedded Ruby by setting EMBEDDED_RUBY=true
|
210
|
+
in /etc/default/sensu
|
211
|
+
rdoc_options: []
|
212
|
+
require_paths:
|
213
|
+
- lib
|
214
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
215
|
+
requirements:
|
216
|
+
- - ">="
|
217
|
+
- !ruby/object:Gem::Version
|
218
|
+
version: 2.0.0
|
219
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
220
|
+
requirements:
|
221
|
+
- - ">="
|
222
|
+
- !ruby/object:Gem::Version
|
223
|
+
version: '0'
|
224
|
+
requirements: []
|
225
|
+
rubyforge_project:
|
226
|
+
rubygems_version: 2.4.5
|
227
|
+
signing_key:
|
228
|
+
specification_version: 4
|
229
|
+
summary: Sensu plugin for checking Barman backups
|
230
|
+
test_files: []
|