@@ -81,6 +81,7 @@ Storage::Storage(const ipx_ctx_t *ctx, const struct cfg_format &fmt)
8181 if (m_format.split_biflow ) {
8282 m_flags |= FDS_CD2J_REVERSE_SKIP;
8383 }
84+
8485}
8586
8687Storage::~Storage ()
@@ -149,6 +150,9 @@ Storage::records_store(ipx_msg_ipfix_t *msg, const fds_iemgr_t *iemgr)
149150 // Process all data records
150151 const uint32_t rec_cnt = ipx_msg_ipfix_get_drec_cnt (msg);
151152
153+ // Message header
154+ auto hdr = (fds_ipfix_msg_hdr*) ipx_msg_ipfix_get_packet (msg);
155+
152156 for (uint32_t i = 0 ; i < rec_cnt; ++i) {
153157 ipx_ipfix_record *ipfix_rec = ipx_msg_ipfix_get_drec (msg, i);
154158
@@ -159,7 +163,7 @@ Storage::records_store(ipx_msg_ipfix_t *msg, const fds_iemgr_t *iemgr)
159163 }
160164
161165 // Convert the record
162- convert (ipfix_rec->rec , iemgr, false );
166+ convert (ipfix_rec->rec , iemgr, hdr, false );
163167
164168 // Store it
165169 for (Output *output : m_outputs) {
@@ -174,7 +178,7 @@ Storage::records_store(ipx_msg_ipfix_t *msg, const fds_iemgr_t *iemgr)
174178 }
175179
176180 // Convert the record from reverse point of view
177- convert (ipfix_rec->rec , iemgr, true );
181+ convert (ipfix_rec->rec , iemgr, hdr, true );
178182
179183 // Store it
180184 for (Output *output : m_outputs) {
@@ -198,20 +202,47 @@ Storage::records_store(ipx_msg_ipfix_t *msg, const fds_iemgr_t *iemgr)
198202 * \throw runtime_error if the JSON converter fails
199203 */
200204void
201- Storage::convert (struct fds_drec &rec, const fds_iemgr_t *iemgr, bool reverse)
205+ Storage::convert (struct fds_drec &rec, const fds_iemgr_t *iemgr, fds_ipfix_msg_hdr *hdr, bool reverse)
202206{
203207 // Convert the record
204208 uint32_t flags = m_flags;
205209 flags |= reverse ? FDS_CD2J_BIFLOW_REVERSE : 0 ;
206210
207211 int rc = fds_drec2json (&rec, flags, iemgr, &m_record.buffer , &m_record.size_alloc );
208212 if (rc < 0 ) {
209- throw std::runtime_error (" Conversion to JSON failed (probably a memory allocation error!" );
213+ throw std::runtime_error (" Conversion to JSON failed (probably a memory allocation error) !" );
210214 }
211215
212216 m_record.size_used = size_t (rc);
213- // Append the record with end of line character
214- buffer_append (" \n " );
217+
218+ if (m_format.detailed_info ) {
219+
220+ // Remove '}' parenthesis at the end of the record
221+ m_record.size_used --;
222+
223+ // Array for formatting detailed info fields
224+ char field[64 ];
225+ snprintf (field, 64 , " ,\" ipfix:exportTime\" :\" %" PRIu32 " \" " , ntohl (hdr->export_time ));
226+ buffer_append (field);
227+
228+ snprintf (field, 64 , " ,\" ipfix:seqNumber\" :\" %" PRIu32 " \" " , ntohl (hdr->seq_num ));
229+ buffer_append (field);
230+
231+ snprintf (field, 64 , " ,\" ipfix:odid\" :\" %" PRIu32 " \" " , ntohl (hdr->odid ));
232+ buffer_append (field);
233+
234+ snprintf (field, 32 , " ,\" ipfix:msgLength\" :\" %" PRIu16 " \" " , ntohs (hdr->length ));
235+ buffer_append (field);
236+
237+ snprintf (field, 32 , " ,\" ipfix:templateId\" :\" %" PRIu16 " \" " , rec.tmplt ->id );
238+ buffer_append (field);
239+
240+ // Append the record with '}' parenthesis removed before
241+ buffer_append (" }" );
242+ }
243+
244+ // Append the record with end of line character
245+ buffer_append (" \n " );
215246
216247 /* Note: additional information (e.g. ODID, Export Time, etc.) can be added here,
217248 * just use buffer_append() and buffer_reserve() to append and extend buffer, respectively.
0 commit comments