Exemplo n.º 1
0
    def get_config_indexes(self, cm_stats):
        """
        Get the config indexes for all policy & object indexes.

        indexes is a list of tuples of (policy_index, object_index)
        :param cm_stats: ClassMap Statistics
        :return:
        {
            ('policy_index', 'object_index'): 'config_index'
        }
        """
        try:
            oids = [
                str('1.3.6.1.4.1.9.9.166.1.5.1.1.2.' + cs.pol_ind + '.' +
                    cs.obj_ind) for cs in cm_stats
            ]
            res = query_oids(self.cmd_gen, runner.security_object(),
                             runner.transport(), oids)
            logging.debug("config_index_oids=" + str(res))
            # output looks like
            # iso.3.6.1.4.1.9.9.166.1.5.1.1.2.836311857.601391474 = Gauge32: 1965376995

            config_indexes = {}
            for name, val in res:
                if not isinstance(val, NoSuchInstance):
                    policy_index = str(name[-2])
                    object_index = str(name[-1])
                    value = str(val.prettyPrint())
                    config_indexes[(policy_index, object_index)] = value
            return config_indexes
        except SnmpException as ex:
            logging.error('error=%s msg=%s method=get_config_indexes',
                          splunk_escape(ex.error_type), splunk_escape(ex.msg))
            raise HandledSnmpException
Exemplo n.º 2
0
def do_run():
    runner.read_config()
    snmputils.set_logger_format(name=runner.name())

    cmd_gen = snmputils.get_cmd_gen()

    while True:
        try:
            for operation in runner.operations():
                try:
                    oid_args = [str(b + '.' + operation) for b in symbols]
                    var_binds = snmputils.query_oids(cmd_gen,
                                                     runner.security_object(),
                                                     runner.transport(),
                                                     oid_args)
                    handle_output(var_binds, runner.destination(), operation)
                except SnmpException as ex:
                    logging.error('error=%s msg=%s operation=%s',
                                  splunk_escape(ex.error_type),
                                  splunk_escape(ex.msg), operation)
                    break
        except PySnmpError as ex:
            logging.error('msg=%s', splunk_escape(ex.message))
        except Exception:
            logging.exception("Exception with getCmd to %s:%s" %
                              (runner.destination(), runner.port))

        time.sleep(float(runner.snmpinterval()))
Exemplo n.º 3
0
def do_run():
    snmpif.read_config()
    snmputils.set_logger_format(name=snmpif.name())

    cmd_gen = snmputils.get_cmd_gen()

    while True:
        try:
            startTime = time.time()
            endTime = 0
            for interface in snmpif.interfaces():
                oid_args = [str(b + '.' + interface) for b in interface_mibs.keys()]
                logging.debug('oid_args=%s', oid_args)
                var_binds = snmputils.query_oids(cmd_gen, snmpif.security_object(), snmpif.transport(), oid_args)
                logging.debug('var_binds=%s', var_binds)
                handle_output(var_binds, snmpif.destination())

            endTime = time.time()

        except SnmpException as ex:
            logging.error('error=%s msg=%s interfaces=%s', splunk_escape(ex.error_type),
                          splunk_escape(ex.msg), splunk_escape(','.join(snmpif.interfaces())))
        except PySnmpError as ex:
            logging.error('msg=%s', splunk_escape(ex.message))
        except Exception:
            logging.exception('msg="Exception in main loop"')

        interval = int(snmpif.snmpinterval())
        runningTime = endTime - startTime
        if (runningTime > 0 ) and (runningTime < interval):
            time.sleep(interval-runningTime)
Exemplo n.º 4
0
 def get_policy_interface_indexes(self):
     """
     Get the policy indexes for all configured interfaces
     :return: A dictionary that has the policy index as the key and a tuple of (interface, direction) as the value
     {
         'policyIndex': ('interface', 'direction'),
         '836311857': ('324', 'in'),
         '836311858': ('324', 'out')
     }
     """
     try:
         oids = [
             str('1.3.6.1.4.1.9.9.166.1.2.1.1.1.' + i + '.' + direction)
             for i in self.interfaces() for direction in ['1', '2']
         ]
         table = query_oids(self.cmd_gen, runner.security_object(),
                            runner.transport(), oids)
         logging.debug('policy_interface_indexes=%s', table)
         # output looks like
         # iso.3.6.1.4.1.9.9.166.1.2.1.1.1.324.1 = Gauge32: 836311857 <- policy index
         # iso.3.6.1.4.1.9.9.166.1.2.1.1.1.324.2 = Gauge32: 836311858
         return extract_policy_interface_indexes(table)
     except SnmpException as ex:
         logging.error('error=%s msg=%s interfaces=%s',
                       splunk_escape(ex.error_type), splunk_escape(ex.msg),
                       splunk_escape(','.join(self.interfaces())))
         raise HandledSnmpException
