~singpolyma/sgx-jmp

e417c052f23e1306b69ce0f6585ab76ff370caff — Stephen Paul Weber 1 year, 24 days ago 257d026
Send to StatsD for different inbound stanza types
2 files changed, 34 insertions(+), 4 deletions(-)

M Gemfile
M sgx_jmp.rb
M Gemfile => Gemfile +1 -0
@@ 14,6 14,7 @@ gem "eventmachine"
gem "money-open-exchange-rates"
gem "ruby-bandwidth-iris"
gem "sentry-ruby"
gem "statsd-instrument"
gem "value_semantics", git: "https://github.com/singpolyma/value_semantics"

group(:development) do

M sgx_jmp.rb => sgx_jmp.rb +33 -4
@@ 11,6 11,7 @@ require "em-hiredis"
require "em_promise"
require "ruby-bandwidth-iris"
require "sentry-ruby"
require "statsd-instrument"

Sentry.init



@@ 136,7 137,9 @@ setup(
	workqueue_count: 0
)

message to: /\Aaccount@/ do |m|
message to: /\Aaccount@/, body: /./ do |m|
	StatsD.increment("deprecated_account_bot")

	self << m.reply.tap do |out|
		out.body = "This bot is deprecated. Please talk to xmpp:cheogram.com"
	end


@@ 150,6 153,8 @@ before(
) { |iq| halt if IQ_MANAGER.fulfill(iq) }

before nil, to: /\Acustomer_/, from: /(\A|@)#{CONFIG[:sgx]}(\/|\Z)/ do |s|
	StatsD.increment("stanza_customer")

	sentry_hub = new_sentry_hub(s, name: "stanza_customer")
	Customer.for_customer_id(
		s.to.node.delete_prefix("customer_")


@@ 172,12 177,13 @@ def billable_message(m)
end

message do |m|
	StatsD.increment("message")

	sentry_hub = new_sentry_hub(m, name: "message")
	today = Time.now.utc.to_date
	Customer.for_jid(m.from.stripped).then { |customer|
		sentry_hub.current_scope.set_user(
			id: customer.customer_id,
			jid: m.from.stripped.to_s
			id: customer.customer_id, jid: m.from.stripped.to_s
		)
		EMPromise.all([
			customer,


@@ 202,6 208,8 @@ message do |m|
end

message :error? do |m|
	StatsD.increment("message_error")

	puts "MESSAGE ERROR: #{m.inspect}"
end



@@ 264,6 272,8 @@ disco_info to: Blather::JID.new(CONFIG[:component][:jid]) do |iq|
end

disco_items node: "http://jabber.org/protocol/commands" do |iq|
	StatsD.increment("command_list")

	sentry_hub = new_sentry_hub(iq, name: iq.node)
	reply = iq.reply



@@ 280,6 290,8 @@ disco_items node: "http://jabber.org/protocol/commands" do |iq|
end

iq "/iq/ns:services", ns: "urn:xmpp:extdisco:2" do |iq|
	StatsD.increment("extdisco")

	reply = iq.reply
	reply << Nokogiri::XML::Builder.new {
		services(xmlns: "urn:xmpp:extdisco:2") do


@@ 294,6 306,8 @@ iq "/iq/ns:services", ns: "urn:xmpp:extdisco:2" do |iq|
end

command :execute?, node: "jabber:iq:register", sessionid: nil do |iq|
	StatsD.increment("command", tags: ["node:#{iq.node}"])

	sentry_hub = new_sentry_hub(iq, name: iq.node)
	EMPromise.resolve(nil).then {
		Customer.for_jid(iq.from.stripped)


@@ 335,6 349,8 @@ command node: [
	"configure-calls",
	"record-voicemail-greeting"
] do |iq|
	StatsD.increment("command", tags: ["node:#{iq.node}"])

	sentry_hub = new_sentry_hub(iq, name: iq.node)
	Customer.for_jid(iq.from.stripped).then { |customer|
		sentry_hub.current_scope.set_user(


@@ 347,6 363,8 @@ command node: [
end

command :execute?, node: "credit cards", sessionid: nil do |iq|
	StatsD.increment("command", tags: ["node:#{iq.node}"])

	sentry_hub = new_sentry_hub(iq, name: iq.node)
	reply = iq.reply
	reply.status = :completed


@@ 367,6 385,8 @@ command :execute?, node: "credit cards", sessionid: nil do |iq|
end

command :execute?, node: "top up", sessionid: nil do |iq|
	StatsD.increment("command", tags: ["node:#{iq.node}"])

	sentry_hub = new_sentry_hub(iq, name: iq.node)
	reply = iq.reply
	reply.allowed_actions = [:complete]


@@ 393,6 413,8 @@ command :execute?, node: "top up", sessionid: nil do |iq|
end

command :execute?, node: "alt top up", sessionid: nil do |iq|
	StatsD.increment("command", tags: ["node:#{iq.node}"])

	sentry_hub = new_sentry_hub(iq, name: iq.node)
	reply = iq.reply
	reply.status = :executing


@@ 415,6 437,8 @@ command :execute?, node: "alt top up", sessionid: nil do |iq|
end

command :execute?, node: "reset sip account", sessionid: nil do |iq|
	StatsD.increment("command", tags: ["node:#{iq.node}"])

	sentry_hub = new_sentry_hub(iq, name: iq.node)
	Customer.for_jid(iq.from.stripped).then { |customer|
		sentry_hub.current_scope.set_user(


@@ 430,6 454,8 @@ command :execute?, node: "reset sip account", sessionid: nil do |iq|
end

command :execute?, node: "usage", sessionid: nil do |iq|
	StatsD.increment("command", tags: ["node:#{iq.node}"])

	sentry_hub = new_sentry_hub(iq, name: iq.node)
	report_for = (Date.today..(Date.today << 1))



@@ 449,6 475,8 @@ command :execute?, node: "usage", sessionid: nil do |iq|
end

command :execute?, node: "web-register", sessionid: nil do |iq|
	StatsD.increment("command", tags: ["node:#{iq.node}"])

	sentry_hub = new_sentry_hub(iq, name: iq.node)

	begin


@@ 462,7 490,6 @@ command :execute?, node: "web-register", sessionid: nil do |iq|
		else
			IQ_MANAGER.write(Blather::Stanza::Iq::Command.new.tap { |cmd|
				cmd.to = CONFIG[:web_register][:to]
				cmd.from = CONFIG[:component][:jid]
				cmd.node = "push-register"
				cmd.form.fields = [var: "to", value: jid]
				cmd.form.type = "submit"


@@ 486,5 513,7 @@ iq type: [:result, :error] do |iq|
end

iq type: [:get, :set] do |iq|
	StatsD.increment("unknown_iq")

	self << Blather::StanzaError.new(iq, "feature-not-implemented", :cancel)
end