Re: [logs] Novell logs

From: Buck Buchanan (lbuchanaat_private)
Date: Thu Jan 30 2003 - 10:02:42 PST

  • Next message: Devin Kowatch: "Re: [logs] sql-worm and the address generator"

    Hi,
    
    Writing a minimal syslog client in Perl is pretty easy for someone with
    basic Perl scripting skills, some understanding of network sockets and has
    a copy of the book "Perl Cookbook" by Tom Christiansen and Nathan
    Torkington.  I wrote one in an afternoon a few years ago and is included
    below.  To be honest, I modified Example 17-3 udpmsg from the Perl
    Cookbook.  I edited the second line, changed the port number and commented
    out the code to process the response from the server.  Not much sense in
    waiting for something that will never come.
    
    The hard part (which is left as an exercise to the reader :-) is to write a
    loop to get messages and use $sock>send() to send the messages.  An
    additional assignment would be to add error checking and to prepend the
    message with time stamp, severity and facility information.
    
    B Cing U
    
    Buck
    
    #!/usr/local/bin/perl -w
    # syslog - send a message to the indicated syslogd server
    
    use IO::Socket;
    use strict;
    
    my($sock, $server_host, $msg, $port, $ipaddr, $hishost,
       $MAXLEN, $PORTNO, $TIMEOUT);
    
    $MAXLEN  = 1024;
    $PORTNO  = 514;
    $TIMEOUT = 5;
    
    $server_host = shift;
    $msg         = "@ARGV";
    $sock = IO::Socket::INET->new(Proto     => 'udp',
                                  PeerPort  => $PORTNO,
                                  PeerAddr  => $server_host)
        or die "Creating socket: $!\n";
    $sock->send($msg) or die "send: $!";
    
    #eval {
    #    local $SIG{ALRM} = sub { die "alarm time out" };
    #    alarm $TIMEOUT;
    #    $sock->recv($msg, $MAXLEN)      or die "recv: $!";
    #    alarm 0;
    #    1;  # return value from eval on normalcy
    #} or die "recv from $server_host timed out after $TIMEOUT seconds.\n";
    
    #($port, $ipaddr) = sockaddr_in($sock->peername);
    #$hishost = gethostbyaddr($ipaddr, AF_INET);
    #print "Server $hishost responded ``$msg''\n";
    
    
    _______________________________________________
    LogAnalysis mailing list
    LogAnalysisat_private
    http://lists.shmoo.com/mailman/listinfo/loganalysis
    



    This archive was generated by hypermail 2b30 : Thu Jan 30 2003 - 11:39:46 PST