Exemplo n.º 5
0
def do_run():
    snmpEkinops.read_config()
    snmputils.set_logger_format(name=snmpEkinops.name())

    cmd_gen = snmputils.get_cmd_gen()

    while True:
        try:
            for interface in snmpEkinops.interfaces():
                interfaceId = interface.split(':')[0]
                cardType = interface.split(':')[1]
                ipAddr = socket.gethostbyname(snmpEkinops.destination())

                # Get the card number
                oid_args = [mgnt2Position + "." + interfaceId]
                logging.debug('get card number, oid_args=%s', oid_args)
                var_binds = snmputils.query_ekinops_card(
                    cmd_gen, snmpEkinops.security_object(),
                    snmpEkinops.transport(), oid_args)
                card_number = var_binds[0][1].prettyPrint()

                # Set card to read from
                oid_args = [
                    str(mgnt2GigmSelectedBoard),
                    rfc1902.Integer(card_number)
                ]
                logging.debug('set card number, oid_args=%s', oid_args)
                snmp_result = cmd_gen.setCmd(snmpEkinops.security_object(),
                                             snmpEkinops.transport(), oid_args)

                # Create array of oids to read
                oid_args = [
                    interface_mibs[e] + ".0" for e in managed_oids[cardType]
                ]
                logging.debug('queryOids, oid_args=%s', oid_args)
                var_binds = snmputils.query_oids(cmd_gen,
                                                 snmpEkinops.security_object(),
                                                 snmpEkinops.transport(),
                                                 oid_args)
                logging.debug('var_binds=%s', var_binds)

                interface_attrs = {}
                interface_attrs['card'] = card_number
                interface_attrs['interfaceIdx'] = interfaceId
                interface_attrs['cardType'] = cardType
                interface_attrs['ipAddr'] = ipAddr

                handle_output(var_binds, snmpEkinops.destination(),
                              interface_attrs)

        except SnmpException as ex:
            logging.error('error=%s msg=%s interfaces=%s',
                          splunk_escape(ex.error_type), splunk_escape(ex.msg),
                          splunk_escape(','.join(snmpEkinops.interfaces())))
        except PySnmpError as ex:
            logging.error('msg=%s', splunk_escape(ex.message))
        except Exception:
            logging.exception('msg="Exception in main loop"')

        time.sleep(float(snmpEkinops.snmpinterval()))
Exemplo n.º 6
0
    def get_config_indexes(self, cm_stats):
        """
        Get the config indexes for all policy & object indexes.

        indexes is a list of tuples of (policy_index, object_index)
        :param cm_stats: ClassMap Statistics
        :return:
        {
            ('policy_index', 'object_index'): 'config_index'
        }
        """
        try:
            oids = [str('1.3.6.1.4.1.9.9.166.1.5.1.1.2.' + cs.pol_ind + '.' + cs.obj_ind) for cs in cm_stats]
            res = query_oids(self.cmd_gen, runner.security_object(), runner.transport(), oids)
            logging.debug("config_index_oids=" + str(res))
            # output looks like
            # iso.3.6.1.4.1.9.9.166.1.5.1.1.2.836311857.601391474 = Gauge32: 1965376995

            config_indexes = {}
            for name, val in res:
                if not isinstance(val, NoSuchInstance):
                    policy_index = str(name[-2])
                    object_index = str(name[-1])
                    value = str(val.prettyPrint())
                    config_indexes[(policy_index, object_index)] = value
            return config_indexes
        except SnmpException as ex:
            logging.error('error=%s msg=%s method=get_config_indexes', splunk_escape(ex.error_type),
                          splunk_escape(ex.msg))
            raise HandledSnmpException
Exemplo n.º 7
0
def do_run():
    snmpEkinops.read_config()
    snmputils.set_logger_format(name=snmpEkinops.name())

    cmd_gen = snmputils.get_cmd_gen()

    while True:
        try:
            for interface in snmpEkinops.interfaces():
                interfaceId = interface.split(':')[0]
                cardType = interface.split(':')[1]
                ipAddr = socket.gethostbyname(snmpEkinops.destination())

                # Get the card number
                oid_args = [mgnt2Position + "." + interfaceId]
                logging.debug('get card number, oid_args=%s', oid_args)
                var_binds = snmputils.query_ekinops_card(cmd_gen, snmpEkinops.security_object(), snmpEkinops.transport(),oid_args)
                card_number = var_binds[0][1].prettyPrint()

                # Set card to read from
                oid_args = [str(mgnt2GigmSelectedBoard), rfc1902.Integer(card_number)]
                logging.debug('set card number, oid_args=%s', oid_args)
                snmp_result = cmd_gen.setCmd(snmpEkinops.security_object(), snmpEkinops.transport(), oid_args)

                # Create array of oids to read
                oid_args = [interface_mibs[e] + ".0" for e in managed_oids[cardType]]
                logging.debug('queryOids, oid_args=%s', oid_args)
                var_binds = snmputils.query_oids(cmd_gen, snmpEkinops.security_object(), snmpEkinops.transport(), oid_args)
                logging.debug('var_binds=%s', var_binds)

                interface_attrs = {}
                interface_attrs['card'] = card_number
                interface_attrs['interfaceIdx'] = interfaceId
                interface_attrs['cardType'] = cardType
                interface_attrs['ipAddr'] = ipAddr

                handle_output(var_binds, snmpEkinops.destination(), interface_attrs)

        except SnmpException as ex:
            logging.error('error=%s msg=%s interfaces=%s', splunk_escape(ex.error_type),
                          splunk_escape(ex.msg), splunk_escape(','.join(snmpEkinops.interfaces())))
        except PySnmpError as ex:
            logging.error('msg=%s', splunk_escape(ex.message))
        except Exception:
            logging.exception('msg="Exception in main loop"')

        time.sleep(float(snmpEkinops.snmpinterval()))
Exemplo n.º 8
0
 def get_policy_interface_indexes(self):
     """
     Get the policy indexes for all configured interfaces
     :return: A dictionary that has the policy index as the key and a tuple of (interface, direction) as the value
     {
         'policyIndex': ('interface', 'direction'),
         '836311857': ('324', 'in'),
         '836311858': ('324', 'out')
     }
     """
     try:
         oids = [str('1.3.6.1.4.1.9.9.166.1.2.1.1.1.' + i + '.' + direction) for i in self.interfaces() for direction in ['1', '2']]
         table = query_oids(self.cmd_gen, runner.security_object(), runner.transport(), oids)
         logging.debug('policy_interface_indexes=%s', table)
         # output looks like
         # iso.3.6.1.4.1.9.9.166.1.2.1.1.1.324.1 = Gauge32: 836311857 <- policy index
         # iso.3.6.1.4.1.9.9.166.1.2.1.1.1.324.2 = Gauge32: 836311858
         return extract_policy_interface_indexes(table)
     except SnmpException as ex:
         logging.error('error=%s msg=%s interfaces=%s', splunk_escape(ex.error_type),
                       splunk_escape(ex.msg), splunk_escape(','.join(self.interfaces())))
         raise HandledSnmpException
Exemplo n.º 9
0
def do_run():
    runner.read_config()
    snmputils.set_logger_format(name=runner.name())

    cmd_gen = snmputils.get_cmd_gen()

    while True:
        try:
            for operation in runner.operations():
                try:
                    oid_args = [str(b + '.' + operation) for b in symbols]
                    var_binds = snmputils.query_oids(cmd_gen, runner.security_object(), runner.transport(), oid_args)
                    handle_output(var_binds, runner.destination(), operation)
                except SnmpException as ex:
                    logging.error('error=%s msg=%s operation=%s', splunk_escape(ex.error_type),
                                  splunk_escape(ex.msg), operation)
                    break
        except PySnmpError as ex:
            logging.error('msg=%s', splunk_escape(ex.message))
        except Exception:
            logging.exception("Exception with getCmd to %s:%s" % (runner.destination(), runner.port))

        time.sleep(float(runner.snmpinterval()))