CSV2Syslog perl script

Posted on 2006-03-24
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.

Question by:cdukes

    Author Comment

    I should mention that the csv files are on a windows box, so using logger is out :-(
    LVL 4

    Expert Comment

    by:Romi Kuntsman
    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?


    Author Comment

    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,,tty130,

    These fields are as follows:

    So I need to read each line with these tokens and spit them out to a syslog server.
    LVL 84

    Accepted Solution

    $_="03/28/2006,10:00:00,Authen OK,cisco,Engineering,,tty130,";
    my($DATE, $TIME, $MSG, $USER, $GROUP, $CALLERID, $NASPRT, $NASIP) = split/,/;
    use Net::Syslog;
    my $s=new Net::Syslog(Facility=>'local4',Priority=>'debug');

    Author Comment

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

    Author Comment

    Also, how do I read the values from a .csv file instead of declaring $_ ?
    LVL 84

    Expert Comment

    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    

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
    I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now