From 33335e37e770dae74e200fa8b63bda8b8c2f5681 Mon Sep 17 00:00:00 2001 From: Aaron Mildenstein Date: Mon, 20 Jun 2016 18:03:18 -0600 Subject: [PATCH] Update to use Java Event set and get Update version dependency for zabbix_protocol ruby gem Update to do testing with Travis CI Disabling Docker testing for now TravisCI and JRuby are not playing nice. Filed a ticket at: https://github.com/travis-ci/travis-rubies/issues/18 Fixes #15 --- .travis.yml | 19 +++++++++++++++---- CHANGELOG.md | 6 +++++- lib/logstash/outputs/zabbix.rb | 16 ++++++++-------- logstash-output-zabbix.gemspec | 6 +++--- travis-run.sh | 8 ++++++++ 5 files changed, 39 insertions(+), 16 deletions(-) create mode 100755 travis-run.sh diff --git a/.travis.yml b/.travis.yml index 350c4eb..c6710db 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,18 @@ +--- +#sudo: required sudo: false +jdk: oraclejdk8 +env: + - INTEGRATION=false +# - INTEGRATION=true language: ruby -cache: bundler +cache: + bundler: true +#services: +# - docker rvm: - - jruby-1.7.23 -script: - - bundle exec rspec spec + - jruby-1.7.25 +#before_install: +# - docker pull untergeek/logstash_output_zabbix_rspec:latest +# - docker run -i --name="logstash_zabbix_rspec" -t -d -p 10051:10051 untergeek/logstash_output_zabbix_rspec:latest run +script: "./travis-run.sh" diff --git a/CHANGELOG.md b/CHANGELOG.md index db0237b..7eb496f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 3.0.0 + - Breaking: Updated plugin to use new Java Event APIs + - Use zabbix_protocol 0.1.5 or greater (tasty fixes for Zabbix) + - Make TravisCI use JRuby 1.7.25, and have Travis run the unit & integration tests. # 2.0.2 - Depend on logstash-core-plugin-api instead of logstash-core, removing the need to mass update plugins on major releases of logstash # 2.0.1 @@ -7,4 +11,4 @@ instead of using Thread.raise on the plugins' threads. Ref: https://github.com/elastic/logstash/pull/3895 - Dependency on logstash-core update to 2.0 - Update to allow semicolons (or not, e.g. Zabbix 2.0). #6 (davmrtl) - - Update to prevent Logstash from crashing when the Zabbix server becomes unavailable while the plugin is sending data. #9 (dkanbier) + - Update to prevent Logstash from crashing when the Zabbix server becomes unavailable while the plugin is sending data. #9 (dkanbier) diff --git a/lib/logstash/outputs/zabbix.rb b/lib/logstash/outputs/zabbix.rb index 0bf8eaa..3614dec 100644 --- a/lib/logstash/outputs/zabbix.rb +++ b/lib/logstash/outputs/zabbix.rb @@ -104,7 +104,7 @@ def register public def field_check(event, fieldname) - if !event[fieldname] + if !event.get(fieldname) @logger.warn("Field referenced by #{fieldname} is missing") false else @@ -142,10 +142,10 @@ def format_request(event) data = [] (0..validated.length-1).step(2) do |idx| data << { - "host" => event[@zabbix_host], - "key" => event[validated[idx]], - "value" => event[validated[idx+1]], - "clock" => event["@timestamp"].to_i + "host" => event.get(@zabbix_host), + "key" => event.get(validated[idx]), + "value" => event.get(validated[idx+1]), + "clock" => event.get("@timestamp").to_i } end { @@ -183,12 +183,12 @@ def info_check(event, data) total = info[5].to_i if failed == total @logger.warn("Zabbix server at #{@zabbix_server_host} rejected all items sent.", - :zabbix_host => event[@zabbix_host] + :zabbix_host => event.get(@zabbix_host) ) false elsif failed > 0 @logger.warn("Zabbix server at #{@zabbix_server_host} rejected #{info[3]} item(s).", - :zabbix_host => event[@zabbix_host] + :zabbix_host => event.get(@zabbix_host) ) false elsif failed == 0 && total > 0 @@ -237,7 +237,7 @@ def send_to_zabbix(event) public def receive(event) - + return unless field_check(event, @zabbix_host) send_to_zabbix(event) end # def event diff --git a/logstash-output-zabbix.gemspec b/logstash-output-zabbix.gemspec index 863c9e4..643cb1d 100644 --- a/logstash-output-zabbix.gemspec +++ b/logstash-output-zabbix.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = 'logstash-output-zabbix' - s.version = '2.0.2' + s.version = '3.0.0' s.licenses = ["Apache License (2.0)"] s.summary = "This output sends key/value pairs to a Zabbix server." s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program" @@ -18,8 +18,8 @@ Gem::Specification.new do |s| s.metadata = { "logstash_plugin" => "true", "logstash_group" => "output" } # Gem dependencies - s.add_runtime_dependency "logstash-core-plugin-api", "~> 1.0" - s.add_runtime_dependency "zabbix_protocol" + s.add_runtime_dependency "logstash-core-plugin-api", "~> 2.0" + s.add_runtime_dependency "zabbix_protocol", ">= 0.1.5" s.add_runtime_dependency "logstash-codec-plain" s.add_development_dependency "logstash-devutils", ">= 0.0.12" s.add_development_dependency "logstash-filter-mutate" diff --git a/travis-run.sh b/travis-run.sh new file mode 100755 index 0000000..146a4e6 --- /dev/null +++ b/travis-run.sh @@ -0,0 +1,8 @@ +#!/bin/bash +set -ex + +if [[ "$INTEGRATION" != "true" ]]; then + bundle exec rspec -fd spec +elif [[ "$INTEGRATION" == "true" ]]; then + bundle exec rspec -fd spec -t integration +fi