Friday, 1 November 2013

Dirty, dirty devops

No this isn't an opinionated rant about devops culture or anything. Its just a hacky knife plugin that lets me play with Sensu quickly.

I want to play with as an alternative to Nagios and Zabbix etc. I've already got a nice git repo full of our cookbooks etc, but I don't want to go near them. I don't want to even risk messing up master etc.

Note: This assumes you have a chef workstation set up with knife available etc.

Anyway, I wrote this tiny little knife plugin that just calls a couple of bash commands:

require 'chef/knife'
# other require attributes, as needed

module Sandbox
  class SandboxInit < Chef::Knife

    deps do

    banner "knife sandbox init (options)"

    def run
      puts "Creating chef repo as chef-repo"
      system("git clone git://")
      puts "Creating .chef dir"
      system("mkdir chef-repo/.chef")
      puts "Creating knife config file"
      system("echo 'current_dir = File.dirname(__FILE__)\ncookbook_path [\"\#{current_dir}/../cookbooks\"]' > chef-repo/.chef/knife.rb")
      puts "Done. You can know cd into chef-repo, run knife cookbook site install BLAH and use vagrant etc"

See what I mean with hacky? Eww. Anyway, stick this file in ~/.chef/plugins/knife/ then you can use it as follows:

$ mkdir playing-around
$ cd playing-around
$ knife sandbox init
WARNING: No knife configuration file found
Creating chef repo as chef-repo
Cloning into 'chef-repo'...
remote: Counting objects: 223, done.
remote: Compressing objects: 100% (139/139), done.
remote: Total 223 (delta 80), reused 178 (delta 49)
Receiving objects: 100% (223/223), 38.14 KiB | 0 bytes/s, done.
Resolving deltas: 100% (80/80), done.
Checking connectivity... done
Creating .chef dir
Creating knife config file
Done. You can know cd into chef-repo, run knife cookbook site install BLAH and use vagrant etc
$ cd chef-repo

Now you can follow the instructions here

$ knife cookbook site install sensu
$ cd cookbooks/sensu/examples
$ bundle install
$ librarian-chef install
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
[default] Importing base box 'opscode-ubuntu-13.04'...
[default] Matching MAC address for NAT networking...
[default] Clearing any previously set forwarded ports...
[default] Creating shared folders metadata...
[default] Clearing any previously set network interfaces...
[default] Preparing network interfaces based on configuration...
[default] Forwarding ports...
[default] -- 22 => 2222 (adapter 1)
[default] -- 8080 => 8080 (adapter 1)
[default] Running 'pre-boot' VM customizations...
[default] Booting VM...
[default] Waiting for machine to boot. This may take a few minutes...
[default] Machine booted and ready!
[2013-11-01T17:16:35+00:00] INFO: Chef Run complete in 227.664146883 seconds
[2013-11-01T17:16:35+00:00] INFO: Running report handlers
[2013-11-01T17:16:35+00:00] INFO: Report handlers complete
[2013-11-01T17:12:47+00:00] INFO: Forking chef instance to converge...

We now have a machine that should have Sensu on it:

$ vagrant ssh
Welcome to Ubuntu 13.04 (GNU/Linux 3.8.0-19-generic x86_64)

 * Documentation:

94 packages can be updated.
55 updates are security updates.

New release '13.10' available.
Run 'do-release-upgrade' to upgrade to it.

Last login: Sun May 12 22:41:29 2013 from
vagrant@vagrant:~$ ps -ef | grep sens
sensu     6097     1  0 17:16 ?        00:00:00 /opt/sensu/embedded/bin/ruby /opt/sensu/bin/sensu-server -b -c /etc/sensu/config.json -d /etc/sensu/conf.d -e /etc/sensu/extensions -p /var/run/sensu/ -l /var/log/sensu/sensu-server.log -L info
sensu     6154     1  0 17:16 ?        00:00:00 /opt/sensu/embedded/bin/ruby /opt/sensu/bin/sensu-api -b -c /etc/sensu/config.json -d /etc/sensu/conf.d -e /etc/sensu/extensions -p /var/run/sensu/ -l /var/log/sensu/sensu-api.log -L info
sensu     6211     1  0 17:16 ?        00:00:00 /opt/sensu/embedded/bin/ruby /opt/sensu/bin/sensu-dashboard -b -c /etc/sensu/config.json -d /etc/sensu/conf.d -e /etc/sensu/extensions -p /var/run/sensu/ -l /var/log/sensu/sensu-dashboard.log -L info
sensu     6276     1  0 17:16 ?        00:00:00 /opt/sensu/embedded/bin/ruby /opt/sensu/bin/sensu-client -b -c /etc/sensu/config.json -d /etc/sensu/conf.d -e /etc/sensu/extensions -p /var/run/sensu/ -l /var/log/sensu/sensu-client.log -L info
vagrant   6740  6651  0 17:21 pts/0    00:00:00 grep --color=auto sens

Woot. You can even browse the dashboard on http://localhost:8080 (username is admin and the password is secret).

When you're done, you can quickly clean up after yourself:

$ vagrant destroy
$ cd
$ rm -rf playing-around

No comments:

Post a Comment