Skip to content

Instantly share code, notes, and snippets.

@sysboss
sysboss / sonar.md
Last active April 21, 2022 15:24
SonarQube on AWS EC2 - Installation and integration with Jenkins

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
@sysboss
sysboss / Docker_Images_Cleanup_ByTag.md
Created April 27, 2017 12:47
Clean old Docker Images
#!/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 "")
@sysboss
sysboss / AWS_SpotTerminationNotifier.sh
Created May 8, 2017 16:37
Handling AWS Spot Instance Termination Notices
#!/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
@sysboss
sysboss / trust.sh
Created May 15, 2017 14:05
Ultimately trust a public key non-interactively mode
#!/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 / ec2_tags_as_bash_variables.sh
Created August 21, 2017 10:24
Get all EC2 tags and set them as Bash variables
#!/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 / inject_bash_code.sh
Created January 17, 2018 13:52
Bash code injection into bash script
#!/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 / clean_old_grafana_rules_from_sensu.py
Created February 9, 2018 09:32
Remove dummy grafana_rule hosts from Sensu
#!/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 / query_athena.py
Created May 21, 2018 15:41
SQL Query Amazon Athena using Python
#!/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