GithubHelp home page GithubHelp logo

logstash-output-nagios_nsca's Introduction

Logstash Plugin

Travis Build Status

This is a plugin for Logstash.

It is fully free and fully open source. The license is Apache 2.0, meaning you are pretty much free to use it however you want in whatever way.

Documentation

Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one central location.

Need Help?

Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.

Developing

1. Plugin Developement and Testing

Code

  • To get started, you'll need JRuby with the Bundler gem installed.

  • Create a new plugin or clone and existing from the GitHub logstash-plugins organization. We also provide example plugins.

  • Install dependencies

bundle install

Test

  • Update your dependencies
bundle install
  • Run tests
bundle exec rspec

2. Running your unpublished Plugin in Logstash

2.1 Run in a local Logstash clone

  • Edit Logstash Gemfile and add the local plugin path, for example:
gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
  • Install plugin
# Logstash 2.3 and higher
bin/logstash-plugin install --no-verify

# Prior to Logstash 2.3
bin/plugin install --no-verify
  • Run Logstash with your plugin
bin/logstash -e 'filter {awesome {}}'

At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.

2.2 Run in an installed Logstash

You can use the same 2.1 method to run your plugin in an installed Logstash by editing its Gemfile and pointing the :path to your local plugin development directory or you can build the gem and install it using:

  • Build your plugin gem
gem build logstash-filter-awesome.gemspec
  • Install the plugin from the Logstash home
# Logstash 2.3 and higher
bin/logstash-plugin install --no-verify

# Prior to Logstash 2.3
bin/plugin install --no-verify
  • Start Logstash and proceed to test the plugin

Contributing

All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.

Programming is not a required skill. Whatever you've seen about open source and maintainers or community members saying "send patches or die" - you will not see that here.

It is more important to the community that you are able to contribute.

For more information about contributing, see the CONTRIBUTING file.

logstash-output-nagios_nsca's People

Contributors

alxrem avatar andsel avatar colinsurprenant avatar electrical avatar jakelandis avatar jordansissel avatar jsvd avatar kurtado avatar nnebojsa avatar ph avatar robbavey avatar talevy avatar yaauie avatar ycombinator avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

logstash-output-nagios_nsca's Issues

TypeError: no implicit conversion of Fixnum into String

We are having problem with logstash-output-nagios_nsca and the latest version of Logstash 6.1.2

Centos7, Logstash Docker image

[2018-01-23T14:00:00,893][WARN ][logstash.outputs.nagiosnsca] Skipping nagios_nsca output; error calling send_nsca {:error=>#<TypeError: no implicit conversion of Fixnum into String>, :nagios_nsca_command=>"/usr/sbin/send_nsca -H -p 5667 -d : -c /usr/share/logstash/config/send_nsca.cfg", :message=>"test_salesws:OrderAdjustmentBatchService.autoAdjustInternetOrders TICKET_NO:0:Job finished sucessfully in PT0.568S", :missed_event=>#LogStash::Event:0x76331c93}

Remove usage of `LogStash::SHUTDOWN`

With the removal of Ruby Execution Engine elastic/logstash#12517 the LogStash::SHUTDOWN was removed.
This plugin starts failing on 8.0.

Build scan:
https://app.travis-ci.com/github/logstash-plugins/logstash-output-nagios_nsca/jobs/538358481#L480

Repro line:
NA

Reproduces locally?:
Yes

Applicable branches:
master

Failure history:

Failure excerpt:

logstash_1_d54db825a42b | Failures:
logstash_1_d54db825a42b | 
logstash_1_d54db825a42b |   1) LogStash::Outputs::NagiosNsca send send the event to nagios
logstash_1_d54db825a42b |      Failure/Error: return if event == LogStash::SHUTDOWN
logstash_1_d54db825a42b |      
logstash_1_d54db825a42b |      NameError:
logstash_1_d54db825a42b |        uninitialized constant LogStash::SHUTDOWN
logstash_1_d54db825a42b |        Did you mean?  LogStash::ShutdownSignal
logstash_1_d54db825a42b |      # ./lib/logstash/outputs/nagios_nsca.rb:69:in `receive'
logstash_1_d54db825a42b |      # ./spec/outputs/nagios_nsca_spec.rb:26:in `block in <main>'

