Exemple #1
0
def create_graph(graph_stats, sample_duration):
    """Generate the graph files."""

    print()
    x_labels = []
    for x_label in range(1, 13):
        x_labels.append(str(x_label * sample_duration))

    # Create the graphs
    if line_graph.twoline("pynet-rtr1-octets.svg", "pynet-rtr1 Fa4 Input/Output Bytes",
                          graph_stats["in_octets"], "In Octets", graph_stats["out_octets"],
                          "Out Octets", x_labels):
        print("In/Out Octets graph created")

    if line_graph.twoline("pynet-rtr1-pkts.svg", "pynet-rtr1 Fa4 Input/Output Unicast Packets",
                          graph_stats["in_ucast_pkts"], "In Packets", graph_stats["out_ucast_pkts"],
                          "Out Packets", x_labels):
        print("In/Out Packets graph created")
    print()
def main():
    ''' main function - runs the programs from global variables and defined methods '''
    snmp_user = (A_USER, AUTH_KEY, ENCRYPT_KEY)
    pynet_rtr2 = (IP, SNMP_PORT2)

    in_packet_list = []
    out_packet_list = []
    in_packet_unicast_list = []
    out_packet_unicast_list = []


    print '\n'

    for time_track in range(0, 65, 5):

        print "\n%20s %-60s" % ("time", time_track)
        in_packet_list.append(get_packet_stats(pynet_rtr2, snmp_user, snmp_oids[0]))
        out_packet_list.append(get_packet_stats(pynet_rtr2, snmp_user, snmp_oids[1]))
        in_packet_unicast_list.append(get_packet_stats(pynet_rtr2, snmp_user, snmp_oids[2]))
        out_packet_unicast_list.append(get_packet_stats(pynet_rtr2, snmp_user, snmp_oids[3]))
        
    time.sleep(300)

    
    x_labels = []
    for x_label in range(5, 65, 5):
        x_labels.append(str(x_label))


      # Create the graphs
    if line_graph.twoline("pynet-rtr2-octets.svg", "pynet-rtr2 Fa4 Input/Output Bytes",
                          in_packet_list, "In Octets", out_packet_list,
                          "Out Octets", x_labels):
        print "In/Out Octets graph created"

    if line_graph.twoline("pynet-rtr2-pkts.svg", "pynet-rtr2 Fa4 Input/Output Unicast Packets",
                          in_packet_unicast_list, "In Packets", out_packet_unicast_list,
                          "Out Packets", x_labels):
        print "In/Out Packets graph created"
Exemple #3
0
def main():
    '''
    Connect to router via SNMPv3.

    Create two graphs in/out octets and in/out packets
    '''
    debug = False

    # SNMPv3 Connection Parameters
    rtr1_ip_addr = raw_input("Enter pynet-rtr1 IP: ")
    my_key = getpass(prompt="Auth + Encryption Key: ")

    a_user = '******'
    auth_key = 'galileo1'
    encrypt_key = 'galileo1'

    snmp_user = (a_user, auth_key, encrypt_key)
    snmp_device = (rtr1_ip_addr, 161)

    # Fa4 is in row number5 in the MIB-2 interfaces table
    row_number = 5
    graph_stats = {
        "in_octets": [],
        "out_octets": [],
        "in_ucast_pkts": [],
        "out_ucast_pkts": [],
    }
    base_count_dict = {}

    # Enter a loop gathering SNMP data every 5 minutes for an hour.
    for time_track in range(0, 65, 5):
        print "\n%20s %-60s" % ("time", time_track)

        # Gather SNMP statistics for these four fields
        for entry in ("in_octets", "out_octets", "in_ucast_pkts",
                      "out_ucast_pkts"):
            # Retrieve the SNMP data
            snmp_retrieved_count = get_interface_stats(snmp_device, snmp_user,
                                                       entry, row_number)
            # Get the base counter value
            base_count = base_count_dict.get(entry)
            print entry
            print base_count
            if base_count:
                # Save the data to graph_stats dictionary
                graph_stats[entry].append(snmp_retrieved_count - base_count)
                print "%20s %-60s" % (entry, graph_stats[entry][-1])
            # Update the base counter value
            base_count_dict[entry] = snmp_retrieved_count
        time.sleep(10)

    print
    if debug:
        print graph_stats
    x_labels = []
    for x_label in range(5, 65, 5):
        x_labels.append(str(x_label))
    if debug:
        print x_labels

    # Create the graphs
    if line_graph.twoline("pynet-rtr1-octets.svg",
                          "pynet-rtr1 Fa4 Input/Output Bytes",
                          graph_stats["in_octets"], "In Octets",
                          graph_stats["out_octets"], "Out Octets", x_labels):
        print "In/Out Octets graph created"

    if line_graph.twoline("pynet-rtr1-pkts.svg",
                          "pynet-rtr1 Fa4 Input/Output Unicast Packets",
                          graph_stats["in_ucast_pkts"], "In Packets",
                          graph_stats["out_ucast_pkts"], "Out Packets",
                          x_labels):
        print "In/Out Packets graph created"
    print
def main():
    '''
    Connect to router via SNMPv3.

    Create two graphs in/out octets and in/out packets
    '''

    DEBUG = False

    ip_addr = '10.10.10.10'

    a_user = '******'
    auth_key = '********'
    encrypt_key = '********'

    snmp_user = (a_user, auth_key, encrypt_key)

    pynet_rtr1 = (ip_addr, 7961)
    snmp_device = pynet_rtr1

    # Fa4 is in row number5 in the MIB-2 interfaces table
    row_number = 5

    graph_stats = {
        "in_octets": [],
        "out_octets": [],
        "in_ucast_pkts": [],
        "out_ucast_pkts": [],
    }
    base_count_dict = {}

    # Enter a loop gathering SNMP data every 5 minutes for an hour.
    for time_track in range(0, 65, 5):

        print "\n%20s %-60s" % ("time", time_track)

        # Gather SNMP statistics for these four fields
        for entry in ("in_octets", "out_octets", "in_ucast_pkts", "out_ucast_pkts"):

            # Retrieve the SNMP data
            snmp_retrieved_count = get_interface_stats(snmp_device, snmp_user, entry, row_number)

            # Get the base counter value
            base_count = base_count_dict.get(entry)
            if base_count:
                # Save the data to graph_stats dictionary
                graph_stats[entry].append(snmp_retrieved_count - base_count)
                print "%20s %-60s" % (entry, graph_stats[entry][-1])

            # Update the base counter value
            base_count_dict[entry] = snmp_retrieved_count

        time.sleep(300)


    print
    if DEBUG:
        print graph_stats

    x_labels = []
    for x_label in range(5, 65, 5):
        x_labels.append(str(x_label))

    if DEBUG:
        print x_labels


    # Create the graphs
    if line_graph.twoline("pynet-rtr1-octets.svg", "pynet-rtr1 Fa4 Input/Output Bytes",
                          graph_stats["in_octets"], "In Octets", graph_stats["out_octets"],
                          "Out Octets", x_labels):
        print "In/Out Octets graph created"

    if line_graph.twoline("pynet-rtr1-pkts.svg", "pynet-rtr1 Fa4 Input/Output Unicast Packets",
                          graph_stats["in_ucast_pkts"], "In Packets", graph_stats["out_ucast_pkts"],
                          "Out Packets", x_labels):
        print "In/Out Packets graph created"

    print
