Skip to content

Instantly share code, notes, and snippets.

View Esl1h's full-sized avatar
🌎
Quem não tem cUrl, caça com get.

Esli Silva Esl1h

🌎
Quem não tem cUrl, caça com get.
View GitHub Profile
@Esl1h
Esl1h / policy.json
Last active April 29, 2019 22:50
AWS S3 bucket policy example - one bucket (public, to a cloudfront distribution) and restrict permissions on some folders by username.
{
"Version": "2012-10-17",
"Id": "Policy1556318075116",
"Statement": [
{
"Sid": "Stmt1556317630862",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::cdn.example/videos/*"
@Esl1h
Esl1h / sysctl.conf
Last active May 31, 2023 14:10
A hardening/tunning to sysctl.conf to Linux servers (tested on Debian, CentOS, Amazon Linux and Ubuntu). Otimização para o sysctl.conf em servidores linux
#CONTEUDO PARA O SYSCTL.CONF
# Aumentar o num. max de conex tcp orfans
# Conexões que foram encerrados e já não têm um identificador de arquivo anexado a eles
net.ipv4.tcp_max_orphans = 262144
# Aumentar o número de conexões
net.core.somaxconn = 16384
# Aumentar o número de conexões de entrada backlog
#!/bin/bash
#
# ## BEGIN INIT INFO
# Provides: Firewall
# Required-Start: $all
# Required-Stop:
# Should-Start: S
# Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
@Esl1h
Esl1h / dec_to_ipv4.py
Created August 18, 2020 01:20
Python converting decimal to IPv4 using ipaddress module (in databases IPv4 are recorded as decimal, mostly.
#!/usr/bin/python3.8
import ipaddress
decip = 2887123457 # Example for 172.22.2.1
ip = str(ipaddress.IPv4Address(decip))
print(ip)
@Esl1h
Esl1h / AWS_tags-EC2-to-volumeEBS.py
Created September 21, 2020 19:50
AWS.Adiciona no volume EBS as tags da EC2.
import boto3
ec2 = boto3.client('ec2')
tags = None
def getVolumesId(filters):
global tags
instances = getInstances(filters)
volumes = []
for instance in instances['Reservations']:
# recupera as tags adicionadas na EC2
@Esl1h
Esl1h / AWS_tags-EC2-to-volumeEBS.py
Created September 21, 2020 19:51
AWS. Adiciona no volume EBS as mesmas tags da EC2. Adds the same EC2 tags to the EBS volume.
import boto3
ec2 = boto3.client('ec2')
tags = None
def getVolumesId(filters):
global tags
instances = getInstances(filters)
volumes = []
for instance in instances['Reservations']:
# recupera as tags adicionadas na EC2
@Esl1h
Esl1h / topics.sh
Created September 21, 2020 19:55
List kafka topics and partitions. Lista as partições dos tópicos no kafka.
#!/bin/sh
path="/opt/kafka_2.12-2.2.2/bin"
$path/kafka-topics.sh --zookeeper zookeeper.intranet:2181 --list | grep -v "__consumer_offsets" > topic.txt
cat topic.txt | while read line
do
partitions=`$path/kafka-topics.sh --describe --zookeeper zookeeper.intranet:2181 --topic $line | grep PartitionCount | awk '{ print $1,$2 }'`
echo $partitions
done
@Esl1h
Esl1h / ssh_config
Created September 21, 2020 20:07
configuração do SSH: Usar tunel SSH sempre que conectar nos hosts do domínio especifico. Always when connecting to hosts in this domain, SSH will use the Tunel
#
Host *
# ForwardAgent no
# ForwardX11 no
# ForwardX11Trusted yes
# PasswordAuthentication yes
# HostbasedAuthentication no
# GSSAPIAuthentication no
# GSSAPIDelegateCredentials no
@Esl1h
Esl1h / ansible.cfg
Created September 21, 2020 20:21
Ansible config simple example with mitogen and SSH control session. Configuração do ansible com o mitogen e controle de sessão do SSH
[defaults]
inventory = ./conf/host
local_tmp = ./.tmp
roles_path = ./roles
remote_user = ec2-user
internal_poll_interval = 0.001
interpreter_python = /usr/bin/python
forks = 20
callback_whitelist = profile_tasks
log_path = ./logs/ansible.log
@Esl1h
Esl1h / script.sh
Created February 1, 2021 02:13
Solução simples para o desafio: extraia 2 resultados a partir de um arquivo de log - quantidade de logs e quantidade de solicitações
#!/bin/bash
: '
DESAFIO:
Dado um arquivo de log do apache (acess.log) com diversas linhas semelhantes a abaixo:
172.19.0.100 - - [18/Feb/2020:22:35:10 +0000] "GET /index HTTP/1.1" 200 31067 "-" "Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)" "172.19.0.2"
172.19.0.103 - - [15/Feb/2020:22:32:02 +0000] "GET /index HTTP/1.1" 200 14034 "-" "Mozilla/5.0 (compatible; SemrushBot/6~bl; +http://www.semrush.com/bot.html)" "172.19.0.4"
172.19.0.104 - - [16/Feb/2020:22:31:32 +0000] "GET /site HTTP/1.1" 200 36565 "https://command-not-found.com/curl" "Mozilla/5.0+(compatible; UptimeRobot/2.0; http://www.uptimerobot.com/)" "172.19.0.3"
172.19.0.105 - - [16/Feb/2020:22:30:10 +0000] "GET /credits HTTP/1.1" 200 31067 "-" "Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)" "172.19.0.2"