Centos 1.4 distro

Good morning,

I figured out a bug that is located in the nagios_nsca.rb output file for the CentOS repo install
[logstash-1.4]
name=logstash repository for 1.4.x packages
baseurl=http://packages.elasticsearch.org/logstash/1.4/centos
gpgcheck=1
gpgkey=http://packages.elasticsearch.org/GPG-KEY-elasticsearch
enabled=1

in the original file that was installed it reads as such:
# build the command
# syntax: echo '!<nagios_service>!!' |
# /usr/sbin/send_nsca -H <nagios_host> -d '!' -c <nsca_config>"

cmd = [@send_nsca_bin, "-H", "@host", "-p", "@port", "-d", "~"]
cmd = cmd + ["-c", @send_nsca_config]  if @send_nsca_config
message = "#{nagios_host}~#{nagios_service}~#{status}~#{msg}"

As you can see, "@host" and "@PORT" are a problem since they are supposed to call a variable but instead act as a string.

It should instead read:
cmd = [@send_nsca_bin, "-H", @host, "-p", @PORT, "-d", "~"]

This allows functionality to the output.

No tests / Tests missing

Hi,
this plugin has no test at all, this is a situation that should be amended soon, so for example changes in both the plugin or the logstash core himself, are properly tested in the CI environment.

If you are giving this plugin some test, feel free to update elastic/logstash#3740 so we keep track of it.

after applying the 2.0.3 error on start

After applying the 2.0.3 version with bin/plugin update logstash-output-nagios_nsca, run into error:

logstash-output-nagios (2.0.2)
logstash-output-nagios_nsca (2.0.3)
logstash-output-null (2.0.2)
logstash-output-opentsdb (2.0.2)
logstash-output-pagerduty (2.0.2)
logstash-output-pipe (2.0.2)
logstash-output-rabbitmq (3.0.5)
logstash-output-redis (2.0.2)
logstash-output-s3 (2.0.3)
logstash-output-sns (3.0.2)
logstash-output-sqs (2.0.2)
logstash-output-statsd (2.0.4)
logstash-output-stdout (2.0.2)
logstash-output-tcp (2.0.2)
logstash-output-udp (2.0.2)
logstash-output-xmpp (2.0.2)
logstash-output-zeromq (2.0.2)
logstash-patterns-core (2.0.2)
[root@dbdev ~]# /opt/logstash/bin/logstash agent -f /etc/logstash/conf.d/shipper.conf --debug -v -l /tmp/logfile.log -vv
RuntimeError: Logstash expects concurrent-ruby version 0.9.1 and version 0.9.2 is installed, please verify this patch: /opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.0.0-java/lib/logstash/patches/silence_concurrent_ruby_warning.rb
(root) at /opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.0.0-java/lib/logstash/patches/silence_concurrent_ruby_warning.rb:53
require at org/jruby/RubyKernel.java:1040
(root) at /opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.0.0-java/lib/logstash/patches.rb:1
require at org/jruby/RubyKernel.java:1040
(root) at /opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.0.0-java/lib/logstash/patches.rb:6
require at org/jruby/RubyKernel.java:1040
(root) at /opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.0.0-java/lib/logstash/environment.rb:1
require at org/jruby/RubyKernel.java:1040
(root) at /opt/logstash/lib/bootstrap/environment.rb:48
[root@dbdev ~]#

OS:
lsb_release -a
LSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID: CentOS
Description: CentOS release 6.4 (Final)
Release: 6.4
Codename: Final

java:
java -version
java version "1.7.0_91"
OpenJDK Runtime Environment (rhel-2.6.2.2.el6_7-x86_64 u91-b00)
OpenJDK 64-Bit Server VM (build 24.91-b01, mixed mode)

RPM:
rpm -qi logstash-2.0.0-1.noarch
Name : logstash Relocations: /
Version : 2.0.0 Vendor: Elasticsearch
Release : 1 Build Date: Tue 27 Oct 2015 07:48:24 PM CET
Install Date: Wed 25 Nov 2015 11:04:57 AM CET Build Host: slave12.build.ci.hetz.es.io
Group : default Source RPM: logstash-2.0.0-1.src.rpm
Size : 136366484 License: ASL 2.0
Signature : RSA/SHA1, Wed 28 Oct 2015 03:47:40 PM CET, Key ID d27d666cd88e42b4
Packager : [email protected]
URL : http://www.elasticsearch.org/overview/logstash/
Summary : An extensible logging pipeline
Description :
An extensible logging pipeline


Workaround for me:
in logstash home:
echo "gem 'concurrent-ruby', '0.9.1'" >> Gemfile

and change everywere in lock file 'concurrent-ruby' to 0.9.1, after them:
bin/plugin install --no-verify

Now its work with the 2.0.3. plugin version.

plugin nagios_nsca doesn't work

(This issue was originally filed by @pulecp at elastic/logstash#2213)


Hi,
I have problem with nagios_nsca plugin on following setup:

logstash: 1.4.2-1_2c0f5a1
kernel: 2.6.32-358.14.1.el6.x86_64
java: version "1.7.0_25"
OpenJDK Runtime Environment (rhel-2.3.10.4.el6_4-x86_64)
OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)

run of plugin is ending with following error:


{:timestamp=>"2014-12-10T08:35:52.571000+0100", :message=>"Backtrace", :backtrace=>["org/jruby/RubyIO.java:2097:in `close'", 
"/opt/logstash/lib/logstash/outputs/nagios_nsca.rb:119:in `receive'", "org/jruby/RubyIO.java:4433:in `popen3'", 
"file:/opt/logstash/vendor/jar/jruby-complete-1.7.11.jar!/META-INF/jruby.home/lib/ruby/1.9/open3.rb:74:in `popen3'", 
"/opt/logstash/lib/logstash/outputs/nagios_nsca.rb:117:in `receive'", "/opt/logstash/lib/logstash/outputs/base.rb:86:in `handle'", "(eval):44:in 
`initialize'", "org/jruby/RubyProc.java:271:in `call'", "/opt/logstash/lib/logstash/pipeline.rb:266:in `output'", 
"/opt/logstash/lib/logstash/pipeline.rb:225:in `outputworker'", "/opt/logstash/lib/logstash/pipeline.rb:152:in `start_outputs'"], :level=>:debug}

I unsuccessfully tried fix described here: https://logstash.jira.com/browse/LOGSTASH-2286

nagios_nsca plugin not working

Moved from https://logstash.jira.com/browse/LOGSTASH-2286
We updated to version 1.4.2 of logstash, using the official rpm package from the elasticsearch repository. After this update, we realized, the nagios_nsca plugin stopped working (stopped to output events to out icinga).
After manualy updating lib/logstash/outputs/nagios_nsca.rb to commit 65af91d0158725fd18dc09897c6d73839efa47d0 and some debugging we found the following solution:
Replace:

