Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. # Magic Online 2016
  3. # # This extension mutator is supposed to format sensu events to InfluxDb line format
  4. #! /usr/bin/env ruby
  5. #
  6. # mutator-influxdb-line-protocol
  7. #
  8. # DESCRIPTION:
  9. # Mutates check results to conform to InfluxDB's line protocol format
  10. #
  11. # Place this file in /etc/sensu/extensions and modify your handlers JSON config
  12. #
  13. # handlers.json
  14. # {
  15. # "influxdb_udp": {
  16. # "type": "udp",
  17. # "mutator": "mutator-influxdb-line-protocol",
  18. # "socket": {
  19. # "host": "mgt-monitor-db1",
  20. # "port": 8090
  21. # }
  22. # }
  23. # }
  24.  
  25. require 'sensu/extension'
  26.  
  27. module Sensu
  28. module Extension
  29. class InfluxDBLineProtocol < Mutator
  30. def name
  31. 'influxdb_line_protocol'
  32. end
  33.  
  34. def description
  35. "returns check output formatted for InfluxDB's line protocol"
  36. end
  37.  
  38. def run(event)
  39. host = event[:client][:name]
  40. metric = event[:check][:name]
  41. output = event[:check][:output]
  42. formahost = host.gsub(".",'_')
  43.  
  44. data = []
  45. output.split("\n").each do |result|
  46. m = result.split
  47. next unless m.count == 3
  48. key = m[0].split('.', 2)[1]
  49. key.tr!('.', '_')
  50. fkey= key.gsub("#{formahost}_","") # Cutsom: replaced key with fkey
  51. value = m[1].to_f
  52. time = m[2].ljust(19, '0')
  53. data << "#{fkey},host=#{host},metric=#{metric} value=#{value} #{time}"
  54. end
  55.  
  56. yield data.join("\n"), 0
  57. end
  58. end
  59. end
  60. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement