Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing setting redis host in _master_search.rb #40

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
.kitchen.local.yml*
tmp/
vendor/
/nbproject/private/
Empty file added .jrebel_disabled
Empty file.
2 changes: 2 additions & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
85 changes: 58 additions & 27 deletions files/default/plugins/check-mtime.rb
Original file line number Diff line number Diff line change
@@ -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. <[email protected]>
# 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
2 changes: 1 addition & 1 deletion metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions nbproject/project.properties
Original file line number Diff line number Diff line change
@@ -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}
16 changes: 16 additions & 0 deletions nbproject/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.ruby.rubyproject</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/ruby-project/1">
<name>chef-monitor</name>
<source-roots>
<root id="src.dir" name="attributes"/>
<root id="files.dir"/>
<root id="recipes.dir"/>
<root id="test.dir"/>
</source-roots>
<test-roots/>
</data>
</configuration>
</project>
1 change: 0 additions & 1 deletion recipes/_master_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
28 changes: 21 additions & 7 deletions recipes/_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
9 changes: 8 additions & 1 deletion recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down