Skip to content

Commit

Permalink
support nagios plugins and their performance data (for graphite)
Browse files Browse the repository at this point in the history
  • Loading branch information
portertech committed Nov 2, 2013
1 parent b4bc699 commit 73facb1
Show file tree
Hide file tree
Showing 12 changed files with 152 additions and 15 deletions.
1 change: 1 addition & 0 deletions .kitchen.yml
Expand Up @@ -64,6 +64,7 @@ suites:
dashboard:
port: 4000
monitor:
use_nagios_plugins: true
metric_handlers: ["graphite"]
additional_client_attributes:
haproxy_services: "servers-http"
1 change: 1 addition & 0 deletions attributes/default.rb
Expand Up @@ -6,6 +6,7 @@
default["monitor"]["use_local_ipv4"] = false

default["monitor"]["sensu_plugin_version"] = "0.2.1"
default["monitor"]["use_nagios_plugins"] = false

default["monitor"]["additional_client_attributes"] = Mash.new

Expand Down
1 change: 1 addition & 0 deletions attributes/nagios_plugins.rb
@@ -0,0 +1 @@
default["monitor"]["nagios_plugin_packages"] = ["nagios-plugins"]
44 changes: 44 additions & 0 deletions files/default/extensions/nagios_perfdata.rb
@@ -0,0 +1,44 @@
#
# Nagios performance data to Graphite plain text mutator extension.
# ===
#
# Copyright 2013 Heavy Water Operations, LLC.
#
# Released under the same terms as Sensu (the MIT license); see LICENSE
# for details.

module Sensu
module Extension
class NagiosPerfData < Mutator
def name
'nagios_perfdata'
end

def description
'converts nagios performance data to graphite plain text'
end

def run(event)
result = []
client = event[:client]
check = event[:check]

# https://www.nagios-plugins.org/doc/guidelines.html#AEN200
perfdata = check[:output].split('|').last.strip

perfdata.split(/\s+/).each do |data|
# label=value[UOM];[warn];[crit];[min];[max]
label, value = data.split('=')

name = label.strip.gsub(/\W/, '_')
measurement = value.strip.split(';').first.gsub(/[^-\d\.]/, '')

path = [client[:name], check[:name], name].join('.')

result << [path, measurement, check[:executed]].join("\t")
end
yield(result.join("\n") + "\n", 0)
end
end
end
end
8 changes: 1 addition & 7 deletions recipes/_chef_node_handler.rb
Expand Up @@ -44,13 +44,7 @@
)
end

sensu_filter "keepalives" do
attributes(
:check => {
:name => "keepalive"
}
)
end
include_recipe "monitor::_filters"

sensu_handler "chef_node" do
type "pipe"
Expand Down
30 changes: 30 additions & 0 deletions recipes/_filters.rb
@@ -0,0 +1,30 @@
#
# Cookbook Name:: monitor
# Recipe:: _filters
#
# Copyright 2013, Sean Porter Consulting
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

sensu_filter "actions" do
attributes(:action => "eval: %w[create resolve].include? value")
end

sensu_filter "keepalives" do
attributes(
:check => {
:name => "keepalive"
}
)
end
19 changes: 11 additions & 8 deletions recipes/_graphite_handler.rb
Expand Up @@ -53,12 +53,15 @@
mutator "only_check_output"
end

sensu_handler "graphite_amqp" do
type "amqp"
exchange(
:type => "topic",
:name => "graphite",
:durable => true
)
mutator "only_check_output"
if node["monitor"]["use_nagios_plugins"]
include_recipe "monitor::_nagios_perfdata"

sensu_handler "graphite_perfdata" do
type "tcp"
socket(
:host => graphite_address,
:port => graphite_port
)
mutator "nagios_perfdata"
end
end
24 changes: 24 additions & 0 deletions recipes/_nagios_perfdata.rb
@@ -0,0 +1,24 @@
#
# Cookbook Name:: monitor
# Recipe:: _nagios_perfdata
#
# Copyright 2013, Sean Porter Consulting
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

cookbook_file "/etc/sensu/extensions/nagios_perfdata.rb" do
source "extensions/nagios_perfdata.rb"
mode 0755
notifies :create, "ruby_block[sensu_service_trigger]", :immediately
end
22 changes: 22 additions & 0 deletions recipes/_nagios_plugins.rb
@@ -0,0 +1,22 @@
#
# Cookbook Name:: monitor
# Recipe:: _nagios_plugins
#
# Copyright 2013, Sean Porter Consulting
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

node["monitor"]["nagios_plugin_packages"].each do |package_name|
package package_name
end
3 changes: 3 additions & 0 deletions recipes/_pagerduty_handler.rb
Expand Up @@ -28,7 +28,10 @@
content(:api_key => node["monitor"]["pagerduty_api_key"])
end

include_recipe "monitor::_filters"

sensu_handler "pagerduty" do
type "pipe"
command "pagerduty.rb"
filters ["actions"]
end
4 changes: 4 additions & 0 deletions recipes/default.rb
Expand Up @@ -39,6 +39,10 @@
version node["monitor"]["sensu_plugin_version"]
end

if node["monitor"]["use_nagios_plugins"]
include_recipe "monitor::_nagios_plugins"
end

%w[
check-procs.rb
check-banner.rb
Expand Down
10 changes: 10 additions & 0 deletions test/integration/data_bags/sensu_checks/ntp.json
@@ -0,0 +1,10 @@
{
"id": "ntp",
"type": "metric",
"command": "/usr/lib/nagios/plugins/check_ntp -H time.nrc.ca",
"subscribers": [
"all"
],
"interval": 60,
"handlers": ["graphite_perfdata"]
}

0 comments on commit 73facb1

Please sign in to comment.