Skip to content

Instantly share code, notes, and snippets.

View srinivasmohan's full-sized avatar

Srinivasan Mohan srinivasmohan

View GitHub Profile
@srinivasmohan
srinivasmohan / whatsmyname.rb
Last active October 3, 2015 18:27
Chef recipe (snippets) to setup FQDN, hostname, IP etc properly
#Knife invocations supply FQDN as the node name at creation time and this becomes hostname( option -N)
execute "Configure Hostname" do
command "hostname --file /etc/hostname"
action :nothing
end
#Ensure the hostname of the system is set to knife provided node name
file "/etc/hostname" do
content node.name
@srinivasmohan
srinivasmohan / update_hosts.sh
Created April 26, 2012 22:16
Update /etc/hosts to have the "current" IP address of eth0
#!/bin/bash
#/etc/network/if-up.d/update_hosts
set -e
#Variable IFACE is setup by Ubuntu network init scripts to whichever interface changed status.
[ "$IFACE" == "eth0" ] || exit
myname=`cat /etc/hostname`
shortname=`cat /etc/hostname | cut -d "." -f1`
hostsfile="/etc/hosts"
#Knock out line with "old" IP
@srinivasmohan
srinivasmohan / hipchat_notify.rb
Created April 19, 2012 05:32
Post Nagios alerts to Hipchat
#!/usr/bin/ruby
require 'rubygems'
require 'hipchat-api'
require 'getopt/long'
require 'socket'
require 'erb'
#Do not modify these constants! (after you set these up, of course)
HipApiKey='ABCDEFGHKJHKJHKJHKJH'
Room='Nagios'
@srinivasmohan
srinivasmohan / knife_status.rb
Created April 19, 2012 05:28
Knife Status - Display absolute times and show latest checkins on top
#Run this from your Knife folder with "knife exec /pathto/knife_status.rb"
stats=Array.new
sizes=[0,0,0]
TimeFormat="%F %R"
Sep='|'
nodes.all do |thisnode|
checkintime=Time.at(thisnode['ohai_time']).to_i
rubyver = thisnode['languages']['ruby']['version']
recipes = thisnode.run_list.expand(thisnode.chef_environment).recipes.join(",")