Skip to content

Instantly share code, notes, and snippets.

@jib
Created November 15, 2012 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jib/4112f72078071ce19b9b to your computer and use it in GitHub Desktop.
Save jib/4112f72078071ce19b9b to your computer and use it in GitHub Desktop.
1) An event that won't be converted to JSON
======== prn ===============
#riemann.codec.Event{:host "ops-dev005", :service "check_http.py", :state "warning", :description "audience_segments: HTTP 503 from http://localhost/audience_segments/__status?indent=4", :metric nil, :tags ["puppet_environment:development" "zone:us-east-1e" "s_sandbox::charlie" "instance_type:c1.medium" "instance_id:i-13ff6b75" "security_group:krux-ops-dev" "team:ops"], :time 1353009793609/1000, :ttl nil}
======== tcp send ==========
INFO [2012-11-15 20:03:13,610] pool-489-thread-4 - krux.test - About to send event: #riemann.codec.Event{:host ops-dev005, :service check_http.py, :state warning, :description audience_segments: HTTP 503 from http://localhost/audience_segments/__status?indent=4, :metric nil, :tags [puppet_environment:development zone:us-east-1e s_sandbox::charlie instance_type:c1.medium instance_id:i-13ff6b75 security_group:krux-ops-dev team:ops], :time 1353009793609/1000, :ttl nil}
INFO [2012-11-15 20:03:13,610] pool-489-thread-4 - krux.test - About to convert to JSON: #riemann.codec.Event{:host ops-dev005, :service check_http.py, :state warning, :description audience_segments: HTTP 503 from http://localhost/audience_segments/__status?indent=4, :metric nil, :tags [puppet_environment:development zone:us-east-1e s_sandbox::charlie instance_type:c1.medium instance_id:i-13ff6b75 security_group:krux-ops-dev team:ops], :time 1353009793609/1000, :ttl nil}
### Note: there's no JSON string generated
=====================================
2) An event converted to malformed JSON
======== prn ===============
#riemann.codec.Event{:host "ops-dev005", :service "check_http.py", :state "warning", :description "urlmapper_store: HTTP 503 from http://localhost/store/__status", :metric nil, :tags ["puppet_environment:development" "zone:us-east-1e" "s_sandbox::charlie" "instance_type:c1.medium" "instance_id:i-13ff6b75" "security_group:krux-ops-dev" "team:ops"], :time 1353009793579/1000, :ttl nil}
======== tcp send ==========
INFO [2012-11-15 20:03:13,580] pool-486-thread-4 - krux.test - About to send event: #riemann.codec.Event{:host ops-dev005, :service check_http.py, :state warning, :description urlmapper_store: HTTP 503 from http://localhost/store/__status, :metric nil, :tags [puppet_environment:development zone:us-east-1e s_sandbox::charlie instance_type:c1.medium instance_id:i-13ff6b75 security_group:krux-ops-dev team:ops], :time 1353009793579/1000, :ttl nil}
INFO [2012-11-15 20:03:13,580] pool-486-thread-4 - krux.test - About to convert to JSON: #riemann.codec.Event{:host ops-dev005, :service check_http.py, :state warning, :description urlmapper_store: HTTP 503 from http://localhost/store/__status, :metric nil, :tags [puppet_environment:development zone:us-east-1e s_sandbox::charlie instance_type:c1.medium instance_id:i-13ff6b75 security_group:krux-ops-dev team:ops], :time 1353009793579/1000, :ttl nil}
INFO [2012-11-15 20:03:13,580] pool-486-thread-4 - krux.test - Will be writing this string: {"description":"urlmapper_store: HTTP 503 from http://localhost/store/__status","tags":["puppet_environment:development","zone:us-east-1e","s_sandbox::charlie","instance_type:c1.medium","instance_id:i-13ff6b75","security_group:krux-ops-dev","team:ops"],"service":"check_http.py","ttl":null,"metric":null,"state":"warning","host":"ops-dev005","time"}
### Note: the JSON string is malformed, with "time" not having a value.
======================================
====== code for tcp send ============
(fn [event]
(info "About to send event:" event)
;(when (:metric event)
(with-pool [ [sock out] pool (:claim-timeout opts) ]
(let [
debug (info "About to convert to JSON:" event)
; generate a JSON string from the event, a la pagerduty
string (str (json/generate-string event) "\n") ]
(info "Will be writing this string:" string)
(.write ^OutputStreamWriter out string)
(.flush ^OutputStreamWriter out)
)
)
;)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment