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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / mapping.json
Created November 28, 2011 13:42
Mapping table
mapper.mappingSource()
{"users":{"_all":{"analyzer":"fuzzy"},"_source":{"enabled":false},"properties":{"album_names":{"type":"string","index_name":"album_name","boost":0.8,"include_in_all":true},"created_at":{"type":"date","store":"yes","format":"dateOptionalTime","include_in_all":false},"description":{"type":"string","boost":0.5,"include_in_all":true},"dversion":{"type":"integer"},"features":{"type":"string","include_in_all":false},"firstname":{"type":"string","boost":0.8,"store":"yes","include_in_all":true},"furtive":{"type":"boolean"},"id":{"type":"string","index":"not_analyzed","store":"yes","include_in_all":false},"img_data":{"type":"binary"},"img_url":{"type":"string","index":"no","store":"yes","include_in_all":false},"lastname":{"type":"multi_field","fields":{"lastname":{"type":"string","boost":0.8,"store":"yes","include_in_all":true},"alphaSort":{"type":"string","index":"not_analyzed","store":"yes","include_in_all":false}}},"location":{"type":"string","store":"yes","include_in_all":true},"name":{"typ
@octplane
octplane / changes.sh
Created December 6, 2011 12:24
Upload changes cookbook / roles
#!/bin/sh
COOKBOOKS_FOLDER=cookbooks
[ -d .git ] && {
git fetch
if [ -f .git/latest_changes ]; then
SRC="$(cat .git/latest_changes).."
else
SRC=""