Skip to content

Commit a764ed9

Browse files
author
Suyog Rao
committed
Added more tests without the need for live syslog input
Closes elastic#1593
1 parent bdd6906 commit a764ed9

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

lib/logstash/inputs/syslog.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def register
5656
@grok_filter = LogStash::Filters::Grok.new(
5757
"overwrite" => "message",
5858
"match" => { "message" => "<%{POSINT:priority}>%{SYSLOGLINE}" },
59-
"tag_on_failure" => ["_grokparsefailure_sysloginputplugin"],
59+
"tag_on_failure" => ["_grokparsefailure_sysloginput"],
6060
)
6161

6262
@date_filter = LogStash::Filters::Date.new(
@@ -198,7 +198,7 @@ def close_tcp
198198
def syslog_relay(event)
199199
@grok_filter.filter(event)
200200

201-
if event["tags"].nil? || !event["tags"].include?("_grokparsefailure")
201+
if event["tags"].nil? || !event["tags"].include?(@grok_filter.tag_on_failure)
202202
# Per RFC3164, priority = (facility * 8) + severity
203203
# = (facility << 3) & (severity)
204204
priority = event["priority"].to_i rescue 13

spec/inputs/syslog.rb

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# coding: utf-8
22
require "test_utils"
33
require "socket"
4+
require "logstash/inputs/syslog"
5+
require "logstash/event"
46

5-
describe "inputs/syslog", :socket => true do
7+
describe "inputs/syslog" do
68
extend LogStash::RSpec
79

8-
describe "properly handles priority, severity and facilities" do
10+
it "should properly handle priority, severity and facilities", :socket => true do
911
port = 5511
1012
event_count = 10
1113

@@ -39,7 +41,7 @@
3941
end
4042
end
4143

42-
describe "adds unique tag when grok parsing fails" do
44+
it "should add unique tag when grok parsing fails with live syslog input", :socket => true do
4345
port = 5511
4446
event_count = 10
4547

@@ -70,4 +72,21 @@
7072
end
7173
end
7274
end
75+
76+
it "should add unique tag when grok parsing fails" do
77+
input = LogStash::Inputs::Syslog.new({})
78+
input.register
79+
80+
# event which is not syslog should have a new tag
81+
event = LogStash::Event.new({ "message" => "hello world, this is not syslog RFC3164" })
82+
input.syslog_relay(event)
83+
insist { event["tags"] } == ["_grokparsefailure_sysloginput"]
84+
85+
syslog_event = LogStash::Event.new({ "message" => "<164>Oct 26 15:19:25 1.2.3.4 %ASA-4-106023: Deny udp src DRAC:10.1.2.3/43434" })
86+
input.syslog_relay(syslog_event)
87+
insist { syslog_event["priority"] } == 164
88+
insist { syslog_event["severity"] } == 4
89+
insist { syslog_event["tags"] } == nil
90+
end
91+
7392
end

0 commit comments

Comments
 (0)