def update( self, tfv: dap_update_pb2.DapUpdate.TableFieldValue ) -> dap_interface_pb2.Successfulness: r = dap_interface_pb2.Successfulness() r.success = True if tfv: row_key = (tfv.key.core, tfv.key.agent) core_ident, agent_ident = row_key field_type, field_value = ProtoHelpers.decodeAttributeValueInfoToPythonType( tfv.value) if field_type == "key-type-value_list": for k, t, v in field_value: self.table.setdefault( row_key, {})[k] = DapAttributeStore.StoredFieldValue(ft=t, fv=v) else: target_field_name = tfv.fieldname if target_field_name[0:5] != 'them.': target_field_name = 'them.' + target_field_name #self.log.info("INSERT: core={}, agent={}".format(core_ident, agent_ident)) self.table.setdefault( row_key, {} )[target_field_name] = DapAttributeStore.StoredFieldValue( ft=field_type, fv=field_value) return r
def update( self, tfv: dap_update_pb2.DapUpdate.TableFieldValue ) -> dap_interface_pb2.Successfulness: r = dap_interface_pb2.Successfulness() r.success = True if tfv: row_key = (tfv.key.core, tfv.key.agent) core_ident, agent_ident = row_key field_type, field_value = ProtoHelpers.decodeAttributeValueInfoToPythonType( tfv.value) if field_type == "key-type-value_list": row_present = row_key in self.table duplicate_inserted = False new_inserted = False for k, t, v in field_value: target = self.table.setdefault(row_key, {}) new_value = DapAttributeStore.StoredFieldValue(ft=t, fv=v) if k in target and target[k] == new_value: self.stats["fields_add_duplicate"] += 1 duplicate_inserted = True else: self.stats["fields_added"] += 1 new_inserted = True target[k] = new_value if not row_present and (not duplicate_inserted and new_inserted): self.stats["rows_added"] += 1 elif row_present and (duplicate_inserted and not new_inserted): self.stats["row_add_duplicate"] += 1 else: target_field_name = tfv.fieldname if target_field_name[0:5] != 'them.': target_field_name = 'them.' + target_field_name #self.log.info("INSERT: core={}, agent={}".format(core_ident, agent_ident)) new_value = DapAttributeStore.StoredFieldValue(ft=field_type, fv=field_value) row_present = row_key in self.table duplicate_inserted = False new_inserted = False target = self.table.setdefault(row_key, {}) if target_field_name in target and target[ target_field_name] == new_value: self.stats["fields_add_duplicate"] += 1 duplicate_inserted = True else: self.stats["fields_added"] += 1 new_inserted = True target[target_field_name] = new_value if not row_present and (not duplicate_inserted and new_inserted): self.stats["rows_added"] += 1 elif row_present and (duplicate_inserted and not new_inserted): self.stats["row_add_duplicate"] += 1 agent_parts = tfv.key.agent.decode("UTF-8").split("/") if len(agent_parts) == 2 and len(agent_parts[1]) > 0: self._service_alias_store.setdefault(agent_parts[0], []).append(tfv.key.agent) return r