Coder Social home page Coder Social logo

sbitio / puppet-monit Goto Github PK

View Code? Open in Web Editor NEW
7.0 5.0 21.0 551 KB

Puppet module to perform installation and configuration of Monit service

Home Page: https://forge.puppetlabs.com/sbitio/monit

License: MIT License

Ruby 23.24% Puppet 59.26% HTML 17.02% Pascal 0.19% Dockerfile 0.29%

puppet-monit's Introduction

monit

Table of Contents

  1. Description
  2. Setup - The basics of getting started with monit
  3. Usage - Configuration options and additional functionality
  4. Reference - An under-the-hood peek at what the module is doing and how
  5. Limitations - OS compatibility, etc.
  6. 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', '[email protected] 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'
  - '[email protected] 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

puppet-monit's People

Contributors

derjohn avatar himpich avatar jonhattan avatar jurgenweber avatar krismagjistari avatar mniedzielski avatar mpdude avatar niteman avatar thatgraemeguy avatar thomaslohner avatar triforce avatar wdec avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

puppet-monit's Issues

Systemd file paths differs on Debian and Redhat/Centos (regresion introduced in 4ff388c)

Using ntpd as example.

CentOs 7:

# service ntpd status
Redirecting to /bin/systemctl status  ntpd.service
ntpd.service - Network Time Service
   Loaded: loaded (/usr/lib/systemd/system/ntpd.service; enabled)
   Active: active (running) since jue 2015-06-25 13:04:51 CEST; 1 weeks 4 days ago
  Process: 685 ExecStart=/usr/sbin/ntpd -u ntp:ntp $OPTIONS (code=exited, status=0/SUCCESS)
 Main PID: 703 (ntpd)
   CGroup: /system.slice/ntpd.service
           └─703 /usr/sbin/ntpd -u ntp:ntp -g

Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.

Debian 8:

# service ntp status
● ntp.service - LSB: Start NTP daemon
   Loaded: loaded (/etc/init.d/ntp)
   Active: active (running) since lun 2015-07-06 22:20:36 CEST; 2min 5s ago
  Process: 17754 ExecStop=/etc/init.d/ntp stop (code=exited, status=0/SUCCESS)
  Process: 17779 ExecStart=/etc/init.d/ntp start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/ntp.service
           └─17788 /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 106:111

Tag current release, or branch.

It would be very useful if we had a nice ref to include for versioning.
Following master is't a good idea in prod, and had coding commit hashes isn't great either.

Can you maybe create tag for the current state, or even better make a 2.x stable branch or something to follow?

Puppet 4 and puppetserver setup > add puppetlabs-concat to fix this dependency issue

On a puppet agent run

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Evaluation Error: Error while evaluating a Resource Statement, Invalid resource type concat at /etc/puppetlabs/code/environments/production/modules/monit/manifests/check/instance.pp:26:5 on node client.example.com
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run

I had to add puppetlabs-concat to my Puppetfile to fix this

Regression: parameter 'every' expects a String value

Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Resource Statement, Monit::Check::Instance[wh3]: parameter 'every' expects a String value, got Undef (file: /etc/puppetlabs/code/environments/master/modules/monit/manifests/check/system.pp, line: 46) on node wh3

exec action param becomes uppercase

class { '::monit':
      system_fs  => ['/'],
      httpserver => false,
      checks     => {
        "mycheck"             => {
          type   => 'host',
          config => {
            'address'       => '127.0.0.1',
          },
          tests  => [
            {
              'type'          => 'connection',
              'host'          => '127.0.0.1',
              'port'          => '9091',
              'protocol'      => 'http',
              'protocol_test' => {'request'=>'/ping'},
              'tolerance'     => {'cycles' =>5},
              'action'        => 'exec',
              'exec'          => '/sbin/poweroff',
            },
          ],
        }
      }

produce:

# This file is managed by Puppet. DO NOT EDIT.
CHECK HOST mycheck ADDRESS 127.0.0.1
  GROUP mycheck

