def check(self):
        sudo = find_binary(SUDO)
        if self.use_sudo:
            if not sudo:
                self.error('can\'t locate "{0}" binary'.format(SUDO))
                return False
            err = self.execute([sudo, '-n', '-v'], True)
            if err:
                self.error(' '.join(err))
                return False

        arcconf = find_binary(ARCCONF)
        if not arcconf:
            self.error('can\'t locate "{0}" binary'.format(ARCCONF))
            return False

        if self.use_sudo:
            self.arcconf = SudoArcconf(arcconf, sudo)
        else:
            self.arcconf = Arcconf(arcconf)

        lds = self.get_lds()
        if not lds:
            return False

        self.debug('discovered logical devices ids: {0}'.format([ld.id for ld in lds]))

        pds = self.get_pds()
        if not pds:
            return False

        self.debug('discovered physical devices ids: {0}'.format([pd.id for pd in pds]))

        self.update_charts(lds, pds)
        return True
Example #2
0
    def check(self):
        sudo_binary, smbstatus_binary = find_binary('sudo'), find_binary('smbstatus')

        if not (sudo_binary and smbstatus_binary):
            self.error("Can\'t locate 'sudo' or 'smbstatus' binary")
            return False

        self.command = [sudo_binary, '-v']
        err = self._get_raw_data(stderr=True)
        if err:
            self.error(''.join(err))
            return False

        self.command = ' '.join([sudo_binary, '-n', smbstatus_binary, '-P'])

        return ExecutableService.check(self)
Example #3
0
 def __init__(self, configuration=None, name=None):
     SimpleService.__init__(self, configuration=configuration, name=name)
     self.order = ORDER
     self.definitions = CHARTS
     self.host = self.configuration.get('host', DEFAULT_HOST)
     self.port = self.configuration.get('port', DEFAULT_PORT)
     self.secret = self.configuration.get('secret')
     self.do_acct = self.configuration.get('acct', DEFAULT_DO_ACCT)
     self.do_proxy_auth = self.configuration.get('proxy_auth', DEFAULT_DO_PROXY_AUTH)
     self.do_proxy_acct = self.configuration.get('proxy_acct', DEFAULT_DO_PROXY_ACCT)
     self.echo = find_binary('echo')
     self.radclient = find_binary('radclient')
     self.sub_echo = [self.echo, RADIUS_MSG]
     self.sub_radclient = radclient_status(
         self.radclient, RADCLIENT_RETRIES, RADCLIENT_TIMEOUT, self.host, self.port, self.secret,
     )
 def __init__(self, configuration=None, name=None):
     SimpleService.__init__(self, configuration=configuration, name=name)
     self.definitions = CHARTS
     self.host = self.configuration.get('host', 'localhost')
     self.port = self.configuration.get('port', '18121')
     self.secret = self.configuration.get('secret')
     self.acct = self.configuration.get('acct', False)
     self.proxy_auth = self.configuration.get('proxy_auth', False)
     self.proxy_acct = self.configuration.get('proxy_acct', False)
     chart_choice = [True, bool(self.acct), bool(self.proxy_auth), bool(self.proxy_acct)]
     self.order = [chart for chart, choice in zip(ORDER, chart_choice) if choice]
     self.echo = find_binary('echo')
     self.radclient = find_binary('radclient')
     self.sub_echo = [self.echo, RADIUS_MSG]
     self.sub_radclient = [self.radclient, '-r', '1', '-t', '1', '-x',
                           ':'.join([self.host, self.port]), 'status', self.secret]
Example #5
0
 def __init__(self, configuration=None, name=None):
     ExecutableService.__init__(self, configuration=configuration, name=name)
     self.order = ORDER
     self.definitions = CHARTS
     varnishstat = find_binary('varnishstat')
     self.command = [varnishstat, '-1'] if varnishstat else None
     self.parser = Parser()
