Skip to content

Instantly share code, notes, and snippets.

@majormoses
majormoses / gist:b4cc44accb0e8ac264a3eef5023c39f3
Created May 13, 2017 01:42
Attempting to replicate install failure with sensu-plugins-memcached
# in the repo root we checkout latest released version
$ git checkout 0.0.3
Note: checking out '0.0.3'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
@majormoses
majormoses / mkrf_conf.rb
Created June 10, 2017 16:35
Install xmlrpc on ruby versions >= 2.4
# This file needs to be named mkrf_conf.rb
# so that rubygems will recognize it as a ruby extension
# file and not think it is a C extension file
require 'rubygems/dependency_installer.rb'
# Load up the rubygem's dependency installer to
# installer the gems we want based on the version
# of Ruby the user has installed
@majormoses
majormoses / check_chef_convergence.rb
Last active July 4, 2017 15:58
Recipe to create a bunch of sensu checks from attributes
# non-converge checks
default['MY_CUSTOM_NAMESPACE']['sensu']['checks']['chef_client']['command'] = "check-chef-nodes.rb -U #{Chef::Config[:chef_server_url]} -C :::chef.client.node|#{node.name}::: -K /etc/sensu/conf.d/chef-client.pem -t 1800"
default['MY_CUSTOM_NAMESPACE']['sensu']['checks']['chef_client']['handlers'] = ['pagerduty']
default['MY_CUSTOM_NAMESPACE']['sensu']['checks']['chef_client']['subscribers'] = ['chef_server']
default['MY_CUSTOM_NAMESPACE']['sensu']['checks']['chef_client']['interval'] = 60
default['MY_CUSTOM_NAMESPACE']['sensu']['checks']['chef_client']['additional'] = {
'pager_team' => 'non_urgent',
'notification' => 'A chef client is not converging',
'occurrences' => 2,
'subdue' => {
@majormoses
majormoses / xml_to_json.rb
Created July 9, 2017 18:31
Converting xml to json
#! /usr/bin/env ruby
require 'sensu-plugin/check/cli'
require 'active_support/all'
require 'json'
dir_to_check = Dir.glob('/tmp/testdir/*')
# Dir always returns an empty list even if the dir does not even exist
if dir_to_check.empty?
p 'this is an empty dir, does not exist, or have permissions to view'
@majormoses
majormoses / delete-noprompt
Created September 1, 2017 23:18
Various Test cases for knife cookbook-cleanup plugin
$ knife cookbook cleanup --versions 5 --yes
The following cookbook versions will remain on the chef server:
7-zip: 1.0.2
ant:
1.0.2
1.0.3
apache2:
3.1.0
@majormoses
majormoses / check-http-healthcheck.rb
Created October 12, 2017 23:00
A script that checks an http endpoint, parses json, and alerts when healthchecks fail
#! /usr/bin/env ruby
#
# check-cc-heap-limit
#
# DESCRIPTION:
# A script that checks an http endpoint, parses json, and alerts when healthchecks fail
#
# OUTPUT:
# plain-text
#
@majormoses
majormoses / jenkins_recipe.rb
Last active November 8, 2017 04:19
Example of how to restart a service, wait for it to come up, and then do more things
# drop in a template and immediately restart jenkins
template "#{node['jenkins']['master']['home']}/config.xml" do
source 'config.xml.erb'
variables({
'github_client_id' => <REDACTED>,
'github_client_secret' => <REDACTED>
})
owner node['jenkins']['master']['user']
group node['jenkins']['master']['group']
mode '0600'
diff --git a/bin/metrics-logstash-node.rb b/bin/metrics-logstash-node.rb
index d8251b3..3975230 100755
--- a/bin/metrics-logstash-node.rb
+++ b/bin/metrics-logstash-node.rb
@@ -112,32 +112,62 @@ class LogstashNodeMetrics < Sensu::Plugin::Metric::CLI::Graphite
metrics['process.open_file_descriptors'] = node['process']['open_file_descriptors']
metrics['process.peak_open_file_descriptors'] = node['process']['peak_open_file_descriptors']
metrics['process.max_file_descriptors'] = node['process']['max_file_descriptors']
-
- node['pipeline']['events'].each do |key, value|
@majormoses
majormoses / keybase.md
Created March 8, 2018 02:26
Keybase Proof

Keybase proof

I hereby claim:

  • I am majormoses on github.
  • I am majormoses (https://keybase.io/majormoses) on keybase.
  • I have a public key ASDkf6DeBHYQYgrqCPmlhZXXHQ3YGmhjcg6xWRPUh-wI-Ao

To claim this, I am signing this object:

@majormoses
majormoses / testing-artifact
Created March 17, 2018 06:26
Testing artifact for fixing sensu-plugins-ssl #35
# test without debug and default options
$ time bundle exec ./bin/check-ssl-qualys.rb -d google.com
CheckSSLQualys OK: google.com rated A
real 2m48.673s
user 0m0.208s
sys 0m0.020s
# test without debug and default options
$ time bundle exec ./bin/check-ssl-qualys.rb -d google.com