/usr/lib/python2.7/dist-packages/carbon/relayrules.py is in graphite-carbon 0.9.15-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60  | import re
from carbon.conf import OrderedConfigParser
from carbon.util import parseDestinations
from carbon.exceptions import CarbonConfigException
class RelayRule:
  def __init__(self, condition, destinations, continue_matching=False):
    self.condition = condition
    self.destinations = destinations
    self.continue_matching = continue_matching
  def matches(self, metric):
    return bool( self.condition(metric) )
def loadRelayRules(path):
  rules = []
  parser = OrderedConfigParser()
  if not parser.read(path):
    raise CarbonConfigException("Could not read rules file %s" % path)
  defaultRule = None
  for section in parser.sections():
    if not parser.has_option(section, 'destinations'):
      raise CarbonConfigException("Rules file %s section %s does not define a "
                       "'destinations' list" % (path, section))
    destination_strings = parser.get(section, 'destinations').split(',')
    destinations = parseDestinations(destination_strings)
    if parser.has_option(section, 'pattern'):
      if parser.has_option(section, 'default'):
        raise CarbonConfigException("Section %s contains both 'pattern' and "
                        "'default'. You must use one or the other." % section)
      pattern = parser.get(section, 'pattern')
      regex = re.compile(pattern, re.I)
      continue_matching = False
      if parser.has_option(section, 'continue'):
        continue_matching = parser.getboolean(section, 'continue')
      rule = RelayRule(condition=regex.search, destinations=destinations, continue_matching=continue_matching)
      rules.append(rule)
      continue
    if parser.has_option(section, 'default'):
      if not parser.getboolean(section, 'default'):
        continue # just ignore default = false
      if defaultRule:
        raise CarbonConfigException("Only one default rule can be specified")
      defaultRule = RelayRule(condition=lambda metric: True,
                              destinations=destinations)
  if not defaultRule:
    raise CarbonConfigException("No default rule defined. You must specify exactly one "
                    "rule with 'default = true' instead of a pattern.")
  rules.append(defaultRule)
  return rules
 |