#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    2
    Rep Power
    0

    Syslog Implementation


    Hello,

    I'm a beginner in Perl programming.

    I've been trying to implement the Syslog module in my application.

    I'm able to create the SysLog on one Linux machine (LINUX1).
    Now I require to transmit the logs to another remote Linux machine (LINUX2).

    #!/usr/bin/perl
    use strict;
    use warnings;
    use Sys::Syslog;
    use Sys::Syslog qw(:standard :macros);
    use Sys::Syslog qw(: DEFAULT setlogsock);
    my $program="SysLog_Impl.pl";
    my $host = "10.XXX.XX.X";
    openlog($program, "ndelay,pid", "local3");
    syslog('debug','%s', 'Debug::code debug!again');
    closelog();

    print("Log has added to local server LINUX1.");

    # Log to UDP port on remote $host instead of logging locally
    setlogsock('udp');
    $Sys::Syslog::host = $host;
    openlog($program, 'ndelay,pid', 'local3');
    syslog('info', 'something happened over here');
    closelog();

    print("\nLog has added to Remote server LINUX2.\n");

    The Log is recorded well in local server LINUX1, but no entry is passed on remote server LINUX2 log.

    Can someone please mark what am i doing wrong??

    Also how to achieve replication between LINUX1 AND LINUX2 logs i.e. if a change occurs in LINUX1 log then it automatically gets replicated in LINUX2 log??

    Thanks in advance.

    --Ashish
  2. #2
  3. No Profile Picture
    Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    7
    Rep Power
    0

    Re:Syslog Implementation


    I have been trying to implement the Syslog module in my application.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Location
    Paris area, France
    Posts
    843
    Rep Power
    496
    @ Ashish_PerlPro

    I don't know Syslog, but, once your log file is created, transfering it to another box does no longer seem to be a Syslog question, but rather a simple FTP (or SFTP, or whatever depending on your network system) question. No?

    Originally Posted by iqbal51
    I have been trying to implement the Syslog module in my application.
    Gee, that sounds like a tremendously useful piece of information.
  6. #4
  7. !~ /m$/
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    May 2004
    Location
    Reno, NV
    Posts
    4,264
    Rep Power
    1810
    The thing that jumped out at me in the original code was this:

    Code:
    use Sys::Syslog;
    use Sys::Syslog qw(:standard :macros);
    use Sys::Syslog qw(: DEFAULT setlogsock);
    The space between the colon and the word DEFAULT in the last line is an error, and will stop the code from compiling. That might be a typo here. Still, I think all you need is this one line:

    Code:
    use Sys::Syslog qw(:standard :extended);
    :extended is for the setlogsock function; everything else should be covered by :standard.

    But I don't know if it's possible to log to two locations simultaneously with the module. I don't have a remote machine to test with.

    There are a few other modules for logging to remote computers, such as Net::Syslog and Log::Syslog::Fast. You could use one module for local logs, and the other to communicate with the remote system.

    Another way of doing this would be to log locally in your script, and then occasionally copy your log file to a remote machine with at cron process. Here's a script someone has provided to do that job in perl. You can examine the code here at Github and see that he is using Sys::Syslog to do the job. Fairly short script; reading through that may show something missing from your own code.

IMN logo majestic logo threadwatch logo seochat tools logo