Untitled Delphi (1-Jul @ 17:20)

ripienaar.devco.net

Syntax Highlighted Code

  1. add_callback(:name => :haproxy_new_node, :type => ["archive"]) do |event, callback|
  2.    if event["name"] == "Service[httpd]"
  3.       facts = UM::Util.facts(event["subject"])
  4.  
  5. [6 more lines...]

Plain Code

add_callback(:name => :haproxy_new_node, :type => ["archive"]) do |event, callback|
   if event["name"] == "Service[httpd]"
      facts = UM::Util.facts(event["subject"])

      if facts["role"] == "webserver"
          UM::Util.callback(:agent => "haproxy",
                            :action => "add_node",
                            :args => {:fqdn => event["subject"]})
      end
   end
end

Untitled Ruby (1-Jul @ 17:11)

ripienaar.devco.net

Syntax Highlighted Code

  1. #!/usr/bin/ruby
  2.  
  3. require 'puppet'
  4. require 'json'
  5. [53 more lines...]

Plain Code

#!/usr/bin/ruby

require 'puppet'
require 'json'
require 'stomp'

def newevent
    event = {:subject => nil,
             :type => "archive",
             :metrics => {},
             :origin => "puppet report",
             :extended_data => {},
             :severity => 0,
             :eventtime => nil,
             :text => nil,
             :name => nil}
end

events = []
report = YAML.load_file("/var/lib/puppet/state/last_run_report.yaml")

report.resource_statuses.find_all {|f| f[1].changed?}.each do |resource|
    event = newevent

    event[:eventtime] = report.time.utc.to_i
    event[:name] = resource.first
    event[:subject] = report.host
    event[:metrics][:change_count] = resource[1].change_count
    event[:metrics][:evaluation_time] = resource[1].evaluation_time
    event[:metrics][:events] = resource[1].events.size
    event[:metrics][:out_of_sync_count] = resource[1].out_of_sync_count
    event[:extended_data][:resource_type] = resource[1].resource_type
    event[:extended_data][:resource_title] = resource[1].title
    event[:extended_data][:events] = resource[1].events
    event[:extended_data][:catalog_version] = report.configuration_version

    events << event
end

config           = {}
config[:stomp]   = {:user       => "xx",
                    :password   => "xx",
                    :server     => "stomp",
                    :port       => 6163}
config[:output]                 = ["/queue/unimatrix.portal"]

begin
    Timeout::timeout(2) {
        conn = Stomp::Connection.new(config[:stomp][:user], config[:stomp][:password], config[:stomp][:server], config[:stomp][:port])

        events.each do |event|
            conn.publish(config[:output], event.to_json)
        end
    }
rescue Exception => e
    STDERR.puts "Failed to send: #{e.class}: #{e}"
    exit 1
end

Untitled Ruby (1-Jul @ 17:04)

ripienaar.devco.net

Syntax Highlighted Code

  1. > db.archive.find({"subject":"nephilim.ml.org", "origin":"puppet report"})
  2. { "_id" : ObjectId("4e0def7c2bce345b813647a5"), "name" : "File[/etc/puppet/puppet.conf]", "metrics" : { "change_count" : 1, "out_of_sync_count" : 1, "events" : 1, "evaluation_time" : 1.162043 }, "tags" : { }, "subject" : "nephilim.ml.org", "origin" : "puppet report", "type" : "archive", "extended_data" : { "resource_title" : "/etc/puppet/puppet.conf", "resource_type" : "File", "events" : ["content changed '{md5}9640bba026933facbabaa5d61c3a3876' to '{md5}fcda847ceb31d498e8b8e7238f31ef31'"], "catalog_version" : "6929" }, "eventtime" : 1309533180, "severity" : 0 }
  3. { "_id" : ObjectId("4e0def7c2bce345b813647a6"), "name" : "File[/etc/mcollective/facts.yaml]", "metrics" : { "change_count" : 1, "out_of_sync_count" : 1, "events" : 1, "evaluation_time" : 0.067142 }, "tags" : { }, "subject" : "nephilim.ml.org", "origin" : "puppet report", "type" : "archive", "extended_data" : { "resource_title" : "/etc/mcollective/facts.yaml", "resource_type" : "File", "events" : ["content changed '{md5}ca6aad1ebb21d5a731d57e6ef0791ee2' to '{md5}62bf4f7a05e0e4ccf98ca75557f4f3d9'"], "catalog_version" : "6929" }, "eventtime" : 1309533180, "severity" : 0 }
  4. { "_id" : ObjectId("4e0def7c2bce345b813647a7"), "name" : "Service[httpd]", "metrics" : { "change_count" : 1, "out_of_sync_count" : 1, "events" : 1, "evaluation_time" : 1.006692 }, "tags" : { }, "subject" : "nephilim.ml.org", "origin" : "puppet report", "type" : "archive", "extended_data" : { "resource_title" : "httpd", "resource_type" : "Service", "events" : [ "ensure changed 'stopped' to 'running'" ], "catalog_version" : "6929" }, "eventtime" : 1309533180, "severity" : 0 }

Plain Code

> db.archive.find({"subject":"nephilim.ml.org", "origin":"puppet report"})
{ "_id" : ObjectId("4e0def7c2bce345b813647a5"), "name" : "File[/etc/puppet/puppet.conf]", "metrics" : { "change_count" : 1, "out_of_sync_count" : 1, "events" : 1, "evaluation_time" : 1.162043 }, "tags" : { }, "subject" : "nephilim.ml.org", "origin" : "puppet report", "type" : "archive", "extended_data" : { "resource_title" : "/etc/puppet/puppet.conf", "resource_type" : "File", "events" : ["content changed '{md5}9640bba026933facbabaa5d61c3a3876' to '{md5}fcda847ceb31d498e8b8e7238f31ef31'"], "catalog_version" : "6929" }, "eventtime" : 1309533180, "severity" : 0 }
{ "_id" : ObjectId("4e0def7c2bce345b813647a6"), "name" : "File[/etc/mcollective/facts.yaml]", "metrics" : { "change_count" : 1, "out_of_sync_count" : 1, "events" : 1, "evaluation_time" : 0.067142 }, "tags" : { }, "subject" : "nephilim.ml.org", "origin" : "puppet report", "type" : "archive", "extended_data" : { "resource_title" : "/etc/mcollective/facts.yaml", "resource_type" : "File", "events" : ["content changed '{md5}ca6aad1ebb21d5a731d57e6ef0791ee2' to '{md5}62bf4f7a05e0e4ccf98ca75557f4f3d9'"], "catalog_version" : "6929" }, "eventtime" : 1309533180, "severity" : 0 }
{ "_id" : ObjectId("4e0def7c2bce345b813647a7"), "name" : "Service[httpd]", "metrics" : { "change_count" : 1, "out_of_sync_count" : 1, "events" : 1, "evaluation_time" : 1.006692 }, "tags" : { }, "subject" : "nephilim.ml.org", "origin" : "puppet report", "type" : "archive", "extended_data" : { "resource_title" : "httpd", "resource_type" : "Service", "events" : [ "ensure changed 'stopped' to 'running'" ], "catalog_version" : "6929" }, "eventtime" : 1309533180, "severity" : 0 }

Untitled Ruby (1-Jul @ 16:32)

ripienaar.devco.net

Syntax Highlighted Code

  1. # parsing the new last_run_report.yaml for events.
  2.  
  3. >>> YAML.load_file("last_run_report.yaml").resource_statuses.find_all {|f| f[1].changed?}.each{|r| p r.first}
  4. "File[/etc/puppet/puppet.conf]"
  5. [1 more lines...]

Plain Code

# parsing the new last_run_report.yaml for events.

>>> YAML.load_file("last_run_report.yaml").resource_statuses.find_all {|f| f[1].changed?}.each{|r| p r.first}
"File[/etc/puppet/puppet.conf]"
"File[/etc/mcollective/facts.yaml]"
"Service[httpd]"

Untitled Ruby (24-May @ 18:47)

ripienaar.devco.net

Syntax Highlighted Code

  1. module MCollective
  2.     module Registration
  3.         class Foo<Base
  4.             def body
  5. [26 more lines...]

Plain Code

