Sep
11
2017
0

Automate WordPress backup with Python / Fabric

Python’s Fabric module makes automation easy.  This post shows how to use a Fabric script to backup a WordPress installation, but could be used for most LAMP backup situations!

Goals of this Post:

  • backup SQL to /tmp
  • backup WEB ROOT to /tmp
  • tar SQL + site & zip
  • download
  • delete /tmp

(more…)

Aug
20
2017
0

How to block outside IP addresses with firewalld on CentOS 7

There are situations were specific IP addresses or ranges may need to be blocked.  In my case I have SIP hackers trying to brute force a publicly exposed Asterisk server.  I don’t have control over the exterior gateway or firewalls between the server and public internet.  So in this case I have to specifically block access to a single host. 

From Asterisk:

[Aug 15 14:13:33] NOTICE[20986]: chan_sip.c:26214 handle_request_register: Registration from ‘”3292″ <sip:3292@64.56.135.10>’ failed for ‘195.154.188.25:5170’ – Wrong password

Goals of this Post:

  • Instruct firewalld to ‘drop’ all connection attempts from a single host

 

(more…)

Written by mattb in: Linux | Tags: , , , ,
Aug
10
2017
0

Google Interview Answered in Python

 

I’m in the process of moving my mindset from static linear scripting to an object oriented one.  My goal is to solve problems with algorithms I create myself.  It’s a tough climb because I come from Systems Admin/Networking side of things and didn’t benefit from Computer Science theory and advanced mathematics.  I’m hoping to eventually move into a DevOps role where I can organically absorb from devs.  It would be great to be able to observe other approaches to problem solving.

The video above is a Google interview prep question from Youtube.  The interviewee solves it with C++, I provide my version in Python below.  Essentially, they are solved in a similar way.  Granted, it took me two weeks of stewing on it and the man above did it on the spot, but he’s a Software Engineer, so I feel pretty good!

The problem is to find pairs of integers that add to 8 from a list assumed to be in ascending order.  Negatives and doubles are possible.

(more…)

Aug
01
2017
0

BASH script to cp/mv files of a certain date

I have a client that owns a high volume call center.  For quality assurance and training purposes they record all the calls.  Periodically the volume of recorded calls grows to the point that it slows down the NFS share to the Queuematrics call center software(Tomcat app).  I wrote a script that finds files by time and moves them to a different directory.

Usage: copy-by-date.sh -i INPUT_PATH -o OUTPUT_PATH -d +DAYS_OLD

(more…)

Jul
27
2017
0

Python module for generating NPC’s in Star Wars RPG

Recently table top gaming has made a huge comeback.  For the first time in 20 years my friends and I are role playing!  We agreed on the new Star Wars RPG by Fantasy Flight games, STAR WARS: Age of Rebellion role playing game.  It’s novel in many aspects compared to the previous D6 and D20 systems.  If you like Role Playing and Star Wars I advise that you take a look!  Since I’m frequently tasked as the GM I’ve automated the process of Non Player Character creation with Python to free up more time for story development.  I developed a module toward this end.  It’s portable between scripts and is easy customize.

The code is on the page below, but you can find updated SWNPC on Github as well.

Goals of this post:

  • Introduce SWNPC module
  • Demonstrate how to customize npc() object
  • Example use

(more…)

Jul
06
2017
0

How to Install mysql-connector for Python

For several months Python mysql-connector has been broken when attempting a install from pip.  In truth I’ve only tried Python 3, CentOS 6/7 and Fedora 21; in fact, this could be a more wide spread.  The simple solution is to install an earlier version.  The purpose of this post is to be a quick reminder of which is the most recent working version!

(more…)

Jul
03
2017
0

How to connect Asterisk SIP Clients over Duel Layers of NAT

A common problem with SIP is it’s difficulty handling NAT(especially over multiple layers).  A common symptom is no audio stream.  The Asterisk CLI  shows a successful call connection succeeding followed by an error in /var/log/asterisk/messages:

[Jun 14 17:16:26] WARNING[2967] chan_sip.c: Retransmission timeout reached on transmission 4e2a8586-3a91c1cf-e73f6b64@10.1.10.115 for seqno 2 (Critical Response) — See https://wiki.asterisk.org/wiki/display/AST/SIP+Retransmissions
Packet timed out after 6399ms with no response

(more…)

Jun
26
2017
0

How to handle Python 3 Fabric exceptions with a Decorator

Python’s Fabric module is an easy and efficient way for task based automation.  I use it to automate the installation of VoIP phone systems on CentOS 6/7.  In a nut shell, Fabric executes shell commands over SSH.  It also can be used to automate local tasks.  The purpose of this article is to highlight the basic process of capturing Fabric exceptions(try/except) using a wrapper function called a decorator.  A few well placed decorators can save lot of time coding the same thing over and over(like capturing a specific error). 

Most of you in the know about Python/Fabric probably  will find my examples trivial, but I had to dig to find the Fabric exception environment variable.  I’m sure it’s somewhere on the Fabric site… but I gave up after 30 minutes.  So hopefully you will find this post useful either way!

If you need help installing Python3, pip3 and Fabric please refer to my previous post.

Goals of this Post:

  • create a simple Fabric function that creates a directory
  • create a Fabric exception
  • create Decorator for adding exception handling

Lets start with a basic fabfile.py: 

(more…)

Jun
21
2017
0

Automate Git Repository Setup with Python & Fabric

I love Git.  I find Git to be an intuitive way to track many versions between many systems.  Now all my default config files and scripts utilize Git.  However, logging into a server and creating the Git repo, then cloning it is a number of steps that detracts from getting work done.  

This tutorial outlines a basic example of using Fabric(Python automation module) to automate the process of creating  a ‘mycode.git’ repository and cloning it.  This tutorial was written for Cent OS 6.5, but could be adapted for Ubuntu and Fedora.  Basic knowledge of Linux and Python 3 is required.

If you need help setting up Python3, pip, and Fabric on CentOS 6 please refer to my earlier tutorial: https://www.savelono.com/linux/how-to-install-python-3-and-pip-3-for-centos-6.html

Goals of this post:

  • Write Python/Fabric function to automate the Git setup process
  • Write Python/Fabric function to automate cloning Git repository on local host

(more…)

Jun
08
2017
0

How to Install and Configure Basic Git Server on CentOS 6

Git has changed my life.  I’m not exaggerating.  I work with a lot of ‘one off’ scripts (BASH, PHP, and Python).  They are spread out among systems and developed from my workstation and(sometimes) laptop.  I spent 15 years keeping multiple versions and copies of the same scripts spread between systems.  Looking back it seems Crazy!

While I’ve known about Git for years, but I had no idea how badly I needed it until I interviewed for a contract and the interviewer repeatedly mentioned Git as a crucial part of their development process.  I admitted to him that I didn’t use it, but I would set it up myself and answer his questions in the next interview.  I installed it and set out to learn the centralized Git workflow(similar to SVN; one master setup).  There are other workflows and I recommend taking a look at this post if you are curious: https://www.atlassian.com/git/tutorials/comparing-workflows  

Goals of this Post:

  • Install  and configure basic Git for centralized workflow

 

(more…)

Written by mattb in: Automation,Linux | Tags: , , , , ,