Skip to content

Instantly share code, notes, and snippets.

View ThabetAmer's full-sized avatar
🎯
In the search for a new challenge!

Thabet Amer ThabetAmer

🎯
In the search for a new challenge!
View GitHub Profile
@ThabetAmer
ThabetAmer / container-down.rules
Last active February 5, 2020 15:28
Prometheus rule for a container status
- alert: container_down
expr: absent(container_last_seen{job="cadvisor",name="rabbitmq"})
for: 30s
labels:
severity: critical
annotations:
summary: "Container down"
description: "{{ $labels.instance }} {{ $labels.name }} container is down for more than 30 seconds."
@ThabetAmer
ThabetAmer / get-ecr-login.sh
Created February 7, 2020 15:52
ECR login via CLI
#!/bin/bash
aws ecr get-login --no-include-email | sh
# to read the authentication string only, so it can be used in apps.
#aws ecr get-authorization-token --output text --query 'authorizationData[].authorizationToken' --region eu-central-1 \
# | base64 -d | cut -d: -f2
@ThabetAmer
ThabetAmer / create-jenkins-cred-harbor.sh
Last active April 8, 2020 07:29
Creates Jenkins credentials with username and password, made for Harbor Robot Accounts, but can be used for any username/password json file
#!/bin/bash
# Creates Jenkins credentials with username and password,
# made for Harbor Robot Accounts, but can be used for any username/password json file
# @author thabet.amer@gmail.com
# @since Jenkins 2.222.1
# @params json file with {"name":"","token":""} tags
# @output Jenkins credential with ID name "harbor-NAME"
@ThabetAmer
ThabetAmer / run-shell.groovy
Created April 8, 2020 08:34
Runs shell command and prints back stdout and stderr
#!/usr/bin/env groovy
/*
* Runs shell command and prints back stdout and stderr
*/
command='ls -al'
println new ProcessBuilder('sh','-c',command).redirectErrorStream(true).start().text
@ThabetAmer
ThabetAmer / mongo-export.sh
Created April 28, 2020 16:08
Mongo backup of whole database collections using mongoexport shell tool in json format
#!/bin/bash
# tested on Mongo 3.6
DB='test'
USR='admin'
PSW='admin''
BACKUP_FOLDER="$DB-backup"
COLLECTIONS=$(mongo localhost:27017/$DB -u $USR -p $PSW --authenticationDatabase admin --quiet --eval "db.getCollectionNames()" | tr -d '\[\]\"[:space:]' | tr ',' ' ')
@ThabetAmer
ThabetAmer / office365-enableSMTP.ps1
Created July 8, 2020 17:52
Enables SMTP Auth for Office365 emails
#
# Enables SMTP Auth for Office365 emails, so you can send emails via a script for application.
# Shall be run via Powershell terminal.
#
# Define your email address that will send emails via SMTP auth
$emailAddress = 'test@test.com'
# asks for email/password
$UserCredential = Get-Credential
@ThabetAmer
ThabetAmer / s3-make-public-from-other.sh
Created October 5, 2020 09:34
AWS S3 bash script to make recent objects uploaded by other owners publicly accessible
#!/bin/bash
BUCKET=
PROFILE_OTHER=
PROFILE_MINE=
DATE=$(date +%Y-%m-%dT%H:00:00)
IFS=$'\t'
@ThabetAmer
ThabetAmer / get_tables_counts.sql
Created November 22, 2021 12:51
SQL query to list numbers of rows in each table in a db schema
# tested on Mysql 5.7-8
# set database schema name to run against
SET @db_name = "DBNAME";
# actual query, two columns resulted: table name and its rows count
SELECT
TABLE_NAME,
SUM(TABLE_ROWS) as c
FROM
@ThabetAmer
ThabetAmer / get_aws_account_no.sh
Created December 8, 2021 07:58
Returns AWS account number from cli
aws sts --profile "${PROFILE:=default}" get-caller-identity --output text --query 'Account'
@ThabetAmer
ThabetAmer / get-last-successful-build-no.groovy
Last active June 17, 2022 15:34
Groovy/Jenkins function to return the ID number of last successful build for a specific Jenkins job
#!/usr/bin/env groovy
/**
* Gets last successful build number
* @author thabet.amer@gmail.com
* @since Jenkins 2.204.1
* @param String job name
* @return String number of build number
*
*/