monit
Version information
This version is compatible with:
- Puppet Enterprise 2023.2.x, 2023.1.x, 2023.0.x, 2021.7.x, 2021.6.x, 2021.5.x, 2021.4.x, 2021.3.x, 2021.2.x, 2021.1.x, 2021.0.x, 2019.8.x, 2019.7.x, 2019.5.x, 2019.4.x, 2019.3.x, 2019.2.x, 2019.1.x, 2019.0.x, 2018.1.x, 2017.3.x, 2017.2.x, 2017.1.x, 2016.5.x, 2016.4.x
- Puppet >= 4.0.0 < 8.0.0
- FreeBSD, , , ,
Start using this module
Add this module to your Puppetfile:
mod 'sbitio-monit', '2.2.2'
Learn more about managing modules with a PuppetfileDocumentation
monit
Table of Contents
- Description
- Setup - The basics of getting started with monit
- Usage - Configuration options and additional functionality
- Reference - An under-the-hood peek at what the module is doing and how
- Limitations - OS compatibility, etc.
- Development - Guide for contributing to the module
Description
Performs installation and configuration of Monit service, along with fine grained definition of checks.
All check types provided by Monit are supported. Namely: directory
, fifo
,
file
, filesystem
, host
, process
, program
, and system
.
In adition to primitive types, a compound check type is provided: service
.
It is a set of primitives to check a service's init script, binary and process.
Setup
Beginning with monit
include '::monit'
is enough to get you up and running. It will configure the basis of monit, with HTTP server listening at localhost:2812
and a system check for LOADAVG
, CPU
, MEMORY
and FILESYSTEM
at /
.
To pass in parameters and override default configuration:
class { '::monit':
check_interval => 60,
check_start_delay => 120,
mailserver => 'localhost',
eventqueue => true,
alerts => ['root@localhost', 'sla1@example.com only on { timeout, nonexist }'],
httpserver => true,
httpserver_allow => ['admin:secret'],
}
Usage
All parameters for the monit module are contained within the main ::monit
class, so for any function of the module, set the options you want.
See the common usages below for examples.
Check types are implemented by defined types, named after monit::check::TYPE
.
All check types have several configuration options in common (ex: group,
priority, alerts, dependencies, etc.), along with the check specific options.
On the other hand, monit::check
defined type is a facade for all check types.
It works as a single entry point to declare any type of check in the same way.
Common configuration options are parameters of the defined type, and check
specific options are passed through a hash in the config
parameter.
So there're several entry points to declare your own checks:
- Create an instance of the specific defined type for the given check (ex:
monit::check::TYPE
) - Create an instance of the generic
monit::check
defined type, and pass in the details of the check - Pass in a hash of checks to
::monit
class. This enables providing the checks from Hiera, with your preferred merge strategy
Install and enable monit
include '::monit'
Customize the system check
class { '::monit':
system_cpu_wait => '40%',
system_memory => '84%',
system_loadavg_1min => 14.0,
system_fs_space_usage => '88%',
system_fs => ['/', '/mnt/backups'],
}
Declare a check by instantiating the check's defined type
include ::monit
monit::check::filesystem { 'somefs':
paths => ['/mount/somefs',],
tests => [
{'type' => 'fsflags'},
{'type' => 'permission', 'value' => '0755'},
{'type' => 'space', 'operator' => '>', 'value' => '80%'},
]
}
Declare a check by instantiating the generic check defined type
include ::monit
# Add a check for ntp process.
monit::check { 'ntp':
type => 'process',
config => {
'pidfile' => '/var/run/ntpd.pid',
'program_start' => '/etc/init.d/ntp start',
'program_stop' => '/etc/init.d/ntp stop',
},
tests => [
{
'type' => 'connection',
'host' => '127.0.0.1',
'port' => '123',
'protocol' => 'ntp',
'action' => 'restart',
},
],
}
Provide the monit class with a check for ssh service
include::monit
class { '::monit':
checks => {
'sshd' => {
'type' => 'service',
'config' => {
'pidfile' => '/var/run/sshd.pid',
},
'tests' => [
{
'type' => 'connection',
'host' => '127.0.0.1',
'port' => '22',
'protocol' => 'ssh',
'action' => 'restart',
},
],
},
}
}
Provide full module config and checks from Hiera
# Main monitrc configuration options.
monit::check_interval: '60'
monit::check_start_delay: '120'
monit::mailserver: 'localhost'
monit::eventqueue: true
monit::alerts:
- 'root@localhost'
- 'sla1@example.com only on { timeout, nonexist }'
monit::httpserver: true
monit::httpserver_allow:
- 'admin:secret'
# Tweak system check.
monit::system_fs: ['/', '/mnt/backups']
# Add some checks.
monit::checks:
somefs:
type: filesystem
config:
paths:
- /
- /mount/somefs
tests:
- type: fsflags
- type: permission
value: '0755'
- type: space
operator: '>'
value: 80%
sshd:
type: process
config:
pidfile: /var/run/sshd.pid
program_start: /etc/init.d/sshd start
program_stop: /etc/init.d/sshd stop
tests:
- type: connection
host: 127.0.0.1
port: 22
protocol: ssh
action: restart
php5-fpm:
type: process
config:
pidfile: /var/run/php5-fpm.pid
program_start: /etc/init.d/php5-fpm start
program_stop: /etc/init.d/php5-fpm stop
tests:
- type: connection
host: 127.0.0.1
port: 9000
socket_type: TCP
protocol: GENERIC
protocol_test:
- send: '"\0x01\0x09\0x00\0x00\0x00\0x00\0x08\0x00\0x00\0x00\0x00\0x00\0x00\0x00\0x00\0x00"'
expect: '"\0x01\0x0A"'
action: restart
ntp:
type: process
config:
pidfile: /var/run/ntpd.pid
program_start: /etc/init.d/ntpd start
program_stop: /etc/init.d/ntpd stop
tests:
- type: connection
host: 127.0.0.1
socket_type: udp
port: 123
protocol: ntp
action: restart
varnish:
type: process
config:
pidfile: /var/run/varnish.pid
program_start: /etc/init.d/varnish start
program_stop: /etc/init.d/varnish stop
tests:
- type: connection
host: 127.0.0.1
port: 8080
protocol: http
protocol_test:
request: /health.varnish
- type: cpu(user)
operator: '>'
value: 60%
tolerance:
cycles: 2
- type: children
operator: '>'
value: 150
httpd:
type: service
config:
pidfile: /var/run/httpd/httpd.pid
binary: /usr/sbin/httpd
tests:
- type: connection
host: 127.0.0.1
port: 80
protocol: http
# Notice: Param 'HOSTHEADER' changed to 'HTTP HEADERS' in monit 5.9
# see https://mmonit.com/monit/changes/
http_headers:
type: host
config:
address: 127.0.0.1
tests:
- type: connection
host: 127.0.0.1
port: 80
protocol: http
protocol_test:
request: /
status: 200
http headers: '[host: www.example.com]'
custom-script:
type: program
config:
path: /path/to/custom/pingcheck.sh
tests:
- type: status
operator: '!='
value: 0
tolerance:
cycles: 2
action: exec
exec: sudo /sbin/reboot
# uid, git and repeat_every are optional.
uid: root
gid: root
repeat_every: 1
reboot:
type: system
tests:
- type: uptime
operator: '<'
value: '3 MINUTES'
There's a bunch of examples for configuring real services across Debian and RedHat families in sbitio/ducktape module. Please refer to manifests/*/external/monit.pp files.
Reference
See Puppet Strings doc at doc/index.html
Limitations
This module requires Puppet 4.x or above, and is compatible with the following OSes/versions:
- FreeBSD
- Debian 7, 8, 9, 10, 11
- RedHat/CentOS 7, 8
- Ubuntu 12.04, 14.04, 16.04
For Puppet 3 or older versions of Debian, please use 1.x.x releases.
Development
Development happens on GitHub.
Please log issues for any bug report, feature or support request.
Pull requests are welcome.
License
MIT License, see LICENSE file
Contact
Use contact form on http://sbit.io
Changelog
2.2.2 (2023-10-17)
Fixed bugs:
- Regression: parameter 'every' expects a String value #69
- Regression: parameter 'tests' index 1 entry 'value' expects a value of type Array, Hash, Integer, or String, got Float #68
2.2.1 (2023-10-16)
Closed issues:
- Puppet 7 support #67
2.2.0 (2023-10-11)
Closed issues:
- Cant configure start/stop_program at type host #64
- Centos 7 - undef lsbmajdistrelease (legacy facts) #56
- Lookup variables in scope from templates -> Sets 'undef' in some environments. #20
Merged pull requests:
- Host ping #66 (jonhattan)
- Check network #65 (jonhattan)
- Add fault tolerance for system tests. Same for all #63 (jonhattan)
- Add support for service poll time (only positive) #62 (NITEMAN)
- Support
https
as test protocol #61 (mpdude) - Declare compatibility with Ubuntu 20.04 #60 (mpdude)
- Allow up-to-date versions of the stdlib and concat modules to be used #59 (mpdude)
- pdk update #58 (KrisMagjistari)
- Switch to use modern facts. Fix #56 #57 (NITEMAN)
- Fix system_fs_*_usage params #55 (NITEMAN)
2.1.0 (2020-09-23)
Implemented enhancements:
- Use type aliases to improve code legibility #52
Fixed bugs:
- Allow to remove (ensure=absent) system checks #53
Closed issues:
- Add support for EXEC action extra options #48
- exec action param becomes uppercase #47
- idfile and statefile are set to undef on RedHat systems #46
- Start and stop program parameters #34
- Add UPTIME tests to valid tests #16
Merged pull requests:
2.0.1 (2020-01-29)
Closed issues:
Merged pull requests:
2.0.0 (2020-01-15)
Closed issues:
- Deprecate hiera_merge_strategy #42
- Check all filesystems by default (not only /) #41
- Upgrade module to support Puppet4 #35
- Make IP address parameter optional #33
- Wrong permissions for monitrc #32
- Concat requirements #29
- permissions of monitrc on Debian 9.1 - monit 1:5.20.0-6 #28
Merged pull requests:
- Add support for EXIST check #39 (NITEMAN)
- Added FreeBSD support #38 (jurgenweber)
- Make bind IP address optional. #31 (wdec)
- Add example for Centos 7 #27 (nvtkaszpir)
- Fixed the host check having an OR-check when it should be an AND-check #24 (aepgit)
- Added checksum test for files. #21 (triforce)
- Update instance.pp #19 (MNiedzielski)
- missing space for tests before UNIXSOCKET #18 (gytisgreitai)
- Make monit auto-start on Debian Squeeze, as it does not do so by default when installed #15 (thatgraemeguy)
- fix 'http headers' param in test-validation #13 (ThomasLohner)
- Made monit's PROGRAM STATUS TESTING work, made ACTION EXEC work, made exec path accept parameters. #9 (derjohn)
- Support hiera_hash for custom checks #8 (himpich)
1.1.0 (2017-08-21)
Closed issues:
- On cetons missing repo epel #26
- Checking error in host.pp #22
- monit won't start on Debian Squeeze #14
- Puppet 4 and puppetserver setup > add puppetlabs-concat to fix this dependency issue #12
- template vars are missing scope #11
1.0.0 (2015-07-07)
0.3.3 (2015-07-07)
Merged pull requests:
0.3.2 (2015-07-06)
Closed issues:
- Systemd file paths differs on Debian and Redhat/Centos (regresion introduced in 4ff388c) #6
0.3.1 (2015-07-06)
0.3.0 (2015-07-06)
Closed issues:
- Add support for MATCHING in services (when no PID available) #4
- Add "default" support for CentOS 7 (systemd instead of initd) #3
- Improve quality score #2
- monit_validate_tests.rb: warning: already initialized constant #1
Merged pull requests:
- Update monit_validate_tests.rb #5 (MNiedzielski)
0.2.1 (2015-04-23)
0.2.0 (2015-04-23)
0.1.0 (2015-04-23)
* This Changelog was automatically generated by github_changelog_generator
Dependencies
- puppetlabs/stdlib (>= 4.14.0 < 9.0.0)
- puppetlabs/concat (>= 1.2.1 < 8.0.0)
The MIT License (MIT) Copyright (c) 2014 SB IT Media, S.L. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.