Ejemplo n.º 1
0
 def check_parquet(self, filename):
     stderr = subprocess.PIPE
     if self.verbose > 2:
         stderr = None
     if not which("parquet-cat"):
         die("parquet-cat not found in $PATH")
     if subprocess.call(["parquet-cat", filename], stdout=subprocess.PIPE, stderr=stderr, shell=False) == 0:
         print(self.valid_parquet_msg)
     else:
         die(self.invalid_parquet_msg)
Ejemplo n.º 2
0
 def enable_commands(self):
     if self.event in ['query', 'event']:
         cmd = None
         if self.event == 'query':
             cmd = self.query_name
         elif self.event == 'user':
             cmd = self.user_event
         # if the first part of the query is found in $PATH then assume it's a command that was passed
         if which(cmd.split()[0]):
             self.command = cmd
Ejemplo n.º 3
0
 def enable_commands(self):
     if self.event in ['query', 'event']:
         cmd = None
         if self.event == 'query':
             cmd = self.query_name
         elif self.event == 'user':
             cmd = self.user_event
         # if the first part of the query is found in $PATH then assume it's a command that was passed
         if which(cmd.split()[0]):
             self.command = cmd
 def check_parquet(self, filename):
     stderr = subprocess.PIPE
     if self.verbose > 2:
         stderr = None
     if not which('parquet-cat'):
         die('parquet-cat not found in $PATH')
     if subprocess.call(['parquet-cat', filename], stdout=subprocess.PIPE, stderr=stderr, shell=False) == 0:
     # not very tolerant, get exception with this error:
     # pyarrow.lib.ArrowNotImplementedError: No support for reading columns of type list<array: int32 not null>
     #if pq.read_table(filename):
         print(self.valid_parquet_msg)
     else:
         die(self.invalid_parquet_msg)
Ejemplo n.º 5
0
 def construct_msg(self):
     # user = os.getenv('USER', '').strip()
     user = getpass.getuser()
     if not isUser(user):
         # print("invalid user '%s' determined from environment variable $USER, failed regex validation" % user)
         print(
             "invalid user '%s' returned by getpass.getuser(), failed regex validation"
             % user)
         sys.exit(ERRORS['CRITICAL'])
     user = self.case_user(user)
     msg = 'Welcome %s - ' % user
     last = ''
     if which("last"):
         _ = os.popen('last -100')
         _.readline()
         re_skip = re.compile(r'^(?:reboot|wtmp)|^\s*$')
         last = ''
         for line in _:
             last = line.rstrip('\n')
             if re_skip.match(last):
                 last = ''
                 continue
             break
         _.close()
     else:
         printerr(
             "WARNING: 'last' command not found, will not be able to get last login information"
         )
     if last:
         msg += 'last login was '
         last_user = re.sub(r'\s+.*$', '', last)
         if last_user == 'root':
             last_user = '******'
         # strip up to "Day Mon NN" ie "%a %b %e ..."
         (last, num_replacements) = re.subn(r'.*(\w{3}\s+\w{3}\s+\d+)',
                                            r'\g<1>', last)
         if not num_replacements:
             print('failed to find the date format in the last log')
             sys.exit(ERRORS['CRITICAL'])
         last = re.sub(' *$', '', last)
         if last_user == 'ROOT':
             msg += 'ROOT'
         elif last_user.lower() == user.lower():
             msg += 'by you'
         else:
             msg += 'by %s' % last_user
         msg += ' => %s' % last
     else:
         msg += 'no last login information available!'
     return msg
Ejemplo n.º 6
0
 def construct_msg(self): # pylint: disable=no-self-use
     # user = os.getenv('USER', '').strip()
     user = getpass.getuser()
     if not isUser(user):
         # print("invalid user '%s' determined from environment variable $USER, failed regex validation" % user)
         print("invalid user '%s' returned by getpass.getuser(), failed regex validation" % user)
         sys.exit(ERRORS['CRITICAL'])
     user = self.case_user(user)
     msg = 'Welcome %s - ' % user
     last = ''
     if which("last"):
         _ = os.popen('last -100')
         _.readline()
         re_skip = re.compile(r'^(?:reboot|wtmp)|^\s*$')
         last = ''
         for line in _:
             last = line.rstrip('\n')
             if re_skip.match(last):
                 last = ''
                 continue
             break
         _.close()
     else:
         printerr("WARNING: 'last' command not found, will not be able to get last login information")
     if last:
         msg += 'last login was '
         last_user = re.sub(r'\s+.*$', '', last)
         if last_user == 'root':
             last_user = '******'
         # strip up to "Day Mon NN" ie "%a %b %e ..."
         (last, num_replacements) = re.subn(r'.*(\w{3}\s+\w{3}\s+\d+)', r'\g<1>', last)
         if not num_replacements:
             print('failed to find the date format in the last log')
             sys.exit(ERRORS['CRITICAL'])
         last = re.sub(' *$', '', last)
         if last_user == 'ROOT':
             msg += 'ROOT'
         elif last_user.lower() == user.lower():
             msg += 'by you'
         else:
             msg += 'by %s' % last_user
         msg += ' => %s' % last
     else:
         msg += 'no last login information available!'
     return msg
 def run(self):
     if not which('docker'):
         raise UnknownError("'docker' command not found in $PATH")
     process = subprocess.Popen(['docker', 'images', '{repo}'.format(repo=self.docker_image)],
                                stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE)
     (stdout, stderr) = process.communicate()
     exitcode = process.returncode
     log.debug('stdout:\n%s', stdout)
     log.debug('stderr:\n%s', stderr)
     log.debug('exitcode: %s', exitcode)
     if stderr:
         raise UnknownError(stderr)
     if exitcode != 0:
         raise UnknownError("exit code returned was '{0}': {1} {2}".format(exitcode, stdout, stderr))
     if not stdout:
         raise UnknownError('no output from docker images command!')
     self.parse(stdout)
Ejemplo n.º 8
0
 def run(self):
     if not which('docker'):
         raise UnknownError("'docker' command not found in $PATH")
     process = subprocess.Popen(['docker', 'images', '{repo}'.format(repo=self.docker_image)],
                                stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE)
     (stdout, stderr) = process.communicate()
     exitcode = process.returncode
     log.debug('stdout:\n%s', stdout)
     log.debug('stderr:\n%s', stderr)
     log.debug('exitcode: %s', exitcode)
     if stderr:
         raise UnknownError(stderr)
     if exitcode != 0:
         raise UnknownError("exit code returned was '{0}': {1} {2}".format(exitcode, stdout, stderr))
     if not stdout:
         raise UnknownError('no output from docker images command!')
     self.parse(stdout)
Ejemplo n.º 9
0
 def process_args(self):
     self.skip_errors = self.get_opt('continue')
     self.quick = self.get_opt('quick')
     self.regex = self.get_opt('regex')
     args = uniq_list_ordered(self.args)
     if not args:
         self.usage('no files/dirs specified')
     log_option('files/dirs', args)
     log_option('regex', self.regex)
     log_option('quick', self.quick)
     log_option('continue-on-error', self.skip_errors)
     if self.regex:
         validate_regex(self.regex)
         self.regex = re.compile(self.regex, re.I)
     if self.quick:
         self.validate_cmd = 'ffprobe'
     if not which(self.validate_cmd.split()[0]):
         die('ffmpeg / ffprobe not found in $PATH')
     return args
Ejemplo n.º 10
0
 def process_args(self):
     self.skip_errors = self.get_opt('continue')
     self.quick = self.get_opt('quick')
     self.regex = self.get_opt('regex')
     args = uniq_list_ordered(self.args)
     if not args:
         self.usage('no files/dirs specified')
     log_option('files/dirs', args)
     log_option('regex', self.regex)
     log_option('quick', self.quick)
     log_option('continue-on-error', self.skip_errors)
     if self.regex:
         validate_regex(self.regex)
         self.regex = re.compile(self.regex, re.I)
     if self.quick:
         self.validate_cmd = 'ffprobe'
     if not which(self.validate_cmd.split()[0]):
         die('ffmpeg / ffprobe not found in $PATH')
     return args
Ejemplo n.º 11
0
 def cmd(command):
     log.debug('command: %s', command)
     command_binary = command.split()[0]
     if not which(command_binary):
         die("command '{command}' not found in $PATH".format(command=command_binary))
     try:
         process = subprocess.Popen(command.split(),
                                    stdin=subprocess.PIPE,
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.STDOUT)
         (stdout, _) = process.communicate()
         process.wait()
         log.debug('returncode: %s', process.returncode)
         log.debug('output: %s\n', stdout)
         return(stdout, process.returncode)
     except subprocess.CalledProcessError as _:
         log.debug('CalledProcessError Exception!')
         log.debug('returncode: %s', _.returncode)
         log.debug('output: %s\n', _.output)
         return(_.output, _.returncode)
Ejemplo n.º 12
0
 def cmd(command):
     log.debug('command: %s', command)
     command_binary = command.split()[0]
     if not which(command_binary):
         die("command '{command}' not found in $PATH".format(
             command=command_binary))
     try:
         process = subprocess.Popen(command.split(),
                                    stdin=subprocess.PIPE,
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.STDOUT)
         (stdout, _) = process.communicate()
         process.wait()
         log.debug('returncode: %s', process.returncode)
         log.debug('output: %s\n', stdout)
         return (stdout, process.returncode)
     except subprocess.CalledProcessError as _:
         log.debug('CalledProcessError Exception!')
         log.debug('returncode: %s', _.returncode)
         log.debug('output: %s\n', _.output)
         return (_.output, _.returncode)