Skip to content

Instantly share code, notes, and snippets.

@ryandotclair
ryandotclair / index.html.erb
Created October 26, 2015 16:23
Chef Example #2 index.html.erb
<h1>Hello <%= node['apache']['greeting'] %>!</h1>
<p>My IP address is <%= node['ipaddress'] %></p>
@ryandotclair
ryandotclair / webserver.json
Last active October 26, 2015 16:24
Chef example Role
{
"name" : "webserver",
"default_attributes": {
"apache" : {
"greeting" : "Person"
}
},
"run_list" : [
"recipe[apache]"
]
@ryandotclair
ryandotclair / SRDFA_Reporter1.py
Last active October 31, 2015 02:08
SRDFA Reporter WIP File1
#! /usr/bin/env python3
@ryandotclair
ryandotclair / SRDFA_imports.py
Last active October 31, 2015 02:40
SRDFA_Reporter2.py
import requests
import json
import time
import os
import logging
import sys
import csv
from datetime import datetime, date, timedelta
from datetime import time as dt_time
@ryandotclair
ryandotclair / SRDFA_logging.py
Last active October 31, 2015 08:24
logging
logging.basicConfig(
level=logging.getLevelName('DEBUG'),
format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
filename='SRDFA_Reporter_Error.log')
console_write = logging.StreamHandler()
console_write.setLevel(logging.getLevelName('INFO'))
logger = logging.getLogger()
logger.addHandler(console_write)
@ryandotclair
ryandotclair / disable.py
Last active October 31, 2015 03:21
Disable warnings
# Disable warnings from untrusted server certificates
try:
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
except Exception:
logger.info("Ignore messages related to insecure SSL certificates")
#Date
TIMESTAMP = date.today() - timedelta(days=1)
# Get the URL from environmentals. Example: "10.241.209.162:8443"
try:
location = os.environ['SRUNILOCATION']
except KeyError:
logger.critical('Need an IP:Port. Please set the environment variable SRUNILOCATION to IP:Port of Unisphere '
'using either "export SRUNILOCATION=IP:PORT" (linux command) or "set SRUINLOCATION=IP:PORT" '
'(Windows command)')
sys.exit(1)
# Get credentials for Unisphere login from environmentals
# Get today's midnight
midnight = datetime.combine(date.today(), dt_time.min)
# Convert to unix epoch time
unix_midnight = time.mktime(midnight.timetuple())
# Convert to milliseconds
unix_midnight *= 1000
# Remove trailing .0 float from the time
unix_midnight = str(unix_midnight).replace(".0", "")
# Get yesterday's midnight
# If SRDFA_Reporter.csv file doesn't exist, create it with a header.
if not os.path.isfile('SRDFA_Reporter.csv'):
with open('SRDFA_Reporter.csv', 'w') as csvfile:
writer = csv.writer(csvfile, delimiter=',',
quotechar=',', quoting=csv.QUOTE_MINIMAL)
writer.writerow(
['24h Period', 'Array', 'Storage Group', 'Total MB Sent by SRDFA'])