Example #1
0
 def get_page_count(self) -> Optional[int]:
     try:
         snmp = SNMP(self.ip, community="public")
         return snmp.get(self.oid)
     except SNMPError as error:
         print(error)
         return None
Example #2
0
 def get_SNMP(ip_addr, config):
     snmp = SNMP(ip_addr,
                 version=3,
                 username=config['snmp_username'],
                 authproto=config['snmp_authproto'],
                 authkey=config['snmp_authkey'],
                 privproto=config['snmp_privproto'],
                 privkey=config['snmp_privkey'])
     return snmp
Example #3
0
def funcionPrincipal(servidorGUI=False,
                     checkGUI=False,
                     prd=False,
                     texto=False):
    "La funcion que realiza el trabajo, checkeaServidor()->lector()->setter()/checker()"
    global servidor
    global lock
    global check
    global iteracion
    if (not lock):
        lock = True  # Bloque las ejecuciones
        # Aumenta el numero de ejecuciones
        iteracion = iteracion + 1
        cadena = "Ejecutado: " + str(iteracion)
        print(cadena)
        if (texto):
            texto.insert("end", cadena + "\n", "importante")
            texto.see("end")  # Se asegura de ir al final
        # Trabajo
        if (checkeaServidor(servidor)):
            # Conexion con el servidor
            snmp = SNMP(servidor, community="public")  # v2c
            # Solo comprobar
            if (check):
                cadena = "Comprobacion:"
                print(cadena)
                if (texto):
                    texto.insert("end", cadena + "\n", "importante")
                    texto.see("end")  # Se asegura de ir al final
                lector(snmp, checker, prd, texto)
            # Asignar y comprobar
            else:
                cadena = "Configuracion:"
                print(cadena)
                if (texto):
                    texto.insert("end", cadena + "\n", "importante")
                    texto.see("end")  # Se asegura de ir al final
                lector(snmp, setter, prd, texto)
                cadena = "Comprobacion:"
                print(cadena)
                if (texto):
                    texto.insert("end", cadena + "\n", "importante")
                    texto.see("end")  # Se asegura de ir al final
                lector(snmp, checker, prd, texto)
            informacion = "Fin Iteracion"
        else:
            informacion = "Error " + servidor + " no es una ip"
        lock = False  # Libera las ejecuciones
    else:
        informacion = "Ya se esta ejecutando"
    print('\a')  # Audio bell
    return informacion
Example #4
0
    def _run(self):
        result = StatusCheckResult(check=self)
        # instances = self.instance_set.all()
        target = self.instance_set.get().address

        # We need to read both STDOUT and STDERR because ping can write to both, depending on the kind of error. Thanks a lot, ping.
        # ping_process = subprocess.Popen("ping -c 1 " + target, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
        # response = ping_process.wait()

        response = SNMP(target, community='')

        # if response == 0:
        #     result.succeeded = True
        # else:
        #     output = ping_process.stdout.read()
        #     result.succeeded = False
        #     result.error = output
        #
        # return result
        return response
#uses hnmp library https://github.com/trehn/hnmp
#pip install hnmp

__author__ = "Rob Weber"
__email__ = "*****@*****.**"
__version__ = "1.1"

#parse the arguments
parser = argparse.ArgumentParser()
parser.add_argument('-c', '--community', required=True, help='The community string')
parser.add_argument('-H', '--host', required=True, help='The host address')
parser.add_argument('-d', '--device', required=False, help='check the total device count', action='store_true')
parser.add_argument('-w', '--warning', required=False, help='the client count to show a warning', type=int)
args = parser.parse_args()

snmp = SNMP(args.host, community=args.community)

#create snmp table based on UBNT OIDs
table = None
try:
  table = snmp.table('.1.3.6.1.4.1.41112.1.6.1.2.1', columns={6: 'ssid', 8: 'clients', 9: 'radio'})
except SNMPError as e:
  print('error')
  print(e)
  sys.exit(1)

if(table is not None):

  #get the available SSIDs
  allNames = {}
  index = 0