Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- # Magic Online 2016
- # # This extension mutator is supposed to format sensu events to InfluxDb line format
- #! /usr/bin/env ruby
- #
- # mutator-influxdb-line-protocol
- #
- # DESCRIPTION:
- # Mutates check results to conform to InfluxDB's line protocol format
- #
- # Place this file in /etc/sensu/extensions and modify your handlers JSON config
- #
- # handlers.json
- # {
- # "influxdb_udp": {
- # "type": "udp",
- # "mutator": "mutator-influxdb-line-protocol",
- # "socket": {
- # "host": "mgt-monitor-db1",
- # "port": 8090
- # }
- # }
- # }
- require 'sensu/extension'
- module Sensu
- module Extension
- class InfluxDBLineProtocol < Mutator
- def name
- 'influxdb_line_protocol'
- end
- def description
- "returns check output formatted for InfluxDB's line protocol"
- end
- def run(event)
- host = event[:client][:name]
- metric = event[:check][:name]
- output = event[:check][:output]
- formahost = host.gsub(".",'_')
- data = []
- output.split("\n").each do |result|
- m = result.split
- next unless m.count == 3
- key = m[0].split('.', 2)[1]
- key.tr!('.', '_')
- fkey= key.gsub("#{formahost}_","") # Cutsom: replaced key with fkey
- value = m[1].to_f
- time = m[2].ljust(19, '0')
- data << "#{fkey},host=#{host},metric=#{metric} value=#{value} #{time}"
- end
- yield data.join("\n"), 0
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement