Sensu检查结果事件数据

时间:2016-08-11 07:51:48

标签: json ruby sensu

我正在研究Sensu。我在CentOS安装了sensu。我需要获取由Sensu checks生成的事件消息。我添加了一些sensu社区插件,如check-procs.rb,check-load.rb,check-banner.rb,metrics-ebs-volume.rb等我已经为事件处理这些.rb文件编写了一些处理程序文件。我在sensu-server.log中获取事件。

示例:

{“timestamp”:“2016-08-10T07:32:08.000003 + 0000”,“level”:“info”,“message”:“发布检查请求”,“有效负载”:{“name”:“ swap-free“,”发出“:1470814327,”command“:”check-swap.sh 20 10“},”subscriber“:[”base_centos_monitoring“]}

我编写了一个ruby文件“nephele_events_handler.rb”,它通过其他服务器的休息调用发送事件消息。 ruby文件位于“/ etc / sensu / handlers /”位置。我正在阅读STDIN.read的活动,我从官方的sensu文档中读到,事件将存储在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

在“/etc/sensu/conf.d/handlers”位置内编写处理程序json文件“processor.json”。

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

但面临的问题是我只能从'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}

检查哪个正在执行

{
  "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"
    }
  }
}

我没有从其他插件获取事件。你能解释一下我要为此做些什么。

0 个答案:

没有答案