Puppet Twitter
So on with our week of Puppet report processors. We started the week with the Puppet Campfire and Puppet IRC processors. Today I am doing a somewhat more complex (and potentially not very practical … :) ) report processor that sends notifications of failed runs to Twitter. It requires a bit more setup than the other processors starting with the Twitter and OAuth gems.
-
Install the oauth and twitter gems on your Puppet master
$ sudo gem install oauth twitter
-
Create a new Twitter app here. For Application Type specify Client and for Default Access Type specify Read & Write. Make a note of the consumer key and consumer secret. You’re going to need them in Step 3.
-
Run the poauth.rb script (you’ll find it in the repository) and provide the consumer key and secret from the Twitter application you created in Step 2. Go to the URL provided by the script and authorise the Twitter user you wish to tweet your reports with to use this application. You will be provided with a PIN number. Paste it into the script where you are prompted. This will create a file called twitter.yaml in your current directory:
$ ruby poauth.rb Set up your application at https://twitter.com/apps/, then enter your ‘Consumer key’ and ‘Consumer secret’:
Consumer key: d26cebWimPohUXxXFBMl0Q Consumer secret: ZI4E5QDt15iplUn3QTJyLATNO6deMwCLeZOHN3WPd0g Visit http://api.twitter.com//oauth/authorize?oauth_token=sd4HGcFSpK7vI in your browser to authorize the app, then enter the PIN you are given: 3300514
-
Copy the twitter.yaml file you created in Step 3. into your /etc/puppet/ directory.
-
Install puppet-twitter as a module in your Puppet master’s module path.
-
Enable pluginsync and reports on your master and clients in puppet.conf
[master] report = true reports = twitter pluginsync = true [agent] report = true pluginsync = true
-
Run the Puppet client and sync the report as a plugin And bingo your Puppet server will tweet when Puppet runs fail! Of course this may annoy a lot of the free world so YMMV on the usefulness of this. You could also tweak the code pretty simply to send you and others DMs, for example by editing:
Twitter.update(“Puppet run for #{self.host} #{self.status}”) to: Twitter.direct_message_create(“user_to_receive_DM”, “Puppet run for #{self.host} #{self.status}”)