Skip to content

Instantly share code, notes, and snippets.

View ccaum's full-sized avatar

Carl Caum ccaum

  • Amazon Web Services
  • Portland, OR
  • X @ccaum
View GitHub Profile
@ccaum
ccaum / nagios2python.py
Created November 19, 2010 03:54
nagios2python converts a nagios resource file to a puppet manifest
#!/usr/bin/python
from sys import *
import os
import re
## Variables
# Which parameter to use for the resource's title for each nagios define type
# NOTE: If you use the name_map dictionary, the values in the name_map dictionary
# should be used in the values for the title_parameters dictionary
@ccaum
ccaum / warranty.rb
Created November 19, 2010 04:02
facter facts that pull warranty info from Apple site
require 'facter'
if Facter.value('kernel') == 'Darwin'
# First grab the serial number. For some reason I can't get it from Facter
sn = %x{ioreg -l | grep IOPlatformSerialNumber | sed -e s/\\"//g}.chomp.split{"="}[-1].chomp
url = "https://selfsolve.apple.com/Warranty.do?serialNumber=#{sn}&country=USA&fullCountryName=United%20States"
# Next fetch warranty information from Apple, convert the resulting json to a hash
warranty_info = eval %x{curl -k -s "#{url}"}.split(',').each { |element|
element.sub! ':', ' => '
@ccaum
ccaum / timemachine.rb
Created November 19, 2010 04:09
Time Machine facter facts
require 'facter'
require 'facter/util/plist/parser'
completed = File.exists? '/private/var/db/.TimeMachine.Results.plist'
Facter.add("timemachine_volume") do
confine :kernel => "Darwin"
setcode do
%x{defaults read /Library/Preferences/com.apple.TimeMachine LocalizedDiskImageVolumeName}.chomp
end
@ccaum
ccaum / externalresources.rb
Created December 1, 2010 22:21
Puppet class to turn parameters in to puppet resources
hostclass :externalresources do
scope_h = scope.to_hash.reject { |k,v| !( k.is_a?(String) && v.is_a?(String) ) }
scope_h.keys.each do |var|
if scope_h[var][0].chr == '{'
begin
#Convert the variable from a string to a hash
var_h = eval scope_h[var]
rescue => e
notice "Couldn't convert variable #{var} to hash: #{e}"
@ccaum
ccaum / lifter.pp
Created December 1, 2010 22:33
Example of externalized resources
case $site {
'1': {
@lifter {
"lifter1":
param1 => 'my param',
param2 => 'my other param';
"lifter2":
param1 => 'my param',
param2 => 'my other param';
}
@ccaum
ccaum / type.erb
Created March 15, 2011 03:07
Template Documentation
{toc}
h1. <%= type.name %>
<%= type.doc.gsub(/[{\[\]}]/) { |s| '\\' + s } %>
h2. Parameters
<% type.parameters.each do |param| %>
* <%= param %>
@ccaum
ccaum / confluence4r.rb
Created March 15, 2011 03:22
Confluence Puppet Doc Generator
require 'xmlrpc/client'
# A useful helper for running Confluence XML-RPC from Ruby. Takes care of
# adding the token to each method call (so you can call server.getSpaces()
# instead of server.getSpaces(token)). Also takes care of re-logging in
# if your login times out.
#
# Usage:
#
# server = Confluence::Server.new :server => 'http://confluence02.lightningsoure.com'
@ccaum
ccaum / provider.rb
Created June 23, 2011 22:23
RAL hash/embedded array bug?
Puppet::Type.type(:sampletype).provide(:default) do
def self.instances
@instances ||= get_instances
@instances
end
def prefetch
instances.each do |instance|
@ccaum
ccaum / face_patch.rb
Created June 27, 2011 19:53
Faceless Face
require 'puppet/indirector/face'
require 'puppet/patch'
Puppet::Indirector::Face.define(:patch, '0.0.1') do
copyright "Puppet Labs", 2011
license "Apache 2 license; see COPYING"
summary "View and manage patch levels on a node."
description <<-'EOT'
This subcommand interacts with package objects, using the default provider.
@ccaum
ccaum / post-merge.rb
Created August 19, 2011 21:57
Git Post Merge Script
#!/usr/bin/env ruby
require 'rubygems'
require 'puppet'
require 'puppet/face'
require 'puppet/cloudpack'
options = {
:image => 'ami-3d76b754',
:type => 'm1.large',