Ejemplo n.º 1
0
# Global variables
api_key = meraki_info.api_key
base_url = meraki_info.base_url
org_id_list = []  # create a blank list

# Set the CSV output file and settings
output_file = open('network_id_list_report.csv', mode='wb')
csv_writer = csv.writer(output_file, delimiter=',', escapechar=' ', 
                        quoting=csv.QUOTE_NONE)

# Write the header row of the CSV file
header_row_text = "Net ID,Name"
csv_writer.writerow([header_row_text])

# Get all Org ID's
org_ids_json = merakiapi.myorgaccess(api_key)
# print org_ids_json

# Create a list of Org ID's called org_id_list
# For every row of JSON output, append the value of "v" (org ID) when k = 'id'
for row in org_ids_json:
    # print row
    for k,v in row.iteritems():
        if k == 'id':
            org_id_list.append(v)
        else:
            continue

# print org_id_list

# For every 'org' in org_id_list, use the getnetworklist function in the
base_url = meraki_info.base_url
org_id_list = []  # create a blank list

# Set the CSV output file and settings
output_file = open('network_id_list_report.csv', mode='wb')
csv_writer = csv.writer(output_file,
                        delimiter=',',
                        escapechar=' ',
                        quoting=csv.QUOTE_NONE)

# Write the header row of the CSV file
header_row_text = "Net ID,Name"
csv_writer.writerow([header_row_text])

# Get all Org ID's
org_ids_json = merakiapi.myorgaccess(api_key)
# print org_ids_json

# Create a list of Org ID's called org_id_list
# For every row of JSON output, append the value of "v" (org ID) when k = 'id'
for row in org_ids_json:
    # print row
    for k, v in row.iteritems():
        if k == 'id':
            org_id_list.append(v)
        else:
            continue

# print org_id_list

# For every 'org' in org_id_list, use the getnetworklist function in the
Ejemplo n.º 3
0
def main():
    # read from xlsx file
    configurations = {}
    from openpyxl import load_workbook
    wb = load_workbook(filename='template.xlsx')
    first_sheet = wb.get_sheet_names()[0]
    ws = wb[first_sheet]

    my_row = []
    for i in range(1, ws.max_row - 2):
        for j in range(1, ws.max_column - 1):
            my_row.append(ws.cell(row=i + 1, column=j).value)

        #configurations[ws.cell(row=i + 1, column=2).value + str(ws.cell(row=i + 1, column=3).value)] = SwitchPort(my_row)  # dictionary
        print(
            ws.cell(row=i + 1, column=2).value +
            str(ws.cell(row=i + 1, column=3).value))
        print(my_row)

    print(configurations)

    # API key.
    api_key = "8b43aaa7b92b6d3ad06234e6f581077620d3e512"

    # Get the organization name.
    print("Organization Name:")
    org_name = input()

    # Pull the organizations associated to the provided API key.
    orgs = merakiapi.myorgaccess(api_key, True)

    # Look for the organization that we want to configure.
    org_id = ""
    for org in orgs:
        if org_name in org["name"]:
            org_id = org["id"]

    if org_id == "":
        print("Organization not found.")
        return

    # Pull the networks associated with the organization.
    networks = merakiapi.getnetworklist(api_key, org_id, True)

    # Pull the devices from all of the networks.
    devices = []
    for network in networks:
        devices += merakiapi.getnetworkdevices(api_key, network["id"], True)

    # print devices

    switch_ports = []
    for device in devices:
        current_switch_ports = []
        if device["model"].startswith("MS"):
            # current_switch_port = merakiapi.getswitchports(api_key, device["serial"])
            # current_switch_port["serial"] = device["serial"]
            current_switch_ports = merakiapi.getswitchports(
                api_key, device["serial"], False)

        # Label all current switch ports with the serial number of the parent switch.
        for switch_port in current_switch_ports:
            switch_port["serial"] = device["serial"]

        # Append the switch ports for the current switch to the master list.
        switch_ports += current_switch_ports

    print(switch_ports)

    # Apply configuration to the devices and push them to Meraki.
    for switch_port in switch_ports:
        try:
            switch_port["name"] = configurations[
                switch_port["serial"] + str(switch_port["number"])].name
        except:
            continue
        switch_port["tags"] = configurations[switch_port["serial"] +
                                             str(switch_port["number"])].tags
        switch_port["enabled"] = configurations[
            switch_port["serial"] + str(switch_port["number"])].enabled
        switch_port["rstpEnabled"] = configurations[
            switch_port["serial"] + str(switch_port["number"])].rstp
        switch_port["stpGuard"] = configurations[
            switch_port["serial"] + str(switch_port["number"])].stp_guard
        switch_port["poeEnabled"] = configurations[
            switch_port["serial"] + str(switch_port["number"])].poe
        switch_port["type"] = configurations[switch_port["serial"] +
                                             str(switch_port["number"])].type
        switch_port["vlan"] = configurations[switch_port["serial"] +
                                             str(switch_port["number"])].vlan
        switch_port["voiceVlan"] = configurations[
            switch_port["serial"] + str(switch_port["number"])].voice_vlan
        switch_port["allowedVlans"] = configurations[
            switch_port["serial"] + str(switch_port["number"])].allowed_vlan

        # print switch_port["enabled"]

        merakiapi.updateswitchport(
            api_key, switch_port["serial"], switch_port["number"],
            switch_port["name"], switch_port["tags"], switch_port["enabled"],
            switch_port["type"], switch_port["vlan"], switch_port["voiceVlan"],
            switch_port["allowedVlans"], switch_port["poeEnabled"], "",
            switch_port["rstpEnabled"], switch_port["stpGuard"], "")
def get_all_orgids():
    all_org_ids = []
    result = merakiapi.myorgaccess(my_api_key)
    for row in result:
        all_org_ids.append(row['id'])
    return all_org_ids
                org_inventory[(row['model'])] += 1
    return org_inventory


# Set the CSV output file and settings
ofile = open('msp_license_inventory_report.csv', mode='wb')
csv_writer = csv.writer(ofile, delimiter=',', escapechar=' ', quoting=csv.QUOTE_NONE)


# Write the top row of the CSV file
top_row_text = "Name,License Expiration,MX,MS,MR"
csv_writer.writerow([top_row_text])


# Store the list of organizations in all_orgs_info
all_orgs_info = merakiapi.myorgaccess(my_api_key)


# Store the list of org id's in all_ids
all_ids = get_all_orgids()


# get all org license state and inventory, then write to CSV file
def create_license_model_report():
    # Loop through each org id to grab the name, license state, and device inventory
    for i in all_ids:
        mr_count = 0
        mx_count = 0
        ms_count = 0
        org_name = getorgname(i, all_orgs_info)
        license_state = merakiapi.getlicensestate(my_api_key, i)
Ejemplo n.º 6
0
def get_all_orgids():
    all_org_ids = []
    result = merakiapi.myorgaccess(my_api_key)
    for row in result:
        all_org_ids.append(row['id'])
    return all_org_ids
Ejemplo n.º 7
0
    return org_inventory


# Set the CSV output file and settings
ofile = open('msp_license_inventory_report.csv', mode='wb')
csv_writer = csv.writer(ofile,
                        delimiter=',',
                        escapechar=' ',
                        quoting=csv.QUOTE_NONE)

# Write the top row of the CSV file
top_row_text = "Name,License Expiration,MX,MS,MR"
csv_writer.writerow([top_row_text])

# Store the list of organizations in all_orgs_info
all_orgs_info = merakiapi.myorgaccess(my_api_key)

# Store the list of org id's in all_ids
all_ids = get_all_orgids()


# get all org license state and inventory, then write to CSV file
def create_license_model_report():
    # Loop through each org id to grab the name, license state, and device inventory
    for i in all_ids:
        mr_count = 0
        mx_count = 0
        ms_count = 0
        org_name = getorgname(i, all_orgs_info)
        license_state = merakiapi.getlicensestate(my_api_key, i)
        # remove the comma from the expiration date to avoid CSV trouble