module MCollective
    module Registration
        class Foo<Base
            def body
               config = Config.instance

               collective =  config.pluginconf["registration.target_collective"] || nil

               if collective
                   data = ["hello world!"]

                   target = Util.make_target("registration", :command, collective)
                   reqid = Digest::MD5.hexdigest("#{config.identity}-#{Time.now.to_f.to_s}-#{target}")
                   filter = {"agent" => "registration"}
                   req = PluginManager["security_plugin"].encoderequest(config.identity, target, data, reqid, filter)

                   Log.debug("Sending registration #{reqid} to #{target} in collective #{collective}")

                   PluginManager["connector_plugin"].send(target, req)

                   return nil
               else
                   return data
               end
            rescue Exception => e
                Log.warn("Failed to send registration: #{e.class}: #{e}")
                return nil
            end
        end
    end
end

Untitled Text (14-Apr @ 10:18)

ripienaar.devco.net

Syntax Highlighted Code

  1. $ mco rpc puppetd last_run_summary -I dev1 --np
  2.  
  3. dev1
  4.      Changes:
  5. [25 more lines...]

Plain Code

$ mco rpc puppetd last_run_summary -I dev1 --np

dev1
     Changes:
        {"total"=>1}
      Events:
        {"total"=>1, "success"=>1}
       Times:
        {"group"=>0.001293,
         "last_run"=>1302770955,
         "class"=>0.079552,
         "config_retrieval"=>17.7945790290833,
         "yumrepo"=>0.041205,
         "service"=>2.859459,
         "cron"=>0.002187,
         "schedule"=>0.002547,
         "total"=>37.6036520290832,
         "package"=>0.590787,
         "file"=>15.659662,
         "exec"=>0.562371,
         "filebucket"=>0.000352,
         "user"=>0.009658}
   Resources:
        {"changed"=>1, "total"=>564, "out_of_sync"=>1}



Finished processing 1 / 1 hosts in 86.24 ms

Untitled Text (17-Mar @ 16:59)

ripienaar.devco.net

Syntax Highlighted Code

  1. Tester Node: Xtraordinary Hosting, UK
  2.        Lookup Time: 0.040787
  3.       Connect Time: 0.003306
  4.      Pre-Xfer Time: 0.029035
  5. [92 more lines...]

Plain Code

Tester Node: Xtraordinary Hosting, UK
       Lookup Time: 0.040787
      Connect Time: 0.003306
     Pre-Xfer Time: 0.029035
   Start-Xfer Time: 0.028988
        Total Time: 0.075377
     Bytes Fetched: 21686


Tester Node: Bytemark, UK
       Lookup Time: 0.067504
      Connect Time: 0.00179
     Pre-Xfer Time: 0.043034
   Start-Xfer Time: 0.042988
        Total Time: 0.11425
     Bytes Fetched: 21686


Tester Node: Hetzner, Germany
       Lookup Time: 0.227537
      Connect Time: 0.004639
     Pre-Xfer Time: 0.037592
   Start-Xfer Time: 0.037561
        Total Time: 0.280909
     Bytes Fetched: 21686


Tester Node: Linode, London, UK
       Lookup Time: 0.332508
      Connect Time: 0.001699
     Pre-Xfer Time: 0.04252
   Start-Xfer Time: 0.042467
        Total Time: 0.378775
     Bytes Fetched: 21686


Tester Node: Linode, Newark, NJ
       Lookup Time: 0.22591
      Connect Time: 0.003135
     Pre-Xfer Time: 0.206994
   Start-Xfer Time: 0.206921
        Total Time: 0.450009
     Bytes Fetched: 21686


Tester Node: BE ADSL, UK
       Lookup Time: 0.479527
      Connect Time: 0.022071
     Pre-Xfer Time: 0.035733
   Start-Xfer Time: 0.035533
        Total Time: 0.58386
     Bytes Fetched: 21686


Tester Node: Rapidswitch, Maidenhead, UK
       Lookup Time: 0.737019
      Connect Time: 0.003952
     Pre-Xfer Time: 0.02699
   Start-Xfer Time: 0.026898
        Total Time: 0.772115
     Bytes Fetched: 21686


Tester Node: Linode, Dallas, TX
       Lookup Time: 0.471059
      Connect Time: 0.001428
     Pre-Xfer Time: 0.353136
   Start-Xfer Time: 0.353071
        Total Time: 0.827824
     Bytes Fetched: 21686


Tester Node: MTN Business Hosting, Cape Town, ZA
       Lookup Time: 0.003742
      Connect Time: 0.020814
     Pre-Xfer Time: 0.747418
   Start-Xfer Time: 0.747382
        Total Time: 0.812517
     Bytes Fetched: 21686


Tester Node: Linode, Fremont, CA
       Lookup Time: 0.571142
      Connect Time: 0.0015
     Pre-Xfer Time: 0.347058
   Start-Xfer Time: 0.347
        Total Time: 0.922241
     Bytes Fetched: 21686


Tester Node: Hetzner Cape Town, ZA
       Lookup Time: 0.787274
      Connect Time: 0.023555
     Pre-Xfer Time: 0.498757
   Start-Xfer Time: 0.49873
        Total Time: 1.357386
     Bytes Fetched: 21686

Untitled Ruby (8-Mar @ 14:48)

ripienaar.devco.net

Syntax Highlighted Code

  1. #!/usr/bin/ruby
  2.  
  3. require 'mcollective'
  4. require 'pp'
  5. [53 more lines...]

Plain Code

#!/usr/bin/ruby

require 'mcollective'
require 'pp'

agent = "filemgr"

# the simplerpc request
request = {:action          => "status",
           :data            => {:file => "/tmp"}}


classname = "MCollective::Agent::#{agent.capitalize}"

class NoopConnector
    def method_missing(*args)
        MCollective::Log.debug("connector #{args.pretty_inspect}")
        true
    end
end

configfile = "server.cfg"

# stub the connector with a noop one
MCollective::PluginManager << {:type => "connector_plugin", :class => NoopConnector.new}
connection = MCollective::PluginManager["connector_plugin"]

config = MCollective::Config.instance
config.loadconfig(configfile) unless config.configured

MCollective::PluginManager.loadclass(classname)
MCollective::PluginManager << {:type => "#{agent}_agent", :class => classname}

pp MCollective::PluginManager["#{agent}_agent"].handlemsg({:body => request}, connection)

