Concurrent calls for sippy customers
This is a guide on how the Grafana dashboard for the concurrent calls on Sippy works and how to edit it.
How does it work
The script use the Selenium proejct to do some Web Scraping actions on the SippySoftswitch webapp to get the number of active calls for each customers.
It then use a mysql connector to insert the values it just got into the database. The databse is structured so that every customer has it's own table with the following parameter:
- Data_ora, which is a time stamp that gets the date and time the moment the new record is insert in the table. This is the primary key.
- numero_chiamate, is an int which rappresent the value that we got from the webscaraping action
This script is set to run every 30 seconds with 2 chronjob. They both starts every minute but one of them sleeps for 30 seconds.
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
import re
import mysql.connector
config = {
'user': 'root',
'password': 'root',
'host': '127.0.0.1',
'database': 'prova'
}
connection = None
cursor = None
connection = mysql.connector.connect(**config)
cursor = connection.cursor()
chrome_options = Options()
chrome_options.add_argument("--headless=new") # Use 'new' for recent version of Selenium/Chrome
chrome_options.add_argument("--disable-gpu") # Opzional
driver = webdriver.Chrome(options=chrome_options)
driver.get("https://voip.ccaas.becloudsolutions.com/index.php")
user_field = driver.find_element(by=By.NAME, value="username")
username = "mattia.stalio"
user_field.clear()
user_field.send_keys(username)
pwd = driver.find_element(by=By.NAME, value="password")
password = "zrb)-lCp-QJ<[7Q}Exi,hhscEbD{TU2#"
pwd.clear()
pwd.send_keys(password)
login = driver.find_element(By.NAME, "Login")
login.click()
def ottieniValori(url, table):
driver.get(url)
valore = driver.find_element(By.CLASS_NAME, value="Headline").text
match = re.search(r"(\d+)\s+TOTAL", valore)
total_calls = int(match.group(1))
query = f"INSERT INTO `{table}` (numero_chiamate) VALUES (%s)"
cursor.execute(query, (total_calls,))
connection.commit()
return total_calls
elementi = {
"linea1": ("https://voip.ccaas.becloudsolutions.com/u9/activecalls.php?cli_clause=0&cli=&caller=1_21&state_type=1&cld_clause=0&cld=&vendor=0&connection=0&order=oldest_first&limit_calls=50&auto_refresh_in=0&filter_bt=Filter", "A2Z"),
"linea2": ("https://voip.ccaas.becloudsolutions.com/u9/activecalls.php?cli_clause=0&cli=&caller=1_19&state_type=1&cld_clause=0&cld=&vendor=0&connection=0&order=oldest_first&limit_calls=50&auto_refresh_in=0&filter_bt=Filter", "Digitalker"),
"linea3": ("https://voip.ccaas.becloudsolutions.com/u9/activecalls.php?cli_clause=0&cli=&caller=1_10&state_type=1&cld_clause=0&cld=&vendor=0&connection=0&order=oldest_first&limit_calls=50&auto_refresh_in=0&filter_bt=Filter", "WPI")
}
for chiave, (url, tabella) in elementi.items():
valore = ottieniValori(url, tabella)
cursor.close()
connection.close()
driver.quit()
Simultaneously Grafana get the values from the tables ordering them from the oldest to the newest.
SELECT * FROM nome_tabella ORDER BY data_inserimento DESC;
Add new customers
To add new customers you will have to simply get the cusotmer ID frrom Sippy and add a new line in the dictionary in the script.
elementi = {
"linea1": ("https://voip.ccaas.becloudsolutions.com/u9/activecalls.php?cli_clause=0&cli=&caller=1_21&state_type=1&cld_clause=0&cld=&vendor=0&connection=0&order=oldest_first&limit_calls=50&auto_refresh_in=0&filter_bt=Filter", "A2Z"),
"linea2": ("https://voip.ccaas.becloudsolutions.com/u9/activecalls.php?cli_clause=0&cli=&caller=1_19&state_type=1&cld_clause=0&cld=&vendor=0&connection=0&order=oldest_first&limit_calls=50&auto_refresh_in=0&filter_bt=Filter", "Digitalker"),
"linea3": ("https://voip.ccaas.becloudsolutions.com/u9/activecalls.php?cli_clause=0&cli=&caller=1_10&state_type=1&cld_clause=0&cld=&vendor=0&connection=0&order=oldest_first&limit_calls=50&auto_refresh_in=0&filter_bt=Filter", "WPI"),
"linea4": ("https://voip.ccaas.becloudsolutions.com/u9/activecalls.php?cli_clause=0&cli=&caller=1_**ID**&state_type=1&cld_clause=0&cld=&vendor=0&connection=0&order=oldest_first&limit_calls=50&auto_refresh_in=0&filter_bt=Filter"
}
Since adding a new customers means that the script will require about 2 or 3 seconds more to end, I suggest you to check how long it takes it to finish, and if it takes about 30 seconds, to edit the cronjob dealy.
If you will have to change the db or sippy credential, just simply change the variables in the script.