Open3.popen3(*cmd) do |i, o, e|
i.puts(message)
i.close
end`

with:

Open3.popen3(*cmd) do |i, o, e, t|
i.puts(message)
i.close
t.value
end

To us the problem seamed to be a timing problem because logstash is not waiting for the termination of the process.

TypeError: no implicit conversion of Integer into String

I am having a problem with logstash-output-nagios_nsca and the latest version of Logstash 7.1.1

Centos7

Steps to reproduce:

setup config:

    input {
    beats {
	  port => 5074 
          type => "nagioscheckbeats"
	  ssl => true
	  ssl_certificate_authorities => ["/etc/logstash/certs/cacert.pem"]
	  ssl_certificate => "/etc/logstash/certs/{{ inventory_hostname }}.crt"
	  ssl_key => "/etc/logstash/certs/{{ inventory_hostname }}-logstash.pem"
	  ssl_verify_mode => "force_peer"
      }
    }

    filter {
		if [type] =~ "nagiosmetric" {
			mutate {
			  convert => { "name" => "string" }
			  convert => { "status_code" => "string" }
			  convert => { "message" => "string" }
			}
		}
	}
	
output {

		if [type] == "nagiosmetric" {
		  elasticsearch { 
			hosts => [{{ logstash_elasticsearch_hosts }}]
			user => {{ xpack_management_elasticsearch_username }}
			password => {{ xpack_management_elasticsearch_password }}
			cacert => "{{ logstash_ssl_dir }}/{{ logstash_ssl_certificate_file }}"
			ssl_certificate_verification => false
			index => "nagioscheckbeat-%{+YYYY.MM.dd}" 
		}
		} else {
		    nagios_nsca {
				host => "{{nagios_server}}"
				port => 5667
				nagios_service => "%{name}"
				nagios_status => "%{[status_code]}"
				nagios_host => "%{[beat][hostname]}"
				message_format => "%{name}: %{message}"
			}
			# used for debugging
			#file {
			#  	path => "/tmp/logstash-output.txt"
			#  	codec => line { format => "custom format: %{message}"}
			#}
		}
	}

The debug output is:

[2019-08-31T02:12:26,725][DEBUG][logstash.outputs.nagiosnsca] Running send_nsca command     {:nagios_nsca_command=>"/usr/sbin/send_nsca -H xxxx.xxxx.com -p 5667 -d :", :message=>"xxxx.xxxx.com:heartbeat:0:heartbeat: OK: Hello<br/>"}

[2019-08-31T02:12:26,727][WARN ][logstash.outputs.nagiosnsca] Skipping nagios_nsca output; error calling send_nsca {:error=>#<TypeError: no implicit conversion of Integer into String>, :nagio
s_nsca_command=>"/usr/sbin/send_nsca -H xxxx.xxxx.com -p 5667 -d :", :message=>"xxxx.xxxx.com:heartbeat:0:heartbeat: OK: Hello<br/>", :missed_event=>#<LogStash::Event:0x669acbab>}   
[2019-08-31T02:12:26,727][DEBUG][logstash.outputs.nagiosnsca] Backtrace {:backtrace=>["org/jruby/RubyProcess.java:1567:in `spawn'", "org/jruby/RubyKernel.java:1646:in `spawn'", "uri:classload
er:/META-INF/jruby.home/lib/ruby/stdlib/open3.rb:202:in `popen_run'", "uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/open3.rb:98:in `popen3'", "/usr/share/logstash/vendor/bundle/jruby/
2.5.0/gems/logstash-output-nagios_nsca-3.0.6/lib/logstash/outputs/nagios_nsca.rb:135:in `send_to_nagios'", "/usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/logstash-output-nagios_nsca-3.0.
6/lib/logstash/outputs/nagios_nsca.rb:110:in `receive'", "/usr/share/logstash/logstash-core/lib/logstash/outputs/base.rb:89:in `block in multi_receive'", "org/jruby/RubyArray.java:1792:in `ea
ch'", "/usr/share/logstash/logstash-core/lib/logstash/outputs/base.rb:89:in `multi_receive'", "org/logstash/config/ir/compiler/OutputStrategyExt.java:118:in `multi_receive'", "org/logstash/co
nfig/ir/compiler/AbstractOutputDelegatorExt.java:101:in `multi_receive'", "/usr/share/logstash/logstash-core/lib/logstash/java_pipeline.rb:235:in `block in start_workers'"]}`

I know next to nothing about Ruby, but I messed around with the plugin code enough to narrow the problem down to the cmd variable was trying to join strings with the port as an integer.

I modified the code enough to be able to see the messages coming through to Nagios. The below is NOT meant to represent an improvement on the plugin code - it's just a hack for me to locate the problem and prove that the message can get through. Hopefully, someone else can provide the correct solution in ruby.

I changed this:

def cmd
    return @cmd if @cmd
   # @cmd = [@send_nsca_bin, "-H", @host, "-p", @port, "-d", ":"]
   # @cmd = @cmd + ["-c", @send_nsca_config]  if @send_nsca_config
   @cmd = @send_nsca_bin.to_s + " " + "-H" + " " + @host.to_s + " " + "-p" + " " + @port.to_s + " " + "-d" + " " + ":"
  # @cmd = @cmd + [" " + "-c" + " " + @send_nsca_config  if @send_nsca_config
  @cmd
end

def send_to_nagios(cmd, message)
  Open3.popen3(*cmd) do |i, o, e|
    # added logger for testing
    logger.info("Running send_nsca command", :nagios_nsca_command => cmd, :message => message)
    i.puts(message)
    i.close
   end
end

These changes remove the error and allow data to be processed as expected.

Thanks,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.