require "logstash/devutils/rspec/spec_helper" require "logstash/outputs/opennms" require "logstash/codecs/plain" require "logstash/event" require "socket" require "timeout" require "longshoreman" require "rexml/document" include REXML NAME = "logstash-output-opennms-#{rand(999).to_s}" IMAGE = "untergeek/logstash_output_opennms_rspec" TAG = "latest" OPENNMS_PORT = 5817 TIMEOUT = 1 NODEID = 1 SEVERITY = 6 # MAJOR describe LogStash::Outputs::OpenNMS do # Building block "lets" let(:opennms_server_hosts) { {"localhost" => OPENNMS_PORT} } let(:opennms_server_timeout) { TIMEOUT } let(:opennms_event_timezone) { "cest" } let(:opennms_event_nodeid) { NODEID } let(:opennms_event_interface) { "192.168.1.1" } let(:opennms_event_uei) { "uei.opennms.com" } let(:opennms_event_origin) { "localhost" } let(:opennms_event_severity) { 7 } let(:opennms_event_source) { "logstash" } let(:opennms_event_description) { "sample description" } let(:opennms_event_logmsg) { "sample logmsg" } let(:opennms_event_parms) { { "Type" => "auto", "EventId" => "12345", "OpsInstruct" => "https://en.wikipedia.org/wiki/RTFM", "IncidentMessage" => "Outage of Business Service", "SubSource" => "Webapp", "TicketOwner" => "Linux Team", "TicketPriority" => "1", } } # Assembled "lets" let(:onms_event) { { "opennms_server_hosts" => opennms_server_hosts, "opennms_server_timeout" => opennms_server_timeout, "opennms_event_timezone" => opennms_event_timezone, "opennms_event_nodeid" => opennms_event_nodeid, "opennms_event_interface" => opennms_event_interface, "opennms_event_uei" => opennms_event_uei, "opennms_event_origin" => opennms_event_origin, "opennms_event_severity" => opennms_event_severity, "opennms_event_source" => opennms_event_source, "opennms_event_description" => opennms_event_description, "opennms_event_logmsg" => opennms_event_logmsg, "opennms_event_parms" => opennms_event_parms, } } let(:onms_output) { onms_event } # Finished object "lets" let(:sample_event) { LogStash::Event.new(onms_event) } let(:output) { LogStash::Outputs::OpenNMS.new(onms_output) } before do output.register end describe "Unit Tests" do describe "#field_check" do context "when expected field not found" do subject { output.field_check(sample_event, "not_appearing") } it "should return false" do expect(subject).to eq(false) end end context "when expected field found" do subject { output.field_check(sample_event, "opennms_event_uei") } it "should return true" do expect(subject).to eq(true) end end end # "#field_check" end # "Unit Tests" end # describe LogStash::Outputs::OpenNMS