Example #6
0
 def __init__(self, configuration=None, name=None):
     SimpleService.__init__(self, configuration=configuration, name=name)
     self.varnish = find_binary('varnishstat')
     self.order = ORDER[:]
     self.definitions = dict(CHARTS)
     self.regex_all = re.compile(r'([A-Z]+\.)?([\d\w_.]+)\s+(\d+)')
     self.regex_backend = None
     self.cache_prev = list()
     self.backend_list = list()
 def __init__(self, configuration=None, name=None):
     SimpleService.__init__(self, configuration=configuration, name=name)
     self.order = ORDER
     self.definitions = CHARTS
     self.named_stats_path = self.configuration.get('named_stats_path', '/var/log/bind/named.stats')
     self.rndc = find_binary('rndc')
     self.data = dict(nms_requests=0, nms_responses=0, nms_failure=0, nms_auth=0,
                      nms_non_auth=0, nms_nxrrset=0, nms_success=0, nms_nxdomain=0,
                      nms_recursion=0, nms_duplicate=0, nms_rejected_queries=0,
                      nms_dropped_queries=0)
Example #8
0
    def check(self):
        """
        Parse basic configuration, check if command is whitelisted and is returning values
        :return: <boolean>
        """
        # Preference: 1. "command" from configuration file 2. "command" from plugin (if specified)
        if 'command' in self.configuration:
            self.command = self.configuration['command']

        # "command" must be: 1.not None 2. type <str>
        if not (self.command and isinstance(self.command, str)):
            self.error('Command is not defined or command type is not <str>')
            return False

        # Split "command" into: 1. command <str> 2. options <list>
        command, opts = self.command.split()[0], self.command.split()[1:]

        # Check for "bad" symbols in options. No pipes, redirects etc.
        opts_list = ['&', '|', ';', '>', '<']
        bad_opts = set(''.join(opts)) & set(opts_list)
        if bad_opts:
            self.error("Bad command argument(s): {opts}".format(opts=bad_opts))
            return False

        # Find absolute path ('echo' => '/bin/echo')
        if '/' not in command:
            command = find_binary(command)
            if not command:
                self.error('Can\'t locate "{command}" binary'.format(
                    command=self.command))
                return False
        # Check if binary exist and executable
        else:
            if not os.access(command, os.X_OK):
                self.error(
                    '"{binary}" is not executable'.format(binary=command))
                return False

        self.command = [command] + opts if opts else [command]

        try:
            data = self._get_data()
        except Exception as error:
            self.error(
                '_get_data() failed. Command: {command}. Error: {error}'.
                format(command=self.command, error=error))
            return False

        if isinstance(data, dict) and data:
            return True
        self.error('Command "{command}" returned no data'.format(
            command=self.command))
        return False
Example #9
0
    def check(self):
        sudo_binary = find_binary(SUDO)
        if not sudo_binary:
            self.error("can't locate '{0}' binary".format(SUDO))
            return False

        smbstatus_binary = find_binary(SMBSTATUS)
        if not smbstatus_binary:
            self.error("can't locate '{0}' binary".format(SMBSTATUS))
            return False

        command = [sudo_binary, '-n', '-l', smbstatus_binary, '-P']
        smbstatus = '{0} -P'.format(smbstatus_binary)
        allowed = self._get_raw_data(command=command)
        if not (allowed and allowed[0].strip() == smbstatus):
            self.error(
                "not allowed to run sudo for command '{0}'".format(smbstatus))
            return False

        self.command = ' '.join([sudo_binary, '-n', smbstatus_binary, '-P'])
        return ExecutableService.check(self)
Example #10
0
    def create_command(self):
        varnishstat = find_binary(VARNISHSTAT)

        if not varnishstat:
            self.error("can't locate '{0}' binary or binary is not executable by user netdata".format(VARNISHSTAT))
            return False

        if self.instance_name:
            self.command = [varnishstat, '-1', '-n', self.instance_name, '-t', '1']
        else:
            self.command = [varnishstat, '-1', '-t', '1']
        return True
Example #11
0
 def __init__(self, configuration=None, name=None):
     SimpleService.__init__(self, configuration=configuration, name=name)
     self.varnish = find_binary('varnishstat')
     self.rgx_all = compile(r'([A-Z]+\.)?([\d\w_.]+)\s+(\d+)')
     # Could be
     # VBE.boot.super_backend.pipe_hdrbyte (new)
     # or
     # VBE.default2(127.0.0.2,,81).bereq_bodybytes (old)
     # Regex result: [('super_backend', 'beresp_hdrbytes', '0'), ('super_backend', 'beresp_bodybytes', '0')]
     self.rgx_bck = (
         compile(r'VBE.([\d\w_.]+)\(.*?\).(beresp[\w_]+)\s+(\d+)'),
         compile(r'VBE\.[\d\w-]+\.([\w\d_]+).(beresp[\w_]+)\s+(\d+)'))
     self.cache_prev = list()