OUTPUT
======
debug 2011/03/08 15:23:37: ddl.rb:56:in `findddlfile' Found filemgr ddl at /usr/libexec/mcollective/mcollective/agent/filemgr.ddl
debug 2011/03/08 15:23:37: pluginmanager.rb:73:in `[]' Returning plugin filemgr_agent with class MCollective::Agent::Filemgr
debug 2011/03/08 15:23:37: filemgr.rb:63:in `status' Asked for status of '/tmp' - it is present
{:statusmsg=>"OK",
 :data=>
  {:ctime=>Tue Mar 08 15:07:57 +0000 2011,
   :type=>"directory",
   :present=>1,
   :uid=>0,
   :mtime_seconds=>1299596877,
   :gid=>0,
   :ctime_seconds=>1299596877,
   :atime_seconds=>1299529385,
   :atime=>Mon Mar 07 20:23:05 +0000 2011,
   :size=>4096,
   :output=>"present",
   :name=>"/tmp",
   :md5=>0,
   :mtime=>Tue Mar 08 15:07:57 +0000 2011,
   :mode=>"41777"},
 :statuscode=>0}

Untitled Ruby (2-Mar @ 21:28)

ripienaar.devco.net

Syntax Highlighted Code

  1. module Puppet::Parser::Functions
  2.     newfunction(:from_json, :type => :rvalue) do |args|
  3.        PSON.load(args[0])
  4.     end
  5. end

Plain Code

module Puppet::Parser::Functions
    newfunction(:from_json, :type => :rvalue) do |args|
       PSON.load(args[0])
    end
end

Untitled Text (14-Feb @ 18:19)

ripienaar.devco.net

Syntax Highlighted Code

  1. define print {
  2.     notify{$name: }
  3. }
  4.  
  5. [11 more lines...]

Plain Code

define print {
    notify{$name: }
}

$vars = split("one,two,three", ",")

print{$vars: }



notice: two
notice: /Stage[main]//Print[two]/Notify[two]/message: defined 'message' as 'two'
notice: one
notice: /Stage[main]//Print[one]/Notify[one]/message: defined 'message' as 'one'
notice: three
notice: /Stage[main]//Print[three]/Notify[three]/message: defined 'message' as 'three'

Untitled Ruby (11-Feb @ 09:34)

ripienaar.devco.net

Syntax Highlighted Code

  1. #!/usr/bin/ruby
  2.  
  3. require 'mcollective'
  4.  
  5. [31 more lines...]

Plain Code

#!/usr/bin/ruby

require 'mcollective'

include MCollective::RPC

rpcutil = rpcclient("rpcutil")

hosts = {}
count = 0

rpcutil.inventory do |resp|
   facts = resp[:body][:data][:facts]

   pp resp[:body][:data] if facts["hostname"].nil?
   next if facts["hostname"].nil?

   role = facts["hostname"]
   role = $1 if role =~ /gt-(.+?)\d+/

   hosts[role] ||= []

   hosts[role] << {:fqdn => facts["fqdn"], :address => facts["ipaddress"]}

   count += 1
end

hosts.keys.sort.each do |group|
    hosts[group].each do |node|
        puts "[%s;%s]" % [group, node[:fqdn]]
        puts "\taddress %s" % node[:address]
        puts
    end
end

STDERR.puts "Dumped #{count} hosts in #{hosts.keys.size} groups"

Untitled Ruby (7-Feb @ 17:03)

ripienaar.devco.net

Syntax Highlighted Code

  1. Limit                     Soft Limit           Hard Limit           Units    
  2. Max cpu time              unlimited            unlimited            seconds  
  3. Max file size             unlimited            unlimited            bytes    
  4. Max data size             unlimited            unlimited            bytes    
  5. [11 more lines...]

Plain Code

Limit                     Soft Limit           Hard Limit           Units     
Max cpu time              unlimited            unlimited            seconds   
Max file size             unlimited            unlimited            bytes     
Max data size             unlimited            unlimited            bytes     
Max stack size            10485760             unlimited            bytes     
Max core file size        0                    unlimited            bytes     
Max resident set          unlimited            unlimited            bytes     
Max processes             unlimited            unlimited            processes 
Max open files            1024                 1024                 files     
Max locked memory         32768                32768                bytes     
Max address space         unlimited            unlimited            bytes     
Max file locks            unlimited            unlimited            locks     
Max pending signals       114688               114688               signals   
Max msgqueue size         819200               819200               bytes     
Max nice priority         0                    0                    
Max realtime priority     0                    0                    

Untitled Ruby (7-Feb @ 08:53)

ripienaar.devco.net

Syntax Highlighted Code

  1. #!/usr/bin/ruby
  2.  
  3. require 'mcollective'
  4.  
  5. [6 more lines...]

Plain Code

#!/usr/bin/ruby

require 'mcollective'

include MCollective::RPC

u = rpcclient("rpcutil")

u.get_fact(:fact => "uptime_days") do |resp|
    puts "%-30s - %s" % [ resp[:senderid], resp[:body][:data][:value].class ]
end

Untitled Ruby (2-Feb @ 15:25)

ripienaar.devco.net

Syntax Highlighted Code

  1. module MCollective
  2.     module Agent
  3.         class Echo<RPC::Agent
  4.             metadata    :name        => "Echo Agent",
  5. [17 more lines...]

Plain Code

module MCollective
    module Agent
        class Echo<RPC::Agent
            metadata    :name        => "Echo Agent",
                        :description => "Simple Echo Agent",
                        :author      => "Me",
                        :license     => "Apache v.2",
                        :version     => "1.0",
                        :url         => "http://www.devco.net/",
                        :timeout     => 2

            action "echo" do
                validate :msg, String

                reply.fail! "Boom!" if rand(10) % 2 == 0

                reply[:msg] = request[:msg]
                reply[:time] = Time.now.to_s
            end
        end
    end
end

Untitled Ruby (2-Feb @ 15:15)

ripienaar.devco.net

Syntax Highlighted Code

  1. module MCollective
  2.     module Registration
  3.         # A registration plugin that sends in all the meta data we have for a node:
  4.         #
  5. [41 more lines...]

Plain Code

module MCollective
    module Registration
        # A registration plugin that sends in all the meta data we have for a node:
        #
        # - all facts
        # - all agents
        # - all classes if applicable
        #
        # will add cf classes soon
        #
        # http://code.google.com/p/mcollective-plugins/wiki/RegistrationMetaData
        # Author: R.I.Pienaar <rip@devco.net>
        # Licence: Apache 2
        class Meta<Base
            def initialize
              @statefile = Config.instance.pluginconf["puppetd.statefile"] || "/var/lib/puppet/state/state.yaml"
              @last_registration = -1
            end

            def body
                if File.exists?(@statefile)
                  last_puppet_run = File.stat(@statefile).mtime.to_i
                  raise "no puppet run since last registration" unless last_puppet_run > @last_registration
                  @last_registration = Time.now.to_i
                end

                result = {:agentlist => [],
                          :facts => {},
                          :classes => []}

                cfile = Config.instance.classesfile

                Log.instance.info("Reading classes from #{cfile}")

                if File.exist?(cfile)
                    result[:classes] = File.readlines(cfile).map {|i| i.chomp}
                end

                result[:agentlist] = Agents.agentlist
                result[:facts] = PluginManager["facts_plugin"].get_facts

                result
            end
        end
    end
end

Untitled Text (30-Jan @ 16:33)

ripienaar.devco.net

Syntax Highlighted Code

  1. root     27880  4.3  0.2  6424 4256 ?        S     2009 26567:21 /usr/bin/ruby /usr/sbin/flashpolicyd --timeout=10 --xml=/etc/flashpolicy.xml --logfreq=1800 --logfile=/var/log/flashpolicy.l
  2.  
  3. I, [2011-01-30T16:32:07.095244 #27880]  INFO -- : -604046208: Had 12431190 clients and 505338 bogus clients. Uptime 422 days 18 hours 34 min. 0 connection(s) in use now.

Plain Code

root     27880  4.3  0.2  6424 4256 ?        S     2009 26567:21 /usr/bin/ruby /usr/sbin/flashpolicyd --timeout=10 --xml=/etc/flashpolicy.xml --logfreq=1800 --logfile=/var/log/flashpolicy.l

I, [2011-01-30T16:32:07.095244 #27880]  INFO -- : -604046208: Had 12431190 clients and 505338 bogus clients. Uptime 422 days 18 hours 34 min. 0 connection(s) in use now.

Untitled Text (24-Jan @ 18:44)

ripienaar.devco.net

Syntax Highlighted Code

  1. 18:42:39 88.198.86.178> haproxy[10219]: Proxy files_loadshare started.
  2. 18:42:39 88.198.86.178> haproxy[10219]: Proxy rest_loadshare started.
  3. 18:42:39 88.198.86.178> haproxy[10219]: Proxy files_proxy started.
  4. 18:42:39 88.198.86.178> haproxy[10219]: Proxy rest_proxy started.
  5. [8 more lines...]

Plain Code

18:42:39 88.198.86.178> haproxy[10219]: Proxy files_loadshare started.
18:42:39 88.198.86.178> haproxy[10219]: Proxy rest_loadshare started.
18:42:39 88.198.86.178> haproxy[10219]: Proxy files_proxy started.
18:42:39 88.198.86.178> haproxy[10219]: Proxy rest_proxy started.
18:42:39 88.198.86.178> haproxy[10219]: Server files_loadshare/dev4 is DOWN. 1 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
18:42:40 88.198.86.178> haproxy[10220]: Server files_loadshare/dev5 is DOWN. 0 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
18:42:40 88.198.86.178> haproxy[10220]: backend files_loadshare has no server available!
18:42:40 88.198.86.178> haproxy[10220]: Server rest_loadshare/dev4 is DOWN. 1 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
18:42:41 88.198.86.178> haproxy[10220]: Server rest_loadshare/dev5 is DOWN. 0 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
18:42:41 88.198.86.178> haproxy[10220]: backend rest_loadshare has no server available!
18:42:51 88.198.86.178> haproxy[10220]: Server rest_loadshare/dev5 is UP. 1 active and 0 backup servers online. 0 sessions requeued, 0 total in queue.
18:42:52 88.198.86.178> haproxy[10220]: Server files_loadshare/dev5 is UP. 1 active and 0 backup servers online. 0 sessions requeued, 0 total in queue.
18:42:56 88.198.86.178> haproxy[10220]: 87.224.77.66:52587 [24/Jan/2011:18:42:56.555] rest_proxy rest_proxy/<STATS> 0/-1/-1/-1/0 200 11515 - - PR-- 0/0/0/0 0/0 "GET /haproxy?stats HTTP/1.1"

Untitled Ruby (22-Jan @ 12:43)

ripienaar.devco.net

Syntax Highlighted Code

  1. #!/usr/bin/ruby
  2.  
  3. require 'rubygems'
  4. require 'stomp'
  5. [12 more lines...]

Plain Code

#!/usr/bin/ruby

require 'rubygems'
require 'stomp'
require 'pp'

c = Stomp::Connection.open("admin", "secret", "localhost", 6163, true)

10.times { c.publish("/queue/foo", "foo") }

c.subscribe("/queue/foo")
c.subscribe("/temp-queue/bar", { "transformation" => "jms-map-xml"})
c.publish("/queue/ActiveMQ.Statistics.Broker", "", {"reply-to" => "/temp-queue/bar"})

loop do
    pp c.receive
end

Untitled Ruby (22-Jan @ 00:45)

ripienaar.devco.net

Syntax Highlighted Code

  1. #!/usr/bin/ruby
  2.  
  3. # simple prototype of a file upload server supposed to run on a
  4. # pair of drbd machines making a filesystem available.  front it
  5. [114 more lines...]

Plain Code

#!/usr/bin/ruby

# simple prototype of a file upload server supposed to run on a
# pair of drbd machines making a filesystem available.  front it
# with a load balancer and get a cheap cluster web file server
# that supports failover and scaling using shards of redudant
# storage servers
#
#
#                                     - rest service |
#                                   /                 - drbd
#   client | ----- | load balancer |
#                                   \                 - drbd
#                                     - rest service |
#
#
# On the DRBD lives a file 'owner' that is mode 000 and each REST
# service checks for the existence of this file to determine if it
# should serve requests.  The load balancer health checks with GET
# on / which also checks for the existance of this file thus the
# load balancer picks the active host to send file writes and
# deletes to.  Any IO failure results in a 500 error which the
# load balancer also understands as failure
#
# File reads to the CDN that fronts this will still be doing using
# normal apache or lighttpd
#
# This is a prototype showing the protocol, final version will be
# based on node.js
#
# upload with curl
#  curl -F "file=@file.txt" http://localhost:4567/some/long/path/to/file/file.txt
#
# delete with telnet
#  telnet localhost 4567
#  DELETE /some/long/path/to/file/file.txt HTTP/1.0
#
# test with curl
#  curl http://localhost:4567/
#
# R.I.Pienaar <rip@devco.net>


require 'rubygems'
require 'sinatra'
require 'fileutils'

# uploads to /tmp/uploads only if /tmp/uploads/owner exist
DEST="/tmp/uploads"
OWNERFILE="owner"

class Filer
    class << self
        def storage_owner?
            File.exist?(File.join([DEST, OWNERFILE]))
        end

        def delete(file)
            fpath = File.join([DEST, file])

            FileUtils.rm(fpath) if File.exist?(fpath)

            File.exist?(fpath) ? false : true
        end

        def upload(file, tempfile)
            fpath = File.join([DEST, file])
            dirname = File.dirname(fpath)

            FileUtils.mkdir_p(dirname) unless File.exist?(dirname)

            File.open(fpath, "w") do |f|
                while blk = tempfile.read(65536)
                    f.print blk
                end
            end

            return fpath
        end
    end
end

before { halt 500, "Not the storage owner\n" unless Filer.storage_owner? }

get "/" do
    "ok\n"
end

post "/*" do
    halt 500, "please specify a file name\n" unless params[:splat][0]
    halt 500, "No file uploaded\n" unless params[:file] && params[:file][:tempfile]

    tmpfile = params[:file][:tempfile]
    saved_file = ""

    begin
        saved_file = Filer.upload(params[:splat][0], tmpfile)
    rescue Exception => e
        halt 500, "Failed to handle file upload: #{e}\n"
    ensure
        tmpfile.delete
    end

    "saved " << saved_file << "\n"
end

delete "/*" do
    halt 500, "please specify a file name\n" unless params[:splat][0]

    begin
        if Filer.delete(params[:splat][0])
            return "file deleted\n"
        else
            halt 500, "could not delete file\n"
        end
    rescue Exception => e
        halt 500, "Failed to handle file delete: #{e}\n"
    end
end

Untitled Ruby (20-Jan @ 21:35)

ripienaar.devco.net

Syntax Highlighted Code

  1. receive_data: "CONNECT"
  2. receive_data: "\n"
  3. receive_data: "login:rip"
  4. receive_data: "\n"
  5. [22 more lines...]

Plain Code

receive_data: "CONNECT"
receive_data: "\n"
receive_data: "login:rip"
receive_data: "\n"
receive_data: "content-length:0"
receive_data: "\n"
receive_data: "passcode:xxx"
receive_data: "\n"
receive_data: "content-type: text/plain; charset=UTF-8"
receive_data: "\n"
receive_data: "\n"
receive_data: "\000"
Connecting
Sending frame CONNECTED
session:wow


receive_data: "SUBSCRIBE"
receive_data: "\ndestination:/topic/meh\ncontent-length:0\ncontent-type: text/plain; charset=UTF-8\n\n\000"
receive_data: "SEND\ndestination:/topic/meh\ncontent-length:5\ncontent-type: text/plain; charset=UTF-8\n\nhello\000"
Sending frame MESSAGE
message-id:msg-#stompcma-1
content-type:text/plain; charset=UTF-8
destination:/topic/meh
content-length:5

hello

Untitled Text (20-Jan @ 11:57)

ripienaar.devco.net

Syntax Highlighted Code

  1. % stomp-irb -s monitor1 --port 6163
  2. Interactive Ruby shell for STOMP
  3.  
  4. Type 'help' for usage instructions
  5. [11 more lines...]

Plain Code

% stomp-irb -s monitor1 --port 6163
Interactive Ruby shell for STOMP

Type 'help' for usage instructions

>> recv_callback {|f| puts "Return message turn around: #{Time.now.to_f - f.body.to_f}"}
>> subscribe :topic, "test"
Current Subscriptions:
        /topic/test

=> nil
>> topic "test", Time.now.to_f
=> nil
<<stomp>> 1295524583.62089
Return message turn around: 0.0091710090637207
>>

Untitled XML (20-Jan @ 09:36)

ripienaar.devco.net

Syntax Highlighted Code

  1. <beans
  2.   xmlns="http://www.springframework.org/schema/beans"
  3.   xmlns:amq="http://activemq.apache.org/schema/core"
  4.   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5. [70 more lines...]

Plain Code

<beans
  xmlns="http://www.springframework.org/schema/beans"
  xmlns:amq="http://activemq.apache.org/schema/core"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
  http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd
  http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd">

    <broker xmlns="http://activemq.apache.org/schema/core" brokerName="stomp1-foo" useJmx="true" persistent="false">
        <destinationPolicy>
          <policyMap>
            <policyEntries>
              <policyEntry topic="mcollective.>" gcInactiveDestinations="true" inactiveTimoutBeforeGC="30000" producerFlowControl="false"/>
              <policyEntry topic=">" gcInactiveDestinations="true" inactiveTimoutBeforeGC="30000"/>
              <policyEntry queue=">" gcInactiveDestinations="true" inactiveTimoutBeforeGC="30000"/>
            </policyEntries>
          </policyMap>
        </destinationPolicy>

        <managementContext>
          <managementContext connectorPort="1099" jmxDomainName="org.apache.activemq"/>
        </managementContext>

        <networkConnectors>
          <networkConnector name="stomp1-stomp3" uri="static:(tcp://monitor3.fooltd.net:6166)" userName="amq" password="xxx" duplex="true" decreaseNetworkConsumerPriority="true" networkTTL="2" dynamicOnly="true"/>
        </networkConnectors>

        <!--
        <persistenceAdapter>
            <kahaDB directory="activemq-data" journalMaxFileLength="32mb"/>
        </persistenceAdapter>
        -->

        <plugins>
          <statisticsBrokerPlugin/>
          <simpleAuthenticationPlugin>
            <users>
            <!-- removed -->
            </users>
          </simpleAuthenticationPlugin>
          <authorizationPlugin>
            <map>
              <authorizationMap>
                <authorizationEntries>
                  <authorizationEntry queue=">" write="admins" read="admins" admin="admins" />
                  <authorizationEntry topic=">" write="admins" read="admins" admin="admins" />
                </authorizationEntries>
              </authorizationMap>
            </map>
          </authorizationPlugin>
        </plugins>

        <systemUsage>
          <systemUsage>
            <memoryUsage>
              <memoryUsage limit="80 mb" />
            </memoryUsage>
            <storeUsage>
              <storeUsage limit="1 gb" />
            </storeUsage>
            <tempUsage>
              <tempUsage limit="100 mb" />
            </tempUsage>
          </systemUsage>
        </systemUsage>

        <transportConnectors>
          <transportConnector name="openwire" uri="tcp://0.0.0.0:6166"/>
          <transportConnector name="stomp"   uri="stomp://0.0.0.0:6163"/>
        </transportConnectors>

    </broker>

    <import resource="jetty.xml"/>
</beans>

not agents (19-Jan @ 18:00)

ripienaar.devco.net

Syntax Highlighted Code

  1. $ mc-irb rpcutil
  2. The Marionette Collective Interactive Ruby Shell version 1.1.0
  3.  
  4. Active Filter matched 51 hosts:
  5. [11 more lines...]

Plain Code

$ mc-irb rpcutil
The Marionette Collective Interactive Ruby Shell version 1.1.0

Active Filter matched 51 hosts:
        Identity: []
         Classes: []
           Facts: []
          Agents: ["rpcutil"]

Use mc? to get help on using this shell
>> rpc(:inventory) {|r| puts r[:sender] unless r[:data][:agents].include?("foo")}
<list of nodes>

Finished processing 51 / 51 hosts in 827.51 ms
>> true
>>

Untitled Ruby (18-Jan @ 18:34)

ripienaar.devco.net

Syntax Highlighted Code

  1. >> rpc(:list, :pattern => "init") {|r| pp r}
  2. #<MCollective::RPC::Result:0xb7e881b0
  3.  @action="list",
  4.  @agent="process",
  5. [62 more lines...]

Plain Code

>> rpc(:list, :pattern => "init") {|r| pp r}
#<MCollective::RPC::Result:0xb7e881b0
 @action="list",
 @agent="process",
 @results=
  {:statusmsg=>"OK",
   :data=>
    {:pslist=>
      [{:flags=>4194560,
        :processor=>0,
        :session=>1,
        :cminflt=>185351732,
        :euid=>0,
        :rt_priority=>0,
        :tty_nr=>0,
        :kstkeip=>14746626,
        :cutime=>417813,
        :wchan=>0,
        :endcode=>134544728,
        :blocked=>0,
        :utime=>0,
        :name=>"init",
        :uid=>0,
        :egid=>0,
        :cmdline=>"init [3]",
        :startstack=>3219631088,
        :username=>"root",
        :signal=>0,
        :ppid=>0,
        :majflt=>18,
        :cstime=>156676,
        :vsize=>2228224,
        :tpgid=>-1,
        :cmajflt=>6610,
        :gid=>0,
        :nswap=>0,
        :minflt=>1075,
        :sigignore=>1475401980,
        :pid=>1,
        :cwd=>"/",
        :comm=>"init",
        :sigcatch=>671819267,
        :environ=>
         {"TERM"=>"linux",
          "SELINUX_INIT"=>"YES",
          "HOME"=>"/",
          "PATH"=>"/bin:/usr/bin:/sbin:/usr/sbin"},
        :rss=>151,
        :nice=>0,
        :cnswap=>0,
        :policy=>0,
        :itrealvalue=>0,
        :starttime=>16,
        :exit_signal=>0,
        :pgrp=>1,
        :exe=>"/sbin/init",
        :rlim=>4294967295,
        :state=>"S",
        :kstkesp=>3219629772,
        :stime=>8,
        :priority=>15,
        :fd=>{"10"=>"/dev/initctl"},
        :startcode=>134512640,
        :root=>"/"}]},
   :statuscode=>0}>

Finished processing 1 / 1 hosts in 120.47 ms

Untitled Ruby (18-Jan @ 09:36)

ripienaar.devco.net

Syntax Highlighted Code

  1. munin.mc:
  2.  
  3. inventory do
  4.     format "[%s;%s]\n\taddress %s\n\n"
  5. [12 more lines...]

Plain Code

munin.mc:

inventory do
    format "[%s;%s]\n\taddress %s\n\n"

    fields { [ facts["location"], identity, facts["ipaddress"] ] }
end



% mc-inventory --script munin.mc
[hetzner;xen3.xx.net]
        address 213.x.x.x

[hetzner;ns1.yy.net]
        address 78.x.x.x

Untitled Ruby (18-Jan @ 09:15)

ripienaar.devco.net

Syntax Highlighted Code

  1. % mc-rpc -I `hostname` filemgr status file=/etc/group
  2. Determining the amount of hosts matching filter for 2 seconds .... 1
  3.  
  4.  * [ ============================================================> ] 1 / 1
  5. [54 more lines...]

Plain Code

% mc-rpc -I `hostname` filemgr status file=/etc/group
Determining the amount of hosts matching filter for 2 seconds .... 1

 * [ ============================================================> ] 1 / 1


nephilim.ml.org                          
         Change time:
        Tue Jan 18 09:14:34 +0000 2011
             Present: 1
                Name: /etc/group
               Owner: 0
               Group: 0
                 MD5: 603385407cc936692e7de5e651184a1b
   Modification time: 1295342074
                Size: 897
         Access time: Tue Jan 18 09:15:12 +0000 2011
         Change time: 1295342074
              Status: present
                Type: file
                Mode: 100644
   Modification time: Tue Jan 18 09:14:34 +0000 2011
         Access time: 1295342112

Finished processing 1 / 1 hosts in 78.39 ms

% mc-filemgr status -f /etc/group -I nephilim.ml.org

 * [ ============================================================> ] 1 / 1

nephilim.ml.org                         : present

Finished processing 1 / 1 hosts in 79.00 ms

% mc-filemgr status -f /etc/group -I nephilim.ml.org -d

 * [ ============================================================> ] 1 / 1


nephilim.ml.org                          
         Change time: Tue Jan 18 09:14:34 +0000 2011
             Present: 1
                Name: /etc/group
               Owner: 0
               Group: 0
                 MD5: 603385407cc936692e7de5e651184a1b
   Modification time: 1295342074
              Status: present
                Size: 897
         Access time:
        Tue Jan 18 09:17:46 +0000 2011
         Change time: 1295342074
                Type: file
                Mode: 100644
   Modification time: Tue Jan 18 09:14:34 +0000 2011
         Access time: 1295342266


Finished processing 1 / 1 hosts in 72.91 ms

Untitled Ruby (18-Jan @ 09:10)

ripienaar.devco.net

Syntax Highlighted Code

  1. class MCollective::Application::Facts<MCollective::Application
  2.     description "Reports on usage for a specific fact"
  3.  
  4.     # this will be available in configuration[:fact]
  5. [51 more lines...]

Plain Code

class MCollective::Application::Facts<MCollective::Application
    description "Reports on usage for a specific fact"

    # this will be available in configuration[:fact]
    option :script,
        :description    => "Fact to report on",
        :arguments      => ["--fact FACT", "-f FACT"]

    def post_option_parser(configuration)
        configuration[:fact] = ARGV.shift if ARGV.size > 0
    end

    def validate_configuration(configuration)
        raise "Please specify a fact to report for" unless configuration.include?(:fact)
    end

    def show_single_fact_report(fact, facts, verbose=false)
        puts("Report for fact: #{fact}\n\n")

        facts.keys.sort.each do |k|
            printf("        %-40sfound %d times\n", k, facts[k].size)

            if verbose
                puts

                facts[k].sort.each do |f|
                    puts("            #{f}")
                end

                puts
            end
        end
    end

    def main
        rpcutil = rpcclient("rpcutil", :options => options)
        rpcutil.progress = false

        facts = {}

        rpcutil.get_fact(:fact => configuration[:fact]) do |resp|
            begin
                value = resp[:body][:data][:value]
                if value
                    facts.include?(value) ? facts[value] << resp[:senderid] : facts[value] = [ resp[:senderid] ]
                end
            rescue Exception => e
                STDERR.puts "Could not parse facts for #{resp[:senderid]}: #{e.class}: #{e}"
            end
        end

        show_single_fact_report(configuration[:fact], facts, options[:verbose])

        printrpcstats
    end
end

Untitled Ruby (18-Jan @ 08:58)

ripienaar.devco.net

Syntax Highlighted Code

  1. $ mc help
  2. he Marionette Collection verion @DEVELOPMENT_VERSION@
  3.  
  4.   facts           Reports on usage for a specific fact
  5. [7 more lines...]

Plain Code

$ mc help
he Marionette Collection verion @DEVELOPMENT_VERSION@

  facts           Reports on usage for a specific fact
  find            Find hosts matching criteria
  help            Application list
  inventory       Shows an inventory for a given node
  ping            Ping all nodes

$ mc find -W country=de
box1.net
etc

Untitled Ruby (16-Jan @ 21:02)

ripienaar.devco.net

Syntax Highlighted Code

  1. class nagios::hostgroup::activemq_servers {
  2.     $nodes = search_nodes("{'classes' => 'activemq', 'facts.monitors' => /${fqdn}/}")
  3.  
  4.     if $nodes != []  {
  5. [5 more lines...]

Plain Code

class nagios::hostgroup::activemq_servers {
    $nodes = search_nodes("{'classes' => 'activemq', 'facts.monitors' => /${fqdn}/}")

    if $nodes != []  {
        nagios::hostgroup{"activemq_servers":
            nodes       => $nodes,
            description => "ActiveMQ Servers"
        }
    }
}

Untitled Text (14-Jan @ 16:44)

ripienaar.devco.net

Syntax Highlighted Code

  1. Linux ip-10-228-23-144 2.6.32-305-ec2 #9-Ubuntu SMP Thu Apr 15 04:14:01 UTC 2010 i686 GNU/Linux
  2. Ubuntu 10.04 LTS
  3.      ___   _        __   __   ____            __
  4.     / _ \ (_)___ _ / /  / /_ / __/____ ___ _ / /___
  5. [250 more lines...]

Plain Code

Linux ip-10-228-23-144 2.6.32-305-ec2 #9-Ubuntu SMP Thu Apr 15 04:14:01 UTC 2010 i686 GNU/Linux
Ubuntu 10.04 LTS
     ___   _        __   __   ____            __
    / _ \ (_)___ _ / /  / /_ / __/____ ___ _ / /___
   / , _// // _ `// _ \/ __/_\ \ / __// _ `// // -_)
  /_/|_|/_/ \_, //_//_/\__//___/ \__/ \_,_//_/ \__/
           /___/

Welcome to a managed virtual machine brought to you by RightScale!

********************************************************************
********************************************************************
***       Your instance is now operational.                      ***
***       All of the configuration has completed.                ***
***       Please check /var/log/messages for details.            ***
********************************************************************
********************************************************************

0 packages can be updated.
0 updates are security updates.


The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

root@ip-10-228-23-144:~# apt-get install rubygems
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Couldn't find package rubygems
root@ip-10-228-23-144:~# apt-get update
Get:1 http://ec2-us-east-mirror.rightscale.com lucid Release.gpg [189B]
Ign http://ec2-us-east-mirror.rightscale.com/ubuntu/ lucid/main Translation-en_US
Ign http://ec2-us-east-mirror.rightscale.com/ubuntu/ lucid/restricted Translation-en_US
Ign http://ec2-us-east-mirror.rightscale.com/ubuntu/ lucid/universe Translation-en_US
Ign http://ec2-us-east-mirror.rightscale.com/ubuntu/ lucid/multiverse Translation-en_US
Get:2 http://ec2-us-east-mirror.rightscale.com lucid-updates Release.gpg [198B]
Ign http://ec2-us-east-mirror.rightscale.com/ubuntu/ lucid-updates/main Translation-en_US
Ign http://ec2-us-east-mirror.rightscale.com/ubuntu/ lucid-updates/restricted Translation-en_US
Ign http://ec2-us-east-mirror.rightscale.com/ubuntu/ lucid-updates/universe Translation-en_US
Ign http://ec2-us-east-mirror.rightscale.com/ubuntu/ lucid-updates/multiverse Translation-en_US
Get:3 http://ec2-us-east-mirror.rightscale.com lucid-security Release.gpg [198B]
Ign http://ec2-us-east-mirror.rightscale.com/ubuntu/ lucid-security/main Translation-en_US
Ign http://ec2-us-east-mirror.rightscale.com/ubuntu/ lucid-security/restricted Translation-en_US
Ign http://ec2-us-east-mirror.rightscale.com/ubuntu/ lucid-security/universe Translation-en_US
Ign http://ec2-us-east-mirror.rightscale.com/ubuntu/ lucid-security/multiverse Translation-en_US
Get:4 http://ec2-us-east-mirror.rightscale.com lucid-backports Release.gpg [198B]
Ign http://ec2-us-east-mirror.rightscale.com/ubuntu/ lucid-backports/main Translation-en_US
Ign http://ec2-us-east-mirror.rightscale.com/ubuntu/ lucid-backports/restricted Translation-en_US
Ign http://ec2-us-east-mirror.rightscale.com/ubuntu/ lucid-backports/universe Translation-en_US
Ign http://ec2-us-east-mirror.rightscale.com/ubuntu/ lucid-backports/multiverse Translation-en_US
Get:5 http://ec2-us-east-mirror.rightscale.com lucid Release [57.2kB]
Get:6 http://ec2-us-east-mirror.rightscale.com lucid-updates Release [44.7kB]
Get:7 http://ec2-us-east-mirror.rightscale.com lucid-security Release [38.5kB]
Get:8 http://ec2-us-east-mirror.rightscale.com lucid-backports Release [38.5kB]
Get:9 http://ec2-us-east-mirror.rightscale.com lucid/main Packages [1,386kB]
Get:10 http://ec2-us-east-mirror.rightscale.com lucid/restricted Packages [6,208B]
Get:11 http://ec2-us-east-mirror.rightscale.com lucid/universe Packages [5,448kB]
Get:12 http://ec2-us-east-mirror.rightscale.com lucid/multiverse Packages [180kB]
Get:13 http://ec2-us-east-mirror.rightscale.com lucid-updates/main Packages [423kB]
Get:14 http://ec2-us-east-mirror.rightscale.com lucid-updates/restricted Packages [3,240B]
Get:15 http://ec2-us-east-mirror.rightscale.com lucid-updates/universe Packages [176kB]
Get:16 http://ec2-us-east-mirror.rightscale.com lucid-updates/multiverse Packages [7,669B]
Get:17 http://ec2-us-east-mirror.rightscale.com lucid-security/main Packages [121kB]
Fetched 8,022kB in 10s (742kB/s)
Reading package lists... Done
root@ip-10-228-23-144:~# apt-get install rubygems
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libapparmor1 liburi-perl libxml-namespacesupport-perl libapparmor-perl libfont-afm-perl libmailtools-perl libhtml-parser-perl libterm-readkey-perl libxml-sax-expat-perl librpc-xml-perl libxml-parser-perl
  libxml-libxml-perl libxml-sax-perl libhtml-format-perl libhtml-tree-perl libwww-perl libhtml-tagset-perl
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
  rubygems1.8
Suggested packages:
  rubygems-doc
The following NEW packages will be installed:
  rubygems rubygems1.8
0 upgraded, 2 newly installed, 0 to remove and 102 not upgraded.
Need to get 195kB of archives.
After this operation, 950kB of additional disk space will be used.
Do you want to continue [Y/n]? y
Get:1 http://ec2-us-east-mirror.rightscale.com/ubuntu/ lucid/universe rubygems1.8 1.3.5-1ubuntu2 [192kB]
Get:2 http://ec2-us-east-mirror.rightscale.com/ubuntu/ lucid/universe rubygems 1.3.5-1ubuntu2 [2,684B]
Fetched 195kB in 0s (240kB/s)
Selecting previously deselected package rubygems1.8.
(Reading database ... 37422 files and directories currently installed.)
Unpacking rubygems1.8 (from .../rubygems1.8_1.3.5-1ubuntu2_all.deb) ...
Selecting previously deselected package rubygems.
Unpacking rubygems (from .../rubygems_1.3.5-1ubuntu2_all.deb) ...
Processing triggers for man-db ...
fopen: Permission denied
Setting up rubygems1.8 (1.3.5-1ubuntu2) ...

Setting up rubygems (1.3.5-1ubuntu2) ...
root@ip-10-228-23-144:~# apt-get install ruby rake
Reading package lists... Done
Building dependency tree
Reading state information... Done
ruby is already the newest version.
ruby set to manually installed.
rake is already the newest version.
The following packages were automatically installed and are no longer required:
  libapparmor1 liburi-perl libxml-namespacesupport-perl libapparmor-perl libfont-afm-perl libmailtools-perl libhtml-parser-perl libterm-readkey-perl libxml-sax-expat-perl librpc-xml-perl libxml-parser-perl
  libxml-libxml-perl libxml-sax-perl libhtml-format-perl libhtml-tree-perl libwww-perl libhtml-tagset-perl
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 102 not upgraded.
root@ip-10-228-23-144:~# gem install stomp stompserver  
Successfully installed stomp-1.1.6
Building native extensions.  This could take a while... 
Successfully installed daemons-1.1.0
Successfully installed eventmachine-0.12.10
Successfully installed hoe-2.8.0
Successfully installed stompserver-0.9.9
5 gems installed
Installing ri documentation for stomp-1.1.6...
Installing ri documentation for daemons-1.1.0...
Installing ri documentation for eventmachine-0.12.10... 
Installing ri documentation for hoe-2.8.0...
Installing ri documentation for stompserver-0.9.9...
Installing RDoc documentation for stomp-1.1.6...
Installing RDoc documentation for daemons-1.1.0...
Installing RDoc documentation for eventmachine-0.12.10...
Could not find main page README
Could not find main page README
Could not find main page README
Could not find main page README
Installing RDoc documentation for hoe-2.8.0...
Installing RDoc documentation for stompserver-0.9.9...  

oot@ip-10-228-23-144:~# git clone git://github.com/ripienaar/mcollective-collective-builder.git
Initialized empty Git repository in /root/mcollective-collective-builder/.git/
remote: Counting objects: 69, done.
remote: Compressing objects: 100% (61/61), done.
remote: Total 69 (delta 20), reused 0 (delta 0)
Receiving objects: 100% (69/69), 10.82 KiB, done.
Resolving deltas: 100% (20/20), done.
root@ip-10-228-23-144:~# cd ^C
root@ip-10-228-23-144:~# ls
mcollective-collective-builder
root@ip-10-228-23-144:~# cd mcollective-collective-builder/
root@ip-10-228-23-144:~/mcollective-collective-builder# ls
etc  plugins  Rakefile  README  templates
root@ip-10-228-23-144:~/mcollective-collective-builder# rake create
(in /root/mcollective-collective-builder)
Collective Name (mcollectivedev):
Stomp Server (stomp): localhost
Stomp Port (6163):
Stomp SSL (y|n) (n):
Stomp User (mcollective):
Stomp Password (secret):
GIT Source Repository (git://github.com/puppetlabs/marionette-collective.git):
Remote branch name (master):
MCollective Version (master):
Instances To Create (10):
Instance Count Start (0):
Created a new instance ip-10-228-23-144.eu-west-1.compute.internal-0 in /root/mcollective-collective-builder/collective/ip-10-228-23-144.eu-west-1.compute.internal-0
========================================
Created a new instance ip-10-228-23-144.eu-west-1.compute.internal-1 in /root/mcollective-collective-builder/collective/ip-10-228-23-144.eu-west-1.compute.internal-1
========================================
Created a new instance ip-10-228-23-144.eu-west-1.compute.internal-2 in /root/mcollective-collective-builder/collective/ip-10-228-23-144.eu-west-1.compute.internal-2
========================================
Created a new instance ip-10-228-23-144.eu-west-1.compute.internal-3 in /root/mcollective-collective-builder/collective/ip-10-228-23-144.eu-west-1.compute.internal-3
========================================
Created a new instance ip-10-228-23-144.eu-west-1.compute.internal-4 in /root/mcollective-collective-builder/collective/ip-10-228-23-144.eu-west-1.compute.internal-4
========================================
Created a new instance ip-10-228-23-144.eu-west-1.compute.internal-5 in /root/mcollective-collective-builder/collective/ip-10-228-23-144.eu-west-1.compute.internal-5
========================================
Created a new instance ip-10-228-23-144.eu-west-1.compute.internal-6 in /root/mcollective-collective-builder/collective/ip-10-228-23-144.eu-west-1.compute.internal-6
========================================
Created a new instance ip-10-228-23-144.eu-west-1.compute.internal-7 in /root/mcollective-collective-builder/collective/ip-10-228-23-144.eu-west-1.compute.internal-7
========================================
Created a new instance ip-10-228-23-144.eu-west-1.compute.internal-8 in /root/mcollective-collective-builder/collective/ip-10-228-23-144.eu-west-1.compute.internal-8
========================================
Created a new instance ip-10-228-23-144.eu-west-1.compute.internal-9 in /root/mcollective-collective-builder/collective/ip-10-228-23-144.eu-west-1.compute.internal-9
========================================
Created a new instance client in /root/mcollective-collective-builder/client
========================================

Created a collective with 10 members:
  Collective Name: mcollectivedev
       Node Names: ip-10-228-23-144.eu-west-1.compute.internal-{0-9}
    Stomp Version: master
     Stomp Server: stomp://mcollective:secret@localhost:6163

To recreate this collective use this command:

   MC_NAME=mcollectivedev MC_SERVER=localhost MC_USER=mcollective \
   MC_PASSWORD=secret MC_PORT=6163 MC_VERSION=master \  
   MC_COUNT=10 MC_COUNT_START=0 MC_SSL=n \
   MC_SOURCE=git://github.com/puppetlabs/marionette-collective.git \
   MC_SOURCE_BRANCH=master rake create

The collective instances are stored in collective/* and a client is setup in client/

Use rake start to start the collective, rake -T to see commands available to start,
stop and update it.

root@ip-10-228-23-144:~/mcollective-collective-builder# rake start
(in /root/mcollective-collective-builder)
Started ip-10-228-23-144.eu-west-1.compute.internal-4 status: false
Started ip-10-228-23-144.eu-west-1.compute.internal-6 status: false
Started ip-10-228-23-144.eu-west-1.compute.internal-3 status: 1431
Started ip-10-228-23-144.eu-west-1.compute.internal-8 status: false
Started ip-10-228-23-144.eu-west-1.compute.internal-2 status: false
Started ip-10-228-23-144.eu-west-1.compute.internal-7 status: false
Started ip-10-228-23-144.eu-west-1.compute.internal-9 status: false
Started ip-10-228-23-144.eu-west-1.compute.internal-1 status: false
Started ip-10-228-23-144.eu-west-1.compute.internal-0 status: false
Started ip-10-228-23-144.eu-west-1.compute.internal-5 status: false
root@ip-10-228-23-144:~/mcollective-collective-builder# rake status
(in /root/mcollective-collective-builder)
ip-10-228-23-144.eu-west-1.compute.internal-4:  running 
ip-10-228-23-144.eu-west-1.compute.internal-6:  running 
ip-10-228-23-144.eu-west-1.compute.internal-3:  running 
ip-10-228-23-144.eu-west-1.compute.internal-8:  running 
ip-10-228-23-144.eu-west-1.compute.internal-2:  running 
ip-10-228-23-144.eu-west-1.compute.internal-7:  running 
ip-10-228-23-144.eu-west-1.compute.internal-9:  running 
ip-10-228-23-144.eu-west-1.compute.internal-1:  running 
ip-10-228-23-144.eu-west-1.compute.internal-0:  running 
ip-10-228-23-144.eu-west-1.compute.internal-5:  running 
root@ip-10-228-23-144:~/mcollective-collective-builder# rake shell
(in /root/mcollective-collective-builder)

Running /bin/bash to start a subshell with MCOLLECTIVE_EXTRA_OPTS and RUBYLIB set

Please run the following once started:

    PATH=`pwd`/client:$PATH

To return to your normal shell and collective just type exit

root@ip-10-228-23-144:~/mcollective-collective-builder#     PATH=`pwd`/client:$PATH
root@ip-10-228-23-144:~/mcollective-collective-builder# mc-ping
ip-10-228-23-144.eu-west-1.compute.internal-3 time=70.74 ms
ip-10-228-23-144.eu-west-1.compute.internal-8 time=73.67 ms
ip-10-228-23-144.eu-west-1.compute.internal-2 time=76.05 ms
ip-10-228-23-144.eu-west-1.compute.internal-7 time=78.72 ms
ip-10-228-23-144.eu-west-1.compute.internal-9 time=81.00 ms
ip-10-228-23-144.eu-west-1.compute.internal-0 time=98.95 ms
ip-10-228-23-144.eu-west-1.compute.internal-5 time=99.33 ms
ip-10-228-23-144.eu-west-1.compute.internal-6 time=103.81 ms
ip-10-228-23-144.eu-west-1.compute.internal-4 time=104.22 ms
ip-10-228-23-144.eu-west-1.compute.internal-1 time=123.81 ms
^C

---- ping statistics ----
10 replies max: 123.81 min: 70.74 avg: 91.03

Untitled Ruby (14-Jan @ 13:03)

ripienaar.devco.net

Syntax Highlighted Code

  1. #!/usr/bin/ruby
  2.  
  3. require 'mcollective'
  4.  
  5. [15 more lines...]

Plain Code

#!/usr/bin/ruby

require 'mcollective'

include MCollective::RPC

rpc = rpcclient("puppetd")

enabled = running = 0

rpc.status do |resp|
    begin
        enabled += resp[:body][:data][:enabled]
        running += resp[:body][:data][:running]
    rescue Exception => e
        STDERR.puts "Failed to get results: #{e}"
    end
end

puts "enabled: #{enabled} runnig: #{running}"

Untitled JavaScript (14-Jan @ 10:03)

ripienaar.devco.net

Syntax Highlighted Code

  1. {"ConnectionInfo": {
  2.   "commandId": 0,
  3.   "responseRequired": true,
  4.   "connectionId": {
  5. [10 more lines...]

Plain Code

{"ConnectionInfo": {
  "commandId": 0,
  "responseRequired": true,
  "connectionId": {
    "value": "ID:yy.xx.net-57901-1294599217160-5:3943"
  },
  "clientId": "ID:yy.xx.net-57901-1294599217160-5:3943",
  "userName": "",
  "password": "",
  "brokerMasterConnector": false,
  "manageable": false,
  "clientMaster": true,
  "faultTolerant": false,
  "failoverReconnect": false
}}

Untitled Ruby (14-Jan @ 09:17)

ripienaar.devco.net

Syntax Highlighted Code

  1. ====================
  2. #<Stomp::Message:0xb7e3d8e0
  3.  @body=
  4.   "{\"ConnectionInfo\": {\n  \"commandId\": 0,\n  \"responseRequired\": true,\n  \"connectionId\": {\n    \"value\": \"ID:xx.xx.net-57901-1294599217160-5:3943\"\n  },\n  \"clientId\": \"ID:xx.xx.net-57901-1294599217160-5:3943\",\n  \"userName\": \"\",\n  \"password\": \"\",\n  \"brokerMasterConnector\": false,\n  \"manageable\": false,\n  \"clientMaster\": true,\n  \"faultTolerant\": false,\n  \"failoverReconnect\": false\n}}",
  5. [14 more lines...]

Plain Code

====================
#<Stomp::Message:0xb7e3d8e0
 @body=
  "{\"ConnectionInfo\": {\n  \"commandId\": 0,\n  \"responseRequired\": true,\n  \"connectionId\": {\n    \"value\": \"ID:xx.xx.net-57901-1294599217160-5:3943\"\n  },\n  \"clientId\": \"ID:xx.xx.net-57901-1294599217160-5:3943\",\n  \"userName\": \"\",\n  \"password\": \"\",\n  \"brokerMasterConnector\": false,\n  \"manageable\": false,\n  \"clientMaster\": true,\n  \"faultTolerant\": false,\n  \"failoverReconnect\": false\n}}",
 @command="MESSAGE",
 @headers=
  {"timestamp"=>"0",
   "message-id"=>
    "ID:xx.xx.net-57901-1294599217160-2:0:0:0:63185",
   "expires"=>"0",
   "destination"=>"/topic/ActiveMQ.Advisory.Connection",
   "priority"=>"0",
   "type"=>"Advisory",
   "originBrokerURL"=>"tcp://xx.xx.net:6166",
   "originBrokerId"=>"ID:xx.xx.net-57901-1294599217160-0:0",
   "originBrokerName"=>"xx-xx"},
 @original=
  "MESSAGE\nmessage-id:ID:xx.xx.net-57901-1294599217160-2:0:0:0:63185\noriginBrokerName:xx-xx\ntype:Advisory\ndestination:/topic/ActiveMQ.Advisory.Connection\ntimestamp:0\nexpires:0\npriority:0\noriginBrokerURL:tcp://xx.xx.net:6166\noriginBrokerId:ID:xx.xx.net-57901-1294599217160-0:0\n\n{\"ConnectionInfo\": {\n  \"commandId\": 0,\n  \"responseRequired\": true,\n  \"connectionId\": {\n    \"value\": \"ID:xx.xx.net-57901-1294599217160-5:3943\"\n  },\n  \"clientId\": \"ID:xx.xx.net-57901-1294599217160-5:3943\",\n  \"userName\": \"\",\n  \"password\": \"\",\n  \"brokerMasterConnector\": false,\n  \"manageable\": false,\n  \"clientMaster\": true,\n  \"faultTolerant\": false,\n  \"failoverReconnect\": false\n}}\000">
====================

Untitled Ruby (13-Jan @ 15:41)

ripienaar.devco.net

Syntax Highlighted Code

  1. class ipsec::servers::monitor1 {
  2.     $clients = search_nodes("{'classes' => 'ipsec::endpoint::monitor1'}")
  3.  
  4.     ipsec::endpoints_from_nodes{$clients: }
  5. [20 more lines...]

Plain Code

class ipsec::servers::monitor1 {
    $clients = search_nodes("{'classes' => 'ipsec::endpoint::monitor1'}")

    ipsec::endpoints_from_nodes{$clients: }
}

define ipsec::endpoints_from_nodes {
    $node = load_node($name)

    ipsec::endpoint{$node["fqdn"]:
        dest    => $node["facts"]["ipaddress"]
    }
}

define ipsec::endpoint($dest, $ensure = "present", $mode = "transport") {
    $safe_name = regsubst($name, '-', '_', 'G')

    file{"/etc/sysconfig/network-scripts/ifcfg-ipsec.${safe_name}":
        owner   => root,
        group   => root,
        mode    => 644,
        ensure  => $ensure,
        content => template("ipsec/${mode}-mode-endpoint.erb")
    }
}

Untitled ActionScript (13-Jan @ 11:30)

ripienaar.devco.net

Syntax Highlighted Code

  1. #!/usr/bin/ruby
  2.  
  3. require 'mcollective'
  4.  
  5. [6 more lines...]

Plain Code

#!/usr/bin/ruby

require 'mcollective'

include MCollective::RPC

rpc = rpcclient("rpcutil")

rpc.get_fact(:fact => "foo").each do |resp|
    puts "%40s: %s %s" % [ resp[:sender], resp[:statuscode], resp[:statusmsg]]
end

Untitled ActionScript (13-Jan @ 11:24)

ripienaar.devco.net

Syntax Highlighted Code

  1. #!/usr/bin/ruby
  2.  
  3. require 'mcollective'
  4.  
  5. [6 more lines...]

Plain Code

#!/usr/bin/ruby

require 'mcollective'

include MCollective::RPC

rpc = rpcclient("rpcutil")

rpc.get_fact(:fact => "foo") do |resp|
    pp resp[:body]
end

Untitled Ruby (13-Jan @ 02:57)

ripienaar.devco.net

Syntax Highlighted Code

  1. define ipsec::endpoints_from_nodes {
  2.     $node = load_node($name)
  3.  
  4.     ipsec::endpoint{$node["fqdn"]:
  5. [8 more lines...]

Plain Code

define ipsec::endpoints_from_nodes {
    $node = load_node($name)

    ipsec::endpoint{$node["fqdn"]:
        dest    => $node["facts"]["ipaddress"]
    }
}

class ipsec::servers::monitor1 {
    $clients = search_nodes("{'classes' => 'ipsec::endpoint::monitor1'}")

    ipsec::endpoints_from_nodes{$clients: }
}