def update(self, processProxy): self._config = processProxy self._compiled_regex = re.compile(self._config.regex) # Set up a regex for comparing the process name: # _config.name contains the MD5'd args appended to the process name, # with the whole thing prepId'd. We call prepId on the _name_only in # order to strip trailing WS and underscores, which were not stripped # originally due to the appended MD5 hash. result = self._config.name.rsplit(' ', 1) self._name_only = globalPrepId(result[0]) self._compiled_name_regex = re.compile('(.?)' + re.escape(self._name_only) + '$') self.digest = EMPTY_MD5_DIGEST if not self._config.ignoreParameters: # The modeler plugin computes the MD5 hash of the args, # and then tosses that into the name of the process if len(result) == 2 and result[1] != '': self.digest = result[1]
def prepId(self, id, subchar='_'): """ Clean out an id of illegal characters. @type id: string @param subchar: Character to be substituted with illegal characters @type subchar: string @rtype: string >>> dmd.Devices.prepId('ab^*cd') 'ab__cd' >>> dmd.Devices.prepId('ab^*cd', subchar='Z') 'abZZcd' >>> dmd.Devices.prepId('/boot') 'boot' >>> dmd.Devices.prepId('/') '-' >>> dmd.Devices.prepId(' mydev ') 'mydev' """ return globalPrepId(id, subchar)
def match(self, name, args, useName=True, useMd5Digest=True): """ Perform exact comparisons on the process names. @parameter name: name of a process to compare @type name: string @parameter args: argument list of the process @type args: string @parameter useMd5Digest: ignore true result if MD5 doesn't match the process name? @type useMd5Digest: boolean @return: does the name match this process's info? @rtype: Boolean """ if self._config.name is None: return False # SNMP agents return a 'flexible' number of characters, # so exact matching isn't always reliable. processName = ('%s %s' % (name, args or '')).strip() # Make the comparison result = self._compiled_regex.search(processName) is not None # We can a match, but it might not be for us if result and useMd5Digest: # Compare this arg list against the digest of this proc digest = md5(args).hexdigest() if self.digest and digest != self.digest: result = False if result and useName: cleanNameOnly = globalPrepId(name) nameMatch = self._compiled_name_regex.search(cleanNameOnly) if not nameMatch or nameMatch.group(1) not in ('', '_'): log.debug("Discarding match based on name mismatch: %s %s", cleanNameOnly, self._name_only) result = False return result
def prepId(self, id, subchar='_'): return globalPrepId(id, subchar)
def prepId(self, id, subchar='_'): """Return the global prep ID """ # TODO: document what this means and why we care return globalPrepId(id, subchar)