Example #12
0
    def check(self):
        if not os.path.isfile(self.ssacli_path):
            ssacli_path = find_binary(self.ssacli_path)
            if ssacli_path:
                self.ssacli_path = ssacli_path
            else:
                self.error('Cannot locate "{}" binary'.format(
                    self.ssacli_path))
                return False

        if self.use_sudo:
            sudo = find_binary('sudo')
            if not sudo:
                self.error('Cannot locate "{}" binary'.format('sudo'))
                return False

            allowed = self._get_raw_data(
                command=[sudo, '-n', '-l', self.ssacli_path])
            if not allowed or allowed[0].strip() != os.path.realpath(
                    self.ssacli_path):
                self.error('Not allowed to run sudo for command {}'.format(
                    self.ssacli_path))
                return False

            self.cmd = [sudo, '-n']

        self.cmd.extend(
            [self.ssacli_path, 'ctrl', 'all', 'show', 'config', 'detail'])
        self.info('Command: {}'.format(self.cmd))

        adapters = self.get_adapters()

        self.info('Discovered adapters: {}'.format(
            [adapter['type'] for adapter in adapters]))
        if not adapters:
            self.error('No adapters discovered')
            return False

        return True
 def __init__(self, configuration=None, name=None):
     SimpleService.__init__(self, configuration=configuration, name=name)
     self.order = ORDER
     self.definitions = CHARTS
     self.host = self.configuration.get('host', DEFAULT_HOST)
     self.port = self.configuration.get('port', DEFAULT_PORT)
     self.secret = self.configuration.get('secret')
     self.do_acct = self.configuration.get('acct', DEFAULT_DO_ACCT)
     self.do_proxy_auth = self.configuration.get('proxy_auth',
                                                 DEFAULT_DO_PROXY_AUTH)
     self.do_proxy_acct = self.configuration.get('proxy_acct',
                                                 DEFAULT_DO_PROXY_ACCT)
     self.echo = find_binary('echo')
     self.radclient = find_binary('radclient')
     self.sub_echo = [self.echo, RADIUS_MSG]
     self.sub_radclient = radclient_status(
         self.radclient,
         RADCLIENT_RETRIES,
         RADCLIENT_TIMEOUT,
         self.host,
         self.port,
         self.secret,
     )
Example #14
0
    def check(self):
        arcconf = find_binary(ARCCONF)
        if not arcconf:
            self.error('can\'t locate "{0}" binary'.format(ARCCONF))
            return False

        sudo = find_binary(SUDO)
        if self.use_sudo:
            if not sudo:
                self.error('can\'t locate "{0}" binary'.format(SUDO))
                return False
            err = self.execute([sudo, '-n', '-v'], True)
            if err:
                self.error(' '.join(err))
                return False

        if self.use_sudo:
            self.arcconf = SudoArcconf(arcconf, sudo)
        else:
            self.arcconf = Arcconf(arcconf)

        lds = self.get_lds()
        if not lds:
            return False

        self.debug('discovered logical devices ids: {0}'.format(
            [ld.id for ld in lds]))

        pds = self.get_pds()
        if not pds:
            return False

        self.debug('discovered physical devices ids: {0}'.format(
            [pd.id for pd in pds]))

        self.update_charts(lds, pds)
        return True
Example #15
0
    def check(self):
        """
        Parse basic configuration, check if command is whitelisted and is returning values
        :return: <boolean>
        """
        # Preference: 1. "command" from configuration file 2. "command" from plugin (if specified)
        if 'command' in self.configuration:
            self.command = self.configuration['command']

        # "command" must be: 1.not None 2. type <str>
        if not (self.command and isinstance(self.command, str)):
            self.error('Command is not defined or command type is not <str>')
            return False

        # Split "command" into: 1. command <str> 2. options <list>
        command, opts = self.command.split()[0], self.command.split()[1:]

        # Check for "bad" symbols in options. No pipes, redirects etc.
        opts_list = ['&', '|', ';', '>', '<']
        bad_opts = set(''.join(opts)) & set(opts_list)
        if bad_opts:
            self.error("Bad command argument(s): {opts}".format(opts=bad_opts))
            return False

        # Find absolute path ('echo' => '/bin/echo')
        if '/' not in command:
            command = find_binary(command)
            if not command:
                self.error('Can\'t locate "{command}" binary'.format(command=self.command))
                return False
        # Check if binary exist and executable
        else:
            if not os.access(command, os.X_OK):
                self.error('"{binary}" is not executable'.format(binary=command))
                return False

        self.command = [command] + opts if opts else [command]

        try:
            data = self._get_data()
        except Exception as error:
            self.error('_get_data() failed. Command: {command}. Error: {error}'.format(command=self.command,
                                                                                       error=error))
            return False

        if isinstance(data, dict) and data:
            return True
        self.error('Command "{command}" returned no data'.format(command=self.command))
        return False
    def create_command(self):
        varnishstat = find_binary(VARNISHSTAT)

        if not varnishstat:
            self.error(
                "can't locate '{0}' binary or binary is not executable by user netdata"
                .format(VARNISHSTAT))
            return False

        if self.instance_name:
            self.command = [
                varnishstat, '-1', '-n', self.instance_name, '-t', '1'
            ]
        else:
            self.command = [varnishstat, '-1', '-t', '1']
        return True
Example #17
0
 def __init__(self, configuration=None, name=None):
     SimpleService.__init__(self, configuration=configuration, name=name)
     self.order = ORDER
     self.definitions = CHARTS
     self.named_stats_path = self.configuration.get(
         'named_stats_path', '/var/log/bind/named.stats')
     self.rndc = find_binary('rndc')
     self.data = dict(nms_requests=0,
                      nms_responses=0,
                      nms_failure=0,
                      nms_auth=0,
                      nms_non_auth=0,
                      nms_nxrrset=0,
                      nms_success=0,
                      nms_nxdomain=0,
                      nms_recursion=0,
                      nms_duplicate=0,
                      nms_rejected_queries=0,
                      nms_dropped_queries=0)
Example #18
0
    def create_command(self):
        varnishstat = find_binary(VARNISHSTAT)

        if not varnishstat:
            self.error(
                "can't locate '{0}' binary or binary is not executable by user netdata"
                .format(VARNISHSTAT))
            return False

        command = [varnishstat, '-V']
        reply = self._get_raw_data(stderr=True, command=command)
        if not reply:
            self.error(
                "no output from '{0}'. Is varnish running? Not enough privileges?"
                .format(' '.join(self.command)))
            return False

        ver = parse_varnish_version(reply)
        if not ver:
            self.error(
                "failed to parse reply from '{0}', used regex :'{1}', reply : {2}"
                .format(
                    ' '.join(command),
                    re_version.pattern,
                    reply,
                ))
            return False

        if self.instance_name:
            self.command = [varnishstat, '-1', '-n', self.instance_name]
        else:
            self.command = [varnishstat, '-1']

        if ver.major > 4:
            self.command.extend(['-t', '1'])

        self.info("varnish version: {0}, will use command: '{1}'".format(
            ver, ' '.join(self.command)))

        return True
Example #19
0
 def __init__(self):
     self.command = find_binary(NVIDIA_SMI)
     self.active_proc = None
Example #20
0
 def __init__(self):
     self.s = find_binary('sudo')
     self.m = find_binary('megacli')
     self.sudo_check = [self.s, '-n', '-v']
     self.disk_info = [self.s, '-n', self.m, '-LDPDInfo', '-aAll']
     self.battery_info = [self.s, '-n', self.m, '-AdpBbuCmd', '-a0']
Example #21
0
 def __init__(self):
     self.s = find_binary('sudo')
     self.m = find_binary('megacli')
     self.sudo_check = [self.s, '-n', '-v']
     self.disk_info = [self.s, '-n', self.m, '-LDPDInfo', '-aAll', '-NoLog']
     self.battery_info = [self.s, '-n', self.m, '-AdpBbuCmd', '-a0', '-NoLog']
Example #22
0
 def __init__(self):
     self.command = find_binary(NVIDIA_SMI)
     self.active_proc = None