Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

138 user registration report #144

Merged
merged 13 commits into from
Nov 22, 2024
10 changes: 9 additions & 1 deletion odins_spear/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,12 @@ def group_users_call_statistics(self, service_provider_id: str, group_id: str,
return reports.group_users_call_statistics.main(self.api, service_provider_id, group_id,
start_date, end_date, start_time, end_time, time_zone)


def user_registration_report(self, service_provider_id: str, group_id: str, remove_null_entires: bool = False):
"""Generates an Excel Worksheet deatiling each users device, lineport and registration status within a group.

Args:
service_provider_id (str): Service Provider/ Enterprise where group is hosted.
group_id (str): Target Group you would like to check the registration of.
remove_null_entries (bool): If a user does not have a device endpoint assigned, setting this to true will remove them from the final Workbook.
malkin0xb8 marked this conversation as resolved.
Show resolved Hide resolved
"""
return reports.user_registration_report.main(self.api, service_provider_id, group_id, remove_null_entires)
1 change: 1 addition & 0 deletions odins_spear/reports/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@

from .call_flow import main
from .group_users_call_statistics import main
from .user_registration_report import main
47 changes: 47 additions & 0 deletions odins_spear/reports/user_registration_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import pandas as pd


def export_to_xlsx(data: dict, remove_null_entries: bool, group_id: str):
malkin0xb8 marked this conversation as resolved.
Show resolved Hide resolved
rows = []

for user_id, devices in data.items():
if not devices and not remove_null_entries:
rows.append(
{
"UserID": user_id,
"Lineport": "N/A",
"Device Name": "N/A",
"Registered": "N/A",
}
)
continue

device_items = devices.items() if devices else []

for _, device_details in device_items:
rows.append(
{
"UserID": user_id,
"Lineport": device_details.get("linePort", "N/A"),
"Device Name": device_details.get("deviceName", "N/A"),
"Registered": device_details.get("isRegistered", "N/A"),
}
)

dataframe = pd.DataFrame(rows)
dataframe.to_excel(
f"./os_reports/Registration_report_for_{group_id}.xlsx", index=False
)


def main(api, service_provider_id: str, group_id: str, remove_null_entries: bool):
"""Generates an Excel Worksheet detailing each users device, lineport and registration status within a group.

Args:
service_provider_id (str): Service Provider/ Enterprise where group is hosted.
group_id (str): Target Group you would like to check the registration of.
remove_null_entries (bool): If a user does not have a device endpoint assigned, setting this to true will remove them from the final Workbook.
"""
malkin0xb8 marked this conversation as resolved.
Show resolved Hide resolved
data = api.scripter.user_registration(service_provider_id, group_id)

export_to_xlsx(data, remove_null_entries, group_id)
14 changes: 13 additions & 1 deletion odins_spear/scripter.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,16 @@ def webex_builder(self, service_provider_id: str, group_id: str, user_id: str,
"""

return scripts.webex_builder.main(self.api, service_provider_id, group_id, user_id, device_type,
email, primary_device, webex_feature_pack_name, enable_integrated_imp)
email, primary_device, webex_feature_pack_name, enable_integrated_imp)

def user_registration(self, service_provider_id: str, group_id: str):
"""Generates a dictionary deatiling each users device, lineport and registration status within a group.

Args:
service_provider_id (str): Service Provider/ Enterprise where group is hosted.
group_id (str): Target Group you would like to know user statistics for.

Returns:
dict: User's device, lineport and registration status.
"""
return scripts.user_registration.main(self.api, service_provider_id, group_id)
1 change: 1 addition & 0 deletions odins_spear/scripts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
from .service_provider_trunking_capacity import main
from .user_activity import main
from .user_association import main
from .user_registration import main
from .webex_builder import main
41 changes: 41 additions & 0 deletions odins_spear/scripts/user_registration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from ..exceptions import OSObjectParseError

def main( api, service_provider_id: str, group_id: str ):

# Dictionary Descripting Total Users Devices
registrations_out = {}

users = api.get.users(
service_provider_id,
group_id
)

if not users:
malkin0xb8 marked this conversation as resolved.
Show resolved Hide resolved
raise OSObjectParseError

for user in users:
malkin0xb8 marked this conversation as resolved.
Show resolved Hide resolved

registration_info = api.get.user_registration(
user["userId"]
)

registrations_out[user["userId"]] = {}

device_identifier = 1

for registration_entry in registration_info["registrations"]:

is_registered = "False"
malkin0xb8 marked this conversation as resolved.
Show resolved Hide resolved

if registration_entry["linePort"]:
is_registered = "True"

registrations_out[user["userId"]][f"deviceId: {device_identifier}"] = {
malkin0xb8 marked this conversation as resolved.
Show resolved Hide resolved
"linePort": registration_entry["linePort"],
"deviceName": registration_entry["deviceName"],
"isRegistered": is_registered
}

device_identifier += 1

return registrations_out
Loading