Skip to content

Instantly share code, notes, and snippets.

View bmhatfield's full-sized avatar
🍌
I'm a banana.

Brian Hatfield bmhatfield

🍌
I'm a banana.
View GitHub Profile
@bmhatfield
bmhatfield / keybase.md
Created March 27, 2014 18:05
keybase.md

Keybase proof

I hereby claim:

  • I am bmhatfield on github.
  • I am brianhatfield (https://keybase.io/brianhatfield) on keybase.
  • I have a public key whose fingerprint is 2DF5 8084 BCAC BB25 AA51 9650 FFD6 0508 E5D9 0536

To claim this, I am signing this object:

@bmhatfield
bmhatfield / gist:e49022dbea8013c3cef4
Created September 11, 2014 16:55
Stubbed-Search (Chef)
module StubbedSearch
def stubbed_search(index, query, stub)
# When running in the 'local' environment, dynamically set the hostname
# value for the search_stub to the hostname of the running VM
if node.chef_environment == 'local'
node.normal[:search_stub][stub] = node[:search_stub][stub].map do |n|
hsh = n.to_hash
hsh[:hostname] = node[:hostname]
hsh
end
; Expire old events from the index every 15 seconds.
(periodically-expire 10 {:keep-keys [:host :service :tags]})
(def rollup-ttl 60)
(def throttle-ttl 120)
(defn event-log [prefix]
(fn [e] (info prefix (str e))))
(def email (mailer {:from "riemann@domain"}))
@bmhatfield
bmhatfield / gist:5454382
Created April 24, 2013 18:31
Attributes
time: 1366828063
service: "myservice"
host: "myhost.foobar.com"
ttl: 300.0
attributes {
key: "zoinks"
value: "4"
}
attributes {
key: "forks"
var fields map[string]interface{} = make(map[string]interface{})
func main() {
fields["device"] = json.RawMessage(`{"OMG": 13}`)
jsn, err := json.Marshal(fields)
if err == nil {
fmt.Println(string(jsn))
} else {
@bmhatfield
bmhatfield / gist:8600671
Created January 24, 2014 16:24
Working Ohai Plugin
require_plugin "#{os}::network"
provides 'ipaddress'
if virtualization['system'] == 'vbox'
network['interfaces']['eth1']['addresses'].each do |ip, params|
if params['family'] == 'inet'
ipaddress ip
end
end
@bmhatfield
bmhatfield / ec2-security-group-rules
Created March 9, 2016 04:15
Output a human-readable & colorized view of your EC2 security group rules
#!/usr/bin/env ruby
require 'aws-sdk'
require 'colorize'
ec2 = Aws::EC2::Resource.new
ec2.security_groups.sort_by{|s| s.group_name }.each do |sg|
puts sg.group_name.underline unless sg.ip_permissions.empty?
sg.ip_permissions.each do |perm|
@bmhatfield
bmhatfield / local_databag.rb
Created March 29, 2016 00:45
Encrypt, Edit and key-rotate databags.
require 'chef/knife'
module LocalDatabags
class Encrypt < Chef::Knife
deps do
require 'chef/encrypted_data_bag_item'
end
banner "knife encrypt BAGNAME ITEM KEYFILE"
@bmhatfield
bmhatfield / check-recent-oom
Created April 16, 2016 15:10
A simple, time-based OOM check script for use with riemann-sumd
#!/bin/bash
# Run on a minutely basis by https://github.com/bmhatfield/riemann-sumd/
LAST_OOM_WINDOW=5;
LAST_OOM="$(grep 'Out of memory' /var/log/kern.log | tail -n 1)";
LAST_OOM_TIME=${LAST_OOM:0:15};
if [ -n "${LAST_OOM_TIME}" ]; then
if [ $(($((`date +%s` - `date --date="${LAST_OOM_TIME}" +%s`)) / 60 )) -le ${LAST_OOM_WINDOW} ]; then
echo "CRITICAL: OOM within last ${LAST_OOM_WINDOW} minutes!"
echo ${LAST_OOM}
@bmhatfield
bmhatfield / clibalance.proto
Created August 11, 2020 12:44
GRPC load balancing sample in Go
syntax = "proto3";
package clibalance;
service Balanceable {
rpc Relay(Ping) returns (Pong);
}
message Ping {
int64 id = 1;
}