This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 ' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get credentials for Unisphere login from environmentals. Default to smc/smc | |
uni_user = os.getenv('SRUSER', "smc") | |
uni_pass = os.getenv('SRPASS', "smc") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python3 | |
import requests | |
import json | |
import time | |
import os | |
import logging | |
import sys | |
import csv | |
from datetime import datetime, date, timedelta |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Date | |
timestamp = date.today() - timedelta(days=1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | |
} |