diff --git a/.gitignore b/.gitignore index 5cf74dd..c82d4b8 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ .kitchen.local.yml* tmp/ vendor/ +/nbproject/private/ \ No newline at end of file diff --git a/.jrebel_disabled b/.jrebel_disabled new file mode 100644 index 0000000..e69de29 diff --git a/attributes/default.rb b/attributes/default.rb index 272c1b3..a6d0a4d 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -19,3 +19,5 @@ default["monitor"]["client_extension_dir"] = "/etc/sensu/extensions/client" default["monitor"]["server_extension_dir"] = "/etc/sensu/extensions/server" + +default["monitor"]["subscriptions"] = Array.new diff --git a/files/default/plugins/check-mtime.rb b/files/default/plugins/check-mtime.rb index 056226f..ffa1cf3 100755 --- a/files/default/plugins/check-mtime.rb +++ b/files/default/plugins/check-mtime.rb @@ -1,61 +1,92 @@ -#!/usr/bin/env ruby +#! /usr/bin/env ruby # -# Checks a file's mtime -# === +# check-mtime # # DESCRIPTION: # This plugin checks a given file's modified time. # # OUTPUT: -# plain-text +# plain text # # PLATFORMS: -# linux -# bsd +# Linux, BSD # # DEPENDENCIES: -# sensu-plugin Ruby gem +# gem: sensu-plugin +# +# USAGE: +# #YELLOW +# +# NOTES: +# +# LICENSE: +# Copyright 2014 Sonian, Inc. and contributors. +# Released under the same terms as Sensu (the MIT license); see LICENSE +# for details. # -# Released under the same terms as Sensu (the MIT license); see LICENSE -# for details. -require 'rubygems' if RUBY_VERSION < '1.9.0' require 'sensu-plugin/check/cli' require 'fileutils' class Mtime < Sensu::Plugin::Check::CLI - option :file, - :description => 'File to check last modified time', - :short => '-f FILE', - :long => '--file FILE' + description: 'File to check last modified time', + short: '-f FILE', + long: '--file FILE' - option :warn_age, - :description => 'Warn if mtime greater than provided age in seconds', - :short => '-w SECONDS', - :long => '--warn SECONDS' + option :warning_age, + description: 'Warn if mtime greater than provided age in seconds', + short: '-w SECONDS', + long: '--warning SECONDS' option :critical_age, - :description => 'Critical if mtime greater than provided age in seconds', - :short => '-c SECONDS', - :long => '--critical SECONDS' + description: 'Critical if mtime greater than provided age in seconds', + short: '-c SECONDS', + long: '--critical SECONDS' + + option :ok_no_exist, + description: 'OK if file does not exist', + short: '-o', + long: '--ok-no-exist', + boolean: true, + default: false + + option :ok_zero_size, + description: 'OK if file has zero size', + short: '-z', + long: '--ok-zero-size', + boolean: true, + default: false def run_check(type, age) to_check = config["#{type}_age".to_sym].to_i - if(to_check > 0 && age >= to_check) + # #YELLOW + if to_check > 0 && age >= to_check # rubocop:disable GuardClause send(type, "file is #{age - to_check} seconds past #{type}") end end def run unknown 'No file specified' unless config[:file] - unknown 'No warn or critical age specified' unless config[:warn_age] || config[:critical_age] - if(File.exists?(config[:file])) - age = Time.now.to_i - File.mtime(config[:file]).to_i + unknown 'No warn or critical age specified' unless config[:warning_age] || config[:critical_age] + if File.exist?(config[:file]) + if File.size?(config[:file]).nil? && !config[:ok_zero_size] + critical 'file has zero size' + end + end + f = Dir.glob(config[:file]).first + if f + if File.size?(f).nil? && !config[:ok_zero_size] + critical 'file has zero size' + end + age = Time.now.to_i - File.mtime(f).to_i run_check(:critical, age) || run_check(:warning, age) || ok("file is #{age} seconds old") else - critical 'file not found' + if config[:ok_no_exist] + ok 'file does not exist' + else + critical 'file not found' + end end end - end diff --git a/metadata.rb b/metadata.rb index dc82ed1..b1b2012 100644 --- a/metadata.rb +++ b/metadata.rb @@ -4,7 +4,7 @@ license "Apache 2.0" description "A cookbook for monitoring services, using Sensu, a monitoring framework." long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version "0.0.5" +version "0.0.7" %w[ ubuntu diff --git a/nbproject/project.properties b/nbproject/project.properties new file mode 100644 index 0000000..a9d971c --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,12 @@ +file.reference.chef-monitor-attributes=attributes +file.reference.chef-monitor-files=files +file.reference.chef-monitor-recipes=recipes +file.reference.chef-monitor-test=test +files.dir=${file.reference.chef-monitor-files} +javac.classpath= +main.file= +platform.active=Ruby +recipes.dir=${file.reference.chef-monitor-recipes} +source.encoding=UTF-8 +src.dir=${file.reference.chef-monitor-attributes} +test.dir=${file.reference.chef-monitor-test} diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 0000000..edb8ea4 --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,16 @@ + + + org.netbeans.modules.ruby.rubyproject + + + chef-monitor + + + + + + + + + + diff --git a/recipes/_master_search.rb b/recipes/_master_search.rb index 5e073da..002987f 100644 --- a/recipes/_master_search.rb +++ b/recipes/_master_search.rb @@ -45,5 +45,4 @@ end node.override["sensu"]["rabbitmq"]["host"] = master_address -node.override["sensu"]["redis"]["host"] = master_address node.override["sensu"]["api"]["host"] = master_address diff --git a/recipes/_worker.rb b/recipes/_worker.rb index 7bf7433..464bde5 100644 --- a/recipes/_worker.rb +++ b/recipes/_worker.rb @@ -53,14 +53,28 @@ end check_definitions.each do |check| - sensu_check check["id"] do - type check["type"] - command check["command"] - subscribers check["subscribers"] - interval check["interval"] - handlers check["handlers"] - additional check["additional"] + if check.has_key?("checks") + check["checks"].each do |check_id, check_val| + sensu_check check_id do + type check_val["type"] + command check_val["command"] + subscribers check_val["subscribers"] + interval check_val["interval"] + handlers check_val["handlers"] + additional check_val["additional"] + end + end + else + sensu_check check["id"] do + type check["type"] + command check["command"] + subscribers check["subscribers"] + interval check["interval"] + handlers check["handlers"] + additional check["additional"] + end end + end include_recipe "sensu::server_service" diff --git a/recipes/default.rb b/recipes/default.rb index 5f6598c..7fff706 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -25,13 +25,20 @@ client_attributes = node["monitor"]["additional_client_attributes"].to_hash +tags_subs = [] +if node.attribute?('tags') + tags_subs = node['tags'].select{ |tag| tag.index('sensu_') == 0 }.map do |tag| + tag[tag.index('_') + 1..-1] + end +end + sensu_client node.name do if node.has_key?("cloud") address node["cloud"][ip_type] || node["ipaddress"] else address node["ipaddress"] end - subscriptions node["roles"] + ["all"] + subscriptions (node["roles"] + ["all", Chef::Config[:node_name]] + node['monitor']['subscriptions'] + tags_subs).uniq additional client_attributes end