Last active
February 19, 2020 08:22
-
-
Save mrlesmithjr/43b4e97bf16a7423bbd2 to your computer and use it in GitHub Desktop.
Logstash Configuration File
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
input { | |
redis { | |
host => "127.0.0.1" | |
data_type => "list" | |
key => "logstash" | |
} | |
} | |
input { | |
udp { | |
type => "syslog" | |
port => "514" | |
} | |
} | |
input { | |
tcp { | |
type => "eventlog" | |
port => 3515 | |
format => 'json' | |
} | |
} | |
input { | |
tcp { | |
type => "iis" | |
port => 3525 | |
format => 'json' | |
} | |
} | |
filter { | |
if [type] == "syslog" { | |
dns { | |
reverse => [ "host" ] action => "replace" | |
} | |
if [host] =~ /.*?(nsvpx).*?(everythingshouldbevirtual.local)?/ { | |
mutate { | |
add_tag => [ "Netscaler", "Ready" ] | |
} | |
} | |
if [host] =~ /.*?(pfsense).*?(everythingshouldbevirtual.local)?/ { | |
mutate { | |
add_tag => [ "PFSense", "Ready" ] | |
} | |
} | |
if [host] =~ /.*?(esxi).*?(everythingshouldbevirtual.local)?/ { | |
mutate { | |
add_tag => [ "VMware", "Ready" ] | |
} | |
} | |
if [host] =~ /.*?(vcsa).*?(everythingshouldbevirtual.local)?/ { | |
mutate { | |
add_tag => [ "vCenter", "Ready" ] | |
} | |
} | |
if "Ready" not in [tags] { | |
mutate { | |
add_tag => [ "syslog" ] | |
} | |
} | |
} | |
if [type] == "eventlog" { | |
mutate { | |
add_tag => [ "WindowsEventLog" ] | |
} | |
} | |
if [type] == "iis" { | |
mutate { | |
add_tag => [ "IISLogs" ] | |
} | |
} | |
} | |
filter { | |
if [type] == "syslog" { | |
mutate { | |
remove_tag => "Ready" | |
} | |
} | |
} | |
filter { | |
if "syslog" in [tags] { | |
grok { | |
match => { "message" => "<%{POSINT:syslog_pri}>%{SYSLOGTIMESTAMP:syslog_timestamp} %{SYSLOGHOST:syslog_hostname} %{DATA:syslog_program}(?:\[%{POSINT:syslog_pid}\])?: %{GREEDYDATA:syslog_message}" } | |
add_field => [ "received_at", "%{@timestamp}" ] | |
add_field => [ "received_from", "%{host}" ] | |
} | |
syslog_pri { } | |
date { | |
match => [ "syslog_timestamp", "MMM d HH:mm:ss", "MMM dd HH:mm:ss" ] | |
} | |
if !("_grokparsefailure" in [tags]) { | |
mutate { | |
replace => [ "@source_host", "%{syslog_hostname}" ] | |
replace => [ "@message", "%{syslog_message}" ] | |
} | |
} | |
mutate { | |
remove_field => [ "syslog_hostname", "syslog_message", "syslog_timestamp" ] | |
} | |
if "_grokparsefailure" in [tags] { | |
drop { } | |
} | |
} | |
} | |
filter { | |
if "VMware" in [tags] { | |
grok { | |
break_on_match => false | |
match => [ | |
"message", "<%{POSINT:syslog_pri}>%{TIMESTAMP_ISO8601:@timestamp} %{SYSLOGHOST:hostname} %{SYSLOGPROG:message_program}: (?<message-body>(?<message_system_info>(?:\[%{DATA:message_thread_id} %{DATA:syslog_level} \'%{DATA:message_service}\'\ ?%{DATA:message_opID}])) \[%{DATA:message_service_info}]\ (?<message-syslog>(%{GREEDYDATA})))", | |
"message", "<%{POSINT:syslog_pri}>%{TIMESTAMP_ISO8601:@timestamp} %{SYSLOGHOST:hostname} %{SYSLOGPROG:message_program}: (?<message-body>(?<message_system_info>(?:\[%{DATA:message_thread_id} %{DATA:syslog_level} \'%{DATA:message_service}\'\ ?%{DATA:message_opID}])) (?<message-syslog>(%{GREEDYDATA})))", | |
"message", "<%{POSINT:syslog_pri}>%{TIMESTAMP_ISO8601:@timestamp} %{SYSLOGHOST:hostname} %{SYSLOGPROG:message_program}: %{GREEDYDATA:message-syslog}" | |
] | |
} | |
syslog_pri { } | |
mutate { | |
replace => [ "@source_host", "%{hostname}" ] | |
} | |
mutate { | |
replace => [ "@message", "%{message-syslog}" ] | |
} | |
if "Device naa" in [message] { | |
grok { | |
match => [ | |
"message", "Device naa.%{WORD:device_naa} performance has %{WORD:device_status}" | |
] | |
} | |
} | |
if "connectivity issues" in [message] { | |
grok { | |
match => [ | |
"message", "Hostd: %{GREEDYDATA} : %{DATA:device_access} to volume %{DATA:device_id} %{DATA:datastore} (following|due to)" | |
] | |
} | |
} | |
if "WARNING" in [message] { | |
grok { | |
match => [ | |
"message", "WARNING: %{GREEDYDATA:vmware_warning_msg}" | |
] | |
} | |
} | |
} | |
if "_grokparsefailure" in [tags] { | |
if "VMware" in [tags] { | |
grok { | |
break_on_match => false | |
match => [ | |
"message", "<%{POSINT:syslog_pri}>%{DATA:message_system_info}, (?<message-body>(%{SYSLOGHOST:hostname} %{SYSLOGPROG:message_program}: %{GREEDYDATA:message-syslog}))", | |
"message", "${GREEDYDATA:message-syslog}" | |
] | |
} | |
} | |
} | |
} | |
filter { | |
if "vCenter" in [tags] { | |
grok { | |
break_on_match => false | |
match => [ | |
"message", "%{TIMESTAMP_ISO8601:@timestamp} (?<message-body>(?<message_system_info>(?:\[%{DATA:message_thread_id} %{DATA:syslog_level} \'%{DATA:message_service}\'\ ?%{DATA:message_opID}])) \[%{DATA:message_service_info}]\ (?<message-syslog>(%{GREEDYDATA})))", | |
"message", "%{TIMESTAMP_ISO8601:@timestamp} (?<message-body>(?<message_system_info>(?:\[%{DATA:message_thread_id} %{DATA:syslog_level} \'%{DATA:message_service}\'\ ?%{DATA:message_opID}])) (?<message-syslog>(%{GREEDYDATA})))", | |
"message", "<%{POSINT:syslog_pri}>%{TIMESTAMP_ISO8601:@timestamp} %{GREEDYDATA:message-syslog}" | |
] | |
} | |
if "_grokparsefailure" in [tags] { | |
grok { | |
break_on_match => false | |
match => [ | |
"message", "${GREEDYDATA:message-syslog}" | |
] | |
} | |
} | |
syslog_pri { } | |
mutate { | |
replace => [ "@message", "%{message-syslog}" ] | |
rename => [ "host", "@source_host" ] | |
rename => [ "hostname", "syslog_source-hostname" ] | |
rename => [ "program", "message_program" ] | |
rename => [ "message_vce_server", "syslog_source-hostname" ] | |
remove_field => [ "@version", "type", "path" ] | |
} | |
} | |
} | |
filter { | |
if "PFSense" in [tags] { | |
grok { | |
add_tag => [ "firewall" ] | |
match => [ "message", "<(?<evtid>.*)>(?<datetime>(?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\s+(?:(?:0[1-9])|(?:[12][0-9])|(?:3[01])|[1-9]) (?:2[0123]|[01]?[0-9]):(?:[0-5][0-9]):(?:[0-5][0-9])) (?<prog>.*?): (?<msg>.*)" ] | |
} | |
mutate { | |
gsub => ["datetime"," "," "] | |
} | |
date { | |
match => [ "datetime", "MMM dd HH:mm:ss" ] | |
} | |
mutate { | |
replace => [ "message", "%{msg}" ] | |
} | |
mutate { | |
remove_field => [ "msg", "datetime" ] | |
} | |
} | |
if [prog] =~ /^pf$/ { | |
mutate { | |
add_tag => [ "packetfilter" ] | |
} | |
multiline { | |
pattern => "^\s+|^\t\s+" | |
what => "previous" | |
} | |
mutate { | |
remove_field => [ "msg", "datetime" ] | |
remove_tag => [ "multiline" ] | |
} | |
grok { | |
match => [ "message", "rule (?<rule>.*)\(.*\): (?<action>pass|block) .* on (?<iface>.*): .* proto (?<proto>TCP|UDP|IGMP|ICMP) .*\n\s*(?<src_ip>(\d+\.\d+\.\d+\.\d+))\.?(?<src_port>(\d*)) [<|>] (?<dest_ip>(\d+\.\d+\.\d+\.\d+))\.?(?<dest_port>(\d*)):" ] | |
} | |
} | |
if [prog] =~ /^dhcpd$/ { | |
if [message] =~ /^DHCPACK|^DHCPREQUEST|^DHCPOFFER/ { | |
grok { | |
match => [ "message", "(?<action>.*) (on|for|to) (?<src_ip>[0-2]?[0-9]?[0-9]\.[0-2]?[0-9]?[0-9]\.[0-2]?[0-9]?[0-9]\.[0-2]?[0-9]?[0-9]) .*(?<mac_address>[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]).* via (?<iface>.*)" ] | |
} | |
} | |
if [message] =~ /^DHCPDISCOVER/ { | |
grok { | |
match => [ "message", "(?<action>.*) from (?<mac_address>[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]).* via (?<iface>.*)" ] | |
} | |
} | |
if [message] =~ /^DHCPINFORM/ { | |
grok { | |
match => [ "message", "(?<action>.*) from (?<src_ip>.*).* via (?<iface>.*)" ] | |
} | |
} | |
} | |
if "_grokparsefailure" in [tags] { | |
drop { } | |
} | |
} | |
filter { | |
if "PFSense" in [tags] { | |
mutate { | |
replace => [ "@source_host", "%{host}" ] | |
} | |
mutate { | |
replace => [ "@message", "%{message}" ] | |
} | |
} | |
} | |
filter { | |
if "Netscaler" in [tags] { | |
grok { | |
break_on_match => true | |
match => [ | |
"message", "<%{POSINT:syslog_pri}> %{DATE_US}:%{TIME} GMT %{SYSLOGHOST:syslog_hostname} %{GREEDYDATA:netscaler_message} : %{DATA} %{INT:netscaler_spcbid} - %{DATA} %{IP:netscaler_client_ip} - %{DATA} %{INT:netscaler_client_port} - %{DATA} %{IP:netscaler_vserver_ip} - %{DATA} %{INT:netscaler_vserver_port} %{GREEDYDATA:netscaler_message} - %{DATA} %{WORD:netscaler_session_type}", | |
"message", "<%{POSINT:syslog_pri}> %{DATE_US}:%{TIME} GMT %{SYSLOGHOST:syslog_hostname} %{GREEDYDATA:netscaler_message}" | |
] | |
} | |
syslog_pri { } | |
mutate { | |
replace => [ "@source_host", "%{host}" ] | |
} | |
mutate { | |
replace => [ "@message", "%{netscaler_message}" ] | |
} | |
geoip { | |
source => "netscaler_client_ip" | |
target => "geoip" | |
add_field => [ "[geoip][coordinates]", "%{[geoip][longitude]}" ] | |
add_field => [ "[geoip][coordinates]", "%{[geoip][latitude]}" ] | |
} | |
mutate { | |
convert => [ "[geoip][coordinates]", "float" ] | |
} | |
} | |
} | |
filter { | |
if "apache" in [type] { | |
geoip { | |
source => "clientip" | |
target => "geoip" | |
add_field => [ "[geoip][coordinates]", "%{[geoip][longitude]}" ] | |
add_field => [ "[geoip][coordinates]", "%{[geoip][latitude]}" ] | |
} | |
mutate { | |
convert => [ "[geoip][coordinates]", "float" ] | |
} | |
mutate { | |
replace => [ "@source_host", "%{host}" ] | |
} | |
mutate { | |
replace => [ "@message", "%{message}" ] | |
} | |
mutate { | |
rename => [ "verb" , "method" ] | |
} | |
mutate { | |
add_tag => [ "apache" ] | |
} | |
grok { | |
match => [ | |
"message", "%{DATA:apache_vhost} " | |
] | |
} | |
} | |
} | |
filter { | |
if [type] == "eventlog" { | |
grep { | |
match => { "EventReceivedTime" => "\d+"} | |
} | |
mutate { | |
lowercase => [ "EventType", "FileName", "Hostname", "Severity" ] | |
} | |
mutate { | |
rename => [ "Hostname", "@source_host" ] | |
} | |
date { | |
match => [ "EventReceivedTime", "UNIX" ] | |
} | |
mutate { | |
rename => [ "Message", "@message" ] | |
rename => [ "Severity", "eventlog_severity" ] | |
rename => [ "SeverityValue", "eventlog_severity_code" ] | |
rename => [ "Channel", "eventlog_channel" ] | |
rename => [ "SourceName", "eventlog_program" ] | |
rename => [ "SourceModuleName", "nxlog_input" ] | |
rename => [ "Category", "eventlog_category" ] | |
rename => [ "EventID", "eventlog_id" ] | |
rename => [ "RecordNumber", "eventlog_record_number" ] | |
rename => [ "ProcessID", "eventlog_pid" ] | |
} | |
mutate { | |
remove => [ "SourceModuleType", "EventTimeWritten", "EventTime", "EventReceivedTime", "EventType" ] | |
} | |
} | |
} | |
filter { | |
if [type] == "iis" { | |
if [message] =~ "^#" { | |
drop {} | |
} | |
grok { | |
match => [ | |
"message", "<%{POSINT:syslog_pri}>%{SYSLOGTIMESTAMP} %{WORD:servername} %{TIMESTAMP_ISO8601} %{IP:hostip} %{WORD:method} %{URIPATH:request} (?:%{NOTSPACE:query}|-) %{NUMBER:port} (?:%{NOTSPACE:param}|-) %{IPORHOST:clientip} %{NOTSPACE:agent} %{NUMBER:response} %{NUMBER:subresponse} %{NUMBER:bytes} %{NUMBER:time-taken}", | |
"message", "<%{POSINT:syslog_pri}>%{SYSLOGTIMESTAMP} %{WORD:servername} %{GREEDYDATA:syslog_message}" | |
] | |
} | |
date { | |
match => ["eventtime", "YY-MM-dd HH:mm:ss"] | |
} | |
mutate { | |
replace => [ "@source_host", "%{servername}" ] | |
} | |
mutate { | |
replace => [ "@message", "%{message}" ] | |
} | |
geoip { | |
source => "clientip" | |
target => "geoip" | |
add_field => [ "[geoip][coordinates]", "%{[geoip][longitude]}" ] | |
add_field => [ "[geoip][coordinates]", "%{[geoip][latitude]}" ] | |
} | |
mutate { | |
convert => [ "[geoip][coordinates]", "float" ] | |
} | |
} | |
} | |
filter { | |
if [type] == "mysql-slowquery" { | |
mutate { | |
add_tag => [ "Mysql" ] | |
} | |
} | |
} | |
output { | |
elasticsearch_http { | |
host => "127.0.0.1" | |
flush_size => 1 | |
manage_template => true | |
template => "/opt/logstash/lib/logstash/outputs/elasticsearch/elasticsearch-template.json" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment