IIS logs in Graylog

Before you post: Your responses to these questions will help the community help you. Please complete this template if you’re asking a support question.
Don’t forget to select tags to help index your topic!

1. Describe your incident:

hello everyone,
I am configuring nxlog to send IIS logs to Graylog.
I managed to configure everything correctly but I would like to make the logs more readable on Graylog.
I currently display them like this:

would it be possible to somehow get the login name and ip of the user who logged in out of the “message” field?

my current current nxlog configuration is this:

Panic Soft
#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>

<Extension _gelf>
    Module      xm_gelf
</Extension>

<Extension _json>
    Module      xm_json
</Extension>

#######################################################################
####                         IIS NXLOG                           ######
#######################################################################

<Extension w3c>
    Module	xm_csv
    Fields	$date, $time, $s_ip, $cs_method, $cs_uri_stem, $cs_uri_query, $s_port, $cs_username, $c_ip, $cs_User_Agent, $cs_Referer, $sc_status, $sc_substatus, $sc_win32_status, $time_taken
    FieldTypes	string, string, string, string, string, string, string, string, string, string, string, string, string, string, string
    Delimiter 		' '
    QuoteChar 		'"'
    EscapeControl 	FALSE
    UndefValue 		-
</Extension>

<Input iis>
	Module   im_file
    File     "C:\inetpub\logs\LogFiles\W3SVC*\u_ex*"
    SavePos  TRUE
#   Exec $ShortMessage = $raw_event;
    Exec if $raw_event =~/^#/ drop();\
       else\
       {\
        w3c->parse_csv();\
        $EventTime = parsedate($date + " " + $time);\
	$EventTime = parsedate($date + " " + $time + "Z");\
        $SourceName = "IIS";\
	$raw_event = to_json();\
       }
</Input>

#######################################################################
####                         /IIS NXLOG                           #####
#######################################################################


# Snare compatible example configuration
# Collecting event log
# <Input in>
#     Module      im_msvistalog
# </Input>
# 
# Converting events to Snare format and sending them out over TCP syslog
<Output out>
	Module		om_tcp
	Host		ha-centlog-vip.xxxxxxxx
	Port		12201
        Exec 		to_json();
	OutputType	GELF_TCP
        Exec        $Hostname = hostname_fqdn();
        Exec        $raw_event =$Hostname + ' IIS-NXLOG ' + $raw_event;
        #Use the following line for debugging (uncomment the fileop extension above as well)
	#Exec file_write("C:\\Program Files (x86)\\nxlog\\data\\nxlog_output.log", $raw_event);
</Output>

<Route iis-to-graylog>
	Path		iis => out
</Route>

# 
# Connect input 'in' to output 'out'
# <Route 1>
#     Path        in => out
# </Route>

2. Describe your environment:

  • OS Information:
    Windows server 2019

  • Package Version:

  • Service logs, configurations, and environment variables:

3. What steps have you already taken to try and solve the problem?

4. How can the community help?

Helpful Posting Tips: Tips for Posting Questions that Get Answers [Hold down CTRL and link on link to open tips documents in a separate tab]

I did some testing and was able to find a good sample config to provide. I tested this on Windows Server 2019 and nxlog-ce-3.2.2329

Some important notes:

  • the host and port should be changed to suit your needs
  • Your fields list may differ, i grabbed the default fields in the IIS log file i had and made that into a comma separated list. I did the same for the field types.
Panic Soft
#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 _exec>
    Module      xm_exec
</Extension>

<Extension gelfExt>
  Module xm_gelf
  # Avoid truncation of the short_message field to 64 characters.
  ShortMessageLength 65536
</Extension>

<Extension w3c>
    Module          xm_csv
    Fields          date, time, s-ip, cs-method, cs-uri-stem, cs-uri-query, s-port, cs-username, c-ip, cs(User-Agent), cs(Referer), sc-status, sc-substatus, sc-win32-status, sc-bytes, cs-bytes, time-taken
    FieldTypes      string, string, string, string, string, string, integer, string, string, string, string, integer, integer, integer, integer, integer, integer
    Delimiter       ' '
    EscapeChar      '"'
    QuoteChar       '"'
    EscapeControl   FALSE
    UndefValue      -
</Extension>

<Input iis>
    Module          im_file
    File            'C:\inetpub\logs\LogFiles\W3SVC*\u_ex*.log'
    <Exec>
        if $raw_event =~ /^#/ drop();
        else
        {
            w3c->parse_csv();
            $EventTime = parsedate($date + "T" + $time + ".000Z");
        }
    </Exec>
</Input>

<Output out>
	Module om_tcp
	Host 192.168.0.86
	Port 12206
	OutputType  GELF_TCP
</Output>

<Route 1>
    Path        iis => out
</Route>

EventReceivedTime
2023-08-03 12:07:35
SourceModuleName
iis
SourceModuleType
im_file
c-ip
192.168.0.164
c-ip_reserved_ip
true
cs-bytes
543
cs-method
GET
cs-uri-stem
/
date
2023-08-03 00:00:00.000
level
6
message
2023-08-03 17:06:58 192.168.0.97 GET / - 80 - 192.168.0.164 Mozilla/5.0+(Macintosh;+Intel+Mac+OS+X+10_15_7)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/115.0.0.0+Safari/537.36 - 304 0 0 166 543 0
s-ip
192.168.0.97
s-ip_reserved_ip
true
s-port
80
sc-bytes
166
sc-status
304
sc-substatus
0
sc-win32-status
0
source
winser-sec
time
17:06:58
time-taken
0
timestamp
2023-08-03 12:06:58.000

Hope that helps!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.