Skip to content

Commit e630436

Browse files
committed
refactoring, use string formating
1 parent 05bbec0 commit e630436

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

bin/check-trello-incidents.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class CheckTrelloIncidents < Sensu::Plugin::Check::CLI
4949
description: 'Trello port',
5050
short: '-p PORT',
5151
long: '--port PORT',
52-
default: '443'
52+
default: 443
5353

5454
option :list,
5555
description: 'Trello list to check',
@@ -73,7 +73,7 @@ class CheckTrelloIncidents < Sensu::Plugin::Check::CLI
7373

7474
def run
7575
host = config[:host]
76-
port = config[:port]
76+
port = config[:port].to_i
7777
key = config[:api_key] || settings['trello_incidents']['api']['key']
7878
token = config[:api_token] || settings['trello_incidents']['api']['token']
7979
list = config[:list]
@@ -86,25 +86,25 @@ def run
8686
rescue Timeout::Error
8787
unknown 'Connection timed out'
8888
rescue => e
89-
unknown 'Error: ' + e.message
89+
unknown 'Error: %s' % [e.message]
9090
end
9191
end
9292

9393
def check_list(host, port, key, token, list)
9494
if list.match(/\A[a-z0-9]*\z/).nil?
95-
raise 'Invalid value for list parameter: ' + list
95+
raise 'Invalid value for list parameter: %s' % [list]
9696
end
9797

98-
path = '/1/lists/' + list + '/cards'
98+
path = '/1/lists/%s/cards/' % [list]
9999

100-
uri = URI.parse('https://' + host + ':' + port + path)
100+
uri = URI.parse('https://%<host>s:%<port>d/%<path>s' % {
101+
:host => host, :port => port, :path => path
102+
})
101103
params = { :key => key, :token => token }
102104
uri.query = URI.encode_www_form(params)
103-
res = Net::HTTP.get_response(uri)
104105

105-
unless res.code =~ /^2/
106-
unknown res.code
107-
end
106+
res = Net::HTTP.get_response(uri)
107+
res.value()
108108

109109
incidents = JSON.parse(res.body)
110110

@@ -113,7 +113,7 @@ def check_list(host, port, key, token, list)
113113
else
114114
msgs = []
115115
incidents.each do |incident|
116-
msgs.push(incident['name'] + ' ' + incident['dateLastActivity'])
116+
msgs.push('%s %s' % [incident['name'], incident['dateLastActivity']])
117117
end
118118
msg = msgs.join(';')
119119

0 commit comments

Comments
 (0)