def _add_new_channel(self, channel_name):
        '''
        Callback for newly registered channels.
        We check if they should be tracked and if so, add them.
        '''
        self._logger.debug ("New channel available: %s" % channel_name)

        channel_list = self._sensor_channel_list_to_subscribe_to_setting
        # channel_list != Node: mandatory setting
        
        # search first for exact match
        self._logger.debug ("Checking if channel matches one of %s" % str(channel_list))
        if (channel_name in channel_list):
            self._logger.debug('Subscribing to channel: %s' % channel_name)
            self._subscribe(channel_name)
            
            return
            # NOT REACHED
        else:
            # check for wildcards
            wild_list = [x for x in channel_list if (x.find('*') != -1) or (x.find('?') != -1)]
            for i in wild_list:
                if wild_match(i, channel_name):
                    self._logger.debug('Channel name matches pattern %s.' % i)
                    self._logger.debug('Subscribing to channel %s.' % channel_name)
                    self._subscribe(channel_name)

                    return
                    # NOT REACHED
                    
            
        # otherwise, ignore the new channel
        self._logger.debug('Channel %s not matched in %s.' % (channel_name, str(channel_list)))
Beispiel #2
0
    def _get_tracer(self, name):
        '''
        Use tracing.get_tracer(name) for grabbing Tracer objects
        outside of this model.

        If a tracer with 'name' does not exist, the list of filters is
        checked and applied.

        This means that special tracers (like the scheduler's)
        can still have filter rules written for them, because
        the filter registry is build before any other part of
        the system comes up.
        '''
        if not name in self.__tracer_registry:

            # check all potential filters for a match
            filters = []

            for i, j in self._filter_pairs:
                if wild_match(i, name):
                    filters.append(j)

            self.__tracer_registry[name] = \
                self._make_tracer(name, filters or None)

        return self.__tracer_registry[name]
Beispiel #3
0
    def _get_tracer(self, name):
        '''
        Use tracing.get_tracer(name) for grabbing Tracer objects
        outside of this model.

        If a tracer with 'name' does not exist, the list of filters is
        checked and applied.

        This means that special tracers (like the scheduler's)
        can still have filter rules written for them, because
        the filter registry is build before any other part of
        the system comes up.
        '''
        if not name in self.__tracer_registry:

            # check all potential filters for a match
            filters = []

            for i, j in self._filter_pairs:
                if wild_match(i, name):
                    filters.append(j)

            self.__tracer_registry[name] = \
                self._make_tracer(name, filters or None)

        return self.__tracer_registry[name]
Beispiel #4
0
    def start(self):
        """
        This procedure processes that match the pattern, then subscribes
        to those channels to continue processing upon updates.
        """
        self.__tracer.info("Officially starting device")
        patt = SettingsBase.get_setting(self, "channel_pattern")
        # Initially process each channel. Relying solely on the callback
        # does not work because some channels (such as the ones from InfoDevice)
        # may never update beyond their initial setting.
        for channel_name in self.channel_database.channel_list():
            if wild_match(patt, channel_name):
                channel = self.channel_database.channel_get(channel_name)
                self.process_channel(channel)
        # Now that the CSVDevice has created the new channels, keep them
        # updated through subscription.
        self.anon[patt] = wild_subscribe(self.core, patt, self.process_channel)
        self.__tracer.info("Subscribed to all of the relevant channels")

        return True
    def _add_new_channel(self, channel):
        '''
        Callback for newly registered channels.

        We check if they should be tracked and if so, add them.
        '''

        channel_list = SettingsBase.get_setting(self, "channels")

        if (len(channel_list) == 0 or channel in channel_list) and \
               channel not in self.channel_blacklist:
            TRACER.debug('Subscribed to channel %s.' % (channel))
            self._subscribe(channel)
        else:
            # check for wildcards
            wild_list = [x for x in channel_list if \
                         x.find('*') + x.find('?') > -2]
            for i in wild_list:
                if wild_match(i, channel) and \
                       channel not in self.channel_blacklist:
                    TRACER.debug('Subscribed to channel %s.' % (channel))
                    self._subscribe(channel)
                    break
Beispiel #6
0
def _parse_msg_block(block):
    return lambda x: wild_match(block, x)
Beispiel #7
0
def _parse_msg_block(block):
    return lambda x: wild_match(block, x)
    def __match_filter(self, channel):
        """\
            Given a full channel name, determine whether any of our
            patterns/filters matches against it.
            Returns the list of matched filters.
        """
        current_time = digitime.time()

        filters = []
        for update_type in ["updates", "alarms"]:

            # Get our updates and alarms list.
            #
            # Because of the way DIA requires defining a list in its
            # configuration file, the get_setting() call below will first
            # return this value in a dictionary with the actual updates and
            # alarms list stored under the key name of 'instance_list'.
            entry_list = SettingsBase.get_setting(self, update_type)

            # It's possible the user doesn't have any of the given type set up.
            # This is fine, and we should just continue to the next type.
            if len(entry_list) == 0:
                continue

            try:
                entry_list = entry_list['instance_list']
            except Exception, e:
                self.__tracer.error("Exception trying to get instance_list: %s", \
                       str(e))
                continue

            for entry in entry_list:

                if 'settings' not in entry or entry['settings'] == None:
                    continue

                settings = entry['settings']
                if 'filter' in settings:

                    # If this filter matches something we care about,
                    # add it to our list.
                    if wild_match(settings['filter'], channel) == True:
                        self.__tracer.info("Match (%s) Filter of %s and DIA channel name of %s", \
                                    update_type, settings['filter'], channel)
                        if update_type == "updates":
                            data = dict(type=update_type,
                                        filter=settings['filter'],
                                        clients=settings['clients'],
                                        interval=settings['interval'],
                                        condition=None,
                                        synched=False,
                                        total_sent=0,
                                        last_sent=current_time)
                        else:
                            data = dict(type=update_type,
                                        filter=settings['filter'],
                                        clients=settings['clients'],
                                        interval=0,
                                        condition=settings['condition'],
                                        synched=False,
                                        total_sent=0,
                                        last_sent=0.0)

                        filters.append(data)
    def __match_filter(self, channel):
        """\
            Given a full channel name, determine whether any of our
            patterns/filters matches against it.
            Returns the list of matched filters.
        """
        current_time = time.time()

        filters = []
        for update_type in [ "updates", "alarms" ]:

            # Get our updates and alarms list.
            #
            # Because of the way Dia requires defining a list in its
            # configuration file, the get_setting() call below will first
            # return this value in a dictionary with the actual updates and
            # alarms list stored under the key name of 'instance_list'.
            entry_list = SettingsBase.get_setting(self, update_type)

            # It's possible the user doesn't have any of the given type set up.
            # This is fine, and we should just continue to the next type.
            if len(entry_list) == 0:
                continue

            try:
                entry_list = entry_list['instance_list']
            except Exception, e:
                self.__tracer.error("Exception trying to get instance_list: %s", \
                       str(e))
                continue

            for entry in entry_list:

                if 'settings' not in entry or entry['settings'] == None:
                    continue

                settings = entry['settings']
                if 'filter' in settings:

                    # If this filter matches something we care about,
                    # add it to our list.
                    if wild_match(settings['filter'], channel) == True:
                        self.__tracer.info("Match (%s) Filter of %s and Dia channel name of %s", \
                                    update_type, settings['filter'], channel)
                        if update_type == "updates":
                            data = dict(type           = update_type,
                                        filter         = settings['filter'],
                                        clients        = settings['clients'],
                                        interval       = settings['interval'],
                                        condition      = None,
                                        synched        = False,
                                        total_sent     = 0,
                                        last_sent      = current_time)
                        else:
                            data = dict(type           = update_type,
                                        filter         = settings['filter'],
                                        clients        = settings['clients'],
                                        interval       = 0,
                                        condition      = settings['condition'],
                                        synched        = False,
                                        total_sent     = 0,
                                        last_sent       = 0.0)

                        filters.append(data)