Awesome Open Source
Awesome Open Source

Hari Sekhon - DevOps Python Tools

GitHub stars GitHub forks License Lines of Code GitHub Last Commit

Codacy CodeFactor Codiga Grade Codiga Score Language grade: Python Quality Gate Status Maintainability Rating Reliability Rating Security Rating Total alerts

Linux Mac Docker Dockerfile DockerHub Pulls DockerHub Build Automated StarTrack StarCharts

CI Builds Overview Jenkins Concourse GoCD TeamCity

CircleCI BuildKite AppVeyor Drone Codeship Status for HariSekhon/DevOps-Python-tools Codefresh Cirrus CI Semaphore Wercker Buddy Shippable Travis CI

Azure DevOps Pipeline GitLab Pipeline BitBucket Pipeline AWS CodeBuild GCP Cloud Build

Repo on Azure DevOps Repo on GitHub Repo on GitLab Repo on BitBucket ShellCheck JSON YAML XML Validation Semgrep Semgrep Cloud Kics

Docker Build (Alpine) Docker Build (CentOS) Docker Build (Debian) Docker Build (Fedora) Docker Build (Ubuntu)

GitHub Actions Ubuntu Mac Mac 11 Mac 12 Ubuntu Ubuntu 14.04 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04 Debian Debian 8 Debian 9 Debian 10 CentOS CentOS 7 CentOS 8 Fedora Alpine Alpine 3

Python versions Python 2.7 Python 3.6 Python 3.7 Python 3.8 Python 3.9 Python 3.10 PyPy 2 PyPy 3

AWS, Docker, Spark, Hadoop, HBase, Hive, Impala, Python & Linux Tools

DevOps, Cloud, Big Data, NoSQL, Python & Linux tools. All programs have --help.

See Also:

repos which contains hundreds more scripts and programs for Cloud, Big Data, SQL, NoSQL, Web and Linux.

Hari Sekhon

Cloud & Big Data Contractor, United Kingdom

My LinkedIn

(you're welcome to connect with me on LinkedIn)
Make sure you run make update if updating and not just git pull as you will often need the latest library submodule and possibly new upstream libraries.

Quick Start

Ready to run Docker image

All programs and their pre-compiled dependencies can be found ready to run on DockerHub.

List all programs:

docker run harisekhon/pytools

Run any given program:

docker run harisekhon/pytools <program> <args>

Automated Build from source

installs git, make, pulls the repo and build the dependencies:

curl -L | sh

or manually:

git clone pytools
cd pytools

To only install pip dependencies for a single script, you can just type make and the filename with a .pyc extension instead of .py:

make anonymize.pyc

Make sure to read Detailed Build Instructions further down for more information.

Some Hadoop tools with require Jython, see Jython for Hadoop Utils for details.


All programs come with a --help switch which includes a program description and the list of command line options.

Environment variables are supported for convenience and also to hide credentials from being exposed in the process list eg. $PASSWORD, $TRAVIS_TOKEN. These are indicated in the --help descriptions in brackets next to each option and often have more specific overrides with higher precedence eg. $AMBARI_HOST, $HBASE_HOST take priority over $HOST.

DevOps Python Tools - Inventory

  • Linux:
    • - anonymizes your configs / logs from files or stdin (for pasting to Apache Jira tickets or mailing lists)
      • anonymizations include these and more:
        • hostnames / domains / FQDNs
        • email addresses
        • IP + MAC addresses
        • AWS Access Keys, Secret Keys, ARNs, STS tokens
        • Kerberos principals
        • LDAP sensitive fields (eg. CN, DN, OU, UID, sAMAccountName, member, memberOf...)
        • Cisco & Juniper ScreenOS configurations passwords, shared keys and SNMP strings
      • anonymize_custom.conf - put regex of your Name/Company/Project/Database/Tables to anonymize to <custom>
      • placeholder tokens indicate what was stripped out (eg. <fqdn>, <password>, <custom>)
      • --ip-prefix leaves the last IP octect to aid in cluster debugging to still see differentiated nodes communicating with each other to compare configs and log communications
      • --hash-hostnames - hashes hostnames to look like Docker temporary container ID hostnames so that vendors support teams can differentiate hosts in clusters
      • - splits files in to multiple parts and runs on each part in parallel before re-joining back in to a file of the same name with a .anonymized suffix. Preserves order of evaluation important for anonymization rules, as well as maintaining file content order. On servers this parallelization can result in a 30x speed up for large log files
    • - finds duplicate files in one or more directory trees via multiple methods including file basename, size, MD5 comparison of same sized files, or bespoke regex capture of partial file basename
    • - finds fastest responding healthy server or active master in high availability deployments, useful for scripting against clustered technologies (eg. Elasticsearch, Hadoop, HBase, Cassandra etc). Multi-threaded for speed and highly configurable - socket, http, https, ping, url and/or regex content match. See further down for more details and sub-programs that simplify usage for many of the most common cluster technologies
    • - cool spinning welcome message greeting your username and showing last login time and user to put in your shell's .profile (there is also a perl version in my DevOps Perl Tools repo)
  • Amazon Web Services:
    • - lists all users access keys, status, date of creation and age in days. Optionally filters for active keys and older than N days (for key rotation governance)
    • - lists users access keys that haven't been used in the last N days or that have never been used (these should generally be removed/disabled). Optionally filters for only active keys
    • - lists all users and their days since last use across both passwords and access keys. Optionally filters for users not used in the last N days to find old accounts to remove
    • - lists all users and dates since their passwords were last used. Optionally filters for users with passwords not used in the last N days
  • Google Cloud Platform:
    • GCF - Google Cloud Functions written in Python:
    • - lists all GCP service account credential keys for a given project with their age and expiry details, optionally filtering by non-expiring, already expired, or will expire within N days
  • Docker:
    • / / - shows tags for docker repos in a docker registry or on DockerHub or - Docker CLI doesn't support this yet but it's a very useful thing to be able to see live on the command line or use in shell scripts (use -q/--quiet to return only the tags for easy shell scripting). You can use this to pre-download all tags of a docker image before running tests across versions in a simple bash for loop, eg.
    • - search DockerHub with a configurable number of returned results (older official docker search was limited to only 25 results), using --verbose will also show you how many results were returned to the termainal and how many DockerHub has in total (use -q / --quiet to return only the image names for easy shell scripting). This can be used to download all of my DockerHub images in a simple bash for loop eg. and can be chained with to download all tagged versions for all docker images eg.
    • dockerfiles_check_git*.py - check Git tags & branches align with the containing Dockerfile's ARG *_VERSION
  • Spark & Data Format Converters:
    • - PySpark Avro => Parquet converter
    • - PySpark Parquet => Avro converter
    • - PySpark CSV => Avro converter, supports both inferred and explicit schemas
    • - PySpark CSV => Parquet converter, supports both inferred and explicit schemas
    • - PySpark JSON => Avro converter
    • - PySpark JSON => Parquet converter
    • - XML to JSON converter
    • - JSON to XML converter
    • - JSON to YAML converter
    • - converts json files to bulk multi-record one-line-per-json-document format for pre-processing and loading to big data systems like Hadoop and MongoDB, can recurse directory trees, and mix json-doc-per-file / bulk-multiline-json / directories / standard input, combines all json documents and outputs bulk-one-json-document-per-line to standard output for convenient command line chaining and redirection, optionally continues on error, collects broken records to standard error for logging and later reprocessing for bulk batch jobs, even supports single quoted json while not technically valid json is used by MongoDB and even handles embedded double quotes in 'single quoted json'
    • - YAML to JSON converter (because some APIs like GitLab CI Validation API require JSON)
    • see also validate_*.py further down for all these formats and more
  • Hadoop ecosystem & NoSQL:
    • Ambari:

      • - Blueprint cluster templating and deployment tool using Ambari API
        • list blueprints
        • fetch all blueprints or a specific blueprint to local json files
        • blueprint an existing cluster
        • create a new cluster using a blueprint
        • sorts and prettifies the resulting JSON template for deterministic config and line-by-line diff necessary for proper revision control
        • optionally strips out the excessive and overly specific configs to create generic more reusable templates
        • see the ambari_blueprints/ directory for a variety of Ambari blueprint templates generated by and deployable using this tool
      • ambari_ams_*.sh - query the Ambari Metrics Collector API for a given metrics, list all metrics or hosts
      • - cancel all ongoing operations using the Ambari API
      • - trigger service checks using the Ambari API
    • Hadoop HDFS:

      • - finds HDFS files with replication factor 1, optionally resetting them to replication factor 3 to avoid missing block alerts during datanode maintenance windows
      • hdfs_time_block_reads.jy - HDFS per-block read timing debugger with datanode and rack locations for a given file or directory tree. Reports the slowest Hadoop datanodes in descending order at the end. Helps find cluster data layer bottlenecks such as slow datanodes, faulty hardware or misconfigured top-of-rack switch ports.
      • hdfs_files_native_checksums.jy - fetches native HDFS checksums for quicker file comparisons (about 100x faster than doing hdfs dfs -cat | md5sum)
      • hdfs_files_stats.jy - fetches HDFS file stats. Useful to generate a list of all files in a directory tree showing block size, replication factor, underfilled blocks and small files
    • Hive / Impala:

      • / - dumps all databases, tables, columns and types out in CSV format to standard output

      The following programs can all optionally filter by database / table name regex:

      • / - execute any query or statement against every Hive / Impala table
      • / - outputs tables row counts. Useful for reconciliation between cluster migrations
      • / - outputs tables column counts. Useful for finding unusually wide tables
      • / - outputs tables row and column counts. Useful for finding unusually big tables
      • / - outputs tables row counts where any field is NULL. Useful for reconciliation between cluster migrations or catching data quality problems or subtle ETL bugs
      • / - outputs tables columns containing only NULLs. Useful for catching data quality problems or subtle ETL bugs
      • / - outputs tables row counts where all fields contain NULLs. Useful for catching data quality problems or subtle ETL bugs
      • / - outputs for each table the matching regex metadata DDL property from describe table
      • / - outputs for each table its data location
    • HBase:

      • - inserts random generated data in to a given HBase table, with optional skew support with configurable skew percentage. Useful for testing region splitting, balancing, CI tests etc. Outputs stats for number of rows written, time taken, rows per sec and volume per sec written.
      • - dumps HBase table region ranges information, useful when pre-splitting tables
      • - calculates the distribution of rows across regions in an HBase table, giving per region row counts and % of total rows for the table as well as median and quartile row counts per regions
      • - calculates the distribution of row keys by configurable prefix length in an HBase table, giving per prefix row counts and % of total rows for the table as well as median and quartile row counts per prefix
      • - compacts HBase tables (for off-peak compactions). Defaults to finding and iterating on all tables or takes an optional regex and compacts only matching tables.
      • - flushes HBase tables. Defaults to finding and iterating on all tables or takes an optional regex and flushes only matching tables.
      • hbase_regions_by_* - queries given RegionServers JMX to lists topN regions by storeFileSize or memStoreSize, ascending or descending
      • - calculates requests per second per region across all given RegionServers or average since RegionServer startup, configurable intervals and count, can filter to any combination of reads / writes / total requests per second. Useful for watching more granular region stats to detect region hotspotting
      • - calculates requests per regionserver second across all given regionservers or average since regionserver(s) startup(s), configurable interval and count, can filter to any combination of read, write, total, rpcScan, rpcMutate, rpcMulti, rpcGet, blocked per second. Useful for watching more granular RegionServer stats to detect RegionServer hotspotting
      • - finds topN biggest/smallest regions across given RegionServers than have received the least requests (requests below a given threshold)
    • OpenTSDB:

      • - calculates metric distribution in bulk import file(s) to find data skew and help avoid HBase region hotspotting
      • opentsdb_list_metrics*.sh - lists OpenTSDB metric names, tagk or tagv via OpenTSDB API or directly from HBase tables with optionally their created date, sorted ascending
    • Pig

  • - returns first available healthy server or active master in high availability deployments, useful for chaining with single argument tools. Configurable tests include socket, http, https, ping, url and/or regex content match, multi-threaded for speed. Designed to extend tools that only accept a single --host option but for which the technology has later added multi-master support or active-standby masters (eg. Hadoop, HBase) or where you want to query cluster wide information available from any online peer (eg. Elasticsearch)
    • The following are simplified specialisations of the above program, just pass host arguments, all the details have been baked in, no switches required
      • - returns active Hadoop Namenode in HDFS HA
      • - returns active Hadoop Resource Manager in Yarn HA
      • - returns active HBase Master in HBase HA
      • - returns first available HBase Thrift Server (run multiple of these for load balancing)
      • - returns first available HBase Stargate rest server (run multiple of these for load balancing)
      • - returns first available Apache Drill node
      • - returns first available Apache Cassandra node
      • find_active_impala*.py - returns first available Impala node of either Impalad, Catalog or Statestore
      • - returns first available Presto Coordinator
      • - returns first available Kubernetes API server
      • - returns first active Oozie server
      • - returns first available Solr / SolrCloud node
      • - returns first available Elasticsearch node
      • see also: Advanced HAProxy configurations which are part of the Advanced Nagios Plugins Collection
  • Travis CI:
    • - fetches Travis CI latest running / completed / failed build log for given repo - useful for quickly getting the log of the last failed build when CCMenu or BuildNotify applets turn red
    • - launches a Travis CI interactive debug build session via Travis API, tracks session creation and drops user straight in to the SSH shell on the remote Travis build, very convenient one shot debug launcher for Travis CI
  • - checks Selenium Grid Hub / Selenoid is working by calling browsers such as Chrome and Firefox to fetch a given URL and content/regex match the result
  • Data Validation (useful in CI):
    • validate_*.py - validate files, directory trees and/or standard input streams
      • supports the following file formats:
        • Avro
        • CSV
        • INI / Java Properties (also detects duplicate sections and duplicate keys within sections)
        • JSON (both normal and json-doc-per-line bulk / big data format as found in MongoDB and Hadoop json data files)
        • LDAP LDIF
        • Parquet
        • XML
        • YAML
      • directories are recursed, testing any files with relevant matching extensions (.avro, .csv, json, parquet, .ini/.properties, .ldif, .xml, .yml/.yaml)
      • used for Continuous Integration tests of various adjacent Spark data converters as well as configuration files for things like Presto, Ambari, Apache Drill etc found in my DockerHub images Dockerfiles master repo which contains docker builds and configurations for many open source Big Data & Linux technologies

Detailed Build Instructions

Python VirtualEnv localized installs

The automated build will use 'sudo' to install required Python PyPI libraries to the system unless running as root or it detects being inside a VirtualEnv. If you want to install some of the common Python libraries using your OS packages instead of installing from PyPI then follow the Manual Build section below.

Manual Setup

Enter the pytools directory and run git submodule init and git submodule update to fetch my library repo:

git clone pytools
cd pytools
git submodule init
git submodule update
sudo pip install -r requirements.txt

Offline Setup

Download the DevOps Python Tools and Pylib git repos as zip files:

Unzip both and move Pylib to the pylib folder under DevOps Python Tools.


mv -v devops-python-tools-master pytools
mv -v pylib-master pylib
mv -vf pylib pytools/

Proceed to install PyPI modules for whichever programs you want to use using your usual procedure - usually an internal mirror or proxy server to PyPI, or rpms / debs (some libraries are packaged by Linux distributions).

All PyPI modules are listed in the requirements.txt and pylib/requirements.txt files.

Internal Mirror example (JFrog Artifactory or similar):

sudo pip install --index --trusted -r requirements.txt

Proxy example:

sudo pip install --proxy hari:[email protected]:8080 -r requirements.txt
Mac OS X

The automated build also works on Mac OS X but you'll need to install Apple XCode (on recent Macs just typing git is enough to trigger Xcode install).

I also recommend you get HomeBrew to install other useful tools and libraries you may need like OpenSSL for development headers and tools such as wget (these are installed automatically if Homebrew is detected on Mac OS X):

brew install openssl wget

If failing to build an OpenSSL lib dependency, just prefix the build command like so:

sudo OPENSSL_INCLUDE=/usr/local/opt/openssl/include OPENSSL_LIB=/usr/local/opt/openssl/lib ...

You may get errors trying to install to Python library paths even as root on newer versions of Mac, sometimes this is caused by pip 10 vs pip 9 and downgrading will work around it:

sudo pip install --upgrade pip==9.0.1
sudo pip install --upgrade pip

Jython for Hadoop Utils

The 3 Hadoop utility programs listed below require Jython (as well as Hadoop to be installed and correctly configured)


Run like so:

jython -J-cp $(hadoop classpath) hdfs_time_block_reads.jy --help

The -J-cp $(hadoop classpath) part dynamically inserts the current Hadoop java classpath required to use the Hadoop APIs.

See below for procedure to install Jython if you don't already have it.

Automated Jython Install

This will download and install jython to /opt/jython-2.7.0:

make jython
Manual Jython Install

Jython is a simple download and unpack and can be fetched from

Then add the Jython install bin directory to the $PATH or specify the full path to the jython binary, eg:

/opt/jython-2.7.0/bin/jython hdfs_time_block_reads.jy ...

Configuration for Strict Domain / FQDN validation

Strict validations include host/domain/FQDNs using TLDs which are populated from the official IANA list is done via my PyLib library submodule - see there for details on configuring this to permit custom TLDs like .local, .intranet, .vm, .cloud etc. (all already included in there because they're common across companies internal environments).

Python SSL certificate verification problems

If you end up with an error like:

./ centos ubuntu
[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:765)

It can be caused by an issue with the underlying Python + libraries due to changes in OpenSSL and certificates. One quick fix is to do the following:

sudo pip uninstall -y certifi &&
sudo pip install certifi==2015.04.28


Run make update. This will git pull and then git submodule update which is necessary to pick up corresponding library updates.

If you update often and want to just quickly git pull + submodule update but skip rebuilding all those dependencies each time then run make update-no-recompile (will miss new library dependencies - do full make update if you encounter issues).


Continuous Integration is run on this repo with tests for success and failure scenarios:

  • unit tests for the custom supporting python library
  • integration tests of the top level programs using the libraries for things like option parsing
  • functional tests for the top level programs using local test data and Docker containers

To trigger all tests run:

make test

which will start with the underlying libraries, then move on to top level integration tests and functional tests using docker containers if docker is available.


Patches, improvements and even general feedback are welcome in the form of GitHub pull requests and issue tickets.

Related Repositories

  • DevOps Bash Tools - 800+ DevOps Bash Scripts, Advanced .bashrc, .vimrc, .screenrc, .tmux.conf, .gitconfig, CI configs & Utility Code Library - AWS, GCP, Kubernetes, Docker, Kafka, Hadoop, SQL, BigQuery, Hive, Impala, PostgreSQL, MySQL, LDAP, DockerHub, Jenkins, Spotify API & MP3 tools, Git tricks, GitHub API, GitLab API, BitBucket API, Code & build linting, package management for Linux / Mac / Python / Perl / Ruby / NodeJS / Golang, and lots more random goodies

  • SQL Scripts - 100+ SQL Scripts - PostgreSQL, MySQL, AWS Athena, Google BigQuery

  • Templates - dozens of Code & Config templates - AWS, GCP, Docker, Jenkins, Terraform, Vagrant, Puppet, Python, Bash, Go, Perl, Java, Scala, Groovy, Maven, SBT, Gradle, Make, GitHub Actions Workflows, CircleCI, Jenkinsfile, Makefile, Dockerfile, docker-compose.yml, M4 etc.

  • Kubernetes configs - Kubernetes YAML configs - Best Practices, Tips & Tricks are baked right into the templates for future deployments

  • Terraform - Terraform templates for AWS / GCP / Azure / GitHub management

  • DevOps Perl Tools - 25+ DevOps CLI tools for Hadoop, HDFS, Hive, Solr/SolrCloud CLI, Log Anonymizer, Nginx stats & HTTP(S) URL watchers for load balanced web farms, Dockerfiles & SQL ReCaser (MySQL, PostgreSQL, AWS Redshift, Snowflake, Apache Drill, Hive, Impala, Cassandra CQL, Microsoft SQL Server, Oracle, Couchbase N1QL, Dockerfiles, Pig Latin, Neo4j, InfluxDB), Ambari FreeIPA Kerberos, Datameer, Linux...

  • The Advanced Nagios Plugins Collection - 450+ programs for Nagios monitoring your Hadoop & NoSQL clusters. Covers every Hadoop vendor's management API and every major NoSQL technology (HBase, Cassandra, MongoDB, Elasticsearch, Solr, Riak, Redis etc.) as well as message queues (Kafka, RabbitMQ), continuous integration (Jenkins, Travis CI) and traditional infrastructure (SSL, Whois, DNS, Linux)

  • HAProxy Configs - 80+ HAProxy Configs for Hadoop, Big Data, NoSQL, Docker, Elasticsearch, SolrCloud, HBase, Cloudera, Hortonworks, MapR, MySQL, PostgreSQL, Apache Drill, Hive, Presto, Impala, ZooKeeper, OpenTSDB, InfluxDB, Prometheus, Kibana, Graphite, SSH, RabbitMQ, Redis, Riak, Rancher etc.

  • Dockerfiles - 50+ DockerHub public images for Docker & Kubernetes - Hadoop, Kafka, ZooKeeper, HBase, Cassandra, Solr, SolrCloud, Presto, Apache Drill, Nifi, Spark, Mesos, Consul, Riak, OpenTSDB, Jython, Advanced Nagios Plugins & DevOps Tools repos on Alpine, CentOS, Debian, Fedora, Ubuntu, Superset, H2O, Serf, Alluxio / Tachyon, FakeS3

  • PyLib - Python library leveraged throughout the programs in this repo as a submodule

  • Perl Lib - Perl version of above library

You might also be interested in the following really nice Jupyter notebook for HDFS space analysis created by another Hortonworks guy Jonas Straub:

Stargazers over time

Stargazers over time

Alternative Project Comparisons
Related Awesome Lists
Top Programming Languages

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Python (888,324
Docker (99,628
Json (40,048
Aws (39,258
Elasticsearch (11,423
Spark (10,794
Gcp (5,638
Hadoop (5,353
Cloudformation (3,520
Solr (2,992
Travis Ci (2,576
Hdfs (2,225
Hbase (1,595
Pyspark (1,411
Avro (1,193
Parquet (666
Gcf (23