Skip to content

Instantly share code, notes, and snippets.

#! /usr/bin/env ruby
require 'json'
require 'date'
require 'optparse'
require 'pp'
require 'net/http'
config_file = nil
debug = false
Hi Sensuite:
I'd like each node to check our graphite server to determine if its CPU steal percent merited a warning. Of course, when I tried it, that generated a thundering herd when the sensu server published a check request. I was doing this because the check_cpu.rb plugin has steal/usage that are 10x what we get from collectd (or what I observe w/ top).
I can re-implement as a standalone check with some sort of randomization around the interval, but I prefer most checks regarding node health to come from the server.
From https://github.com/sensu/sensu/blob/master/lib/sensu/client.rb#L221 it looks like one could add a random splay to `scheduling_delay` without too much hackery, but that may be undesirable.
So this brings me to the following questions:
* Is there a current method to splay the client scheduling of checks?
#!/usr/bin/env ruby
require 'rubygems'
require 'json'
event = JSON.parse(STDIN.read)
puts event.to_json
@pburkholder
pburkholder / ohai_hashie.rb
Created August 29, 2014 19:05
Here’s a little one liner that you can paste into a terminal that has the chef gem installed:
#/usr/bin/env ruby -r chef
o = Ohai::System.new; o.load_plugins; @data = Mash.new; o.run_plugins.each { |plugin| @data = Chef::Mixin::DeepMerge.deep_merge(@data, plugin.data) }; File.open('/tmp/ohai.json', 'w') { |f| f.write(JSON.pretty_generate(@data)) }”

Mapping Nodes to Organizations

Chef 11.x

You'll need to run this on the Server in Orgmapper, eg:

/opt/opscode/bin/orgmapper
orgmapper>> eval(::File.read("/path/to/code.rb"))
# Orgmapper snippet to output all nodes with client versions in all organizations to a JSON file
# To Use:
# 1) Start orgmapper
# 2) Load the script
# eval(::File.read("/path/to/orgmapper_all_client_versions.rb"))
# 3) output will be printed to the screen and also written to JSON_OUTPUT_FILE
JSON_OUTPUT_FILE = 'chef_versions.json'
@pburkholder
pburkholder / .gemrc
Created November 7, 2014 17:02
What a private .gemrc looks like
---
:update_sources: true
:verbose: true
:backtrace: false
:bulk_threshold: 1000
install: "--user"
update: "--user"
@pburkholder
pburkholder / gist:3e2ef1182d28457a3e8d
Created November 22, 2014 02:57
11.10.4 chef-client YAML dump of ImmutableArray
puts YAML.dump({ 'instances' => @immutable_array_of_mashes.map { |item| item.to_hash }})
---
instances:
- m: m
- b: b
- top: !ruby/hash:Chef::Node::ImmutableMash
second_level: some value
top_level_2: !ruby/array:Chef::Node::ImmutableArray
- array
- of
@pburkholder
pburkholder / client.rb
Created December 18, 2014 15:57
Generic cookbook/.chef/client.rb
current_dir = File.dirname(__FILE__)
# might be interesting as Dir.pwd
my_cookbook = File.expand_path("..", current_dir)
log_level :info
log_location STDOUT
# Need this to create myself as local non-privileged chef client node:
node_name 'workstation_macpro'
# use 'berks vendor' and this cookbook path:
@pburkholder
pburkholder / planning.md
Last active August 29, 2015 14:13
DevOpsDC Planning

Join the DevOpsDC planning sessions!

  • Two weeks after each DevOpsDC meeting
  • Google Hangout (Time TBD based on availability)
  • What do you see for 2015 & DevOpsDC?
  • Tweet #planning to @devopsdc or leave a message at MeetUp

-- Accompanying text: Nathen and Peter have found the offers for help w/ DevOpsDC to be really heartening and we recognize that more participation will be a good thing