Thursday, October 6, 2016

Graylog2 Collector

The new approach

Server side controlled configuration

Staring with Graylog 2 the a new collector approach (Graylog Collector Sidecar) is proposed, based on wrapping NXLog.

Installation is straightforward, as indicated in online documents (sample for Windows, a later post might share Ubuntu experience).

Install NXLog:

  • Download NXLog Windows installation kit NXLog downloads
  • Run the installer
  • Run (as an administrator) "C:\Program Files (x86)\nxlog\nxlog.exe" -u; this will un-install nxlog as a service but will keep binaries

Now download and install latest collector-sidecar binaries (Collector-Sidecar releases)

Before installing/starting the collector as a service:

  • On the server administration site go to System->Collectors->Manage Configurations
  • Add a configuration with a meaningful name
    • Add one or more relevant tags
    • Add an Output (by choosing from already configured Inputs)
    • Add one or more inputs; for file type inputs you can check the multi-line option and provide a RegEx for the start pattern, like /^\d{2}\.\d{2}\.\d{4}/ (notice enclosing slashes!)

Go back to the monitored computer and edit C:\Program Files (x86)\graylog\collector-sidecar\collector-sidecar.yaml:

  • update server_url
  • update to a meaningful name the node_id
  • add one of the tags previously defined in the tags list
  • install and start the service (run as administrator):
    • "C:\Program Files (x86)\graylog\collector-sidecar\graylog-collector-sidecar.exe" -service install
    • "C:\Program Files (x86)\graylog\collector-sidecar\graylog-collector-sidecar.exe" -service start

*Service can be started/stopped also from Task manager (Services tab, collector-sidecar Name) or from Services Manager (Graylog collector sidecar Display name).

Now we should have automatically created, based on the previously defined configuration, the nxlog configuration file C:\Program Files (x86)\graylog\collector-sidecar\generated\nxlog.conf and in administration site the collector should be listed in System->Collectors section.

Please notice that if there is some error in the yaml configuration file the service will not start and no error message will be logged (it happened to me if I commented the tags list, see next section)

Locally controlled configuration

Under certain conditions you might need to use advanced NXLog features which are not supported by the server side configuration. You can do the following trick:

  • Start with the approach described in the previous section and check that everything goes fine; at this moment we should have a valid NXLog configuration file
  • Move the configuration file in another directory and change the configuration_path value to that file
  • Remove all valid tags and add a dummy one that does not exists in server side configuration; do not remove the tags entry or leave the list empty since the collector will not start and no error message will be logged
  • Restart the collector-sidecar service
  • If everything works as expected, read carefully the NXLog manual and do your own enhancements to the configuration
  • Restart the collector-sidecar service

I applied the approach because I needed an aditional message field (Exec $source_id = 'WildFly10';) source_id for one of the inputs, like shown below.

<Input 576d1d3d659fb107f722db38>
    Module im_file
    File "C:\Java\wildfly-10.0.0.Final\standalone\log\server.log"
    PollInterval 1
    SavePos True
    ReadFromLast True
    Recursive False
    RenameCheck False
    Exec $FileName = file_name(); # Send file name with each message
    Exec $source_id = 'WildFly10';
    InputType 576d1d3d659fb107f722db38-multiline
</Input>

The full yaml configuration file content:

server_url: http://graylog.mycompany.local:12900
tls_skip_verify: false
node_id: graylog-collector-sidecar-devsrv
collector_id: file:C:\Program Files (x86)\graylog\collector-sidecar\collector-id
tags:
    - undefined
log_path: C:\Program Files (x86)\graylog\collector-sidecar
update_interval: 10
backends:
    - name: nxlog
      enabled: true
      binary_path: C:\Program Files (x86)\nxlog\nxlog.exe
#      configuration_path: C:\Program Files (x86)\graylog\collector-sidecar\generated\nxlog.conf
      configuration_path: C:\Program Files (x86)\graylog\collector-sidecar\conf\nxlog.conf

As an alternate approach (I haven't tested but it should work) is to go for the first option (server side controlled configuration) but instead of defining Outputs/Inputs just place all nxlog.conf content in the default nxlog snippet, in the Windows section. Be sure you have in sync the collector side client_id with the one in the nxlog.conf content, Output section (see Exec $gl2_source_collector = '0324bd79-b9a9-458e-9977-d0eecbd2d347';):

<Output 576cf426659fb107f722b011>
    Module om_tcp
    Host graylog.mycompany.local
    Port 12201
    OutputType  GELF_TCP
    Exec $short_message = $raw_event; # Avoids truncation of the short_message field.
    Exec $gl2_source_collector = '0324bd79-b9a9-458e-9977-d0eecbd2d347';
    Exec $Hostname = hostname_fqdn();
</Output>

Duplicate configuration on another server

Once we have a collector configured we can duplicate easily the installation on another one:

  • Perform the NXLog installation steps
  • Install the collector-sidecar (just run the setup)
  • Copy yaml and nxlog.conf files on the target server
  • Change the yaml to reflect the right node_id
  • Change the content of the collector-id with some unique string (a GUID?)
  • Change the nxlog.conf Output tag to reflect the collector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