Skip to content

Instantly share code, notes, and snippets.

@sysboss
sysboss / query_athena.py
Created May 21, 2018
SQL Query Amazon Athena using Python
View query_athena.py
#!/usr/bin/env python3
#
# Query AWS Athena using SQL
# Copyright (c) Alexey Baikov <sysboss[at]mail.ru>
#
# This snippet is a basic example to query Athen and load the results
# to a variable.
#
# Requirements:
# > pip3 install boto3 botocore retrying
@sysboss
sysboss / clean_old_grafana_rules_from_sensu.py
Created Feb 9, 2018
Remove dummy grafana_rule hosts from Sensu
View clean_old_grafana_rules_from_sensu.py
#!/usr/bin/python
#
# Removes grafana_rule_* clients from Sensu
# Copyright (c) Alexey Baikov <sysboss[at]mail.ru>
#
# This script cleans up "successful" grafana rules
# that left in Sensu clients list.
import sys
import json
@sysboss
sysboss / inject_bash_code.sh
Created Jan 17, 2018
Bash code injection into bash script
View inject_bash_code.sh
#!/bin/bash
# Bash code injection into bash script
# Copyright (c) Alexey Baikov <sysboss [at] mail.ru>
#
# This script will inject multiline code from 'injection.sh' file
# before or after a certain line in 'script.sh' file
#
# target_script - Script to inject into
# injection_script - Code lines to inject
# patern - Line to inject the code (before/after)
@sysboss
sysboss / ec2_tags_as_bash_variables.sh
Created Aug 21, 2017
Get all EC2 tags and set them as Bash variables
View ec2_tags_as_bash_variables.sh
#!/bin/bash
#
# EC2 tags to variables
# Copyright (c) Alexey Baikov <sysboss[at]mail.ru>
#
# Description:
# Gets all EC2 tags and converts them to Bash variables
# Based on 'jq' (https://stedolan.github.io/jq/)
INSTANCE_REGION="$(curl -s http://169.254.169.254/latest/dynamic/instance-identity/document | grep region | tr -d ' ' | cut -f2 -d: | tr -d '"' | tr -d ',')"
@sysboss
sysboss / trust.sh
Created May 15, 2017
Ultimately trust a public key non-interactively mode
View trust.sh
#!/bin/bash
# Provide key uid from `gpg --list-keys`
# Based on: https://blog.tersmitten.nl/how-to-ultimately-trust-a-public-key-non-interactively.html
KEY_NAME=""
echo "$( \
gpg --list-keys --fingerprint \
| grep "${KEY_NAME}" -B 1 | head -1 \
| tr -d '[:space:]' | awk 'BEGIN { FS = "=" } ; { print $2 }' \
@sysboss
sysboss / AWS_SpotTerminationNotifier.sh
Created May 8, 2017
Handling AWS Spot Instance Termination Notices
View AWS_SpotTerminationNotifier.sh
#!/bin/bash
# AWS Instance Termination Notice Handler
# Based on: https://blog.fugue.co/2015-01-06-spot-termination-notices.html
while true; do
# get meta-data HTTP headers
HEADER=$(curl -Is http://169.254.169.254/latest/meta-data/spot/termination-time)
# HTTP 404 - not marked for termination
if [ -z $(echo $HEADER | head -1 | grep 404 | cut -d \ -f 2) ]; then
View Docker_Images_Cleanup_ByTag.md
#!/bin/bash
#
# Keeps latest X tags of every Docker Image
KEEP_IMAGES_BACK=2
echo Retrieving local images available
# get all images
IMAGES=$(docker images | sort | awk '{print $1}' | uniq | grep -v "<none>")
@sysboss
sysboss / sonar.md
Last active Jun 8, 2021
SonarQube on AWS EC2 - Installation and integration with Jenkins
View sonar.md

This article will briefly describe how to install SonarQube as Docker container on Amazon EC2 and integrate it with Jenkins.

Create database instance and user

Go to RDS > Parameter Groups
Create a new Parameter Group with the following parameter:

max_allowed_packet = 268435456

We need to create a new RDS database for SonarQube (you may use an existing MySQL instance)

  1. Go to RDS Instances