<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>R.I.Pienaar &#187; Code</title>
	<atom:link href="http://www.devco.net/archives/tag/code/feed" rel="self" type="application/rss+xml" />
	<link>http://www.devco.net</link>
	<description>www.devco.net</description>
	<lastBuildDate>Thu, 29 Jul 2010 09:08:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Monitoring ActiveMQ</title>
		<link>http://www.devco.net/archives/2010/07/25/monitoring_activemq.php</link>
		<comments>http://www.devco.net/archives/2010/07/25/monitoring_activemq.php#comments</comments>
		<pubDate>Sun, 25 Jul 2010 16:13:11 +0000</pubDate>
		<dc:creator>R.I. Pienaar</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[activemq]]></category>
		<category><![CDATA[cacti]]></category>
		<category><![CDATA[devops]]></category>
		<category><![CDATA[monitoring]]></category>
		<category><![CDATA[nagios]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.devco.net/?p=1643</guid>
		<description><![CDATA[I have a number of ActiveMQ servers, 7 in total, 3 in a network of brokers the rest standalone. For MCollective I use topics extensively so don&#8217;t really need to monitoring them much other than for availability. I also though do a lot of Queued work where lots of machines put data in a queue [...]]]></description>
			<content:encoded><![CDATA[<p>I have a number of ActiveMQ servers, 7 in total, 3 in a network of brokers the rest standalone.  For MCollective I use topics extensively so don&#8217;t really need to monitoring them much other than for availability.  I also though do a lot of Queued work where lots of machines put data in a queue and others process the data.</p>
<p>In the Queue scenario you absolutely need to monitor queue sizes, memory usage and such.  You also need to graph things like rates of messages, consumer counts and memory use.  I am busy writing a number of Nagios and Cacti plugins to help with this, you can <a href="http://github.com/ripienaar/monitoring-scripts/tree/master/activemq/">find them on Github</a>.</p>
<p>To use these you need to have the <a href="http://activemq.apache.org/statisticsplugin.html">ActiveMQ Statistics Plugin</a> enabled.</p>
<p>First we need to monitor queue sizes:</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">$ check_activemq_queue.rb --host localhost --user nagios --password passw0rd --queue exim.stats --queue-warn 1000 --queue-crit 2000
OK: ActiveMQ exim.stats has 1 messages</pre></div></div>

<p></code></p>
<p>This will connect to localhost monitoring a queue <em>exim.stats</em> warning you when it&#8217;s got 1000 messages and critical at 2000.</p>
<p>I need to add to this the ability to monitor memory usage, this will come over the next few days.</p>
<p>I also have a plugin for Cacti it can output stats for the broker as a whole and also for a specific queue.  First the whole broker:</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">$ activemq-cacti-plugin.rb --host localhost --user nagios --password passw0rd --report broker
stomp+ssl:stomp+ssl storePercentUsage:81 size:5597 ssl:ssl vm:vm://web3 dataDirectory:/var/log/activemq/activemq-data dispatchCount:169533 brokerName:web3 openwire:tcp://web3:6166 storeUsage:869933776 memoryUsage:1564 tempUsage:0 averageEnqueueTime:1623.90502285799 enqueueCount:174080 minEnqueueTime:0.0 producerCount:0 memoryPercentUsage:0 tempLimit:104857600 messagesCached:0 consumerCount:2 memoryLimit:20971520 storeLimit:1073741824 inflightCount:9 dequeueCount:169525 brokerId:ID:web3-44651-1280002111036-0:0 tempPercentUsage:0 stomp:stomp://web3:6163 maxEnqueueTime:328585.0 expiredCount:0</pre></div></div>

<p></code></p>
<p>Now a specific queue:</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">$ activemq-cacti-plugin.rb --host localhost --user nagios --password passw0rd --report exim.stats
size:0 dispatchCount:168951 memoryUsage:0 averageEnqueueTime:1629.42897052992 enqueueCount:168951 minEnqueueTime:0.0 consumerCount:1 producerCount:0 memoryPercentUsage:0 destinationName:queue://exim.stats messagesCached:0 memoryLimit:20971520 inflightCount:0 dequeueCount:168951 expiredCount:0 maxEnqueueTime:328585.0</pre></div></div>

<p></code></p>
<p>Grab the code on <a href="http://github.com/ripienaar/monitoring-scripts/tree/master/activemq/">GitHub </a>and follow there, I expect a few updates in the next few weeks.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devco.net/archives/2010/07/25/monitoring_activemq.php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bootstrapping Puppet on EC2 with MCollective</title>
		<link>http://www.devco.net/archives/2010/07/14/bootstrapping_puppet_on_ec2_with_mcollective.php</link>
		<comments>http://www.devco.net/archives/2010/07/14/bootstrapping_puppet_on_ec2_with_mcollective.php#comments</comments>
		<pubDate>Tue, 13 Jul 2010 23:10:08 +0000</pubDate>
		<dc:creator>R.I. Pienaar</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[devops]]></category>
		<category><![CDATA[mcollective]]></category>
		<category><![CDATA[puppet]]></category>

		<guid isPermaLink="false">http://www.devco.net/?p=1592</guid>
		<description><![CDATA[The problem of getting EC2 images to do what you want is quite significant, mostly I find the whole thing a bit flakey and with too many moving parts. When and what AMI to start Once started how to do you configure it from base to functional. Especially in a way that doesn&#8217;t become a [...]]]></description>
			<content:encoded><![CDATA[<p>The problem of getting EC2 images to do what you want is quite significant, mostly I find the whole thing a bit flakey and with too many moving parts.  </p>
<ul>
<li>When and what AMI to start</li>
<li>Once started how to do you configure it from base to functional.  Especially in a way that doesn&#8217;t become a vendor lock.</li>
<li>How do you manage the massive sprawl of instances, inventory them and track your assets</li>
<li>Monitoring and general life cycle management</li>
<li>When and how do you shut them, and what cleanup is needed.  Being billed by the hour means this has to be a consideration</li>
</ul>
<p>These are significant problems and just a tip of the ice berg.  All of the traditional aspects of infrastructure management &#8211; like Asset Management, Monitoring, Procurement &#8211; are totally useless in the face of the cloud.</p>
<p>A lot of work is being done in this space by tools like Pool Party, Fog, Opscode and many other players like the countless companies launching control panels, clouds overlaying other clouds and so forth.  As a keen believer in Open Source many of these options are not appealing.</p>
<p>I want to focus on the 2nd step above here today and show how I pulled together a number of my Open Source projects to automate that.   I built a generic provisioner that hopefully is expandable and usable in your own environments.  The provisioner deals with all the interactions between Puppet on nodes, the Puppet Master, the Puppet CA and the administrators.</p>
<p>&lt;rant&gt; Sadly the activity in the Puppet space is a bit lacking in the area of making it really easy to get going on a cloud.  There are suggestions on the level of monitoring syslog files from a cronjob and signing certificates based on that.  Really.   It&#8217;s a pretty sad state of affairs when that&#8217;s the state of the art.</p>
<p>Compare the ease of using <a href="http://www.opscode.com/blog/2010/03/24/amazon-ec2-amis-for-ubuntu-9-10-and-chef-0-8-8/">Chef&#8217;s Knife</a> with a lot of the suggestions currently out there for using Puppet in EC2 like these: <a href="http://ubuntumathiaz.wordpress.com/2010/03/24/using-puppet-in-uecec2-puppet-support-in-ubuntu-images/">1</a>, <a href="https://wiki.ubuntu.com/PuppetUECEC2Integration">2</a>, <a href="http://agiletesting.blogspot.com/2009/09/bootstrapping-ec2-images-as-puppet.html">3</a> and <a href="http://ubuntumathiaz.wordpress.com/2010/03/25/using-puppet-in-uecec2-automating-the-signing-process/">4</a>.</p>
<p>Not trying to have a general Puppet Bashing session here but I think it&#8217;s quite defining of the 2 user bases that Cloud readiness is such an after thought so far in Puppet and its community.  &lt;/rant&gt;</p>
<p>My basic needs are that instances all start in the same state, I just want 1 base AMI that I massage into the desired final state.  Most of this work has to be done by Puppet so it&#8217;s repeatable.  Driving this process will be done by MCollective.</p>
<p>I bootstrap the EC2 instances using my <a href="http://www.devco.net/archives/2010/07/12/ec2_bootstrap_helper.php">EC2 Bootstrap Helper</a> and I use that to install MCollective with just a <em>provision</em> agent.  It configures it and hook it into my collective.</p>
<p>From there I have the following steps that need to be done:</p>
<ul>
<li>Pick a nearby Puppet Master, perhaps using EC2 Region or country as guides</li>
<li>Set up the host &#8211; perhaps using <em>/etc/hosts</em> &#8211; to talk to the right master</li>
<li>Revoke and clean any old certs for this hostname on all masters</li>
<li>Instruct the node to create a new CSR and send it to its master</li>
<li>Sign the certificate</li>
<li>Run my initial bootstrap Puppet environment, this sets up some hard to do things like facts my full build needs</li>
<li>Run the final Puppet run in my normal production environment.</li>
<li>Notify me using XMPP, Twitter, Google Calendar, Email, Boxcar and whatever else I want of the new node</li>
</ul>
<p>This is a lot of work to be done on every node.  And more importantly it&#8217;s a task that involves many other nodes like puppet masters, notifiers and so forth.  It has to adapt dynamically to your environment and not need reconfiguring when you get new Puppet Masters.  It has to deal with new data centers, regions and countries without needing any configuration or even a restart.  It has to happen automatically without any user interaction so that your auto scaling infrastructure can take care of booting new instances even while you sleep.</p>
<p>The provisioning system I wrote does just this.  It follows the above logic for any new node and is configurable for which facts to use to pick a master and how to notify you of new systems.  It adapts automatically to your ever changing environments thanks to discovery of resources.  The actions to perform on the node are easily pluggable by just creating an agent that complies to the <a href="http://github.com/ripienaar/mcollective-server-provisioner/blob/master/agent/provision.ddl">published DDL</a> like the <a href="http://github.com/ripienaar/mcollective-server-provisioner/blob/master/agent/provision.rb">sample agent</a>.</p>
<p>You can see it in action in the video below.  I am using Amazon&#8217;s console to start the instance, you&#8217;d absolutely want to automate that for your needs.   You can also see it direct on blip.tv <a href="http://mcollective.blip.tv/file/3876576/">here</a>.  For best effect &#8211; and to be able to read the text &#8211; please fullscreen.</p>
<p><center><embed src="http://blip.tv/play/hfMOge3ibQA" type="application/x-shockwave-flash" width="640" height="417" allowscriptaccess="always" allowfullscreen="true"></embed></center></p>
<p>In case the text is unreadable in the video a log file similar to the one in the video can be seen <a href="http://www.devco.net/code/mcollective-provisioner-log.txt">here</a> and an example config <a href="http://github.com/ripienaar/mcollective-server-provisioner/blob/master/etc/provisioner.yaml">here</a></p>
<p>Past this point my Puppet runs are managed by <a href="http://www.devco.net/archives/2010/03/17/scheduling_puppet_with_mcollective.php">my MCollective Puppet Scheduler</a>.</p>
<p>While this is all done using EC2 nothing prevents you from applying these same techniques to your own data center or non cloud environment.  </p>
<p>Hopefully this shows that you can wrap all the logic needed to do very complex interactions with systems that are perhaps not known for their good reusable API&#8217;s in simple to understand wrappers with MCollective, exposing those systems to the network at large with APIs that can be used to reach your goals.</p>
<p>The various bits of open source I used here are:</p>
<ul>
<li><a href="http://mcollective.googlecode.com/">MCollective</a></li>
<li><a href="http://www.devco.net/archives/2010/07/12/ec2_bootstrap_helper.php">EC2 Bootstrap</a> helper on CentOS 5.5</li>
<li>The <a href="http://github.com/ripienaar/mcollective-server-provisioner">MCollective Server Provisioner</a></li>
<li>The sample <a href="http://github.com/ripienaar/mcollective-server-provisioner/blob/master/agent/provision.rb">provisioner agent</a></li>
<li>My <a href="http://code.google.com/p/nagger/">Nagger notification framework</a> with it&#8217;s XMPP plugin</li>
<li>The <a href="http://github.com/ripienaar/mcollective-plugins/tree/master/agent/naggernotify/">Naggernotify</a> MCollective Agent</li>
<li>The <a href="http://github.com/ripienaar/mcollective-plugins/tree/master/agent/puppetca/">Puppet CA</a> Mcollective Agent</li>
<li><a href="http://www.puppetlabs.com/">Puppet and Facter</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.devco.net/archives/2010/07/14/bootstrapping_puppet_on_ec2_with_mcollective.php/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>EC2 Bootstrap Helper</title>
		<link>http://www.devco.net/archives/2010/07/12/ec2_bootstrap_helper.php</link>
		<comments>http://www.devco.net/archives/2010/07/12/ec2_bootstrap_helper.php#comments</comments>
		<pubDate>Mon, 12 Jul 2010 15:08:41 +0000</pubDate>
		<dc:creator>R.I. Pienaar</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[amazon]]></category>
		<category><![CDATA[cloud]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.devco.net/?p=1580</guid>
		<description><![CDATA[I&#8217;ve been working a bit on streamlining the builds I do on EC2 and wanted a better way to provision my machines. I use CentOS and things are pretty rough to non existent for nicely built EC2 images. I&#8217;ve used the Rightscale ones till now and while they&#8217;re nice they are also full of lots [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working a bit on streamlining the builds I do on EC2 and wanted a better way to provision my machines.  I use CentOS and things are pretty rough to non existent for nicely built EC2 images.  I&#8217;ve used the Rightscale ones till now and while they&#8217;re nice they are also full of lots of code copyrighted by Rightscale.</p>
<p>What I really wanted was something as full featured as Ubuntu&#8217;s <a href="https://help.ubuntu.com/community/CloudInit">CloudInit</a> but also didn&#8217;t feel much like touching any Python.  I hacked up something that more or less do what I need.  You can get it on <a href="http://github.com/ripienaar/ec2-boot-init">GitHub</a>.  It&#8217;s written and tested on CentOS 5.5.</p>
<p>The idea is that you&#8217;ll have a single multi purpose AMI that you can easily bootstrap onto your puppet/mcollective infrastructure using this system.  Below for some details.</p>
<p>I prepare my base CentOS AMI with the following mods:</p>
<ul>
<li>Install Facter and Puppet &#8211; but not enabled</li>
<li>Install the EC2 utilities</li>
<li>Setup the usual <em>getsshkeys</em> script</li>
<li>Install the ec2-boot-init RPM</li>
<li>Add a custom fact that reads <em>/etc/facts.txt</em> &#8211; see later why.  Get one <a href="http://github.com/ripienaar/facter-facts/tree/master/etcfacts/">here</a>.</li>
</ul>
<p>With this in place you need to create some ruby scripts that you will use to bootstrap your machines.  Examples of this would be to install mcollective, configure it to find your current activemq.  Or to set up puppet and do your initial run etc.  </p>
<p>We host these scripts on any webserver &#8211; ideally S3 &#8211; so that when a machine boots it can grab the logic you want to execute on it.  This way you can bug fix your bootstrapping without having to make new AMIs as well as add new bootstrap methods in future to existing AMIs.</p>
<p>Here&#8217;s a simple example that just runs a shell command:</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">newaction<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;shell&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>cmd, ud, md, config<span style="color:#006600; font-weight:bold;">|</span>
    <span style="color:#9966CC; font-weight:bold;">if</span> cmd.<span style="color:#9966CC; font-weight:bold;">include</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:command</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        <span style="color:#CC0066; font-weight:bold;">system</span><span style="color:#006600; font-weight:bold;">&#40;</span>cmd<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:command</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p></code></p>
<p>You want to host this on any webserver in a file called <em>shell.rb</em>.  Now create a file <em>list.txt</em> in the same location that just have this:</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">shell.rb</pre></div></div>

<p></code></p>
<p>You can list as many scripts as you want.  Now when you boot your instance pass it data like this:</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="yaml" style="font-family:monospace;">--- 
:facts: 
  role: webserver
:actions: 
- :url: http://your.net/path/to/actions/list.txt
  :type: :getactions
- :type: :shell
  :command: date &gt; /tmp/test</pre></div></div>

<p></code></p>
<p>The above will fetch the list of actions &#8211; our <em>shell.rb</em> &#8211; from <em>http://your.net/path/to/actions/list.txt</em> and then run using the <em>shell</em> action the command <em>date > /tmp/test</em>.  The actions are run in order so you probably always want <em>getactions</em> to happen first.</p>
<p>Other actions that this script will take:</p>
<ul>
<li>Cache all the user and meta data in <em>/var/spool/ec2boot</em></li>
<li>Create <em>/etc/facts.txt</em> with all your facts that you passed in as well as a flat version of the entire instance meta data</em>.  </li>
<li>Create a MOTD that shows some key data like AMI ID, Zone, Public and Private hostnames</li>
</ul>
<p>The boot library provides a few helpers that help you write scripts for this environment specifically around fetching files and logging:</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">    <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;rubygems-1.3.1-1.el5.noarch.rpm&quot;</span>,
     <span style="color:#996600;">&quot;rubygem-stomp-1.1.6-1.el5.noarch.rpm&quot;</span>,
     <span style="color:#996600;">&quot;mcollective-common-#{version}.el5.noarch.rpm&quot;</span>,
     <span style="color:#996600;">&quot;mcollective-#{version}.el5.noarch.rpm&quot;</span>,
     <span style="color:#996600;">&quot;server.cfg.templ&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>pkg<span style="color:#006600; font-weight:bold;">|</span>
        <span style="color:#6666ff; font-weight:bold;">EC2Boot::Util</span>.<span style="color:#9900CC;">log</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;Fetching pkg #{pkg}&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        <span style="color:#6666ff; font-weight:bold;">EC2Boot::Util</span>.<span style="color:#9900CC;">get_url</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;http://foo.s3.amazonaws.com/#{pkg}&quot;</span>, <span style="color:#996600;">&quot;/mnt/#{pkg}&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
     <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p></code></p>
<p>This code fetches a bunch of files from a S3 bucket and save them into <em>/mnt</em>.  Each one gets logged to console and syslog.  Using this GET helper has the advantage that it has sane retrying etc built in for you already.</p>
<p>It&#8217;s fairly early days for this code but it works and I am using it, I&#8217;ll probably be adding a few more features soon, let me know in comments if you need anything specific or even if you find it useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devco.net/archives/2010/07/12/ec2_bootstrap_helper.php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Puppet resources on demand with MCollective</title>
		<link>http://www.devco.net/archives/2010/07/07/puppet_resources_on_demand.php</link>
		<comments>http://www.devco.net/archives/2010/07/07/puppet_resources_on_demand.php#comments</comments>
		<pubDate>Wed, 07 Jul 2010 16:55:36 +0000</pubDate>
		<dc:creator>R.I. Pienaar</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[mcollective]]></category>
		<category><![CDATA[puppet]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.devco.net/?p=1565</guid>
		<description><![CDATA[Some time ago I wrote how to reuse Puppet providers in your Ruby script, I&#8217;ll take that a bit further here and show you to create any kind of resource. Puppet works based on resources and catalogs. A catalog is a collection of resources and it will apply the catalog to a machine. So in [...]]]></description>
			<content:encoded><![CDATA[<p>Some time ago I wrote how to <a href="http://www.devco.net/archives/2009/10/19/reusing_puppet_providers.php">reuse Puppet providers</a> in your Ruby script, I&#8217;ll take that a bit further here and show you to create any kind of resource.</p>
<p>Puppet works based on resources and catalogs.  A catalog is a collection of resources and it will apply the catalog to a machine.  So in order to do something you can do as before and call the type&#8217;s methods directly but if you wanted to build up a resource and say &#8216;just do it&#8217; then you need to go via a catalog.</p>
<p>Here&#8217;s some code, I don&#8217;t know if this is the best way to do it, I dug around the code for <em>ralsh</em> to figure this out:</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">params = <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:name</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;rip&quot;</span>,
           <span style="color:#ff3333; font-weight:bold;">:comment</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;R.I.Pienaar&quot;</span>,
           <span style="color:#ff3333; font-weight:bold;">:password</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'......'</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
&nbsp;
pup = <span style="color:#6666ff; font-weight:bold;">Puppet::Type</span>.<span style="color:#9900CC;">type</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:user</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>params<span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
catalog = <span style="color:#6666ff; font-weight:bold;">Puppet::Resource::Catalog</span>.<span style="color:#9900CC;">new</span>
catalog.<span style="color:#9900CC;">add_resource</span> pup
catalog.<span style="color:#9900CC;">apply</span></pre></div></div>

<p></code></p>
<p>That&#8217;s really simple and doesn&#8217;t require you to know much about the inner workings of a type, you&#8217;re just mapping the normal Puppet manifest to code and applying it.  Nifty.</p>
<p>The natural progression &#8211; to me anyway &#8211; is to put this stuff into a <a href="http://github.com/ripienaar/mcollective-plugins/blob/master/agent/puppetral/puppetral.rb">MCollective agent</a> and build a distributed <em>ralsh</em>.</p>
<p>Here&#8217;s a sample use case, I wanted to change my users password everywhere:</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">$ mc-rpc puppetral do type=user name=rip password='$1$xxx'</pre></div></div>

<p></code></p>
<p>And that will go out, find all my machines and use the Puppet RAL to change my password for me.  You can do anything puppet can, manage <em>/etc/hosts</em>, add users, remove users, packages, services and anything even your own custom types can be used.   Distributed and in parallel over any number of hosts.</p>
<p>Some other examples:</p>
<p>Add a user:<br />
<code></p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">$ mc-rpc puppetral do type=user name=foo comment=&quot;Foo User&quot; managehome=true</pre></div></div>

<p></code></p>
<p>Run a command using exec, with the magical <em>creates</em> option:<br />
<code></p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">$ mc-rpc puppetral do type=exec name=&quot;/bin/date &gt; /tmp/date&quot; user=root timeout=5 creates=&quot;/tmp/date&quot;</pre></div></div>

<p></code></p>
<p>Add an aliases entry:</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">$ mc-rpc puppetral do type=mailalias name=foo recipient=&quot;rip@devco.net&quot; target=&quot;/etc/aliases&quot;</pre></div></div>

<p></code></p>
<p>Install a package:</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">$ mc-rpc puppetral do type=package name=unix2dos ensure=present</pre></div></div>

<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.devco.net/archives/2010/07/07/puppet_resources_on_demand.php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Aggregating Nagios Checks With MCollective</title>
		<link>http://www.devco.net/archives/2010/07/03/aggregating_nagios_checks_with_mcollective.php</link>
		<comments>http://www.devco.net/archives/2010/07/03/aggregating_nagios_checks_with_mcollective.php#comments</comments>
		<pubDate>Sat, 03 Jul 2010 15:12:00 +0000</pubDate>
		<dc:creator>R.I. Pienaar</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[devops]]></category>
		<category><![CDATA[mcollective]]></category>
		<category><![CDATA[monitoring]]></category>

		<guid isPermaLink="false">http://www.devco.net/?p=1532</guid>
		<description><![CDATA[A very typical scenario I come across on many sites is the requirement to monitor something like Puppet across 100s or 1000s of machines. The typical approaches are to add perhaps a central check on your puppet master or to check using NRPE or NSCA on every node. For this example the option exist to [...]]]></description>
			<content:encoded><![CDATA[<p>A very typical scenario I come across on many sites is the requirement to monitor something like Puppet across 100s or 1000s of machines.</p>
<p>The typical approaches are to add perhaps a central check on your puppet master or to check using NRPE or NSCA on every node.  For this example the option exist to easily check on the master and get one check but that isn&#8217;t always easily achievable.  </p>
<p>Think for example about monitoring mail queues on all your machines to make sure things like root mail isn&#8217;t getting stuck.   In those cases you are forced to do per node checks which inevitably result in huge notification storms in the event that your mail server was down and not receiving the mail from the many nodes.</p>
<p><a href="http://mcollective.googlecode.com/">MCollective</a> has had <a href="http://code.google.com/p/mcollective-plugins/wiki/AgentNRPE">a plugin that can run NRPE commands</a> for a long time, I&#8217;ve now added a nagios plugin using this agent to combine results from many hosts.</p>
<p>Sticking with the Puppet example, here are my needs:</p>
<ul>
<li>I want to know if anywhere some puppet machine isn&#8217;t successfully doing runs.</li>
<li>I want to be able to do <em>puppetd &#8211;disable</em> and not get alerts for those machines.</li>
<li>I do not want to change any configs when I am adding new machines, it should just work.</li>
<li>I want the ability to do monitoring on subsets of machines on different probes</li>
</ul>
<p>This is a pretty painful set of requirements for nagios on its own to achieve.  Easy with the help of MCollective.</p>
<p>Ultimately, I just want this:</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">OK: 42 WARNING: 0 CRITICAL: 0 UNKNOWN: 0</pre></div></div>

<p></code></p>
<p>Meaning 42 machines &#8211; only ones currently enabled &#8211; are all running happily.</p>
<h2>The NRPE Check</h2>
<p>We put the NRPE logic on every node.  A simple check command in <em>/etc/nagios/nrpe.d/check_puppet_run.cfg</em>:</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">command[check_puppet_run]=/usr/lib/nagios/plugins/check_file_age -f /var/lib/puppet/state/state.yaml -w 5400 -c 7200</pre></div></div>

<p></code></p>
<p>In my case I just want to know there are successful runs happening, if I wanted to know the code is actually compiling correctly I&#8217;d monitor the local cache age and size.</p>
<h2>Determining if Puppet is enabled or not</h2>
<p>Currently this is a bit hacky, I&#8217;ve filed tickets with Puppet Labs to improve this.  The way to determine if puppet is disabled is to check if the lock file exist and if its 0 bytes.  If it&#8217;s not zero bytes it means a <em>puppetd</em> is currently doing a run &#8211; there will be a pid in it.  Or the <em>puppetd</em> crashed and there&#8217;s a stale pid preventing other runs.  </p>
<p>To automate this and integrate into MCollective I&#8217;ve made a fact <a href="http://github.com/ripienaar/facter-facts/tree/master/puppet-enabled/">puppet_enabled</a>.  We&#8217;ll use this in MCollective discovery to only monitor machines that are enabled.  Get this onto all your nodes perhaps using <a href="http://docs.reductivelabs.com/guides/plugins_in_modules.html">Plugins in Modules</a>.</p>
<h2>The MCollective Agent</h2>
<p>You want to deploy the <a href="http://code.google.com/p/mcollective-plugins/wiki/AgentNRPE">MCollective NRPE Agent</a> to all your nodes, once you&#8217;ve got it right you can test it easily using something like this:</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">% mc-nrpe -W puppet_enabled=1 check_puppet_run
&nbsp;
 * [ ============================================================&gt; ] 47 / 47
&nbsp;
Finished processing 47 / 47 hosts in 395.51 ms
              OK: 47
         WARNING: 0
        CRITICAL: 0
         UNKNOWN: 0</pre></div></div>

<p></code></p>
<p>Note we&#8217;re restricting the run to only enabled hosts.</p>
<h2>Integrating into Nagios</h2>
<p>The last step is to add this to nagios.  I create SSL certs and a specific client configuration for Nagios and put these in it&#8217;s home directory.</p>
<p>The <em>check-mc-nrpe</em> plugin works best with Nagios 3 as it will return subsequent lines of output indicating which machines are in what state so you get the details hidden behind the aggregation in alerts.  It also outputs performance data for total node, each status and also how long it took to do the check.</p>
<p>The nagios command would be something like this:</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">define command{
        command_name                    check_mc_nrpe
        command_line                    /usr/sbin/check-mc-nrpe  --config /var/log/nagios/.mcollective/client.cfg  -W $ARG1$ $ARG2$
}</pre></div></div>

<p></code></p>
<p>And finally we need to make a service:</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">define service{
        host_name                       monitor1
        service_description             mc_puppet-run
        use                             generic-service
        check_command                   check_mc_nrpe!puppet_enabled=1!check_puppet_run
        notification_period             awakehours
        contact_groups                  sysadmin
}</pre></div></div>

<p></code></p>
<p>Here are a few other command examples I use:</p>
<p>All machines with my Puppet class &#8220;pki&#8221;, check the age of certs:</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">check_command   check_mc_nrpe!pki!check_pki</pre></div></div>

<p></code></p>
<p>All machines with my Puppet class &#8220;bacula::node&#8221;, make sure the FD is running:</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">check_command   check_mc_nrpe!bacula::node!check_fd</pre></div></div>

<p></code></p>
<p>&#8230;and that they were backed up:</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">check_command   check_mc_nrpe!bacula::node!check_bacula_main</pre></div></div>

<p></code></p>
<p>Using this I removed 100s of checks from my monitoring platform, saving on resources and making sure I can do my critical monitor tasks better.</p>
<p>Depending on the quality of your monitoring system you might even get a graph showing the details hidden behind the aggregation:</p>
<p><center><img src="http://www.devco.net/images/mcbacula.png"></center></p>
<p>The above is a graph showing a series of servers where the backup ran later than usual, I had 2 alerts only, would have had more than 30 before aggregation.</p>
<p></p>
<h2>Restrictions for Probes</h2>
<p>The last remaining requirement I had was to be able to do checks on different probes and restrict them.  My Collective is one big one spread all over the world which means sometimes things are a bit slow discovery wise.  </p>
<p>So I have many nagios servers doing local checks.  Using MCollective discovery I can now easily restrict checks, for example If I only wanted to check machines in the USA and I had a fact <em>country</em> I only have to change my command line in the service declaration:</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">check_command   check_mc_nrpe!puppet_enabled=1 country=us!check_puppet_run</pre></div></div>

<p></code></p>
<p>This will then via MCollective discovery just monitor machines in the US.</p>
<h2>What to monitor this way</h2>
<p>As this style of monitoring is done using Discovery you would need to think carefully about what you monitor this way.  It&#8217;s totally conceivable that if a node is under high CPU load that it wont respond to discovery commands in time, and so wont get monitored!</p>
<p>You would then for example not want to monitor things like load averages or really critical services this way, but we all have a lot of peripheral things like zombie process counts and a lot of other places where aggregation makes a lot of sense, in those cases by all means consider this approach.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devco.net/archives/2010/07/03/aggregating_nagios_checks_with_mcollective.php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tutorial: Writing MCollective Agents</title>
		<link>http://www.devco.net/archives/2010/06/27/tutorial_writing_mcollective_agents.php</link>
		<comments>http://www.devco.net/archives/2010/06/27/tutorial_writing_mcollective_agents.php#comments</comments>
		<pubDate>Sun, 27 Jun 2010 15:41:28 +0000</pubDate>
		<dc:creator>R.I. Pienaar</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[devops]]></category>
		<category><![CDATA[mcollective]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.devco.net/?p=1495</guid>
		<description><![CDATA[I&#8217;ve recorded a screencast that walks you through the process of developing a SimpleRPC Agent, give it a DDL and also a simple client to communicate with it. The tutorial creates a small echo agent that takes input and return it unmodified. It validates that you are sending a string and has a sample of [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve recorded a screencast that walks you through the process of developing a SimpleRPC Agent, give it a DDL and also a simple client to communicate with it.</p>
<p><center><embed src="http://blip.tv/play/hfMOgenSZAA" type="application/x-shockwave-flash" width="560" height="360" allowscriptaccess="always" allowfullscreen="true"></embed></center></p>
<p>The tutorial creates a small echo agent that takes input and return it unmodified.  It validates that you are sending a string and has a sample of dealing with intermittent failure.</p>
<p>Once you&#8217;ve watched this, or even during, you can use the following links are reference material:  <a href="http://code.google.com/p/mcollective/wiki/SimpleRPCAgents">Writing Agents</a>, <a href="http://code.google.com/p/mcollective/wiki/SimpleRPCDDL">Data Definition Language</a> and <a href="http://code.google.com/p/mcollective/wiki/SimpleRPCClients">Writing Clients</a>.</p>
<p>You can view it <a href="http://mcollective.blip.tv/file/3808928">directly on blip.tv</a> which will hopefully be better quality.</p>
<p>I used a few VIM Snippets during the demo to boilerplate the agent and DDL, you&#8217;ll find these in the tarball for the upcoming <em>0.4.7</em> release in the <em>ext/vim</em> directory, they are already on GitHub too.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devco.net/archives/2010/06/27/tutorial_writing_mcollective_agents.php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Recent MCollective releases and roadmap.</title>
		<link>http://www.devco.net/archives/2010/06/14/recent_mcollective_releases_and_roadmap.php</link>
		<comments>http://www.devco.net/archives/2010/06/14/recent_mcollective_releases_and_roadmap.php#comments</comments>
		<pubDate>Mon, 14 Jun 2010 08:44:14 +0000</pubDate>
		<dc:creator>R.I. Pienaar</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[devops]]></category>
		<category><![CDATA[mcollective]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.devco.net/?p=1472</guid>
		<description><![CDATA[I&#8217;ve had two successive Marionette Collective releases recently, I was hoping to have one big one but I was waiting for the Stomp maintainers to do a release and it was taking a while. These two releases are both major feature releases covering major feature sets. See lower down for a breakdown of it all. [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve had two successive <a href="http://code.google.com/p/mcollective/">Marionette Collective</a> releases recently, I was hoping to have one big one but I was waiting for the Stomp maintainers to do a release and it was taking a while.</p>
<p>These two releases are both major feature releases covering major feature sets.  See lower down for a breakdown of it all.</p>
<p>We&#8217;re nearing feature completeness for the <a href="http://code.google.com/p/mcollective/wiki/SimpleRPCIntroduction">SimpleRPC</a> layer as I am adding a number of features of interest to Enterprise and Large users especially around security and web UIs.  </p>
<p>Once we&#8217;re at the end of this cycle I&#8217;ll do a 1.0.0 release and then from there move onto the next major feature cycle.  The next cycle will focus on queuing long running tasks, background scheduling, future scheduling of tasks and a lot of related work.  I <a href="http://groups.google.com/group/mcollective-users/msg/35edb9a3fbca3de0">posted some detail</a> about these plans to the list recently.</p>
<p>Over the new few days or weeks I&#8217;ll do a number of Screencasts exploring some of these new features in depth, for now the list of what&#8217;s new:</p>
<h2>Security</h2>
<ul>
<li>New <a href="http://code.google.com/p/mcollective/wiki/SSLSecurityPlugin">SSL based security system</a></li>
<li>New <a href="http://code.google.com/p/mcollective/wiki/SimpleRPCAuthorization">Authorization system</a> [<a href="http://www.devco.net/archives/2010/04/11/authorization_plugins_for_mcollective_simplerpc.php">blog post</a>] and sample plugins, allowing for fine grained control over every request</li>
</ul>
<h2>Connectivity</h2>
<p>We can use Ruby Gem Stomp 1.1.6 which brings a lot of enhancements:</p>
<ul>
<li><a href="http://code.google.com/p/mcollective/wiki/ConnectorStomp">Connection pools for failover</a> between multiple ActiveMQs</li>
<li>Lots of tunables about the connection pools such as retry frequencies etc</li>
<li>SSL TLS between node and ActiveMQ</li>
</ul>
<h2>Writing Web and Dynamic UIs</h2>
<ul>
<li>A <a href="http://code.google.com/p/mcollective/wiki/SimpleRPCDDL">DDL that describes agents</a>, inputs and outputs:</li>
<ul>
<li>Creates auto generated documentation</li>
<li>Can be used to auto generate user interfaces</li>
<li>The client library will only make requests that validate against the DDL</li>
<li>In future input validations will move into the DDL and will be done automatically for you</li>
</ul>
<li>Web UI&#8217;s can <a href="http://code.google.com/p/mcollective/wiki/SimpleRPCClients#Doing_your_own_discovery">bypass or do their own discovery</a> and use the DDL to auto generate user interfaces</li>
</ul>
<h2>Usability</h2>
<ul>
<li><a href="http://code.google.com/p/mcollective/wiki/SimpleRPCClients#Sending_SimpleRPC_requests_without_discovery_and_blocking">Fire-and-Forget</a> style requests, for when you just want something done but do not care about results, these requests are very quick as they do not do any discovery.</li>
<li>Agents can now be reloaded without restarting the daemon</li>
<li>A new <em>mc-inventory</em> tool that can be used to view facts, agents and classes for a node</li>
<li>Many UI enhancements to the CLI tools</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.devco.net/archives/2010/06/14/recent_mcollective_releases_and_roadmap.php/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>MCollective pgrep</title>
		<link>http://www.devco.net/archives/2010/05/23/mcollective_pgrep.php</link>
		<comments>http://www.devco.net/archives/2010/05/23/mcollective_pgrep.php#comments</comments>
		<pubDate>Sun, 23 May 2010 13:19:49 +0000</pubDate>
		<dc:creator>R.I. Pienaar</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[mcollective]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.devco.net/?p=1463</guid>
		<description><![CDATA[The unix pgrep utility is great, it lets you grep through your process list and find interesting things. I wanted to do something similar but for my entire server group so built something quick ontop of MCollective. I am using the Ruby sys-proctable gem to do the hard work, it returns a massive amount of [...]]]></description>
			<content:encoded><![CDATA[<p>The unix pgrep utility is great, it lets you grep through your process list and find interesting things.  I wanted to do something similar but for my entire server group so built something quick ontop of MCollective.</p>
<p>I am using the Ruby <a href="http://raa.ruby-lang.org/project/sys-proctable/">sys-proctable</a> gem to do the hard work, it returns a massive amount of information about each process and have written a simple agent on top of this.</p>
<p>The agent supports grepping the process tree but also supports kill and pgre+kill though I have not yet implemented more than the basic grep on the command line.  Frankly the grep+kill combination scares me and I might remove it.  A simple grep slipup and you will kill all processes on all your machine <img src='http://www.devco.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   Sometimes too much power is too much and should just be avoided.</p>
<p>At the moment mc-pgrep outputs a set format but I intend to make that configurable on the command line, here&#8217;s a sample:</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span> mc-pgrep <span style="color: #660033;">-C</span> <span style="color: #000000; font-weight: bold;">/</span>dev_server<span style="color: #000000; font-weight: bold;">/</span> ruby
&nbsp;
 <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> ============================================================<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000;">4</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000;">4</span>
&nbsp;
dev1.my.com
       root   <span style="color: #000000;">9833</span>  ruby <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>mcollectived <span style="color: #660033;">--pid</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>mcollectived.pid 
       root  <span style="color: #000000;">21608</span>  <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span><span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span>passenger-2.2.2<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>phusion_pass
&nbsp;
dev2.my.com
       root  <span style="color: #000000;">14568</span>  <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span><span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span>passenger-2.2.2<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>phusion_pass
       root  <span style="color: #000000;">31595</span>  ruby <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>mcollectived <span style="color: #660033;">--pid</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>mcollectived.pid 
&nbsp;
dev3.my.com
       root   <span style="color: #000000;">1620</span>  <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span><span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span>passenger-2.2.2<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>phusion_pass
       root  <span style="color: #000000;">14093</span>  ruby <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>mcollectived <span style="color: #660033;">--pid</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>mcollectived.pid 
&nbsp;
dev4.my.com
       root   <span style="color: #000000;">3231</span>  <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span><span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span>passenger-2.2.2<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>phusion_pass
       root  <span style="color: #000000;">20557</span>  ruby <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>mcollectived <span style="color: #660033;">--pid</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>mcollectived.pid 
&nbsp;
   <span style="color: #660033;">----</span> process list stats <span style="color: #660033;">----</span>
        Matched hosts: <span style="color: #000000;">4</span>
    Matched processes: <span style="color: #000000;">8</span>
        Resident Size: 37.264KB
         Virtual Size: 629.578MB</pre></div></div>

<p></code></p>
<p>You can also limit it to only find zombies with the <i>-z</i> option.</p>
<p>This has been quite interesting for me, if I limit the pgrep to &#8220;.&#8221; (the pattern is regex) every machine will send back a Sys::ProcTable hash for all its processes.  This is a 50 to 70 KByte payload per server.  I&#8217;ve so far seen no problem getting his much traffic through ActiveMQ + MCollective and processing it all in a very short time:</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #000000; font-weight: bold;">time</span> mc-pgrep <span style="color: #660033;">-F</span> <span style="color: #ff0000;">&quot;country=/uk|us/&quot;</span> .
&nbsp;
   <span style="color: #660033;">----</span> process list stats <span style="color: #660033;">----</span>
        Matched hosts: <span style="color: #000000;">20</span>
    Matched processes: <span style="color: #000000;">1958</span>
        Resident Size: 1.777MB
         Virtual Size: 60.072GB
&nbsp;
mc-pgrep <span style="color: #660033;">-F</span> <span style="color: #ff0000;">&quot;country=/uk|us/&quot;</span> .  0.19s user 0.06s system <span style="color: #000000;">7</span><span style="color: #000000; font-weight: bold;">%</span> cpu <span style="color: #000000;">3.420</span> total</pre></div></div>

<p></code></p>
<p>That 3.4 seconds is with a 2 second discovery overhead client machine in Germany and the filter matching UK and US machines &#8211; all the way to the West Coast &#8211; my biggest delay here is network and not MC or ActiveMQ.</p>
<p>The code can be found at my <a href="http://github.com/ripienaar/mcollective-plugins/tree/master/agent/process/">GitHub account</a> and still a bit of a work in progress, wiki pages will follow once I am happy with it.</p>
<p>And as an aside, I am slowly migrating at least my code to GitHub if not wiki and ticketing.  So far my Plugins have moved, MC will move soon too.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devco.net/archives/2010/05/23/mcollective_pgrep.php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Puppet Concat 20100507</title>
		<link>http://www.devco.net/archives/2010/05/07/puppet_concat_20100507.php</link>
		<comments>http://www.devco.net/archives/2010/05/07/puppet_concat_20100507.php#comments</comments>
		<pubDate>Fri, 07 May 2010 18:22:59 +0000</pubDate>
		<dc:creator>R.I. Pienaar</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[puppet]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.devco.net/?p=1432</guid>
		<description><![CDATA[I&#8217;ve had quite a lot of contributions to my Puppet Concat module and after some testing by various people I&#8217;m ready to do a new release. Thanks to Paul Elliot, Chad Netzer and David Schmitt for patches and assistance. For background of what this is about please see my earlier post: Building files from fragments [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve had quite a lot of contributions to my Puppet Concat module and after some testing by various people I&#8217;m ready to do a new release.</p>
<p>Thanks to Paul Elliot, Chad Netzer and David Schmitt for patches and assistance.</p>
<p>For background of what this is about please see my earlier post: <a href="http://www.devco.net/archives/2010/02/19/building_files_from_fragments_with_puppet.php">Building files from fragments with Puppet</a></p>
<p>You can download the release <a href="http://www.devco.net/code/concat-20100507.tgz">here</a>.  Please pay special attention to the upgrade instructions below.</p>
<h1>Changes in this release</h1>
<ul>
<li>Several robustness improvements to the helper shell script.</li>
<li>Removed all hard coded paths in the helper script to improve portability.</li>
<li>We now use file{} to copy the combined file to its location.  This means you can now change the ownership of a file by just changing the owner/group in <i>concat{}</i>.</li>
<li>You can specify <i>ensure => &#8220;/some/other/file&#8221;</i> in <i>concat::fragment</i> to include the contents of another file in the fragment.  Even files not managed by puppet.</li>
<li>The code is now <a href="http://github.com/ripienaar/puppet-concat">hosted on Github</a> and we&#8217;ll accept patches there.</li>
</ul>
<h1>Upgrading</h1>
<p>When upgrading to this version you need to take particular care.  All the fragments are now owned by root, the shell script runs as root and we use file{} to copy the resulting file out.</p>
<p>This means you&#8217;ll see the diff of not just the fragments but also the final file when running <i>puppetd &#8211;test</i> but unfortunately it also means the first time you run puppet with the new code your Puppet will fire off all notifies that you have on your concat{} resources.  You&#8217;ll also see a lot of changes to resources in the fragments directory on first run.  This is normal and expected behavior.</p>
<p>So if say you&#8217;re using the concat to create <i>my.cf</i> and notify the service to restart automatically then simply upgrading this module will result in MySQL restarting.  This is a one off notify that happens only the first time, from then on it will be as normal.   So I&#8217;d suggest when upgrading to disable those notifies till this upgrade is running everywhere and then put it back.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devco.net/archives/2010/05/07/puppet_concat_20100507.php/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Authorization plugins for MCollective SimpleRPC</title>
		<link>http://www.devco.net/archives/2010/04/11/authorization_plugins_for_mcollective_simplerpc.php</link>
		<comments>http://www.devco.net/archives/2010/04/11/authorization_plugins_for_mcollective_simplerpc.php#comments</comments>
		<pubDate>Sun, 11 Apr 2010 11:11:12 +0000</pubDate>
		<dc:creator>R.I. Pienaar</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[devops]]></category>
		<category><![CDATA[mcollective]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.devco.net/?p=1405</guid>
		<description><![CDATA[Till now The Marionette Collective has relied on your middleware to provide all authorization and authentication for requests. You&#8217;re able to restrict certain middleware users from certain agents, but nothing more fine grained. In many cases you want to provide much finer grain control over who can do what, some cases could be: A certain [...]]]></description>
			<content:encoded><![CDATA[<p>Till now <a href="http://code.google.com/p/mcollective/">The Marionette Collective</a> has relied on your middleware to provide all authorization and authentication for requests.  You&#8217;re able to <a href="http://code.google.com/p/mcollective/wiki/SecurityWithActiveMQ">restrict certain middleware users from certain agents</a>, but nothing more fine grained.  </p>
<p>In many cases you want to provide much finer grain control over who can do what, some cases could be:</p>
<ul>
<li>A certain user can only request service restarts on machines with a fact <i>customer=acme</i></li>
<li>A user can do any service restart but only on machines that has a certain configuration management class</li>
<li>You want to deny all users except root from being able to stop services, others can still restart and start them</li>
</ul>
<p>This kind of thing is required for large infrastructures with lots of admins all working in their own group of machines but perhaps a central NOC need to be able to work on all the machines, you need fine grain control over who can do what and we did not have this will now.  It would also be needed if you wanted to give clients control over their own servers but not others.</p>
<p>Version 0.4.5 will have support for this kind of scheme for SimpleRPC agents.  We wont provide a authorization plugin out of the box with the core distribution but I&#8217;ve made one which will be available as a plugin.</p>
<p>So how would you write an auth plugin, first a typical agent would be:</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">module</span> MCollective
    <span style="color:#9966CC; font-weight:bold;">module</span> Agent
         <span style="color:#9966CC; font-weight:bold;">class</span> Service<span style="color:#006600; font-weight:bold;">&lt;</span><span style="color:#6666ff; font-weight:bold;">RPC::Agent</span>
             authorized_by <span style="color:#ff3333; font-weight:bold;">:action_policy</span>
&nbsp;
             <span style="color:#008000; font-style:italic;"># ....</span>
         <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p></code></p>
<p>The new <i>authorized_by</i> keyword tells MCollective to use the class <i>MCollective::Util::ActionPolicy</i> to do any authorization on this agent.</p>
<p>The ActionPolicy class can be pretty simple, if it raises any kind of exception the action will be denied.</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">module</span> MCollective
    <span style="color:#9966CC; font-weight:bold;">module</span> Util
         <span style="color:#9966CC; font-weight:bold;">class</span> ActionPolicy
              <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">authorize</span><span style="color:#006600; font-weight:bold;">&#40;</span>request<span style="color:#006600; font-weight:bold;">&#41;</span>
                  <span style="color:#9966CC; font-weight:bold;">unless</span> request.<span style="color:#CC0066; font-weight:bold;">caller</span> == <span style="color:#996600;">&quot;uid=500&quot;</span>
                      <span style="color:#CC0066; font-weight:bold;">raise</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;You are not allow access to #{request.agent}::#{request.action}&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
                  <span style="color:#9966CC; font-weight:bold;">end</span>
              <span style="color:#9966CC; font-weight:bold;">end</span>
         <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p></code></p>
<p>This simple check will deny all requests from anyone but Unix user id 500.</p>
<p>It&#8217;s pretty simple to come up with your own schemes, <a href="http://code.google.com/p/mcollective-plugins/wiki/ActionPolicy">I wrote one</a> that allows you to make policy files like the one below for the <i>service</i> agent:</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">policy default deny
allow   uid=500 *                    *                *
allow   uid=502 status               *                *
allow   uid=600 *                    customer=acme    acme::devserver</pre></div></div>

<p></code></p>
<p>This will allow user 500 to do everything with the service agent.  User 502 can get the status of any service on any node.  User 600 will be able to do any actions on machines with the fact <i>customer=acme</i> that also has the configuration management class <i>acme::devserver</i> on them.  Everything else will be denied.</p>
<p>You can do multiple facts and multiple classes in a simple space separated list.  The entire plugin to implement such policy controls was only <a href="http://code.google.com/p/mcollective-plugins/source/browse/trunk/simplerpc_authorization/action_policy/actionpolicy.rb">120 &#8211; heavy commented &#8211; lines of code</a>.  </p>
<p>I think this is a elegant and easy to use layer that provides a lot of functionality.  We might in future pass more information about the caller to the nodes.  There&#8217;s some limitations, specifically about the source of the caller information being essentially user provided so you need to keep that mind.</p>
<p>As mentioned this will be in MCollective 0.4.5.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devco.net/archives/2010/04/11/authorization_plugins_for_mcollective_simplerpc.php/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
