Skip to content

Instantly share code, notes, and snippets.

View octplane's full-sized avatar
👨‍💻
I came here for the javascript jokes and was disappointed

Pierre Baillet octplane

👨‍💻
I came here for the javascript jokes and was disappointed
View GitHub Profile
@octplane
octplane / gems.rb
Created October 27, 2011 09:54
List gems, show dependencies, show broken gems. Uses trollop gem.
#!/usr/bin/env ruby
require 'rubygems'
require 'trollop'
require 'pp'
opts = Trollop::options do
opt :list, "List local installed gems in shell friendly format", :type => :boolean
opt :info, "Display Dependency information about gem", :type => :string
opt :check, "Check All installed gems and return broken dependencies", :type=> :boolean
end
@octplane
octplane / god_patch.rb
Created October 17, 2011 08:16
God Patch to allow restarting a daemon which has been programmatically stopped (cf http://groups.google.com/group/god-rb/browse_thread/thread/18eb04f0f448b661 )
module God
class Watch < Task
VALID_STATES = [:init, :up, :start, :restart, :stop]
end
end
@octplane
octplane / sumr.god
Created October 14, 2011 13:15
Simple sumr wrapper
def should_i_start?
puts "Should I ?"
Time.now.min % 2 == 1
end
def setup_watch(w)
w.stop_if do |on|
@octplane
octplane / check_mongo_replica_member.rb
Created August 31, 2011 08:32
MongoDb Replica Nagios and Munin checks
#!/usr/bin/env ruby
# Copyright (c) 2011 Fotonauts
# All rights reserved.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
@octplane
octplane / service.cfg.erb
Created August 11, 2011 13:19
Service template for Nagios in chef.
define host {
use generic-host <%# Inherit default values from a template %>
<%# Use FQDN because munin will send alerts using the FQDN %>
host_name <%= @host['fqdn'] %><%# The name we’re giving to this host %>
alias <%= @host['hostname'] %><%# A longer name associated with the host %>
address <%= @host['ipaddress'] %><%# IP address of the host %>
}
<% @services.each do |service, info|
info = info.to_hash
if DefaultMonitoredValues::check_on(info).include?(@host['swissr']['grid'])
@octplane
octplane / server.rb
Created August 11, 2011 13:13
Nagios server cookbook. Part that dumps the configuration on the disk.
ruby_block "Delete Legacy Files" do
block do
existing = []
Dir.new('/etc/nagios3/conf.d/').each do |f|
next if f == '.' or f == '..'
existing << f
end
reals = search(:node, "monitored:[* TO *]").map{ |n| n[:fqdn] +".cfg" }
(existing - reals).each do |leftover|
@octplane
octplane / monitored.rb
Created August 11, 2011 12:38
Chef defines for monitoring: store in definitions/monitored.rb
#
# Cookbook Name:: monitored
define :monitored, :additional_params => {} do
if ! params[:depends].is_a?(Array) && params[:depends] != nil
raise "Depends must be an array (#{params[:depends].inspect})"
end
doc = {}.merge(params[:additional_params])
@octplane
octplane / check_commands.rb
Created August 11, 2011 12:30
Declare default values for monitored jobs and some default usual tests.
module DefaultMonitoredValues
# Handle defaults to prevent cluttering the chef registry with these things
def DefaultMonitoredValues.value_or(hash, key, or_value)
if hash.has_key?(key)
hash[key]
else
or_value
end
@octplane
octplane / lastrecipe.rb
Created August 11, 2011 12:21
Last Recipe that populates the registry
order = node.recipes
if order[-1] != "lastrecipe"
Chef::Log.error("Last Recipe should be the last recipe to run")
raise "Please refactor my runlist"
end
# This recipe is tightly integrated with monitored in fotonauts and recipe
# firstrecipe
@octplane
octplane / firstrecipe.rb
Created August 11, 2011 12:15
First Recipe. Creates the empty monitoring registry and also store the new key
# This recipe should be called at the beginning of the run_list
# If we are not the last item of the run_list break
order = node.recipes
if order[0] != "firstrecipe"
Chef::Log.error("First Recipe should be the first recipe to run; current run list is "+order.inspect)
raise "Please refactor my runlist"
end