Skip to content

Instantly share code, notes, and snippets.

@ryandotclair
ryandotclair / block1.py
Created November 28, 2015 01:08
Block 1 of Code
# 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'])
@ryandotclair
ryandotclair / .py
Last active November 28, 2015 02:18
db write out
# Grab Total MB Sent for a given SG and write out the data to the database.
for item in result:
srdfa_total += item['SRDFA_MBSent']
try:
print("Writing to the the database: {0}, {1}, {2}, {3}".format(
timestamp, symmetrix_id, storage_group_id, srdfa_total))
cursor = db_connection.cursor()
SQL = "INSERT INTO reporterschema.main (date, sn, sg, srdfa_mbsent) VALUES (%s,%s,%s,%s)"
@ryandotclair
ryandotclair / .py
Last active November 27, 2015 20:08
pg8000 connect
# Convert port to an int
db_port = int(db_port)
# Connect to the database
try:
db_connection = pg8000.connect(user=db_user, host=db_host,port=db_port,database=db_database,password=db_pass)
db_connection.autocommit = True
except Exception as e:
logger.critical(
'Unable to connect! Ensure $SRDBHOST, $SRDATABASE, $SRDBUSER and $SRDBPASS environmental variables are '
@ryandotclair
ryandotclair / .py
Created November 27, 2015 19:51
user and replace
# Get credentials for Unisphere login from environmentals. Default to smc/smc
uni_user = os.getenv('SRUSER', "smc")
uni_pass = os.getenv('SRPASS', "smc")
@ryandotclair
ryandotclair / db_info.py
Created November 27, 2015 16:26
db info
# Get DB IP info
if os.environ.get('DB_PORT_5432_TCP_ADDR') != None:
db_host = os.environ['DB_PORT_5432_TCP_ADDR']
else:
db_host = os.getenv('SRDBHOST', "localhost")
# Get DB Port info
if os.environ.get('DB_PORT_5432_TCP_PORT') != None:
db_port = os.environ['DB_PORT_5432_TCP_PORT']
else:
@ryandotclair
ryandotclair / dbhost.py
Last active November 28, 2015 02:02
collector_db host and port env var
# Look for overriding env var's, otherwise assume the defaults for the database user and database name.
db_user = os.getenv('SRDBUSER', 'postgres')
db_database = os.getenv('SRDATABASE', 'reporter')
@ryandotclair
ryandotclair / ci.py
Last active November 26, 2015 06:58
collector_import
import requests
import json
import time
import os
import logging
import sys
import pg8000
from datetime import datetime, date, timedelta
from datetime import time as dt_time
@ryandotclair
ryandotclair / SRDFA_Reporter.py
Created November 25, 2015 01:53
SRDFA_Reporter.py
#! /usr/bin/env python3
import requests
import json
import time
import os
import logging
import sys
import csv
from datetime import datetime, date, timedelta
# Date
timestamp = date.today() - timedelta(days=1)
@ryandotclair
ryandotclair / payload.py
Created October 31, 2015 04:12
SRDFA_Payload
def generate_payload(symmetrix_id, storage_group_id):
return {
"startDate": unix_ym,
"endDate": unix_midnight,
"symmetrixId": symmetrix_id,
"storageGroupId": storage_group_id,
"metrics": ["SRDFA_MBSent"]
}