We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

CSV2Syslog perl script

cdukes
cdukes asked
on
Medium Priority
375 Views
Last Modified: 2006-11-18
Hi Perl junkies :-)

Is there a way to parse a .csv file and convert the strings to syslog?
I want to take in a log file and forward the information to a syslog server.

Thanks!
Comment
Watch Question

Author

Commented:
I should mention that the csv files are on a windows box, so using logger is out :-(
Romi KuntsmanBig Data Engineer

Commented:
Converting formats is always possible, and even easy with perl.

What fields are there in the csv file, and what format is the syslog file?

RK.

Author

Commented:
I think the tricky part is going to be taking in text and pushing the data out to udp port 161

so let's say I  have a line of text:
03/28/2006,10:00:00,Authen OK,cisco,Engineering,10.1.1.2,tty130,20.1.1.1

These fields are as follows:
$DATE, $TIME, $MSG, $USER, $GROUP, $CALLERID, $NASPRT, $NASIP

So I need to read each line with these tokens and spit them out to a syslog server.
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015
Commented:
$_="03/28/2006,10:00:00,Authen OK,cisco,Engineering,10.1.1.2,tty130,20.1.1.1";
my($DATE, $TIME, $MSG, $USER, $GROUP, $CALLERID, $NASPRT, $NASIP) = split/,/;
use Net::Syslog;
my $s=new Net::Syslog(Facility=>'local4',Priority=>'debug');
$s->send($_,Priority=>'info');

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Nice!
Does this just log to the local syslog service? What if it's on winders?

Author

Commented:
Also, how do I read the values from a .csv file instead of declaring $_ ?
ozo
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015

Commented:
while( <> ){
my($DATE, $TIME, $MSG, $USER, $GROUP, $CALLERID, $NASPRT, $NASIP) = split/,/;
...
}


Net::Syslog talks to any syslogd you can reach over the net.
You can set SyslogHost to the address of the remote syslogd    
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.