Ejemplo n.º 1
0
    def register_autostart_scripts(self):
        pmdas_dir = PCP.pmGetConfig('PCP_PMDAS_DIR')
        sysconf_dir = PCP.pmGetConfig('PCP_SYSCONF_DIR')
        autostart_dirs = [
            f"{sysconf_dir}/bpftrace/autostart",
            f"{pmdas_dir}/bpftrace/autostart"
        ]

        for autostart_dir in autostart_dirs:
            self.register_autostart_scripts_from_directory(autostart_dir)
Ejemplo n.º 2
0
 def __init__(self, name, domain):
     self._name = name
     self._domain = domain
     logfile = name + '.log'
     pmdaname = 'pmda' + name
     helpfile = '%s/%s/help' % (PCP.pmGetConfig('PCP_PMDAS_DIR'), name)
     MetricDispatch.__init__(self, domain, pmdaname, logfile, helpfile)
Ejemplo n.º 3
0
Archivo: pmda.py Proyecto: tongfw/pcp
 def __init__(self, name, domain):
     self._name = name
     self._domain = domain
     logfile = name + '.log'
     pmdaname = 'pmda' + name
     helpfile = '%s/%s/help' % (PCP.pmGetConfig('PCP_PMDAS_DIR'), name)
     MetricDispatch.__init__(self, domain, pmdaname, logfile, helpfile)
Ejemplo n.º 4
0
Archivo: pmda.py Proyecto: infinera/pcp
    def register_autostart_scripts(self):
        pmdas_dir = PCP.pmGetConfig('PCP_PMDAS_DIR')
        autostart_dir = f"{pmdas_dir}/bpftrace/autostart"

        try:
            if not self.exclusive_writable_by_root(autostart_dir):
                self.logger.error(f"Austostart directory {autostart_dir} "
                                  f"must be exclusively writable by root")
                return
        except OSError as e:
            self.logger.error(f"Error accessing autostart directory: {e}")
            return

        for script_path in glob.glob(f"{autostart_dir}/*.bt"):
            try:
                if not self.exclusive_writable_by_root(script_path):
                    self.logger.error(
                        f"Skipping autostart script {script_path}: scripts "
                        f"must be exclusively writable by root")
                    continue

                with open(script_path) as f:
                    code = f.read()
            except IOError as e:
                self.logger.error(f"Error reading bpftrace script: {e}")
                continue

            self.logger.info(f"registering script from file {script_path}...")
            script = Script(code)
            script.username = pwd.getpwuid(os.getuid()).pw_name
            script.metadata.name = Path(script_path).stem
            self.register_script(script, update_ctx=False)
Ejemplo n.º 5
0
 def __init__(self, name, domain, logfile=None, helpfile=None):
     self._name = name
     self._domain = domain
     if not logfile:
         # note: logfile == "-" is special, see pmOpenLog(3).
         logfile = name + '.log'
     pmdaname = 'pmda' + name
     if not helpfile:
         helpfile = '%s/%s/help' % (PCP.pmGetConfig('PCP_PMDAS_DIR'), name)
     MetricDispatch.__init__(self, domain, pmdaname, logfile, helpfile)
Ejemplo n.º 6
0
Archivo: pmda.py Proyecto: infinera/pcp
    def parse_config(self) -> PMDAConfig:
        pmdas_dir = PCP.pmGetConfig('PCP_PMDAS_DIR')
        configfile = f"{pmdas_dir}/bpftrace/bpftrace.conf"
        configreader = configparser.ConfigParser()

        # read() will skip missing files
        configreader.read([configfile])

        config = PMDAConfig()
        # compat for PCP < 5.1.0
        if 'authentication' in configreader:
            if 'enabled' in configreader['authentication']:
                config.dynamic_scripts.auth_enabled = configreader.getboolean(
                    'authentication', 'enabled')
            if 'allowed_users' in configreader['authentication']:
                allowed_users = configreader.get('authentication',
                                                 'allowed_users')
                if allowed_users:  # ''.split(',') produces [''] in Python
                    config.dynamic_scripts.allowed_users = allowed_users.split(
                        ',')

        # current config format
        if 'bpftrace' in configreader:
            if 'bpftrace_path' in configreader['bpftrace']:
                config.bpftrace_path = configreader.get(
                    'bpftrace', 'bpftrace_path')
            if 'script_expiry_time' in configreader['bpftrace']:
                config.script_expiry_time = configreader.getint(
                    'bpftrace', 'script_expiry_time')
            if 'max_throughput' in configreader['bpftrace']:
                config.max_throughput = configreader.getint(
                    'bpftrace', 'max_throughput')

        if 'dynamic_scripts' in configreader:
            if 'enabled' in configreader['dynamic_scripts']:
                config.dynamic_scripts.enabled = configreader.getboolean(
                    'dynamic_scripts', 'enabled')
            if 'auth_enabled' in configreader['dynamic_scripts']:
                config.dynamic_scripts.auth_enabled = configreader.getboolean(
                    'dynamic_scripts', 'auth_enabled')
            if 'allowed_users' in configreader['dynamic_scripts']:
                allowed_users = configreader.get('dynamic_scripts',
                                                 'allowed_users')
                if allowed_users:  # ''.split(',') produces [''] in Python
                    config.dynamic_scripts.allowed_users = [
                        user.strip() for user in allowed_users.split(',')
                    ]
                else:
                    config.dynamic_scripts.allowed_users = []

        return config
Ejemplo n.º 7
0
    def parse_config(self) -> PMDAConfig:
        pmdas_dir = PCP.pmGetConfig('PCP_PMDAS_DIR')
        configfile = f"{pmdas_dir}/{self.name}/{self.name}.conf"
        configreader = configparser.ConfigParser()

        # read() will skip missing files
        configreader.read([configfile])

        config = PMDAConfig()
        if configreader.has_section('authentication'):
            for opt in configreader.options('authentication'):
                if opt == 'enabled':
                    config.authentication.enabled = configreader.getboolean(
                        'authentication', opt)
                elif opt == 'allowed_users':
                    allowed_users = configreader.get('authentication', opt)
                    if allowed_users:  # ''.split(',') produces [''] in Python
                        config.authentication.allowed_users = allowed_users.split(
                            ',')
                else:
                    self.logger.error(
                        f"Invalid directive '{opt}' in {configfile}, aborting."
                    )
                    sys.exit(1)
        if configreader.has_section('bpftrace'):
            for opt in configreader.options('bpftrace'):
                if opt == 'bpftrace_path':
                    config.bpftrace_path = configreader.get('bpftrace', opt)
                elif opt == 'script_expiry_time':
                    config.script_expiry_time = configreader.getint(
                        'bpftrace', opt)
                elif opt == 'max_throughput':
                    config.max_throughput = configreader.getint(
                        'bpftrace', opt)
                else:
                    self.logger.error(
                        f"Invalid directive '{opt}' in {configfile}, aborting."
                    )
                    sys.exit(1)
        return config