Update Nagios encoder

This change updates the Nagios encoder to use the GSE cluster metrics
for sending the check results to Nagios.

Change-Id: If5fd926d5043da6cf0a46ad5404b6ea5bd4197b4
Implements: blueprint alerting-lma-collector
This commit is contained in:
Simon Pasquier 2015-09-14 14:32:59 +02:00
parent ae5a3c482e
commit 6c455cb441
3 changed files with 35 additions and 19 deletions

View File

@ -26,11 +26,11 @@ CRIT=3
DOWN=4
local STATUS_LABELS = {
[OKAY]='okay',
[WARN]='warning',
[UNKW]='unkwown',
[CRIT]='critical',
[DOWN]='down'
[OKAY]='OKAY',
[WARN]='WARN',
[UNKW]='UNKNOWN',
[CRIT]='CRITICAL',
[DOWN]='DOWN'
}
function status_label(v)

View File

@ -13,8 +13,9 @@
-- limitations under the License.
require 'table'
require 'string'
require 'cjson'
local utils = require 'lma_utils'
local afd = require 'afd'
local consts = require 'gse_constants'
local host = read_config('nagios_host')
local data = {
@ -27,6 +28,14 @@ local data = {
performance_data = '',
}
local nagios_break_line = '\\n'
-- mapping GSE statuses to Nagios states
local nagios_state_map = {
[consts.OKAY]=0,
[consts.WARN]=1,
[consts.UNKW]=3,
[consts.CRIT]=2,
[consts.DOWN]=2
}
function url_encode(str)
if (str) then
@ -38,21 +47,28 @@ function url_encode(str)
end
function process_message()
local service = read_message('Fields[service]')
local service = afd.get_entity_name('cluster_name')
local service_name = read_config(service)
if not service_name then
local status = afd.get_status()
local alarms = afd.alarms_for_human(afd.extract_alarms())
if not service_name or not nagios_state_map[status] or not alarms then
return -1
end
local status = read_message('Fields[status]')
local payload = read_message('Payload')
data['service'] = service_name
data['plugin_state'] = status
local ok, details = pcall(cjson.decode, payload)
if not ok or not details then details = {'no detail'} end
local title = string.format('%s %s',
service_name,
utils.global_status_to_label_map[status])
table.insert(details, 1, title)
data['plugin_state'] = nagios_state_map[status]
local details = {
string.format('%s %s', service_name, consts.status_label(status))
}
if #alarms == 0 then
details[#details+1] = 'no details'
else
for _, alarm in ipairs(alarms) do
details[#details+1] = alarm
end
end
data['plugin_output'] = table.concat(details, nagios_break_line)
local params = {}

View File

@ -42,7 +42,7 @@ class lma_collector::nagios (
heka::output::http { 'nagios':
config_dir => $lma_collector::params::config_dir,
url => $url,
message_matcher => 'Type == \'heka.sandbox.status\'',
message_matcher => 'Type == \'heka.sandbox.gse_cluster_metric\'',
username => $user,
password => $password,
encoder => 'nagios',