def main():
    '''
    Connect to router via SNMPv3.

    Create two graphs in/out octets and in/out packets
    '''

    DEBUG = False

    ip_addr = '10.10.10.10'

    a_user = '******'
    auth_key = '********'
    encrypt_key = '********'

    snmp_user = (a_user, auth_key, encrypt_key)

    pynet_rtr1 = (ip_addr, 7961)
    snmp_device = pynet_rtr1

    # Fa4 is in row number5 in the MIB-2 interfaces table
    row_number = 5

    graph_stats = {
        "in_octets": [],
        "out_octets": [],
        "in_ucast_pkts": [],
        "out_ucast_pkts": [],
    }
    base_count_dict = {}

    # Enter a loop gathering SNMP data every 5 minutes for an hour.
    for time_track in range(0, 65, 5):

        print "\n%20s %-60s" % ("time", time_track)

        # Gather SNMP statistics for these four fields
        for entry in ("in_octets", "out_octets", "in_ucast_pkts",
                      "out_ucast_pkts"):

            # Retrieve the SNMP data
            snmp_retrieved_count = get_interface_stats(snmp_device, snmp_user,
                                                       entry, row_number)

            # Get the base counter value
            base_count = base_count_dict.get(entry)
            if base_count:
                # Save the data to graph_stats dictionary
                graph_stats[entry].append(snmp_retrieved_count - base_count)
                print "%20s %-60s" % (entry, graph_stats[entry][-1])

            # Update the base counter value
            base_count_dict[entry] = snmp_retrieved_count

        time.sleep(300)

    print
    if DEBUG:
        print graph_stats

    x_labels = []
    for x_label in range(5, 65, 5):
        x_labels.append(str(x_label))

    if DEBUG:
        print x_labels

    # Create the graphs
    if line_graph.twoline("pynet-rtr1-octets.svg",
                          "pynet-rtr1 Fa4 Input/Output Bytes",
                          graph_stats["in_octets"], "In Octets",
                          graph_stats["out_octets"], "Out Octets", x_labels):
        print "In/Out Octets graph created"

    if line_graph.twoline("pynet-rtr1-pkts.svg",
                          "pynet-rtr1 Fa4 Input/Output Unicast Packets",
                          graph_stats["in_ucast_pkts"], "In Packets",
                          graph_stats["out_ucast_pkts"], "Out Packets",
                          x_labels):
        print "In/Out Packets graph created"

    print
def main():
    '''
    Connect to router via SNMPv3

    Create two graphs in/out octeys and in/out packets
    '''

    debug = False

    # SMPNv3 connection Parameters
    ip_addr = raw_input("Enter router IP: ")
    a_user = '******'
    my_key = getpass(prompt="Auth + Encryption Key: ")
    auth_key = my_key
    encrypt_key = my_key

    snmp_user = (a_user, auth_key, encrypt_key)

    pynet_rtr1 = (ip_addr, 7961)
    snmp_device = pynet_rtr1

    # Fa4 is in rownumber5in the MIB-2 interfaces table
    row_number = 5

    graph_stats = {
        "in_octets": [],
        "out_octets": [],
        "in_ucast_pkts": [],
        "out_ucast_pkts": [],
    }
    base_count_dict = {}

    # Enter a loop gathering SNMP date every 5 minutes
    for time_track in range (0, 20, 5):

        print "\n%20s %-20s" % ("time", time_track)

        # Gather SNMP statistics for these four fields
        for entry in ("in_octets", "out_octets", "in_ucast_pkts", "out_ucast_pkts"):

            # Retrieve SNMP data
            snmp_retrieved_count = get_interface_stats(snmp_device, snmp_user, entry, row_number)

            # Get the base counter value
            base_count = base_count_dict.get(entry)

            if base_count:
                #save the data to graph_stats dictionary
                graph_stats[entry].append(snmp_retrieved_count - base_count)
                print "%20s %-20s" % (entry, graph_stats[entry][-1])

            # updat the base counter value
            base_count_dict[entry] = snmp_retrieved_count

        time.sleep(300)

    print
    if debug:
        print graph_stats

    x_labels = []
    for x_label in range(5, 20, 5):
        xlabels.append(str(x_label))

    if debug:
        print x_labels

    # Create graphs
    if line_graph.twoline("pynet-rtr1-octets.svg", "pynet-rtr1 Fa4 Input/Output Bytes",
                          graph_stats["in_octets"], "In Octets", graph_stats["out_octets"],
                          "Out Octets", x_labels):

        print "In/Out Octets graph created"


    print