Example #1
0
    def _check_primary_keys_in_file(self):
        """Validate the values of the primary JSON keys in the ingest file.

        Args:
            None

        Returns:
            valid: True if valid

        """
        # Initialize key variables
        valid = True
        filepath = self.filepath

        # Parse filename for information
        if self.filepath is not None:
            if _valid_filename(filepath) is True:
                filename = os.path.basename(filepath)
                (name, _) = filename.split('.')
                (tstamp, uid, _) = name.split('_')
                timestamp = int(tstamp)

                # Double check that the UID and timestamp in the
                # filename matches that in the file.
                # Ignore invalid files as a safety measure.
                # Don't try to delete. They could be owned by some
                # one else and the daemon could crash
                if uid != self.information['uid']:
                    log_message = (
                        'UID %s in file %s does not match UID %s in filename.'
                        '') % (self.information['uid'], uid, filepath)
                    log.log2warn(1123, log_message)
                    valid = False

                # Check timestamp
                if timestamp != self.information['timestamp']:
                    log_message = (
                        'Timestamp %s in file %s does not match timestamp '
                        '%s in filename.'
                        '') % (
                            self.information['timestamp'],
                            timestamp, filepath)
                    log.log2warn(1111, log_message)
                    valid = False

                # Check timestamp validity
                if jm_general.validate_timestamp(timestamp) is False:
                    log_message = (
                        'Timestamp %s in file %s is not normalized'
                        '') % (self.information['timestamp'], filepath)
                    log.log2warn(1112, log_message)
                    valid = False
            else:
                valid = False

        # Return
        return valid
Example #2
0
    def check_meta(self):
        """Method initializing the class.

        Args:
            None

        Returns:
            valid: True if valid

        """
        # Initialize key variables
        valid = True
        agent_meta_keys = ['timestamp', 'uid', 'agent', 'hostname']

        # Verify universal parameters from file
        for key in agent_meta_keys:
            if key not in self.information:
                valid = False

        # Get agent name for future reporting
        if valid is True:
            # Timestamp must be an integer
            try:
                int(self.information['timestamp'])
            except:
                valid = False

            # Parse filename for information
            if self.filename is not None:
                (name, _) = self.filename.split('.')
                (tstamp, uid) = name.split('_')
                timestamp = int(tstamp)

                # Double check that the UID and timestamp in the
                # filename matches that in the file.
                # Ignore invalid files as a safety measure.
                # Don't try to delete. They could be owned by some
                # one else and the daemon could crash
                if uid != self.information['uid']:
                    valid = False
                if timestamp != self.information['timestamp']:
                    valid = False
                if jm_general.validate_timestamp(timestamp) is False:
                    valid = False

        # Return
        return valid