Skip to content

Instantly share code, notes, and snippets.

@marshyski
marshyski / yum-nginx-api-basic-auth.py
Created October 7, 2014 15:27
yum-nginx-api Basic Auth username & password
#!/usr/bin/python
import os
import magic
from flask import Flask, request, jsonify, make_response
from werkzeug.utils import secure_filename
from werkzeug.contrib.fixers import ProxyFix
from subprocess import call
from flask.ext.httpauth import HTTPBasicAuth
@marshyski
marshyski / multiple-requests-status.py
Last active August 29, 2015 14:08
Grab status from multiple URLs
#!/usr/bin/python
import requests
urls = [
'http://192.168.1.5/',
'http://192.168.1.15/',
'http://192.168.1.5:8080',
]
@marshyski
marshyski / puppet-health-requests.py
Last active August 29, 2015 14:08
Health Check Multiple Puppet Dashboard & PuppetDB with Python Requests
#!/usr/bin/python
import requests
from bs4 import BeautifulSoup
requests.packages.urllib3.disable_warnings()
urls = [
'https://192.168.1.100/nodes/failed?per_page=all',
'https://192.168.1.200/nodes/failed?per_page=all',
@marshyski
marshyski / boto-filter-tag.py
Last active June 14, 2017 23:46
Filter instances by a tag and get private IP address
reservations = ec2.get_all_instances(filters={"tag:Purpose": "Web"})
for res in reservations:
for inst in res.instances:
if inst.private_ip_address:
if inst.state == 'running':
print inst.private_ip_address
@marshyski
marshyski / flask-template-requests.py
Created November 3, 2014 22:41
Flask app to render template with basic status of web servers
#!/usr/bin/python
import flask
import requests
from jinja2 import Environment
from jinja2.loaders import FileSystemLoader
requests.packages.urllib3.disable_warnings()
app = flask.Flask(__name__)
@marshyski
marshyski / base.html
Created November 3, 2014 22:42
base.html template for flask-template-requests.py
{% block body %}
<body>
<center>
{% for line in result %}
{{ line }}
{% endfor %}
</center>
</body>
{% endblock %}
@marshyski
marshyski / marshyski-health.py
Last active August 29, 2015 14:08
marshyski.com health check
#!/usr/bin/python
import requests
from bs4 import BeautifulSoup
requests.packages.urllib3.disable_warnings()
urls = [
'http://marshyski.com/',
'http://marshyski.com/man-behind-the-keyboard/',
@marshyski
marshyski / fabfile-socket.py
Last active August 29, 2015 14:11
Fabric checking for port 22 socket connection
from fabric.api import sudo, env, put
import configuration as config
import socket, time
env.hosts = open('hosts_file', 'r').readline().rstrip()
env.user = config.USERNAME
env.port = '22'
env.key_filename = config.KEY_FILE
env.warn_only = True
@marshyski
marshyski / iptables
Last active December 17, 2020 10:43
DigitalOcean IPTables
*nat
:PREROUTING ACCEPT [235:14024]
:INPUT ACCEPT [235:14024]
:OUTPUT ACCEPT [418:29744]
:POSTROUTING ACCEPT [418:29744]
COMMIT
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [229:47805]
@marshyski
marshyski / JenkinsService.groovy
Created January 27, 2015 19:42
Creating Jenkins Folder via web request with Grails / REST
import grails.plugins.rest.client.RestBuilder
import grails.transaction.Transactional
import sun.misc.BASE64Encoder
@Transactional
class JenkinsService {
def grailsApplication
def createJob(String folderName) {
String url = grailsApplication.config.jenkins.url