Skip to content

Instantly share code, notes, and snippets.

@majormoses
majormoses / check_SOME_portal.rb
Last active September 1, 2018 00:32
How to manage checks with chef and a various collection of sensu configuration artifacts such as filters, handler configs, etc.
default['MY_CUSTOM_NAMESPACE']['sensu']['checks']['some_portal_monitoring']['command'] = "check-http.rb -u #{node['MY_CUSTOM_NAMESPACE']['sensu']['monitoring']['SOME_portal_monitoring']['url']} -q SOME_STRING"
default['MY_CUSTOM_NAMESPACE']['sensu']['checks']['some_portal_monitoring']['handlers'] = ['pagerduty']
default['MY_CUSTOM_NAMESPACE']['sensu']['checks']['some_portal_monitoring']['subscribers'] = ['MY_SUBSCRIPTION']
default['MY_CUSTOM_NAMESPACE']['sensu']['checks']['some_portal_monitoring']['interval'] = 30
default['MY_CUSTOM_NAMESPACE']['sensu']['checks']['some_portal_monitoring']['additional'] = {
'pager_team' => 'urgent',
'notification' => 'Some_PORTAL is not reachable',
'occurrences' => 4,
'runbook' => 'https://docs.google.com/document/d/<REDACTED>'
}
@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 / 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 / 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 / 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 / gist:c78c4b2395625df273900d7c147e72c7
Created June 4, 2017 23:56
sensu-plugins-supervisor-dpkg-deps
listing installed packages:
acl install
adduser install
apt install
base-files install
base-passwd install
bash install
binutils install
bsdutils install
build-essential install
@majormoses
majormoses / gist:e22b1fb88d88bf6c333cbb1aa478a417
Created May 13, 2017 02:21
Finally reproduced issue with sensu-plugins-memcached install on newer versions of sensu
# get into a debian container
$ docker run -it debian:jessie /bin/bash
Unable to find image 'debian:jessie' locally
jessie: Pulling from library/debian
Digest: sha256:476959f29a17423a24a17716e058352ff6fbf13d8389e4a561c8ccc758245937
Status: Downloaded newer image for debian:jessie
# install some pre-reqs
root@62b7a91a1fd8:/# apt-get update
Get:1 http://security.debian.org jessie/updates InRelease [63.1 kB]
# same docker setup with installing deps first
$ docker run -it anroots/sensu-client /bin/bash
# install deps
root@8614d21723f2:/# apt-get update
Get:1 http://security.debian.org jessie/updates InRelease [63.1 kB]
Ign http://httpredir.debian.org jessie InRelease
Get:2 http://httpredir.debian.org jessie-updates InRelease [145 kB]
Get:3 http://security.debian.org jessie/updates/main amd64 Packages [510 kB]
Get:4 http://httpredir.debian.org jessie Release.gpg [2373 B]
@majormoses
majormoses / gist:ecf0a3404c2d140bb32fa5c01c638bd2
Created May 13, 2017 01:59
Attempting to replicate install failure with sensu-plugins-memcached inside docker
# run a docker image and shell in
$ docker run -it anroots/sensu-client /bin/bash
Unable to find image 'anroots/sensu-client:latest' locally
latest: Pulling from anroots/sensu-client
fdd5d7827f33: Pull complete
a3ed95caeb02: Pull complete
a050c2b80c6b: Pull complete
f4beaf51b556: Pull complete
992c0cff1787: Pull complete
a3a48c2b3aa6: Pull complete
@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: