Skip to content

Instantly share code, notes, and snippets.

View hvelarde's full-sized avatar

Héctor Velarde hvelarde

View GitHub Profile
@hvelarde
hvelarde / subdomains.sh-session
Created October 20, 2023 22:54
Search for and resolve subdomain names
$ snap install amass
...
$ amass enum -d cicese.mx -src
[DNS] cicese.mx
[HackerTarget] imp-udb10.cicese.mx
[HackerTarget] wireless-oc211.cicese.mx
[RapidDNS] dhcp-ac14.cicese.mx
[HackerTarget] pc-lankahuasa1.cicese.mx
...
[RapidDNS] cicese-auditorio.cicese.mx
@hvelarde
hvelarde / cleanup.py
Last active June 21, 2018 23:21
Clean up least used catalog keywords
# -*- coding: utf-8 -*-
from plone import api
import transaction
def get_least_used(limit=1):
"""List all keywords used up to limit times in content."""
catalog = api.portal.get_tool('portal_catalog')
keywords = catalog.uniqueValuesFor('Subject')
@hvelarde
hvelarde / normalize.py
Created June 21, 2018 23:20
Normalize catalog keywords
# -*- coding: utf-8 -*-
from plone import api
import transaction
def normalize():
"""Remove spare spaces and transform keywords to lowercase."""
catalog = api.portal.get_tool('portal_catalog')
results = catalog()
@hvelarde
hvelarde / ok.py
Created December 18, 2017 21:55
"ok" probe for zc.monitor
import pkg_resources
import logging
logger = logging.getLogger('zc.monitor')
try:
pkg_resources.get_distribution('zc.monitor')
except pkg_resources.DistributionNotFound:
@hvelarde
hvelarde / haproxy.vcl
Created December 18, 2017 21:25
Varnish configuration to be used with HAProxy backends
vcl 4.0;
import directors;
# probe definition for health checks
probe healthcheck {
.interval = 2s;
.url = "/haproxy?monitor";
.timeout = 1s;
@hvelarde
hvelarde / haproxy.cfg
Created December 18, 2017 20:38
HAProxy configuration file for Plone instances
# Configuration file for HAProxy
#
# This file must me symlinked to /etc/haproxy/haproxy.cfg
global
log /dev/log syslog notice
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin
user haproxy
group haproxy
@hvelarde
hvelarde / capture.py
Created July 5, 2017 12:31
A context manager to capture stdout and stderr
import contextlib
@contextlib.contextmanager
def capture():
"""A context manager to capture stdout and stderr.
http://stackoverflow.com/a/10743550/644075
"""
import sys
from cStringIO import StringIO
# get total requests by status code
awk '{print $9}' /var/log/nginx/access.log | sort | uniq -c | sort -rn
# get top requesters by IP
awk '{print $1}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head | awk -v OFS='\t' '{"host " $2 | getline ip; print $0, ip}'
# get top requesters by user agent
awk -F'"' '{print $6}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head
# get top requests by URL
@hvelarde
hvelarde / supervisor.cfg
Created December 9, 2016 22:53
Typical buildout configuration to add support for Supervisor process control system
[buildout]
parts +=
supervisor
supervisor-cron
[supervisor]
recipe = collective.recipe.supervisor
plugins = superlance
user = admin
password = admin
@hvelarde
hvelarde / restart
Created November 24, 2016 15:04
Part to restart instances with warm up
# need to change permission access to /etc/varnish/secret
[restart]
recipe = collective.recipe.template
input = inline:
#!/bin/bash
for i in {1..4}
do
varnishadm backend.set_health instance$i sick
${buildout:bin-directory}/supervisorctl restart app:instance$i