Skip to content

Instantly share code, notes, and snippets.

@zerthimon
zerthimon / gist:69954a057d183a97c17da055088df6ea
Created October 22, 2019 13:24
Copy docker registry v2 to ECR
#!/bin/bash
srcreg="my.privateregistry.com"
tgtreg="awsacctnum.dkr.ecr.awsregion.amazonaws.com"
repos=`curl -s http://$srcreg/v2/_catalog?n=2048 | jq '.repositories[]' | tr -d '"'`
for repo in $repos; do
echo -e "\n===WORKING ON REPOSITORY" $repo"==="
./easyrsa --subject-alt-name="DNS:www.example.net,DNS:secure.example.net" build-server-full alttest nopass
#!/bin/bash
# Author: Lior Goikhburg
if [ -z "$1" ]; then
echo "Parameter required: Path"
exit 1
fi
pushd $1 > /dev/null
@zerthimon
zerthimon / r53-copyzone.py
Created July 4, 2016 14:22
Script to copy route53 zone records to another zone / account.
#!/usr/bin/env python
__author__ = 'Lior Goikhburg'
import argparse
import ConfigParser
import os
import boto3
app_name = os.path.basename(__file__)
@zerthimon
zerthimon / post-checkout
Last active August 29, 2015 14:22
Git hook to notify Zabbix Server of a branch change in the local git repo.
#!/usr/bin/env bash
oldrev="$1"
newrev="$2"
flag="$3"
# exit if it's not a branch operation (e.g. file checkout)
if [ "$flag" != "1" ]; then
exit
fi
@zerthimon
zerthimon / php5-chroot.cron
Created May 17, 2015 10:23
php5 session cleanup (crontab) in chrooted pools (of php-fpm)
# Look for and purge old sessions every 30 minutes
*/30 * * * * root [ -x /usr/lib/php5/maxlifetime ] && [ -x /usr/lib/php5/sessionclean ] && [ -d /var/www/pools ] && find /var/www/pools -path "*/var/lib/php5" -exec /usr/lib/php5/sessionclean {} $(/usr/lib/php5/maxlifetime) \;
@zerthimon
zerthimon / slack.py
Last active August 29, 2015 14:19
Script for sending Zabbix messages to slack channel and users
#!/usr/bin/env python
#
# Example: ./slack.py \@user PROBLEM::Information::http://trigger.url.com 'Trigger message on common.r24-admin.ru'
# Example: ./slack.py \@channel PROBLEM::Information::http://trigger.url.com 'Trigger message on common.r24-admin.ru'
# Configure your trigger like this:
# subject: {TRIGGER.STATUS}::{TRIGGER.SEVERITY}::{TRIGGER.URL}
# Default message: {TRIGGER.NAME} on {HOST.NAME1}
#
__author__ = 'Lior Goikhburg'
@zerthimon
zerthimon / get_ip.py
Created April 14, 2015 16:35
Get IP address of the interface facing a specific IP
#!/usr/bin/env python
import socket
# Figure out the source IP address that would be used to connect to SERVER_IP
def get_local_ip(master_ip):
local_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
local_socket.connect((SERVER_IP, 0))
local_ip = local_socket.getsockname()[0]
local_socket.close()
@zerthimon
zerthimon / lock
Created April 6, 2015 16:38
Example: Lock a script from multiple execution attemps. Saves a current user, command and time info in a lock file.
# lock the script against multiple run attempts
lock_file_name = '/var/run/deploy.lock'
if not os.path.isfile(lock_file_name):
logger.debug('Creating lock file')
try:
open(lock_file_name, 'w').close()
except Exception as error:
logger.error('Cannot create lock file.')
sys.exit(1)
@zerthimon
zerthimon / rabbit_ping.py
Last active August 29, 2015 14:18
Monitor RabbitMQ Server. Connect, send a message, receive it, exit.
#!/usr/bin/env python
__author__ = 'Lior Goikhburg'
import argparse
import logging
import os
import pika
import signal
import sys