  IF FAILED HOST 127.0.0.1 PORT 9091
    PROTOCOL HTTP
    REQUEST /ping
    FOR 5 CYCLES
  THEN EXEC "/SBIN/POWEROFF"

idfile and statefile are set to undef on RedHat systems

The idfile and statefile are set to undef on RedHat however the variables are then validated in the monit class as not being Optional.

Stdlib::Absolutepath $idfile = $monit::params::idfile,
Stdlib::Absolutepath $statefile = $monit::params::statefile,

This then throws a puppet agent error on RedHat based systems.

Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluat
ing a Resource Statement, Evaluation Error: Error while evaluating a Resource Statement, Class[Monit]:
parameter 'idfile' expects a Stdlib::Absolutepath = Variant[Stdlib::Windowspath = Pattern[/^(([a-zA-Z]:[\/])|([\/][\/]
[^\\\/]+[\/][^\\\/]+)|([\/][\/]?[\/][^\\\/]+))/], Stdlib::Unixpath = Pattern[/^/([^\/\0]+/)$/]] value, got Undef

These settings should be Optional since they are set to default values by monit itself if undefined.

monit_validate_tests.rb: warning: already initialized constant

Using just the example configuration given plus a single process monitor, we get the following on every run.

[foo.bar.org] out: /home/ubuntu/puppet/modules/monit/lib/puppet/parser/functions/monit_validate_tests.rb:11: warning: already initialized constant RESOURCE_TESTS
[foo.bar.org] out: /home/ubuntu/puppet/modules/monit/lib/puppet/parser/functions/monit_validate_tests.rb:17: warning: already initialized constant RESOURCE_TESTS_OPERATORS
[foo.bar.org] out: /home/ubuntu/puppet/modules/monit/lib/puppet/parser/functions/monit_validate_tests.rb:23: warning: already initialized constant PROTOCOL_TESTS
[foo.bar.org] out: /home/ubuntu/puppet/modules/monit/lib/puppet/parser/functions/monit_validate_tests.rb:30: warning: already initialized constant TEST_TYPES
[foo.bar.org] out: /home/ubuntu/puppet/modules/monit/lib/puppet/parser/functions/monit_validate_tests.rb:42: warning: already initialized constant TEST_ACTIONS
[foo.bar.org] out: /home/ubuntu/puppet/modules/monit/lib/puppet/parser/functions/monit_validate_tests.rb:11: warning: already initialized constant RESOURCE_TESTS
[foo.bar.org] out: /home/ubuntu/puppet/modules/monit/lib/puppet/parser/functions/monit_validate_tests.rb:17: warning: already initialized constant RESOURCE_TESTS_OPERATORS
[foo.bar.org] out: /home/ubuntu/puppet/modules/monit/lib/puppet/parser/functions/monit_validate_tests.rb:23: warning: already initialized constant PROTOCOL_TESTS
[foo.bar.org] out: /home/ubuntu/puppet/modules/monit/lib/puppet/parser/functions/monit_validate_tests.rb:30: warning: already initialized constant TEST_TYPES
[foo.bar.org] out: /home/ubuntu/puppet/modules/monit/lib/puppet/parser/functions/monit_validate_tests.rb:42: warning: already initialized constant TEST_ACTIONS
[foo.bar.org] out: /home/ubuntu/puppet/modules/monit/lib/puppet/parser/functions/monit_validate_tests.rb:11: warning: already initialized constant RESOURCE_TESTS
[foo.bar.org] out: /home/ubuntu/puppet/modules/monit/lib/puppet/parser/functions/monit_validate_tests.rb:17: warning: already initialized constant RESOURCE_TESTS_OPERATORS
[foo.bar.org] out: /home/ubuntu/puppet/modules/monit/lib/puppet/parser/functions/monit_validate_tests.rb:23: warning: already initialized constant PROTOCOL_TESTS
[foo.bar.org] out: /home/ubuntu/puppet/modules/monit/lib/puppet/parser/functions/monit_validate_tests.rb:30: warning: already initialized constant TEST_TYPES
[foo.bar.org] out: /home/ubuntu/puppet/modules/monit/lib/puppet/parser/functions/monit_validate_tests.rb:42: warning: already initialized constant TEST_ACTIONS

template vars are missing scope

I'm using this module with a puppet master 3.8.6 and i get lots of these errors:

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Evaluation Error: Error while evaluating a Function Call, Failed to parse template monit/check/common.erb:
  Filepath: /etc/puppet/modules/monit/templates/check/common.erb
  Line: 2
  Detail: undefined method `empty?' for nil:NilClass
 at /etc/puppet/modules/monit/manifests/check/instance.pp:33:16

This template is called by various defines which don't have a local variable called alerts, yet in the template you try to access @alterts. Wouldn't the correct way be scope['monit::alerts']?

The same issue happens in /etc/monit/monitrc:

include /*

In the template it says include <%= @conf_dir %>/* and it's called from monit::config but there is no local param conf_dir in this class. Changing the template to include <%= scope['monit::conf_dir'] %>/* fixes this problem.

Concat requirements

Hello,

I'm having some warnings that concat is not supported (currently it's supported until 3.0.0) but concat is now at version 4.1.1

I've tried so far to update metadata.json to {"name":"puppetlabs/concat","version_requirement":">= 1.2.1 < 5.0.0"} and it's seems to work correctly.

It's possible to update metadata.json to accept the new version of concat?

Also a new tag in forge would be so nice like #23 said

Thank you very much

Wrong permissions for monitrc

The templated monitrc config has incorrect permissions leading to the following message:

monit[186142]: The control file '/etc/monitrc' permission 0644 is wrong, maximum 0700 allowed.

Monit service fails to start

Puppet 7 support

Hi,

Puppet 6 already reached its EOF on February, are there plans to support puppet 7 in this module?

Thanks

Make IP address parameter optional

The use address parameter is optional in monit configs, and setting it to localhost as is done by the module is too restrictive. This patch relaxes this limitation.

Cant configure start/stop_program at type host

Hi!

Puppet7 and Ubuntu 22.

Why we can't configure start_program or stop_program with type "host"?

I get the next error:

Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Resource Statement, Monit::Check::Host[dockerd]: has no parameter named 'program_start' (file: /etc/puppetlabs/code/environments/testing/modules/monit/manifests/check.pp, line: 62) on node xxxxx

In your examples, in type "host" of HTTP_HEADERS, you put "action: restart", but what restart do?

I dont know if is another method to restart the service from Host TCP check, but if i put the next configuration, and one port is failling, monit dont execute the "start".

monit::check:
'dockerd':
type: 'process'
config:
pidfile: '/var/run/docker.pid'
program_start: '/etc/es-ops-puppet7-docker/monit_deploy_puppet.sh'
tests:
- type: 'connection'
host: 'localhost'
port: 8088
socket_type: 'tcp'
action: 'start'
- type: 'connection'
host: 'localhost'
port: 8140
socket_type: 'tcp'
action: 'start'

Only execute the action if the PID is loss. To do an action if host tcp check port is failling i do the next configuration manually and works.

CHECK HOST WITH ADDRESS 127.0.0.1
START PROGRAM = "/etc/es-ops-puppet7-docker/monit_deploy_puppet.sh"
GROUP dockerd
IF FAILED HOST localhost PORT 8088 TYPE TCP
THEN START
IF FAILED HOST localhost PORT 8140 TYPE TCP
THEN START

how can i do this configuration with the puppet module? Thank you!! Sorry if i am doing some mistake.

Time for a new tag?

I need some of the changes since 1.0.0 and I'd still like to point to a forge version, or a tag, rather than a commit hash

Checking error in host.pp

The line host.pp:21 has an error in the if check:
"if !is_domain_name($address) or !is_ip_address($address)"

The "or" should be "and", since now it only passes if the address is both a domain_name AND and ip_address because of the double-negative.
With an "and" it would check if it's neither a domain_name or an ip_address.

I have the fix ready if you grant me rights for creating a branch/pull request.

Centos 7 - undef lsbmajdistrelease (legacy facts)

It seems that an error is thrown indicating lsbmajdistrelease is Undef.

if versioncmp($::lsbmajdistrelease, '7') < 0 {

After doing some searching it seems that yum install redhat-lsb-core is needed so that required modules are installed for faceter to pull data.

lsbdistcodename => Core
lsbdistdescription => CentOS Linux release 7.9.2009 (Core)
lsbdistid => CentOS
lsbdistrelease => 7.9.2009
lsbmajdistrelease => 7
lsbminordistrelease => 9
lsbrelease => :core-4.1-amd64:core-4.1-noarch

It may be an idea to replace with modern facts, found this ticket on another plugin.
puppetlabs/puppetlabs-kubernetes#174

On cetons missing repo epel

Looks like epel repo is required on centos to install monit.

this can be fixed by adding module to Puppetfile:

mod 'stahnma-epel'

and then manifest file can look like this:

  include ::epel
  include ::monit

  Class['epel'] -> Class['monit::install'] # cannot do just Class['monit'] because the way module is constructed

Regression: parameter 'tests' index 1 entry 'value' expects a value of type Array, Hash, Integer, or String, got Float

Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Resource Statement, Monit::Check::System[wh3]:
  parameter 'tests' index 1 entry 'value' expects a value of type Array, Hash, Integer, or String, got Float
  parameter 'tests' index 2 entry 'value' expects a value of type Array, Hash, Integer, or String, got Float (file: /etc/puppetlabs/code/environments/master/modules/monit/manifests/config.pp, line: 53) on node w
h3

It seems a regression in 8eeced0

Automatic configure based on services

I use many different services in foreman puppet and would like to know if there is any way to automatically configure monit service based on what services I have installed in my machine? Defining them one by one is a bit over kill

maybe somekindow profile system?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.