-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eacd694
commit 8b203a8
Showing
2 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/usr/bin/env ruby | ||
# | ||
# This is a drop-in replacement for the graphite mutator written | ||
# as a Sensu Extention for better performance. | ||
# | ||
# It transforms parameter name if it's a hostname. | ||
# | ||
# There are two transforms you can apply separately: | ||
# * Replace dots in FQDN to user specified strings. | ||
# e.g. foo.example.com -> foo_example_com | ||
# * Output the hostname in reverse order. | ||
# e.g. foo.example.com -> com.example.foo | ||
# | ||
# The default configuration is: | ||
# | ||
# { | ||
# "graphite": { | ||
# "reverse": false, | ||
# "replace": "_" | ||
# } | ||
# } | ||
# | ||
# Copyright 2013 Mitsutoshi Aoe <[email protected]> | ||
# | ||
# Released under the same terms as Sensu (the MIT license); see LICENSE | ||
# for details. | ||
|
||
# #YELLOW | ||
module Sensu::Extension # rubocop:disable Style/ClassAndModuleChildren | ||
class Graphite < Mutator | ||
def name | ||
'graphite' | ||
end | ||
|
||
def description | ||
'OnlyCheckOutput mutator for Graphite' | ||
end | ||
|
||
def post_init | ||
@reverse = false | ||
@replace = '_' | ||
|
||
# #YELLOW | ||
if settings['graphite'] # rubocop:disable GuardClause | ||
# #YELLOW | ||
@reverse = true if settings['graphite']['reverse'] == true | ||
if settings['graphite']['replace'] | ||
@replace = settings['graphite']['replace'] | ||
end | ||
end | ||
end | ||
|
||
def run(event, &block) | ||
client_name = event[:client][:name] | ||
if @reverse | ||
renamed_client_name = client_name.split('.').reverse.join('.') | ||
else | ||
renamed_client_name = client_name | ||
end | ||
renamed_client_name = renamed_client_name.gsub('.', @replace) | ||
mutated = event[:check][:output].gsub(client_name, renamed_client_name) | ||
block.call(mutated, 0) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env ruby | ||
# | ||
# Graphite | ||
# === | ||
# | ||
# DESCRIPTION: | ||
# I extend OnlyCheckOutput mutator specialy for Graphite. | ||
# This mutator only send event output (so you don't need to use | ||
# OnlyCheckOutput) and change parameter name if it is hostname | ||
# for better view in Graphite. | ||
# | ||
# OUTPUT: | ||
# event output with all dot changed to underline in host name | ||
# If -r or --reverse parameter given script put hostname in | ||
# reverse order for better graphite tree view | ||
# | ||
# PLATFORM: | ||
# all | ||
# | ||
# DEPENDENCIES: | ||
# | ||
# json Ruby gem | ||
# | ||
# Copyright 2013 Peter Kepes <https://github.com/kepes> | ||
# | ||
# Released under the same terms as Sensu (the MIT license); see LICENSE | ||
# for details. | ||
require 'rubygems' if RUBY_VERSION < '1.9.0' | ||
require 'json' | ||
|
||
# parse event | ||
event = JSON.parse(STDIN.read, symbolize_names: true) | ||
|
||
if ARGV[0] == '-r' || ARGV[0] == '--reverse' | ||
puts event[:check][:output].gsub(event[:client][:name], event[:client][:name].split('.').reverse.join('.')) | ||
else | ||
puts event[:check][:output].gsub(event[:client][:name], event[:client][:name].gsub('.', '_')) | ||
end |