Skip to content

Instantly share code, notes, and snippets.

View maurorappa's full-sized avatar

maurorappa maurorappa

  • zerolatency
  • Asso
View GitHub Profile
@maurorappa
maurorappa / sensu_es_count.rb
Last active March 27, 2018 10:34
Sensu check for ElasticSearch document query
#!/opt/sensu/embedded/bin/ruby
require 'rubygems' if RUBY_VERSION < '1.9.0'
require 'sensu-plugin/check/cli'
require 'net/http'
require 'json'
# Scenario: you are shipping logs to the ES cluster and you want periodically look for errors
# the script will run any query and count the occurences, with the flags -c (critical) and -w (warning) you can trigger SENSU alarms
# the following example will look for Fatal errors occurred between 017-02-12 and 017-02-12 and raise a critical alert if at least one is found
@maurorappa
maurorappa / check-redis.rb
Created February 15, 2017 17:02
Sensu check Redis test
#!/usr/bin/env ruby
# No Frills script with basic dependencies
#
require 'rubygems' if RUBY_VERSION < '1.9.0'
require 'sensu-plugin/check/cli'
require 'socket'
require 'timeout'
class PingRedis < Sensu::Plugin::Check::CLI
@maurorappa
maurorappa / 05_logging.cfg
Last active February 14, 2018 17:24
Devuan AMI creation
## This yaml formated config file handles setting
## logger information. The values that are necessary to be set
## are seen at the bottom. The top '_log' are only used to remove
## redundency in a syslog and fallback-to-file case.
##
## The 'log_cfgs' entry defines a list of logger configs
## Each entry in the list is tried, and the first one that
## works is used. If a log_cfg list entry is an array, it will
## be joined with '\n'.
_log:
@maurorappa
maurorappa / Dockerfile
Last active March 22, 2017 16:35
HTTP obfuscator
FROM alpine:3.5
LABEL type=proxy-in
MAINTAINER Zerolatency - Mauro Rappa
RUN apk --update --no-cache add lua luarocks gcc make lua-dev musl-dev openssl
RUN luarocks-5.1 install copas
# remove fairness in copas client handling
RUN sed -i 's/90/0/' /usr/local/share/lua/5.1/copas.lua
RUN wget -O proxy-in.lua https://gist.githubusercontent.com/maurorappa/0e92df25be62bbb48535a5e0c8a8b965/raw/feb4bc8e4b8fddb41e16410ce85f9eada9f06833/proxy-in.lua
CMD ["lua","proxy-in.lua","*:8080","127.0.0.1:80"]
EXPOSE 8080
FROM centos:latest
MAINTAINER The CentOS Project <[email protected]>
LABEL Vendor="CentOS"
RUN yum -y install sensu erlang rabbitmq-server redis
# rename sample config
RUN mv /etc/sensu/config.json.example /etc/sensu/config.json
# setup rabbitmq
RUN echo $HOSTNAME && /etc/init.d/rabbitmq-server start && rabbitmqctl add_vhost /sensu && rabbitmqctl add_user sensu sensu && rabbitmqctl set_permissions -p /sensu sensu ".*" ".*" ".*"
#start all services
ENTRYPOINT redis-server --daemonize yes && /etc/init.d/rabbitmq-server start && /etc/init.d/sensu-server start && /etc/init.d/sensu-api start && /etc/init.d/sensu-client start && bash
/ # cat r.lua
local f = io.open('/dev/random',"rb")
while true do
local content = f:read(16)
local time = os.date()
print(time .. " : " ..content)
end
[root@localhost ~]# lua r.lua
I have two artemis goodies:
1) to see how many messages went in the broker
curl -s http://$BROKER_IP:8161/jolokia/read/org.apache.activemq.artemis:brokerName=\%22default\%22,module=JMS,name=*,serviceType=Queue,type=Broker/MessagesAdded,MessageCount,Name%7Cjq '.[]' | awk '/MessagesAdded/ { sum+=$2}END {print sum}'
you run before and after the test and you know how much c**p flew around
@maurorappa
maurorappa / Artifactory_Cleanup.rb
Created July 14, 2017 09:13
Artifactory cleanup job, which keeps the production version, any newer one and X older
#!/usr/bin/env ruby
require 'time'
require 'yaml'
require 'json'
require "net/http"
require "uri"
# Variables
dryrun = ARGV[0]
verbose = ARGV[1]
@maurorappa
maurorappa / dns_scraper.go
Last active July 21, 2020 14:05
A DNS Scraper in Go
package main
//simple usage go run dns_scraper.go -h=0.uk.pool.ntp.org -s=3
import (
"flag"
"fmt"
"github.com/bogdanovich/dns_resolver"
"io/ioutil"
"math/rand"
@maurorappa
maurorappa / network_flowlog.go
Created October 13, 2017 09:58
AWS Flowlog local generator
// This script generates flowlog stats for the local traffic
package main
import (
"fmt"
"github.com/google/gopacket"
"github.com/google/gopacket/layers"
"github.com/google/gopacket/pcap"
"log"