Permalink
Browse files

Example42 Monitor module.

  • Loading branch information...
0 parents commit 6cadf4bcbcf3fcee24d17212aa851d7dcfa24cb0 @alvagante alvagante committed Jan 12, 2012
Showing with 366 additions and 0 deletions.
  1. +9 −0 Modulefile
  2. +82 −0 README.markdown
  3. +80 −0 manifests/mount.pp
  4. +53 −0 manifests/port.pp
  5. +61 −0 manifests/process.pp
  6. +81 −0 manifests/url.pp
@@ -0,0 +1,9 @@
+name 'lab42-monitor'
+version '2.0.0'
+author 'Alessandro Franceschi'
+license 'Apache2'
+project_page 'http://www.example42.com'
+summary 'Puppet monitoring abstraction meta module'
+description 'This module provides abstraction defines to monitroing resources managed by Puppet. It's used in the Example42 modules set but can be imported and used in other setups'
+dependency 'puppetlabs/stdlib', '>= 0.1.0'
+dependency 'lab42/stdlib42', '>= 2.0.0'
@@ -0,0 +1,82 @@
+# Puppet module: monitor
+
+This is a Puppet abstraction module to manage monitoring.
+
+Made by Alessandro Franceschi / Lab42 - http://www.example42.com
+
+Released under the terms of Apache 2 License.
+
+Check Modulefile for dependencies.
+
+## Goal of this module
+This module abstracts the monitoring definitions for an host or application, in order to add and use different monitoring methods, without changes on the single application modules.
+
+It's used, as an option disabled by default, in the Example42 modules and provides:
+
+* a common interface for different monitoring tools (Nagios, Monit, Munin....)
+
+* an unified syntax for monitoring resources able to adapt to monitoring modules from different authors
+
+* a standard way to define what an application or an host needs to be monitored
+
+* reversable actions (you can remove a monitor resource previously defined)
+
+## Usage
+In order to activate automatic monitoring for the resources defined in a class you have to pass, at least, these parameters:
+
+ class { "foo":
+ monitor => true,
+ monitor_tool => [ "nagios" , "monit" , "munin" ],
+ }
+
+where monitor_tool is an array of the monitor tools you want to activate to automatically check the resources provided the defined class.
+
+In each module for applications the provide network services, by default, it's activated the monitoring to the listening port and the running process, with a syntax like this:
+
+ monitor::port { "foo_${foo::protocol}_${foo::port}":
+ protocol => "${foo::protocol}",
+ port => "${foo::port}",
+ target => "${foo::params::monitor_target_real}",
+ tool => "${foo::monitor_tool}",
+ enable => $foo::manage_monitor,
+ }
+
+ monitor::process { "foo_process":
+ process => "${foo::process}",
+ service => "${foo::service}",
+ pidfile => "${foo::pidfile}",
+ tool => "${foo::monitor_tool}",
+ enable => $foo::manage_monitor,
+ }
+
+Modules related to web applications generally have a monitor::url define that checks for a specifyed pattern string in an given url:
+
+ monitor::url { "foo_webapp_url":
+ url => "${foo_webapp::url_check}",
+ pattern => "${foo_webapp::url_pattern}",
+ port => "${foo_webapp::port}",
+ target => "${fqdn}",
+ tool => "${foo_webapp::monitor_tool}",
+ enable => $foo_webapp::manage_monitor,
+ }
+
+## Monitor module layout
+This monitor module is to be considered a (working) implementation, entirely based on Puppet's DSL of a (strongly needed) monitor abstraction type.
+The generic monitor defines are placed in files like:
+
+ monitor/manifests/process.pp
+ monitor/manifests/port.pp
+ monitor/manifests/url.pp
+
+here according to the monitor_tool requested are called some specific defines relevant to the requested monitoring tools.
+Note that here you can choose different implementations of the a specific module, so you are free to change the whole module to be used for a specific monitoring tool editing just these few files.
+
+## Dependencies
+This is a meta-module that needs dependencies according to the monitor tools modules you use.
+It also requires PuppetLabs' stdlib and Example42's stdlib42 common modules.
+IMPORTANT: You must have storeconfigs enabled on your PuppetMaster to use monitoring tools that involve a central server, like Nagios or Munin.
+
+## Status of the module
+This module is derived from the monitor module of the first generation of Example42 Puppet modules.
+
+Work and adaptation for the second generation of Example42 Puppet module is in progress, some features may be added or modified.
@@ -0,0 +1,80 @@
+# Define monitor::mount
+#
+# You can use this define to manage monitored mounts.
+# It automatcally monitors the mount point you specify AND IT MOUNTS it using
+# Puppet's native mount define.
+# So, generically, you just have to use monitor::mount instead of mount to manage your mountpoints
+# The possible atguments are the same of the native mount define plus the usual $tool that
+# specifies what monitor tools you can use.
+# If you want to check the mount point only, without actually mounting it via the mount define,
+# set only_check=true
+#
+define monitor::mount (
+ $name,
+ $device,
+ $fstype,
+ $options='',
+ $pass='0',
+ $remounts=true,
+ $ensure='mounted',
+ $atboot='true',
+ $only_check=false,
+ $create_dir=false,
+ $owner='root',
+ $group='root',
+ $mode='755',
+ $enable=true,
+ $tool=$monitor_tool
+ ) {
+
+ validate_bool($enable)
+
+ $escapedname=regsubst($name,'/','_','G')
+
+ $computed_ensure = $enable ? {
+ false => "absent",
+ true => "present",
+ }
+
+ # The mount is actually done (if $only_check != true )
+ if ( $only_check != true ) {
+ mount { "$name":
+ name => "$name",
+ device => "$device",
+ fstype => "$fstype",
+ options => "$options",
+ pass => "$pass",
+ remounts => $remounts,
+ ensure => "$ensure",
+ atboot => true,
+ }
+ }
+
+ if ( $create_dir == true ) and ( $only_check != true ) {
+ file { "$name":
+ path => "$name",
+ owner => "$owner",
+ group => "$group",
+ mode => "$mode",
+ ensure => directory,
+ before => Mount["$name"],
+ }
+ }
+
+ if ($tool =~ /nagios/) {
+ nagios::service { "Mount_$escapedname":
+ ensure => $computed_ensure,
+ check_command => "check_nrpe!check_mount!${name}!${fstype}",
+ }
+ }
+
+ if ($tool =~ /puppi/) {
+ puppi::check { "Mount_$escapedname":
+ enable => $enable,
+ hostwide => "yes",
+ command => "check_mount -m ${name} -t ${fstype}" ,
+ }
+ }
+
+}
+
@@ -0,0 +1,53 @@
+define monitor::port (
+ $port,
+ $protocol,
+ $target,
+ $tool,
+ $checksource='remote',
+ $enable=true
+ ) {
+
+ validate_bool($enable)
+
+ $ensure = $enable ? {
+ false => "absent",
+ true => "present",
+ }
+
+ if ($tool =~ /munin/) {
+ }
+
+ if ($tool =~ /collectd/) {
+ }
+
+ if ($tool =~ /monit/) {
+ }
+
+ if ($tool =~ /nagios/) {
+ nagios::service { "$name":
+ ensure => $ensure,
+ check_command => $protocol ? {
+ tcp => $checksource ? {
+ local => "check_nrpe!check_port_tcp!${target}!${port}",
+ default => "check_tcp!${port}",
+ },
+ udp => $checksource ? {
+ local => "check_nrpe!check_port_udp!${target}!${port}",
+ default => "check_udp!${port}",
+ },
+ }
+ }
+ }
+
+ if ($tool =~ /puppi/) {
+ puppi::check { "$name":
+ enable => $enable,
+ hostwide => "yes",
+ command => $protocol ? {
+ tcp => "check_tcp -H ${target} -p ${port}" ,
+ udp => "check_udp -H ${target} -p ${port}" ,
+ }
+ }
+ }
+
+}
@@ -0,0 +1,61 @@
+define monitor::process (
+ $process,
+ $argument="",
+ $service,
+ $pidfile,
+ $tool,
+ $enable=true
+ ) {
+ validate_bool($enable)
+
+ $ensure = $enable ? {
+ false => "absent",
+ true => "present",
+ }
+
+ if ($tool =~ /munin/) {
+ }
+
+ if ($tool =~ /collectd/) {
+ }
+
+ if ($tool =~ /monit/) {
+ monit::checkpid { "${name}":
+ pidfile => "${pidfile}",
+ process => "${process}${argument}",
+ startprogram => "/etc/init.d/${service} start",
+ stopprogram => "/etc/init.d/${service} stop",
+ enable => $enable,
+ }
+ }
+
+ if ($tool =~ /nagios/) {
+ nagios::service { "$name":
+ ensure => $ensure,
+ check_command => $process ? {
+ undef => "check_nrpe!check_process!${name}" ,
+ default => $argument ? {
+ undef => "check_nrpe!check_process!${process}" ,
+ "" => "check_nrpe!check_process!${process}" ,
+ default => "check_nrpe!check_processwitharg!${process}!${argument}" ,
+ }
+ }
+ }
+ }
+
+ if ($tool =~ /puppi/) {
+ puppi::check { "$name":
+ enable => $enable,
+ hostwide => "yes",
+ command => $process ? {
+ undef => "check_procs -c 1: -C ${name}" ,
+ default => $argument ? {
+ undef => "check_procs -c 1: -C ${process}" ,
+ "" => "check_procs -c 1: -C ${process}" ,
+ default => "check_procs -c 1: -C ${process} -a ${argument}" ,
+ }
+ }
+ }
+ }
+
+}
@@ -0,0 +1,81 @@
+define monitor::url (
+ $url="http://127.0.0.1",
+ $target="",
+ $port='80',
+ $pattern="",
+ $username="",
+ $password="",
+ $monitorgroup="",
+ $useragent="",
+ $tool,
+ $checksource='remote',
+ $enable=true
+ ) {
+
+ validate_bool($enable)
+
+ # If target is not provided we get it from the Url
+ $computed_target = $target ? {
+ '' => url_parse($url,host),
+ default => "${target}",
+ }
+
+ $ensure = $enable ? {
+ false => "absent",
+ "false" => "absent",
+ "no" => "absent",
+ true => "present",
+ "true" => "present",
+ "yes" => "present",
+ }
+
+ $urlq = regsubst($url , '/' , '-' , 'G') # Needed to create flag todo files seamlessly
+
+ if ($tool =~ /munin/) {
+ }
+
+ if ($tool =~ /collectd/) {
+ }
+
+ if ($tool =~ /monit/) {
+ }
+
+ if ($tool =~ /nagios/) {
+ # Use for Example42 service checks (note: are used custom Nagios and nrpe commands)
+ nagios::service { "$name":
+ ensure => $ensure,
+ check_command => $checksource ? {
+ local => $username ? { # CHECK VIA NRPE STILL DOESN'T WORK WITH & and ? in URLS!
+ undef => "check_nrpe!check_url!${computed_target}!${port}!${url}!${pattern}!${useragent}" ,
+ "" => "check_nrpe!check_url!${computed_target}!${port}!${url}!${pattern}!${useragent}" ,
+ default => "check_nrpe!check_url_auth!${computed_target}!${port}!${url}!${pattern}!${username}:${password}!${useragent}" ,
+ },
+ default => $username ? {
+ undef => "check_url!${computed_target}!${port}!${url}!${pattern}!${useragent}" ,
+ "" => "check_url!${computed_target}!${port}!${url}!${pattern}!${useragent}" ,
+ default => "check_url_auth!${computed_target}!${port}!${url}!${pattern}!${username}:${password}!${useragent}" ,
+ },
+ },
+ }
+ }
+
+ if ($tool =~ /puppi/) {
+ # Use for Example42 puppi checks
+ puppi::check { "$name":
+ enable => $enable,
+ hostwide => $monitorgroup ? {
+ undef => "yes" ,
+ "" => "yes" ,
+ default => "no" ,
+ },
+ project => $monitorgroup ,
+ command => $username ? {
+ undef => "check_http -I '${computed_target}' -p '${port}' -u '${url}' -s '${pattern}' -A '${useragent}'" ,
+ "" => "check_http -I '${computed_target}' -p '${port}' -u '${url}' -s '${pattern}' -A '${useragent}'" ,
+ default => "check_http -I '${computed_target}' -p '${port}' -u '${url}' -s '${pattern}' -a ${username}:${password} -A '${useragent}'" ,
+ }
+ }
+ }
+
+}
+

0 comments on commit 6cadf4b

Please sign in to comment.