0

I am working on Sensu. I have installed sensu in CentOS. I need to get the event messages which is generated by Sensu checks.I have added some of the sensu community plugins like check-procs.rb,check-load.rb,check-banner.rb, metrics-ebs-volume.rb etc. I have written some handler files to event handle these .rb files. I am getting events in sensu-server.log.

Example:

{"timestamp":"2016-08-10T07:32:08.000003+0000","level":"info","message":"publishing check request","payload":{"name":"swap-free","issued":1470814327,"command":"check-swap.sh 20 10"},"subscribers":["base_centos_monitoring"]}

I have written a ruby file "nephele_events_handler.rb" which sends events messages through rest call to another server. The ruby file is in the location "/etc/sensu/handlers/". I am reading events from STDIN.read, i have read from official sensu documentation that events will be stored inside STDIN.

#!/opt/sensu/embedded/bin/ruby
require "#{File.dirname(__FILE__)}/base"
require 'rubygems'
require 'json'
require 'uri'
require 'net/http'
require 'net/https'
require 'json'

class RunProcs < BaseHandler

  def payload_check
#Read event data

sensuhash = "{ \"SensuMessage\"" + ":"
braces = "}"
s = sensuhash.to_s


event = JSON.parse(STDIN.read, :symbolize_names => true)
eventPayload = event.to_json
sensujson = s + eventPayload + braces
uri = URI.parse("https://localhost:8080/Processor/services/sourceEvents/requestMsg")
https = Net::HTTP.new(uri.host,uri.port)
https.use_ssl = false
req = Net::HTTP::Post.new(uri.path, initheader = {'Content-Type' =>'application/json'})
req.body = "[ #{sensujson} ]"
res = https.request(req)
end        
info = RunProcs.new
  info.payload_check    
end

Am writing handler json file "processor.json" inside the location "/etc/sensu/conf.d/handlers".

{
  "handlers": {
    "nephele_processor": {
      "type": "pipe",
      "command": "nephele_events_handler.rb"
    }
  }
}  

But the issue am facing is am only getting events from 'check-procs'

{"client":{"address":"10.81.1.105","subscriptions":["base_centos","base_chef-client","python","base_centos_monitoring","base_centos_monitoring_metrics","sensu_client","base_aws","base_aws_monitoring","sensu_master","all"],"name":"ip-localhost.internal","hostname":"ip-localhost","version":"0.25.3","timestamp":1470896756},"check":{"command":"check-procs.rb --pattern='chef-client' -W=1","subscribers":["base_centos_monitoring"],"handlers":["base_with_jira"],"interval":60,"team":"ops","aggregate":true,"occurrences":3,"refresh":300,"ticket":true,"name":"process-chef-client","issued":1470896771,"executed":1470896771,"duration":0.864,"output":"CheckProcs CRITICAL: Found 0 matching processes; cmd /chef-client/\n","status":2,"type":"standard","history":["2","2","2","2","2","2","2","2","2","2","2","2","2","2","2","2","2","2","2","2","2"],"total_state_change":0},"occurrences":19879,"action":"create","timestamp":1470896772,"id":"dc2b0698-dbac-416d-a9ae-42aa09d53cc3","last_state_change":1469690268,"last_ok":null}

The Check which is getting executed

{
  "checks": {
    "process-chef-client": {
      "command": "check-procs.rb --pattern='chef-client' -W=1",
      "subscribers": [
        "base_centos_monitoring"
      ],
      "handlers": [
        "base_with_jira"
      ],
      "interval": 60,
      "team": "ops",
      "aggregate": true,
      "occurrences": 3,
      "interval": 60,
      "refresh": 300,
      "ticket": true
    }
  }
}

base_with_jira.json

{
  "handlers": {
    "base_with_jira": {
      "type": "set",
      "handlers": [
       "jira",
       "nephele_processor"
      ],
      "config": "http://apache.enron.nephele.solutions/uchiwa"
    }
  }
}

I am not getting events from other plugins. Can you explain what i have to do for this.

Adiii
  • 54,482
  • 7
  • 145
  • 148
Mohamed Safi
  • 39
  • 2
  • 10
  • You detailed the current config very well. But I don't think I understand what is the problem. You need a separate check for each of the plugins, do you have those other checks? – Enrique Arriaga Aug 11 '16 at 20:54
  • Also, the handler in the check you posted is "base_with_jira", but the handler definition you posted is "nephele_processor" – Enrique Arriaga Aug 11 '16 at 20:56
  • I will post the other handler also... And i have separate checks for every plugin. Do you need the checks details and plugins? – Mohamed Safi Aug 12 '16 at 07:08
  • Well yes, specially the ones experiencing problems. Probably the definition is not correct(?) – Enrique Arriaga Aug 12 '16 at 15:26
  • I have other checks and respective plugins. I am not getting the events except the command "command": "check-procs.rb --pattern='chef-client' -W=1",. What i have to do for other checks? – Mohamed Safi Aug 16 '16 at 06:47
  • Have you checked the client logs /var/log/sensu/sensu-client.log? Or the server logs /var/log/sensu/sensu-server.log? If the check is correctly defined you could find what is the problem in this logs, i.e. it could be the plugin is not found, or is not executable, etc... – Enrique Arriaga Aug 17 '16 at 15:42
  • Is it fine to read sensu events from STDIN.read. other events are getting triggered from checks. But i cannot post it through REST call. Whether every event messages will be stored in STDIN? – Mohamed Safi Aug 18 '16 at 12:11
  • Whether STDIN will only have critical messages inside it? – Mohamed Safi Aug 18 '16 at 14:24

0 Answers0