Click here to Skip to main content
15,851,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
This is a sample of my log file in text document.

Jan 1 22:54:17 drop %LOGSOURCE% >eth1 rule: 7; rule_uid: {C1336766-9489-4049-9817-50584D83A245}; src: 70.77.116.190; dst: %DSTIP%; proto: tcp; product: VPN-1 & FireWall-1; service: 445; s_port: 2612;
Jan 1 22:54:22 drop %LOGSOURCE% >eth1 rule: 7; rule_uid: {C1336766-9489-4049-9817-50584D83A245}; src: 61.164.41.144; dst: %DSTIP%; proto: udp; product: VPN-1 & FireWall-1; service: 5060; s_port: 5069;

This are the two lines out of few thousand lines in the log file.

The main question is how do I parse this and then import it into database?

*I know the method is using SQL statements but I want to know the exact code for it.*
Posted
Comments
PIEBALDconsult 14-Jul-15 23:38pm    
"I want to know the exact code for it"
Only you know that.

As for parsing, I'd try Regular Expressions first.
iambadatcoding 15-Jul-15 21:33pm    
I learnt a little bit of regular expressions in the past but Im not sure if log parser accepts regular expressions. Since my job is to separate them into different columns and input them into database.
One example is Jan 1 22:54:17, 7, {C1336766-9489-4049-9817-50584D83A245}, 70.77.116.190, %DSTIP%, tcp, VPN-1 & FireWall-1, 445, 2612
This is the output that I really need and I will need to convert it from a log file into csv file so that I can use my javascript to visualize it into graphs etc

1 solution

The sample data looks like each item on a row is separated with a semiciolon. SO basically you can export this as a CSV file, make modifications / conversions to the data if needed and then add the data into the database.

Few articles to get you started:
- C# - CSV Import Export[^]
- Importing CSV Data and saving it in database[^]
 
Share this answer
 
Comments
iambadatcoding 15-Jul-15 21:30pm    
Using CSV import/Export to make modifications?
Wendelius 15-Jul-15 23:36pm    
Yes, you can treat the file as a CSV. just use semicolon ( ; ) as a delimiter and read data from the file. After reading, add relevant data to the database.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900