Code Monkey home page Code Monkey logo

monit-ng's Introduction

Chef monit cookbook Build Status

Installs and configures Monit, with a resource provider for managing additional monit checks.

Suggested background reading:

  • The Fine Manual
  • This README, the resource and provider in cookbook libraries directory.

Recipes

  • monit-ng::default: loads the other recipes in the order below
  • monit-ng::install: installs monit via package or source
  • monit-ng::configure: configures global monit template
  • monit-ng::service: configures and manages the monit service
  • monit-ng::reload: reloads monit service if converge updated a monit_check

Dependencies

  • yum-epel (on rhel hosts)
  • ubuntu (on ubuntu hosts)
  • apt (on debian hosts)
  • build-essential (if installing from source)

Attributes

Most of these are very straight-forward, and pulled directly from the manual. See the inline documentation in attributes/*.rb for details.

The few "special" attributes are noted below:

  • default['monit']['config']['alert'] (default: []): this attributes configures global set alert config option for each Hash element with attribute name and optional event filters

Documentation for event filters can be found here.

"default_attributes": {
  "monit": {
    "config": {
      "alert": [
        {
			    "name": "root@localhost",
			    "but_not_on": [ "nonexist" ]
			  },
			  {
			    "name": "netadmin@localhost",
			    "only_on": [ "nonexist", "timeout", "icmp", "connection"]
			  },
			  {
			    "name": "iwantall@localhost",
			  }
			]
    }
  }
}
  • default['monit']['config']['mail_servers'] (default: []): this attributes configures set mailserver config option for each Hash element (mail server) with hash like so:
"default_attributes": {
  "monit": {
    "config": {
 			"mail_servers": [
  		  {
          "hostname": "localhost",
          "port": 25,
          "username": null,
          "password": null,
          "security": null,
          "timeout": "30 seconds"
        }
			]
    }
  }
}
  • default['monit']['config']['built_in_configs'] (default: []): this defines what built-in configuration files will be included
"default_attributes": {
  "monit": {
    "config": {
      "built_in_configs": [
        "memcached",
        "nginx"
      ]
    }
  }
}

Resources

monit_check

Attribute Description Default
cookbook cookbook from which to source monit config template monit-ng
check_type type of check (e.g. program, process, host) process
check_id check identifier (e.g. pid path, hostname, executable path nil
id_type type of identifier (e.g. pid, matching, address, path) determined by check_type
start_as user to execute start command as nil
start_as_group group to start program as nil
start start command nil
stop_as user to execute stop command as nil
stop_as_group group to execute stop command as nil
stop stop command nil
group check group(s) (e.g. "hosts" or ["hosts", "apis"]) []
depends depends on named service (e.g. "apache") nil
tests array of hashes with 'condition', 'action' keys, maps to monit if, then []
every string for args to "every" configuration (e.g. every n cycles, every "* 8-19 * * 1-5") nil
alert email to alert nil
but_not_on alert modifier to filter events for notification nil
alert_events alert modifier to filter events for notification nil

Contributing

  1. Fork the repository on Github
  2. Create a named feature branch (like add_component_x)
  3. Write your change
  4. Write tests for your change (if applicable)
  5. Run the tests (rake), ensuring they all pass
  6. Write new resource/attribute description to README.md
  7. Write description about changes to PR
  8. Submit a Pull Request using Github

Copyright & License

Authors:: Nathan Williams and contributors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

monit-ng's People

Contributors

helgi avatar kcd83 avatar mattadair avatar maxnasonov avatar micred avatar nathwill avatar ninjatux avatar sakarikl avatar smt116 avatar stuporhero avatar szymonpk avatar vkhatri avatar webframp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

monit-ng's Issues

fix foodcritic lint

foodcritic lint test throws below error.

FC002: Avoid string interpolation where not required: ./recipes/source.rb:29

submitting a PR.

Kill switch capability on service start/restart?

It's a bit of an odd situation, but we have situations where monit is already installed and switched off while we're doing work on either the OS, Java applications, or the databases the Java applications use. In some cases we need a Chef run before we're actually done with the work, and in every case monit-ng sees the installed monit service not running and immediately enables and restarts it. This immediately brings up our apps before we're ready, causing a bit of havoc. We're currently working around it by unmonitoring everything before maintenance, but that has caused a couple of issues as you can imagine.

Would it be strange to have a default attribute that could be overridden so that the monit-ng cookbook won't touch the service for a start or restart?

Thanks!
-Matt

Add template variable for monit check

There should be a way to override template name. Currently it is a hardcoded "monit.check.erb" value. I've added a request #68 but for some reason it is failing.

Provide more than one group for `monit_check`

Hi there,

It is possible to define more than one service's group in monit check configuration. However group attribute is defined as a String in monit-ng. What do you think about adding a support for multiple groups here?

It can be achieved in three ways:

  1. Change group to accept both, string and array types and recognize it in template.
  2. Rename group into groups and force everybody to use an array type even for a single item.
  3. Allow to use both, group and groups and add them in template.

Personally i would go with the first one as it seems to be the most "user friendly". What do you think? I can prepare a pull request if you agree on this.

Missing dependancies in Berksfile

I'm seeing dependancy resolution issues when using this cookbook. I believe this is due to not having the dependancies in metadata.rb referenced in the repo Berksfile, e.g.

metadata.rb
%w( yum-epel ubuntu apt build-essential dpkg_autostart ).each do |dep|
  depends dep
end

Should have the following in the Berksfile

Berksfile
cookbook 'yum-epel', '~> 2.1.2'
cookbook 'ubuntu', '~> 2.0.1'
cookbook 'apt', '~> 6.1.4'
cookbook 'build-essential', '~> 8.0.3'
cookbook 'dpkg_autostart', '~> 0.2.0'

start/stop command limits

A 127-character limit for start/stop commands was added in 22c6eef. For some use cases I'm having to wrap long commands in a shell script because. Is the limit still necessary?

I'm running Monit 5.6 and have not seen any issues with commands being truncated.

make default subscribers and mailservers optional

hello! i am trying to manage monit configuration alone with chef role, but facing some issues.

  1. localhost is always set to first mailserver, where i want to configure it to something else for different location servers and the only way i get it right is overriding attribute in a chef role, but that does not get me so far as i need different config for different chef roles
  2. default root subscribers does not help my scenario much, at some places even local smtp is disabled

what do you think about having an attribute e.g. default['monit']['default_config']? which if set true, then below attributes will get default values otherwise not:

default['monit']['config']['subscribers']
default['monit']['config']['mail_servers']

i have PR ready if this sound good to you.

stop_as support?

Would you mind adding stop_as support? We're using monit to control applications that require a specific uid for both start AND stop.

Monit package missing from Debian Buster repo

        Recipe: monit-ng::install
         * apt_package[monit] action install
           * No candidate version available for monit
           ================================================================================
           Error executing action `install` on resource 'apt_package[monit]'
           ================================================================================

For some reason, the monit package has been moved to buster-backports. Thus the recipe monit-ng::install fails on Debian 10. I'm not sure what's the best way to fix it as enabling buster-backports does not feel like the responsibility of the monit-ng cookbook. Thoughts?

add extended resource types

it'd be nice to provide resources like monit_disk_check, monit_process_check, etc, that wrap the core monit_check resource and remove some of the redundancy of writing monit_check resources and specifying common stuff like id_type, etc.

chef 13 compatibility in monit.conf.erb (was Clarify configuration)

Can you provide examples of how to set the configuration in attribute files? It appears that they should be assigned arrays of hashes with the appropriate data elements, but this does not jive with the default template which apparently uses dot notation to try to access the data. Either the template should use the proper hash key syntax (for example mailserver['hostname'] instead of mailserver.hostname), or an example should be given demonstrating how this is supposed to be used so future users don't have to chase their tails for days trying to figure out what's wrong with their config.

fails rubocop

[nathwill@wyrd monit-ng]$ bundle exec rake rubocop
Running RuboCop...
Inspecting 23 files
..C...C.........C......

Offenses:

libraries/resource_monit_check.rb:121:24: C: Use %w or %W for array of words.
          'process' => ['pidfile', 'matching'], 'procmatch' => ['matching'],
                       ^^^^^^^^^^^^^^^^^^^^^^^
recipes/source.rb:109:13: C: Redundant curly braces around a hash parameter.
  variables({
            ^
recipes/source.rb:110:5: C: Use 2 spaces for indentation in a hash, relative to the first position after the preceding left parenthesis.
    :platform_family => node['platform_family'],
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
recipes/source.rb:113:3: C: Indent the right brace the same as the first position after the preceding left parenthesis.
  })
  ^
attributes/default.rb:15:81: C: Line is too long. [82/80]
  monit['service_provider'] = Chef::Platform.find_provider_for_node node, :service
                                                                                ^^

23 files inspected, 5 offenses detected
RuboCop failed!

fails foodcritic

[nathwill@wyrd monit-ng]$ bundle exec rake foodcritic
FC009: Resource attribute not recognised: /home/nathwill/Public/Code/chef/cookbooks/monit-ng/recipes/config.rb:60
rake aborted!
FC009: Resource attribute not recognised: /home/nathwill/Public/Code/chef/cookbooks/monit-ng/recipes/config.rb:60

check_id is only used when check_type is set, but is required

I'm trying to mask monit instance restarts (because you restart it every Chef run) but this doesn't work:

monit_check 'localhost' do
  check_type   'system'
  alert        '[email protected]'
  but_not_on   true
  alert_events ['instance']
end

because

================================================================================
    Error executing action `create` on resource 'monit_check[localhost]'
    ================================================================================

    Chef::Exceptions::ValidationFailed
    ----------------------------------
    Required argument check_id is missing!

check_id is only used by the template when id_type is set... which isn't true in this situation. From your own resource:

def check_pairs
        {
          'process' => %w( pidfile matching ), 'procmatch' => %w( matching ),
          'file' => %w( path ), 'fifo' => %w( path ),
          'filesystem' => %w( path ), 'directory' => %w( path ),
          'host' => %w( address ), 'system' => %w(),
          'program' => %w( path )
        }
      end

Undefined method or attribute `only_on' on `node'

Using Chef Client, version 11.18.0

I get the error

Chef::Mixin::Template::TemplateError (Undefined method or attribute only_on' onnode') on line #39:

37: <% @alert.each do |alert| %>
38: set alert <%= alert.name %>
39: <% if ! alert.only_on.nil? -%>
40: only on { <%= alert.only_on.join(', ') %>}
41: <% elsif ! alert.subscriptions.nil? -%>

Seems to be from the recent changes (today)

error : Status not available -- the monit daemon is not running

Hi,

I'm running monit-ng in chef-provisioning on Ubuntu 15.04, via:

    recipe "monit-ng"

I'm getting:

error    : Status not available -- the monit daemon is not running

This seems fixed when I do a

$ sudo monit

So I've added

execute "sudo monit"

to service.rb.

Do you have any suggestion on the matter ?
Thanks

including ubuntu recipe overwrites AWS mirrors

When using cloud-init or other similar tools they often change the base sources.list to point to a IaaS specific mirror (region specific or otherwise) for performance

-# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
-# newer versions of the distribution.
-deb http://us-west-2.ec2.archive.ubuntu.com/ubuntu/ trusty main
-deb-src http://us-west-2.ec2.archive.ubuntu.com/ubuntu/ trusty main
+deb http://us.archive.ubuntu.com/ubuntu trusty main restricted universe multiverse
+deb-src http://us.archive.ubuntu.com/ubuntu trusty main restricted universe multiverse

Is anyone aware of how to make it not totally overwrite the hostname there? Haven't looked too deeply into the ubuntu recipe this cookbook sources

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.