Skip to content

Instantly share code, notes, and snippets.

root@ubuntu1404-4:/opt/sensu# cat /etc/sensu/extensions/latest_event_file.rb
module Sensu
module Extension
class LatestEventFile < Bridge
def name
'latest_event_file'
end
def description
'writes the latest event data to /tmp/sensu_event_bridge.json'
@cabecada
cabecada / rb
Created April 13, 2017 14:10
sensu event relay to redis
require 'sensu/extension'
require 'sensu/redis'
require 'sensu/json'
module Sensu
module Extension
class Relay < Bridge
def name
"relay"
end
require 'socket'
require 'sensu/extension'
require 'sensu/json'
require 'time'
module Sensu
module Extension
class EventToFile < Bridge
def name
'event_to_file'
#!/usr/bin/env ruby
require 'rufus-scheduler'
require 'rb-inotify'
require 'json'
require 'thread'
def schedule_checks(jobs, scheduler, content)
jobs.each {|job| job.unschedule } if jobs
content['checks'].each do |k, v|
@cabecada
cabecada / rb
Last active May 17, 2017 13:27
cronicsensu
#!/opt/sensu/embedded/bin/ruby
require 'trollop'
require 'open3'
require 'json'
require 'socket'
require 'shellwords'
TEAM_DATA_FN = '/etc/sensu/team_data.json'
@cabecada
cabecada / rb
Created April 7, 2017 11:56
extension simulating yelp/filter_repeated
module Sensu
module Extension
class Yelp < Filter
def name
"yelp"
end
def description
"filter events using event occurrences"
end
@cabecada
cabecada / py
Last active August 2, 2017 07:42
create/resolve events in VO using API
#!/usr/bin/env python
import argparse
import anyconfig
import requests
BASE_URL = ('https://alert.victorops.com/integrations/generic'
'/20131114/alert/cb98147f-ff10-4152-9e1b-dd0d42c0b11d')
DEFAULT_ROUTING_KEY = 'vjain'
MESSAGE_TYPES = ['CRITICAL', 'WARNING', 'RECOVERY']
@cabecada
cabecada / postgres-cheatsheet.md
Created August 31, 2017 18:28 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
@cabecada
cabecada / vm-resize-hard-disk.md
Created September 7, 2017 09:36 — forked from christopher-hopper/vm-resize-hard-disk.md
Resize a Hard Disk for a Virtual Machine provisioned using Vagrant from a Linux base box to run using VirutalBox.

Resize a Hard Disk for a Virtual Machine

Our Virtual Machines are provisioned using Vagrant from a Linux base box to run using VirutalBox. If the Hard Disk space runs out and you cannot remove files to free-up space, you can resize the Hard Disk using some VirtualBox and Linux commands.

Some assumptions

The following steps assume you've got a set-up like mine, where:

from flask import Flask, request
import json
app = Flask(__name__)
@app.route('/',methods=['POST'])
def foo():
data = json.loads(request.data)
with open("/tmp/webhook.json", mode='a') as f:
f.write(str(data))