From 85b356f73d42fa21d224ffdc9880c8cb6f8721b1 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Wed, 25 Aug 2021 13:46:25 -0500 Subject: [PATCH] Show what tels are paid-up but not in dashboard --- Gemfile | 1 + bin/active_tels_on_catapult | 51 +++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100755 bin/active_tels_on_catapult diff --git a/Gemfile b/Gemfile index fcd7dad..c2c1212 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 0000000..35ff019 --- /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 -- 2.34.2