Skip to content

Instantly share code, notes, and snippets.

View bodsch's full-sized avatar

Bodo Schulz bodsch

View GitHub Profile
@bodsch
bodsch / gist:e02534f6417b44d80a05c41dd225023a
Created May 10, 2017 13:40 — forked from brandonrich/gist:67c0ae24b5abfef65134
Ruby AWS SDK v2 IAM user MFA example
# shows how to use the Ruby AWS SDK to list EC2 instance IDs
# when your API credentials have been placed under MFA requirements
# Prerequisites:
# you are running on a host that already has the AWS CLI set up with an IAM key pair
# that can describe EC2 instances (OTHERWISE, just pass a
# secret_access_id / secret_access_key pair to the STS client initializer)
# You have installed the Ruby AWS SDK Gem
# http://aws.amazon.com/sdk-for-ruby/
# -----------------------------------------------------------------------------
# Monkey patches
# Modify `Object` (https://gist.github.com/Integralist/9503099)
# None of the above solutions work with a multi-level hash
# They only work on the first level: {:foo=>"bar", :level1=>{"level2"=>"baz"}}
# The following two variations solve the problem in the same way
# transform hash keys to symbols
def time_diff(start_time, end_time)
seconds_diff = (start_time - end_time).to_i.abs
years = (seconds_diff / 31556952)
months = (seconds_diff / 2629746)
weeks = (seconds_diff / 2628288.0).round(0)
days = (seconds_diff / 86400)
hours = (seconds_diff / 3600)
minutes = (seconds_diff / 60)
#!/usr/bin/ruby
require 'date'
require 'time_difference'
now = DateTime.now.utc
last = Time.at( 1506470400000 / 1000 )
puts "now is #{now}. class=#{now.class}"
puts "last is #{last}. class=#{last.class}"
@bodsch
bodsch / icinga2.coffee
Created August 18, 2017 05:24
dasching widget for icinga2
class Dashing.Icinga2 extends Dashing.Widget
@accessor 'current', Dashing.AnimatedValue
onData: (data) ->
if data.color
# clear existing "color-*" classes
$(@get('node')).attr 'class', (i,c) ->
c.replace /\bcolor-\S+/g, ''
# add new class
$(@get('node')).addClass "color-#{data.color}"
@bodsch
bodsch / gist:2cc3c1fe5f5869df28de53ccddfaffd6
Last active November 18, 2017 16:40
icinga2-cert-service-client
#!/bin/bash
set -e
ICINGA_VERSION=$(icinga2 --version | head -n1 | awk -F 'version: ' '{printf $2}' | grep -Po '(?<=r)\d.\d')
ICINGA_CERT_SERVICE_BA_USER=admin
ICINGA_CERT_SERVICE_BA_PASSWORD=admin
ICINGA_CERT_SERVICE_API_USER=root
ICINGA_CERT_SERVICE_API_PASSWORD=${ICINGA_CERT_SERVICE_API_PASSWORD:-''}
HOSTNAME=$(grep '^const NodeName' /etc/icinga2/constants.conf | awk -F ' = ' '{printf $2}' | sed -e 's|"||g')
@bodsch
bodsch / create_certificate.sh
Last active November 19, 2017 09:08
icinga2.8 ticket
#!/bin/bash
DIR="/tmp/icinga-pki/xxxxxx"
SATELLITE="icinga2-satellite-2.matrix.lan"
SALT=$(echo ${s} | sha256sum | cut -f 1 -d ' ')
[ -d ${DIR} ] && rm -rf ${DIR}
[ -d ${DIR} ] || mkdir -vp ${DIR}
chown icinga: ${DIR}
icinga2 pki new-cert \
@bodsch
bodsch / gist:1b78bfa81512694ad63a23e8c2b15386
Created November 24, 2017 14:44
icinga2 extract api calls
#!/bin/bash
set -e
ICINGA_HOST=${ICINGA_HOST:-localhost}
ICINGA_API_PORT=${ICINGA_API_PORT:-5665}
ICINGA_API_USER=${ICINGA_API_USER:-root}
ICINGA_API_PASSWORD=${ICINGA_API_PASSWORD:-icinga}
types=
@bodsch
bodsch / cirqle_queue_and_fifo.rb
Created December 11, 2017 13:16 — forked from prepor/cirqle_queue_and_fifo.rb
Simple ruby implementation of Cirqle Queue and FIFO
class CircleQueue
include Enumerable
class Head
attr_accessor :first, :last
def initialize
self.first = self
self.last = self
end
@bodsch
bodsch / dns_check.rb
Created January 21, 2018 09:33 — forked from colszowka/dns_check.rb
Ruby DNS Check
require 'resolv'
class DnsCheck
attr_reader :host
def initialize(host)
@host = host
end
def a
@a ||= Resolv::DNS.new.getresources(host, Resolv::DNS::Resource::IN::A)