Last active
December 24, 2015 10:09
-
-
Save yacn/6782154 to your computer and use it in GitHub Desktop.
Sensu Leading Whitespace Removal Regex. You can test via `cat evnt.json | ruby regex.rb`
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
{ | |
"client":{ | |
"name": "host01", | |
"address": "10.2.1.11", | |
"subscriptions": [ | |
"all", | |
"frontend", | |
"proxy" | |
], | |
"timestamp": 1326390159 | |
}, | |
"check":{ | |
"name": "frontend_http_check", | |
"issued": 1326390169, | |
"output": "HTTP CRITICAL: HTTP/1.1 503 Service Temporarily Unavailable", | |
"status": 2, | |
"command": "check_http -I 127.0.0.1 -u http://web.example.com/healthcheck.html -R 'pageok'", | |
"subscribers":[ | |
"frontend" | |
], | |
"interval": 60, | |
"handler": "campfire", | |
"history": [ | |
"0", | |
"2" | |
], | |
"flapping": false, | |
"password": "FOOBIEBAR" | |
}, | |
"occurrences": 1, | |
"action": "create" | |
} |
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
|ruby-1.9.3-p392@home-ec| persaeus in ~/Git Repositories/yacn | |
○ → cat evnt.json | ruby regex.rb | |
HTTP CRITICAL: HTTP/1.1 503 Service Temporarily Unavailable | |
Host: host01 | |
Timestamp: 2012-01-12 12:42:49 -0500 | |
Address: 10.2.1.11 | |
Check Name: frontend_http_check | |
Command: check_http -I 127.0.0.1 -u http://web.example.com/healthcheck.html -R 'pageok' | |
Status: 2 | |
Occurrences: 1 | |
HTTP CRITICAL: HTTP/1.1 503 Service Temporarily Unavailable | |
Host: host01 | |
Timestamp: 2012-01-12 12:42:49 -0500 | |
Address: 10.2.1.11 | |
Check Name: frontend_http_check | |
Command: check_http -I 127.0.0.1 -u http://web.example.com/healthcheck.html -R 'pageok' | |
Status: 2 | |
Occurrences: 1 |
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
require 'json' | |
evnt = JSON.parse(STDIN.read) | |
def bdy(event, regex='^ {12}') | |
body = <<-BODY.gsub(/#{regex}/,'') | |
#{event['check']['output']} | |
Host: #{event['client']['name']} | |
Timestamp: #{Time.at(event['check']['issued'])} | |
Address: #{event['client']['address']} | |
Check Name: #{event['check']['name']} | |
Command: #{event['check']['command']} | |
Status: #{event['check']['status']} | |
Occurrences: #{event['occurrences']} | |
BODY | |
return body | |
end | |
puts bdy(evnt) | |
puts "\n\n" | |
puts bdy(evnt, regex='^\s+') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment