Skip to content

Instantly share code, notes, and snippets.

View gustavomcarmo's full-sized avatar

Gustavo Muniz do Carmo gustavomcarmo

View GitHub Profile
@gustavomcarmo
gustavomcarmo / databricks-clusters-vms-used-memory-percentage.kql
Last active July 10, 2023 10:39
Databricks clusters VMs used memory percentage KQL
let VMs = Heartbeat
| where OSType == 'Linux'
and Category != 'Azure Monitor Agent'
and ResourceId != ''
| project Computer, TimeGenerated, ClusterId = substring(Computer, 0, 20), VM = tostring(split(ResourceId, "/")[-1])
| summarize arg_max(TimeGenerated, *) by Computer;
let Clusters = DatabricksClusters
| where ActionName in ('create', 'startResult')
| extend ResponseTxt = parse_json(Response)
| where ResponseTxt.statusCode == 200
@gustavomcarmo
gustavomcarmo / databricks-pipeline-maintenance-jobs-clusters.kql
Last active July 3, 2023 20:19
Databricks Pipeline Maintenance Jobs Clusters KQL
let ClustersInitializations = DatabricksClusters
| distinct ActionName, Response, RequestParams, TimeGenerated
| where ActionName in ('create', 'start', 'restart') and TimeGenerated > ago(30d)
| extend ResponseTxt = parse_json(Response)
| where ResponseTxt.statusCode == 200
| extend ResponseResultTxt = parse_json(tostring(ResponseTxt.result))
| extend RequestParamsTxt = parse_json(RequestParams)
| project ClusterId = case(ActionName == 'create', ResponseResultTxt.cluster_id,
ActionName in ('start', 'restart'), RequestParamsTxt.cluster_id, ''),
InitializationTime = TimeGenerated,
@gustavomcarmo
gustavomcarmo / scan-images.sh
Created February 14, 2023 09:16
Docker images vulnerabilities scan with Snyk based on images stored in Sonatype Nexus as private Docker Registry
#!/bin/bash
log_file=snyk-scan-$(date '+%s%3N').log
export SNYK_TOKEN=$1
private_docker_registry=$2
nexus_repo_url=$3
log() {
printf "$(date '+%F %T') - %s\n" "$1"
}
@gustavomcarmo
gustavomcarmo / jenkins-backup.py
Created July 20, 2022 15:44
Jenkins backup by exporting jobs definitions to XML files.
#!/usr/bin/python3
from datetime import datetime
import logging
import os
import requests
def get_params():
if 'JENKINS_URL' not in os.environ or 'JENKINS_ADMIN_USERNAME' not in os.environ or 'JENKINS_ADMIN_PASSWORD' not in os.environ:
@gustavomcarmo
gustavomcarmo / docker-compose.yml
Last active November 6, 2019 11:56
NGINX + WordPress + MySQL Docker Compose
version: '3'
services:
mysql:
image: mariadb:10.3.12
container_name: mysql
restart: always
volumes:
- mysql_data:/var/lib/mysql
environment:
@gustavomcarmo
gustavomcarmo / find-latest-ubuntu-bionic-ami.yml
Created December 11, 2018 19:26
Ansible playbook to find the latest Ubuntu 18.04 LTS (bionic) AMI in AWS.
---
- hosts: localhost
gather_facts: no
vars:
aws_region: "eu-west-2"
tasks:
- name: Find Ubuntu Server 18.04 LTS AMIs
ec2_ami_facts:
region: '{{ aws_region }}'
owners: 099720109477
@gustavomcarmo
gustavomcarmo / docker-volumes-backup.yml
Created September 13, 2018 18:12
Ansible playbook to backup all Docker volumes in a remote host and then upload the backup file to a raw Nexus repository.
---
- hosts: remote
gather_facts: no
tasks:
- name: Make the volumes backup
archive:
path: /var/lib/docker/volumes
dest: volumes.tar.gz
- name: Make the backup available (requires vault-password-file)
uri:
@gustavomcarmo
gustavomcarmo / test_ldap_entry.sh
Last active September 29, 2020 20:27
LDAP Ansible modules integration tests
#!/bin/bash
docker run --name openldap -d -p 389:389 osixia/openldap:1.2.1
if [ $? -ne 0 ]; then
echo "Error on running the OpenLDAP Docker image."
exit 1
fi
until ldapsearch -x -b dc=example,dc=org -D cn=admin,dc=example,dc=org -w admin | grep "dn: dc=example,dc=org"
do
@gustavomcarmo
gustavomcarmo / Dockerfile
Created July 25, 2018 07:59
Example of Ansible playbook for building a custom Jenkins Docker image and running it in a remote host.
FROM jenkins/jenkins:lts
LABEL maintainer "Gustavo Muniz do Carmo <gustavo@esign.com.br>"
ENV JAVA_OPTS="-Djenkins.install.runSetupWizard=false"
COPY config-maven.groovy /usr/share/jenkins/ref/init.groovy.d/
COPY config-sonarqube.groovy /usr/share/jenkins/ref/init.groovy.d/
COPY harden-jenkins.groovy /usr/share/jenkins/ref/init.groovy.d/
COPY default-user.groovy /usr/share/jenkins/ref/init.groovy.d/
@gustavomcarmo
gustavomcarmo / configure-zabbix.yml
Created July 25, 2018 07:30
Example of Ansible playbook for installing and configuring the Zabbix agent in a host and then creating the host in a Zabbix server.
---
- name: Install the Zabbix agent
yum:
name: http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-agent-3.4.8-1.el7.x86_64.rpm
- name: Configure the Zabbix agent
replace:
path: /etc/zabbix/zabbix_agentd.conf
regexp: '{{item.regexp}}'
replace: '{{item.replace}}'
with_items: