sensu-plugins-eventstore 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1c1126b732eb43df69fe274a7e5c56679af3a434
4
- data.tar.gz: 9687c022a0728544d93cf7cd58588c9ec57c0c01
3
+ metadata.gz: c0e69b6da1a9133bddaac28961fa80ceff486e2d
4
+ data.tar.gz: 1cea373cc00a28da343382c1e3817c83b947e9a4
5
5
  SHA512:
6
- metadata.gz: c2cdf09262b96b0c7813ee515d091104f665ca493c95613561769398d558f42c5aed5a8498828800ec4add0ff21688b56ae0c5652a8f7bc4a8c4a1942ec5acf1
7
- data.tar.gz: 11191d4259c444d4e4193186a19c1d53c5c93dd93a79845c12bae36e649cb691ab6e9c240bf68de9de4c915895557c7ee21d6d4d66421ffd13e0fbbb8098f60c
6
+ metadata.gz: 7f6556254599dd9f34b0b575c5aafc6ea0b8911a282566f8a57c7f65259b29c750876d052c3f3d35df9a7112859208d8771ab24630f46a92800bbec313659f1b
7
+ data.tar.gz: 17ddfc644220f4aeddf23b34c0072b32376bd2f4f52755ed854fe8a809e078d7601d2994fb58297af778500fb44b230c3cdc8a84f651941b35f9ccddc7a2f876
@@ -1,6 +1,6 @@
1
1
  #! /usr/bin/env ruby
2
2
  #
3
- # check-gossip
3
+ # Stats
4
4
  #
5
5
  # DESCRIPTION:
6
6
  # Metrics for the event store stats
@@ -46,10 +46,28 @@ class Stats < Sensu::Plugin::Metric::CLI::Graphite
46
46
  default: 'localhost'
47
47
 
48
48
  option :port,
49
- description: 'What port to use. (Default 2113)',
49
+ description: 'What port to use. (Default 2114)',
50
50
  short: '-p',
51
51
  long: '--port port',
52
- default: '2113'
52
+ default: '2114'
53
+
54
+ option :use_authentication,
55
+ description: 'Should use authentication (Default false)',
56
+ short: '-ua',
57
+ long: '--auth auth',
58
+ default: 'false'
59
+
60
+ option :auth_user,
61
+ description: 'Username for stats stream auth. (Default "admin")',
62
+ short: '-usr',
63
+ long: '--auth_user auth_user',
64
+ default: 'admin'
65
+
66
+ option :auth_password,
67
+ description: 'What port to use. (Default "changeit")',
68
+ short: '-pwd',
69
+ long: '--auth_password auth_password',
70
+ default: 'changeit'
53
71
 
54
72
  def run
55
73
  discover_via_dns = config[:discover_via_dns]
@@ -78,12 +96,7 @@ class Stats < Sensu::Plugin::Metric::CLI::Graphite
78
96
  def collect_metrics(address, port)
79
97
  stream_url = "http://#{address}:#{port}/streams/$stats-#{address}:#{port}"
80
98
 
81
- puts "attempting to open #{stream_url}"
82
- stream_temp_file = open stream_url, "Accept" => "application/atom+xml"
83
-
84
- puts "open result:: temp file found? "
85
-
86
- p stream_temp_file
99
+ stream_temp_file = get_stream stream_url
87
100
 
88
101
  namespace_regex = / xmlns="[A-Za-z:\/.0-9]+"/
89
102
 
@@ -98,12 +111,9 @@ class Stats < Sensu::Plugin::Metric::CLI::Graphite
98
111
  .sort { |node| DateTime.parse node.xpath('.//updated').text }
99
112
  .last
100
113
 
101
- event_number_regex = /[0-9]+$/
102
- event_number = event_number_regex.match latest_entry.at_xpath('.//id').content
114
+ latest_event_url = latest_entry.at_xpath('.//id').content
103
115
 
104
- latest_event_url = "#{stream_url}/#{event_number.to_s.to_i}"
105
-
106
- element_temp_file = open latest_event_url, "Accept" => "application/json"
116
+ element_temp_file = get_stream latest_event_url
107
117
  json_stats = JSON.parse element_temp_file.read
108
118
 
109
119
  stats_dict = parse_json_stats json_stats
@@ -113,6 +123,20 @@ class Stats < Sensu::Plugin::Metric::CLI::Graphite
113
123
  ok
114
124
  end
115
125
 
126
+ def get_stream(stream_url)
127
+ puts "opening stream @ url #{stream_url}"
128
+
129
+ use_auth = config[:use_authentication]
130
+
131
+ if "true".casecmp(use_auth) == 0
132
+ username = config[:auth_user]
133
+ password = config[:auth_password]
134
+ return open stream_url, http_basic_authentication:[username, password], "Accept" => "application/atom+xml"
135
+ else
136
+ return open stream_url, "Accept" => "application/atom+xml"
137
+ end
138
+ end
139
+
116
140
  def add_metric(json_stats, stats_dict, stat_name_mapping)
117
141
  stat_value = json_stats[stat_name_mapping[:source_name]]
118
142
  stats_dict[stat_name_mapping[:target_name]] = stat_value
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugins-eventstore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamie Wroe
@@ -70,7 +70,7 @@ description: A collection of checks and metrics for event store, designed for se
70
70
  email: Jamie.Wroe@live.co.uk
71
71
  executables:
72
72
  - check-gossip.rb
73
- - metrics-stats.rb
73
+ - metrics-eventstore-stats-stream.rb
74
74
  extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
@@ -78,7 +78,7 @@ files:
78
78
  - LICENSE
79
79
  - README.md
80
80
  - bin/check-gossip.rb
81
- - bin/metrics-stats.rb
81
+ - bin/metrics-eventstore-stats-stream.rb
82
82
  - lib/ip-helper.rb
83
83
  homepage: https://github.com/JWroe/sensu-plugins-eventstore
84
84
  licenses: