Skip to content

Instantly share code, notes, and snippets.

@pcolazurdo
pcolazurdo / node_exporter_install.md
Last active September 10, 2018 10:11
Installing node_exporter in AmazonLinux

Work in progress

you need go 1.10 or higher installed for this to work

sudo yum install go git
cd ${GOPATH-$HOME/go}/src/github.com/prometheus/node_exporter
go get github.com/prometheus/node_exporter
sudo yum install  glibc-static
make
@pcolazurdo
pcolazurdo / readme.md
Last active September 5, 2018 08:51
Interesting GitHub Projects

Limits

  • Aphelion is used to collect AWS limits across multiple accounts. It uses a combination of Trusted Advisor (TA) as well as direct resource APIs to collect limits for most of the AWS resources where the limit is either in TA, or the particular service exposes the current limit values via API calls https://github.com/FINRAOS/aphelion

CloudFormation

@pcolazurdo
pcolazurdo / ip_range_analysis.sh
Created May 22, 2018 10:26
Example of how to parse IP_RANGE.json from AWS
cat iprange.json | jq '.prefixes[] | select (.ip_prefix | contains( "/25") ) | .ip_prefix + " " + .region + " " + .service' |sort -u | uniq -c
@pcolazurdo
pcolazurdo / pricingapi2jq.sh
Created April 23, 2018 16:42
Example to use AWS Pricing API with jq
aws pricing get-products --service-code AmazonRDS --region us-east-1 >/tmp/pp.json
cat /tmp/pp.json | jq '.PriceList[] | fromjson' >/tmp/ppp.json
cat /tmp/pp.json | jq '.PriceList[] | fromjson' >/tmp/ppp.json
cat /tmp/ppp.json | jq '.|select(.product.attributes.databaseEngine == "MariaDB" and .product.attributes.location =="EU (Ireland)" and .product.attributes.instanceType == "db.m4.large") | .terms.OnDemand' | more
@pcolazurdo
pcolazurdo / authorizeme.sh
Created April 14, 2018 20:01
Update AWS Security Group with self IP address
GROUPNAME=FromHome
MYIP=`curl -s ipinfo.io | jq .ip | cut -d\" -f2`
AUTHORIZEDIP=`aws ec2 describe-security-groups --group-names $GROUPNAME | jq '.SecurityGroups[].IpPermissions[] | select (.FromPort == 22) | .IpRanges[].CidrIp' | cut -d\" -f2 | cut -d/ -f1`
if [ "${MYIP}" == "${AUTHORIZEDIP}" ]; then
echo Nothing to do: $MYIP is equal to $AUTHORIZEDIP
else
echo Revoking authorization for: $AUTHORIZEDIP
aws ec2 revoke-security-group-ingress --group-name $GROUPNAME --protocol tcp --port 22 --cidr $AUTHORIZEDIP/32
aws ec2 revoke-security-group-ingress --group-name $GROUPNAME --protocol tcp --port 3389 --cidr $AUTHORIZEDIP/32
@pcolazurdo
pcolazurdo / delete-indices.sh
Created March 27, 2018 18:01
Deleting multiple indexes from ElasticSearch
ES_HOST=search-4ptw5ao4ierg.eu-west-1.es.amazonaws.com
INDEXTODELETEEXPR=cwl-2017
curl -XGET https://$ES_HOST/_all/ | jq 'reduce path(.[]?) as $path (.; setpath($path; {}))' > /tmp/indexlist.txt
cat /tmp/indexlist.txt | grep $INDEXTODELETEEXPR | cut -d\" -f2 | while read a
do
curl -XDELETE https://$ES_HOST/$a
done
@pcolazurdo
pcolazurdo / aurora_audit_parse.py
Created March 1, 2018 17:05
Parsing sample file for Aurora Audit Files
with open('audit.log.1.2018-03-01-15-57.0', 'rb') as csvfile:
csvreader = csv.reader(csvfile,
delimiter=',',
quotechar='\'')
for n, row in enumerate(csvreader):
print n, row
@pcolazurdo
pcolazurdo / wget.py
Created November 16, 2017 15:26
Sample wget in Python
import urllib2
import logging
def wget(urltxt):
logger = logging.getLogger()
logger.setLevel(logging.INFO)
attempts = 0
while attempts < 3:
try:
response = urllib2.urlopen(urltxt, timeout = 5)
content = response.read()

If you have problems when downloading large results sets from reDash it may be you are running against the default 30 seconds timeout in gunicorn. To solve this you can edit your:

/opt/redash/supervisord/supervisord.conf

and change:

[program:redash_server]
command=/opt/redash/current/bin/run gunicorn -b 127.0.0.1:5000 --name redash -w 4 redash.wsgi:app

If you have problems when downloading large results sets from reDash it may be you are running against the default 30 seconds timeout in gunicorn. To solve this you can edit your:

/opt/redash/supervisord/supervisord.conf

and change:

[program:redash_server]