1.0.3 • Published 2 years ago

winston-logstash-zqctcp v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

winston3-logstash-transport

constructor(options)

Create a new Logstash Transport

options

NameTypeDescriptionValid ValuesDefaultTCPUDP
modestringThe protocol to use to connect to LogStash. tcp is an alias for tcp4 and udp is an alias for udp4.udp udp4 udp6 tcp tcp4 tcp6'udp4'✔️✔️
localhoststringThe hostname sent to LogStashAnyos.hostname✔️✔️
hoststringThe LogStash server ip or hostnameAny valid IP or host address127.0.0.1 (ip4)::0 (ip6)✔️✔️
portintegerThe LogStash server port numberAny integer28777✔️✔️
applicationNamestringThe application name sent to LogStashAnyprocess.title✔️✔️
pidstringThe Operating System process ID for this processAny valid PIDprocess.pid✔️✔️
silentbooleanOffline/Silent mode enabledfalse✔️✔️
maxConnectRetriesintegerThe number of attempts to reconnect to make before erroring outAny integer4✔️✔️
timeoutConnectRetriesintegerThe number of milliseconds to wait between connection attemptsAny integer100✔️✔️
labelstringThe LogStash label to send with the informationAnyprocess.title✔️✔️
sslEnablebooleanWhether SSL/TLS connection should be attempted when connecting via TCPfalse✔️
sslKeyfilepathThe filepath to the SSL KeyAny valid filepath''✔️
sslCertfilepathThe filepath to the SSL CertAny valid filepath''✔️
sslCAfilepath or Array(filepaths)The filepath(s) to the Certificat Authority (CA) Intermediary CertsAny valid filepath(s)''✔️
sslPassPhrasestringThe SSL Cert PassPhrase (if any)Any''✔️
rejectUnauthorizedbooleanEnable connection rejection when cert is not validfalse✔️
trailingLineFeedbooleanEnable appending end of line character to UDP outputfalse✔️
trailingLineFeedCharstringThe type of end of line character(s) to append to UDP outputAnyos.EOL✔️
formattedbooleanEnable/Disable delivery of standard pre-formatted JSON payloads. See Message Payloads for more info.true✔️✔️

Message Payloads

By default or when options.formatted is explicitly set true, this module delivers a standard message payload to logstash as follows:

{
  "timestamp": new Date().toISOString(), // The time the payload was created
  "message": "",                         // JSON Stringified version of your message
  "level": "",                           // The logger level of the message
  "label": `${options.label}`,
  "application": `${options.applicationName}`,
  "serverName": `${options.localhost}`,
  "pid": `${options.pid}`
}

In this case when the log message is a string, boolean, or Number value, then the message is a stringified as:

{
  "data": `${message}`
}

If options.formatted is set to false, then the entire Winston log message object is JSON.stringified and then set to logstash.

Logstash Configuration

Having logstash ingest preformatted messages delivered by this module can be done with a configuration file similar to below:

input {
  # Sample input over TCP
  tcp {
    codec => json
    port => 28777
    add_field => { "category" => "winston_log" }
  }
}
filter {
  if [category] == "winston_log" {
    json {
      source => "message"
    }
    json {
      source => "data"
      remove_field => [ "[headers][secret]", "[headers][apikey]" ]
    }
  }
}
output {
  if [category] == "winston_log" {
    stdout {
      codec => json
    }
    elasticsearch {
      id => "winston_log_tcp"
      index => "winston_log-%{+YYYY.MM.dd}"
      hosts => ["192.168.1.1:9200"] # Use the address of your Elasticsearch server
    }
  }
}