Exemplo n.º 1
0
def main():
    cred = automationassets.get_automation_credential("app_id_mother_finance")
    _id_app = cred["password"]
    cred = automationassets.get_automation_credential(
        "secret_key_mother_finance")
    key_value = cred["password"]
    header = {
        "app-id": _id_app,
        "secret-key": key_value,
        "Accept": "application/json",
        "Content-Type": "application/json"
    }
    payload = {"nrc": "12/YaKaNa(N)123344", "phone_number": "097934333323"}
    #Post method to check the api
    response = requests.post(URL, params=payload, headers=header)
    response_data = response.json()

    if (response.status_code == 200):
        print "Mother finance website is up and running"
    elif (response.status_code == 422) or (response.status_code == 400):
        #ref : https://www.keycdn.com/support/422-unprocessable-entity
        errors = response_data.get('errors')
        print errors
    else:
        send_mail()
Exemplo n.º 2
0
def send_mail():
    '''this function is called when the URL is availble
    - send mail to the related users.
    '''
    cred = automationassets.get_automation_credential("RunBookEmailCred")
    username = cred["username"]
    sender = username
    receiver = ['*****@*****.**']
    password = cred["password"]
    smtpsrv = "smtp.office365.com"
    smtpserver = smtplib.SMTP(smtpsrv, 587)
    smtpserver.ehlo()
    smtpserver.starttls()
    smtpserver.ehlo
    smtpserver.login(sender, password)
    msg = """Subject : Mother Finance Alert

    ALERT: Mother Finance website is unavaible.
    """
    smtpserver.sendmail(sender, receiver, msg)
    print 'Successfully sent mail'
    smtpserver.close()
Exemplo n.º 3
0
def verify_credential():
    actualcredential = automationassets.get_automation_credential(CredentialName)
    if actualcredential["username"] == expectedUser:
        print "Get Automation Credential Successful"
    else:
        print "ERROR: Get Automation Credential Failed" 
for vm in all_vms:
    vmID = vm.id
    vmRG = vmID.split("/")[4]
    vmInstanceView = compute_client.virtual_machines.get(vmRG,
                                                         vm.name,
                                                         expand='instanceView')
    vmExtendGraph = {}
    vmExtendGraph['vm_name'] = vm.name
    vmExtendGraph['vm_rg'] = vmRG
    vmExtendGraph['vm_state'] = vmInstanceView.instance_view.statuses[
        1].display_status
    vmExtendGraph['graph_tag'] = 'extend_graph_vm_state'
    vmPowerStates.append(vmExtendGraph)

# Log Analytics Creds
logAnalyticsCreds = automationassets.get_automation_credential(
    "logAnalyticsCreds")
workspaceId = logAnalyticsCreds['username']
key = logAnalyticsCreds['password']

# Send Datas to Log Analytics
log_type = 'vmExtendGraph'
body = json.dumps(vmPowerStates)


# Build the API signature
def build_signature(customer_id, shared_key, date, content_length, method,
                    content_type, resource):
    x_headers = 'x-ms-date:' + date
    string_to_hash = method + "\n" + str(
        content_length
    ) + "\n" + content_type + "\n" + x_headers + "\n" + resource
