summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJamie Nguyen <jamie.nguyen@bytemark.co.uk>2017-09-20 07:54:35 +0100
committerJamie Nguyen <jamie.nguyen@bytemark.co.uk>2017-09-20 07:54:35 +0100
commit5bfbf71c0b08647ca93460a2eda01f3221716003 (patch)
tree964267e4abdc80685a5f7bdceeae5687d0b3bdd7
parent005013d98d742989d3c000b04054e15bb0482a69 (diff)
parent99394d4a174239ece0aeba5e0a1a5755fd2ec45b (diff)
Merge branch '19-user-agent' into 'master'
Resolve "Can custodian send a user agent string please" Closes #19 See merge request !13
-rw-r--r--debian/changelog7
-rw-r--r--lib/custodian/alerts/graphite.rb24
-rw-r--r--lib/custodian/protocoltest/http.rb3
3 files changed, 29 insertions, 5 deletions
diff --git a/debian/changelog b/debian/changelog
index 3827334..709acf5 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+custodian (0.37) stable; urgency=high
+
+ * Always send a User-Agent-header when submitting HTTP/HTTPS tests.
+ * Updated how we submit metrics to our central graphite host(s).
+
+ -- Steve Kemp <steve@bytemark.co.uk> Wed, 20 Sep 2017 09:33:09 +0200
+
custodian (0.36) stable; urgency=high
* If we receive a DNS-error from the curb-gem we ignore it, unless
diff --git a/lib/custodian/alerts/graphite.rb b/lib/custodian/alerts/graphite.rb
index 0244047..cca5ece 100644
--- a/lib/custodian/alerts/graphite.rb
+++ b/lib/custodian/alerts/graphite.rb
@@ -1,4 +1,5 @@
require 'socket'
+require 'timeout'
#
# The graphite-alerter.
@@ -61,12 +62,25 @@ module Custodian
payload = "custodian.#{test}.#{host}.test_duration_ms #{ms} #{Time.now.to_i}"
#
- # Send via UDP.
+ # Send metrics via TCP.
#
- socket = UDPSocket.new
- socket.send(payload, 0, @target, 2003)
- socket.close
-
+ begin
+ Timeout.timeout(10) do
+ begin
+ socket = TCPSocket.new(@target,2003)
+ puts payload
+ socket.write(payload)
+ socket.flush
+ socket.close
+ rescue Errno::ENETUNREACH
+ puts("Metrics host unreachable: #{e}")
+ rescue StandardError => e
+ puts("Error submitting metrics: #{e}")
+ end
+ end
+ rescue Timeout::Error
+ puts('Timeout submitting metrics')
+ end
end
register_alert_type 'graphite'
diff --git a/lib/custodian/protocoltest/http.rb b/lib/custodian/protocoltest/http.rb
index 0bf1a68..5f013df 100644
--- a/lib/custodian/protocoltest/http.rb
+++ b/lib/custodian/protocoltest/http.rb
@@ -360,6 +360,9 @@ module Custodian
c = Curl::Easy.new(test_url)
+ # setup a user-agent.
+ c.headers["User-Agent"] = "custodian/protocol-tester"
+
c.resolve_mode = resolve_mode
#