def _format_data_into_dictionary(self): # Add <field>: 'unknown' when filter field is not within the response. for result in self._data: for field in self.filter_fields['fields']: if field not in result.keys(): result[field] = 'unknown' fields_to_nest, non_nested = get_fields_to_nest( self.fields.keys(), ['os'], '.') # compute 'status' field, format id with zero padding and remove non-user-requested fields. # Also remove, extra fields (internal key and registration IP) selected_fields = self.select - self.extra_fields if self.remove_extra_fields else self.select aux = list() for item in self._data: aux_dict = dict() for key, value in item.items(): if key in selected_fields: aux_dict[key] = format_fields(key, value) aux.append(aux_dict) self._data = aux self._data = [ plain_dict_to_nested_dict(d, fields_to_nest, non_nested, ['os'], '.') for d in self._data ] return WazuhDBQuery._format_data_into_dictionary(self)
def _format_data_into_dictionary(self): if self.nested: fields_to_nest, non_nested = get_fields_to_nest(self.fields.keys(), self.nested_fields, '.') self._data = [plain_dict_to_nested_dict(d, fields_to_nest, non_nested, self.nested_fields, '.') for d in self._data] return super()._format_data_into_dictionary() if self.array else next(iter(self._data), {})
def _format_data_into_dictionary(self): fields_to_nest, non_nested = get_fields_to_nest( self.fields.keys(), ['os'], '.') # compute 'status' field, format id with zero padding and remove non-user-requested fields. # Also remove, extra fields (internal key and registration IP) selected_fields = self.select - self.extra_fields if self.remove_extra_fields else self.select selected_fields |= self.min_select_fields aux = list() for item in self._data: # As this is a timestamp, we remove it when its value is 0 if item.get("disconnection_time") == 0: del item["disconnection_time"] aux_dict = dict() for key, value in item.items(): if key in selected_fields: aux_dict[key] = format_fields(key, value) aux.append(aux_dict) self._data = aux self._data = [ plain_dict_to_nested_dict(d, fields_to_nest, non_nested, ['os'], '.') for d in self._data ] return super()._format_data_into_dictionary()
def _format_data_into_dictionary(self): def format_fields(field_name, value): if field_name == 'mtime' or field_name == 'date': return datetime.utcfromtimestamp(value) elif field_name == 'end' or field_name == 'start': return None if not value else datetime.utcfromtimestamp(value) elif field_name == 'perm': try: return loads(value) except JSONDecodeError: return value else: return value self._data = [{ key: format_fields(key, value) for key, value in item.items() } for item in self._data] if self.nested: fields_to_nest, non_nested = get_fields_to_nest( self.fields.keys(), self.nested_fields, '.') self._data = [ plain_dict_to_nested_dict(d, fields_to_nest, non_nested, self.nested_fields, '.') for d in self._data ] return super()._format_data_into_dictionary()