Exemplo n.º 5
0
def main():
    """mail loop to execute data and attach to mail and send the mail
    """
    #use automationassets to get credentials
    cred = automationassets.get_automation_credential("xxxx")
    username = cred["username"]
    password = cred["password"]
    driver = '{SQL Server}'

    #declare database connection
    conn = pyodbc.connect(
        'DRIVER={0};SERVER=xxxxx;DATABASE=xxxxx;UID={1};PWD={2}'.format(
            driver, username, password))
    cursor = conn.cursor()

    #execute [App].[RptStagClientFileStatus] procedure and write to csv file
    cursor.execute(
        "SET NOCOUNT ON; EXEC [App].[RptStagClientFileStatus] active")
    results_activeclient = cursor.fetchall()
    activecsv = datetime.now().strftime('activeclientfile-%Y-%m-%d-%H-%M.csv')
    with open(activecsv, 'wb') as fp:
        a = csv.writer(fp, delimiter=',')
        a.writerow(['CreateDate', 'Institution', 'Status', 'RecCount'])
        a.writerows(results_activeclient)

    #execute [App].[RptStagClientFileStatus] procedure and write to csv file
    cursor.execute(
        "SET NOCOUNT ON; EXEC [App].[RptStagClientFileStatus] writeoff")
    results_writeoff = cursor.fetchall()
    writeoffcsv = datetime.now().strftime('writeoff-%Y-%m-%d-%H-%M.csv')
    with open(writeoffcsv, 'wb') as fp:
        a = csv.writer(fp, delimiter=',')
        a.writerow(['CreateDate', 'Institution', 'Status', 'RecCount'])
        a.writerows(results_writeoff)

    #execute [App].[RptMFILog] procedure and write to csv file
    cursor.execute("SET NOCOUNT ON; EXEC [App].[RptMFILog]")
    results_mfilog = cursor.fetchall()
    mficsv = datetime.now().strftime('mfilog-%Y-%m-%d-%H-%M.csv')
    with open(mficsv, 'wb') as fp:
        a = csv.writer(fp, delimiter=',')
        a.writerow(['CreateDate', 'MFILog'])
        a.writerows(results_mfilog)

    #execute [Client].[GetAccountStatistics] procedure and write to csv file
    cursor.execute("SET NOCOUNT ON; EXEC [Client].[GetAccountStatistics]")
    results_percent = cursor.fetchall()
    #create row_as_list for encoding process (changed pyodbc.Row to list data type)
    row_as_list = [x for x in results_percent]
    rawlist = list()
    #create rawlist to build manually list of pyodbc row for easily write to csv
    for x in row_as_list:
        lst2 = list()
        for y in x:
            res = encode(y)
            lst2.append(res)
        rawlist.append(lst2)

    percentcsv = datetime.now().strftime('80percent-%Y-%m-%d-%H-%M.csv')
    with codecs.open(percentcsv, 'wb', encoding='utf-8') as fp:
        a = csv.writer(fp, delimiter=',')
        header = [
            'MFIName', 'ClientCountAtSignUp', 'UploadCountLastMonth',
            'UploadCount', '80%', 'Status'
        ]
        a.writerow(header)
        a.writerows(rawlist)

    #Execute [App].[RptDailyStatusSummary] and show in body of mail
    cursor.execute("SET NOCOUNT ON; EXEC [App].[RptDailyStatusSummary]")
    summary = cursor.fetchall()
    #get summary data to show in mail's body
    sum1 = strip_data(summary[0])
    sum2 = strip_data(summary[1])
    sum3 = strip_data(summary[2])
    sum4 = strip_data(summary[3])
    sum5 = strip_data(summary[4])
    sum6 = strip_data(summary[5])
    sum7 = strip_data(summary[6])

    csvlist = list()
    for file in glob.glob("*.csv"):
        csvlist.append(file)

    #credentials of sender's address
    cred1 = automationassets.get_automation_credential("RunBookEmailCred")
    name = cred1["username"]
    passw = cred1["password"]

    sender = name
    receiver = xxxxxxxx
    smtpsrv = "smtp.office365.com"

    SUBJECT = 'MMCIX Daily Status ({0})'.format(
        datetime.now().strftime('%Y-%m-%d-%H:%M:%S'))
    #get the location of the script
    FILEPATH = os.path.dirname(os.path.abspath(__file__))
    #build mail's body
    msg = MIMEMultipart()
    msg['From'] = sender
    msg['To'] = COMMASPACE.join(receiver)
    msg['Subject'] = SUBJECT
    b1 = 'Daily Status job schedule are processed successfully.'
    b2 = 'Daily Status Summary'
    btle = 'Title, Record'
    body = """
    {0}

    {1}

    {2}
    {3}
    {4}
    {5}
    {6}
    {7}
    {8}
    {9}

    Regards,
    MMCIX Team

    """.format(b1, b2, btle, sum1, sum2, sum3, sum4, sum5, sum6, sum7)
    body = MIMEText(body)
    msg.attach(body)
    #attach multiple csv in csvlist
    for f in csvlist:
        #file_path = os.path.join(FILEPATH, f)
        part = MIMEBase('application', "octet-stream")
        part.set_payload(open(f, "rb").read())
        encoders.encode_base64(part)
        part.add_header('Content-Disposition', 'attachment', filename=f)  # or
        msg.attach(part)

    smtpserver = smtplib.SMTP(smtpsrv, 587)
    smtpserver.ehlo()
    smtpserver.starttls()
    smtpserver.ehlo
    smtpserver.login(sender, passw)
    smtpserver.sendmail(sender, receiver, msg.as_string())
    print 'Successfully sent mail'
    smtpserver.close()
Exemplo n.º 6
0
import automationassets
cred = automationassets.get_automation_credential("app_id_mother_finance")
_id_name = cred["username"]
_id_pwd = cred["password"]

print(_id_name)
print(_id_pwd)

cred = automationassets.get_automation_credential("secret_key_mother_finance")
_key_name = cred["username"]
_key_pwd = cred["password"]
print(_key_name)
print(_key_pwd)
Exemplo n.º 7
0
"""

#This script will remove all images from all repositories from the targeting the docker registry. The possibility of bypass parameters included.

import automationassets
from azure.keyvault import KeyVaultClient
from azure.common.credentials import ServicePrincipalCredentials
import os.path
import requests
import json
import sys
from requests.auth import HTTPBasicAuth
import argparse

# Get credential for Automation Account
cred = automationassets.get_automation_credential("CHANGE_ME")
user = cred["username"]
password = cred["password"]

#Setup settings for Azure Key-Vault
ACR_ADMIN_PWD = 'ADMIN-PASSWORD'
ACR_ADMIN_USR = '******'
URL_KEY_VAULT = 'https://CHANGE_ME.vault.azure.net/'
TENANT_ID_VAR = 'CHANGE_ME'
URL_DOCKER_REGISTRY = 'https://CHANGE_ME.azurecr.io/v2/'

# Get keys from Azure key-vault
credentials = ServicePrincipalCredentials(user, password, tenant=TENANT_ID_VAR)
client = KeyVaultClient(credentials)
# Get version of key for PASSWORD
admin_password_version = list(