# Path: credentials.py
# SNMP_COMMUNITY = "public"


from pysnmp.entity.rfc3413.oneliner import cmdgen
from credentials import SNMP_COMMUNITY
import time
import json
import logging.config

def get_snmp(device, community, snmp_oid1, snmp_oid2, snmp_uptime_oid):
    """Returns the value of the specified snmp OID.
     Also gets the uptime (TimeTicks) so we know exactly when the sample was taken."""

    # Perform a synchronous SNMP GET
    cmd_gen = cmdgen.CommandGenerator()
    error_indication, error_status, error_index, var_binds = cmd_gen.getCmd(
        cmdgen.CommunityData(community), cmdgen.UdpTransportTarget((device, 161)), snmp_oid1, snmp_oid2, snmp_uptime_oid
    )

    snmp_value1 = None
    snmp_value2 = None
    snmp_error = None
    snmp_uptime_value = None

    if error_indication:                         # Check for SNMP errors
        snmp_error = str(error_indication)
    else:
        if error_status:
            snmp_error = error_status.prettyPrint()
        else:
            # varBinds are returned as SNMP objects, so convert to integers
            snmp_value1 = int(var_binds[0][1])
            snmp_value2 = int(var_binds[1][1])
            snmp_uptime_value = int(var_binds[2][1])

    return snmp_value1, snmp_value2, snmp_uptime_value, snmp_error



# Path: credentials.py
# SNMP_COMMUNITY = "public"


# Path: snmp_interface_6.py
from pysnmp.entity.rfc3413.oneliner import cmdgen
from credentials import SNMP_COMMUNITY
import time
import json
import logging.config


def get_snmp(device, community, snmp_oid1, snmp_oid2, snmp_uptime_oid):
    """Returns the value of the specified snmp OID.
     Also gets the uptime (TimeTicks) so we know exactly when the sample was taken."""

    # Perform a synchronous SNMP GET
    cmd_gen = cmdgen.CommandGenerator()
    error_indication, error_status, error_index, var_binds = cmd_gen.getCmd(
        cmdgen.CommunityData(community), cmdgen.UdpTransportTarget((device, 161)), snmp_oid1, snmp_oid2, snmp_uptime_oid
    )

    snmp_value1 = None
    snmp_value2 = None
    snmp_error = None
    snmp_uptime_value = None

    if error_indication:                         # Check for SNMP errors
        snmp_error = str(error_indication)
    else:
        if error_status:
            snmp_error = error_status.prettyPrint()
        else:
            # varBinds are returned as SNMP objects, so convert to integers
            snmp_value1 = int(var_binds[0][1])
            snmp_value2 = int(var_binds[1][1])
            snmp_uptime_value = int(var_binds[2][1])

    return snmp_value1, snmp_value2, snmp_uptime_value, snmp_error



def calculate_bps(current_sample_octets, current_sample_time, historical_sample_octets, historical_sample_time):