DEV Community

Rümeysa Öz for Açıklab

Posted on • Updated on

DHCP Sunucusunun Loglarını 2 Farklı Syslog Sunucusuna Aynı Anda Gönderme

1. Rsyslog Sunucusu Kurulumu

  • Öncelikle syslog log alabilecek şekilde yapılandırılmış herhangi 2 sunucu kurulu olmalıdır. Bu log sunucusu ihtiyacı için açık kaynak kodlu rsyslog sunucusu kurulması için buradan yararlanılabilinir.

‼️ Linkteki 3. madde "Log Üreten Makinanın ayarları" kısmı bu yazı için yapılmayacaktır.

2. DHCP'den 2 Farklı Adrese Log Gönderme

  • Windows makinede DHCP loglarının NXLog kullanılarak ilgili sensöre gönderilmesine daha önce değinilmişti. İlgili makaleden NXLog kurulumu ve kullanımı incelenebilir.

  • Kurulumdan sonra, nxlog.conf dosyasını C:\Program Files\nxlog\conf klasöründe bulun.

Image description

  • Bir text file kullanarak nxlog.conf dosyasını açın. Windows sürümünüz için verilen metni kopyalayıp yapıştırarak Output syslogout satırının içindeki:
    • Host: Log gönderilmek istenen Rsyslog sunucularının IP'lerini yazın.
    • Port: Log gönderilmek istenen Rsyslog sunucu port'u (514) olacak şekilde değiştirin ve ardından dosyayı kaydedin.

Windows x64 bit OS:

#NoFreeOnExit TRUE

define ROOT     C:\Program Files\nxlog
define CERTDIR  %ROOT%\cert
define CONFDIR  %ROOT%\conf\nxlog.d
define LOGDIR   %ROOT%\data

include %CONFDIR%\\*.conf
define LOGFILE  %LOGDIR%\nxlog.log
LogFile %LOGFILE%

Moduledir %ROOT%\modules
CacheDir  %ROOT%\data
Pidfile   %ROOT%\data\nxlog.pid
SpoolDir  %ROOT%\data

<Extension _syslog>
    Module      xm_syslog
</Extension>

<Extension _charconv>
    Module      xm_charconv
    AutodetectCharsets iso8859-2, utf-8, utf-16, utf-32
</Extension>

<Extension _exec>
    Module      xm_exec
</Extension>

<Extension _fileop>
    Module      xm_fileop

    # Check the size of our log file hourly, rotate if larger than 5MB
    <Schedule>
        Every   1 hour
        Exec    if (file_exists('%LOGFILE%') and \
                   (file_size('%LOGFILE%') >= 5M)) \
                    file_cycle('%LOGFILE%', 8);
    </Schedule>

    # Rotate our log file every week on Sunday at midnight
    <Schedule>
        When    @weekly
        Exec    if file_exists('%LOGFILE%') file_cycle('%LOGFILE%', 8);
    </Schedule>
</Extension>

# Snare compatible example configuration
# Collecting event log
<Input watchfile>
  Module im_file
  File 'C:\Windows\System32\dhcp\DhcpSrvLog-*.log'
  Exec $Message = $raw_event;
  Exec if file_name() =~ /.*\\(.*)/ $SourceName = $1;
  SavePos TRUE
  Recursive TRUE
</Input>

<Processor filewatcher_transformer>
  Module pm_transformer
  Exec $Hostname = hostname();
  OutputFormat json
</Processor>

# Converting events to Snare format and sending them out over TCP syslog
<Output out>
    Module      om_tcp
    Host        rsyslog_server_1
    Port        514
    Exec        to_syslog_snare();
</Output>

<Output out2>
    Module      om_tcp
    Host        rsyslog_server_2
    Port        514
    Exec        to_syslog_snare();
</Output>

# Connect input 'in' to output 'out'
<Route route1>
  Path watchfile => filewatcher_transformer => out
</Route>

<Route route2>
  Path watchfile => filewatcher_transformer => out2
</Route>
Enter fullscreen mode Exit fullscreen mode
  • Config işlemini tamamladığımıza göre artık nxlog servisimizi restart ederek loglarımızı gönderebiliriz.

  • Control Panel > Services'e gidin ve nxlog service'ini bulun.

  • nxlog'a sağ tıklayın ve Restart'a tıklayın.

Image description

  • DHCP logları artık istenen 2 syslog sunucusuna da aynı anda yönlendirilir.

  • Syslog sunucularında şu komut çalıştırılır:

ls -l /var/log/remote/
Enter fullscreen mode Exit fullscreen mode
  • Daha sonra gönderilen loglar son satırlardaki gibi iki makinede de görüntülenir:

Image description

Top comments (0)