diff --git a/Gemfile b/Gemfile index fcd7dad4c4e91ddd98359a6dc8138af8203d7d39..c2c1212afe6403620b5a0f380004d0d8e1cc044d 100644 --- a/Gemfile +++ b/Gemfile @@ -9,6 +9,7 @@ gem "money-open-exchange-rates" gem "pg" gem "redis" gem "roda" +gem "ruby-bandwidth-iris" gem "sentry-ruby" gem "slim" diff --git a/bin/active_tels_on_catapult b/bin/active_tels_on_catapult new file mode 100755 index 0000000000000000000000000000000000000000..35ff01928cd6e4576024622571cd1b42975b5aba --- /dev/null +++ b/bin/active_tels_on_catapult @@ -0,0 +1,51 @@ +#!/usr/bin/ruby +# frozen_string_literal: true + +require "dhall" +require "net/http" +require "pg" +require "redis" +require "ruby-bandwidth-iris" + +require_relative "../lib/blather_notify" + +CONFIG = Dhall.load(ARGV[0]).sync + +BandwidthIris::Client.global_options = { + account_id: CONFIG[:creds][:account], + username: CONFIG[:creds][:username], + password: CONFIG[:creds][:password] +} + +REDIS = Redis.new +DB = PG.connect(dbname: "jmp") +DB.type_map_for_results = PG::BasicTypeMapForResults.new(DB) +DB.type_map_for_queries = PG::BasicTypeMapForQueries.new(DB) + +def get_location(tel) + BandwidthIris::Tn.get(tel).get_sip_peers[:name] +rescue BandwidthIris::Errors::GenericError + nil +end + +DB.exec( + <<~SQL + select customer_id + from customer_plans + where expires_at > localtimestamp + SQL +).each do |row| + cid = row["customer_id"] + next if REDIS.exists?("catapult_cred-customer_#{cid}@jmp.chat") + jid = REDIS.get("jmp_customer_jid-#{cid}") + tel = REDIS.lindex("catapult_cred-#{jid}", 3) + location = get_location(tel) + if location.nil? + # in catapult + puts tel + elsif location == "location1" + # in dashboard, using v1 + else + raise "Unexpected location #{location}" + end +end