Skip to content

Commit f26cd61

Browse files
author
admin
committed
added apps count to analytics
1 parent 624edee commit f26cd61

File tree

5 files changed

+51
-0
lines changed

5 files changed

+51
-0
lines changed

app/util/analytics/analytics.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ def __init__(self, application: BaseApplication):
5252
self.application_version = application.version
5353
self.nodes_count = application.nodes_count
5454
self.dataset_information = application.dataset_information
55+
self.apps_count = application.apps_count
56+
self.custom_apps_count = application.custom_app_count
5557
if self.app_type != CROWD:
5658
self.processors = application.processors
5759
self.deployment = application.deployment

app/util/analytics/analytics_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ def generate_report_summary(collector):
106106
summary_report.append(f'Compliant|{compliant}')
107107
summary_report.append(f'Success|{success}')
108108
summary_report.append(f'Has app-specific actions|{bool(collector.app_specific_rates)}')
109+
summary_report.append(f'Applications count|{collector.apps_count}')
110+
summary_report.append(f'Custom applications count|{collector.custom_apps_count}')
109111

110112
if collector.app_type == JSM:
111113
insight = collector.insight

app/util/analytics/application_info.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from util.api.bamboo_clients import BambooClient
99
import json
1010
from lxml import html
11+
from functools import cached_property
1112

1213
JIRA = 'jira'
1314
CONFLUENCE = 'confluence'
@@ -31,6 +32,8 @@ class BaseApplication:
3132
version = None
3233
nodes_count = None
3334
dataset_information = None
35+
apps_count = None
36+
custom_app_count = None
3437

3538
def __init__(self, api_client, config_yml):
3639
self.client = api_client(host=config_yml.server_url,
@@ -99,6 +102,22 @@ def __issues_count(self):
99102
def dataset_information(self):
100103
return f"{self.__issues_count()} issues"
101104

105+
@property
106+
def apps_count(self):
107+
return len(self.__get_apps)
108+
109+
@cached_property
110+
def __get_apps(self):
111+
return self.client.get_installed_apps()
112+
113+
@property
114+
def custom_app_count(self):
115+
all_apps = self.__get_apps
116+
apps_with_vendor_defined = [app for app in all_apps if 'vendor' in app]
117+
non_atlassian_apps = [app for app in apps_with_vendor_defined if 'Atlassian' not in
118+
app['vendor']['name'] and app['userInstalled'] == True]
119+
return len(non_atlassian_apps)
120+
102121

103122
class Confluence(BaseApplication):
104123
type = CONFLUENCE

app/util/api/jira_clients.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,3 +300,21 @@ def get_license_details(self):
300300
'image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7'
301301
r = self.get(api_url, "Could not retrieve license details")
302302
return r.json()
303+
304+
def get_installed_apps(self):
305+
login_url = f'{self.host}/login.jsp'
306+
auth_url = f'{self.host}/secure/admin/WebSudoAuthenticate.jspa'
307+
auth_body = {
308+
'webSudoDestination': '/secure/admin/ViewSystemInfo.jspa',
309+
'webSudoIsPost': False,
310+
'webSudoPassword': self.password
311+
}
312+
self.post(login_url, error_msg='Could not login in')
313+
auth_body['atl_token'] = self.session.cookies.get_dict()['atlassian.xsrf.token']
314+
self._session.post(auth_url, data=auth_body)
315+
self.headers['Accept'] = 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,' \
316+
'image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7'
317+
318+
api_url = f'{self.host}/rest/plugins/1.0/'
319+
r = self.get(api_url, error_msg="ERROR: Could not get the installed apps.")
320+
return r.json()['plugins']

app/util/data_preparation/jira_prepare_data.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,15 @@ def __check_license(client):
177177
raise SystemExit(f'ERROR: Jira license is valid: {license_valid}, license has expired: {license_expired}.')
178178

179179

180+
def __check_number_of_custom_app(client):
181+
all_apps = client.get_installed_apps()
182+
apps_with_vendor_defined = [app for app in all_apps if 'vendor' in app]
183+
non_atlassian_apps = [app for app in apps_with_vendor_defined if 'Atlassian' not in
184+
app['vendor']['name'] and app['userInstalled'] == True]
185+
print(len(non_atlassian_apps))
186+
187+
188+
180189
def main():
181190
print("Started preparing data")
182191

@@ -188,6 +197,7 @@ def main():
188197
__check_for_admin_permissions(client)
189198
__check_current_language(client)
190199
__check_license(client)
200+
__check_number_of_custom_app(client)
191201
dataset = __create_data_set(client)
192202
write_test_data_to_files(dataset)
193203

0 commit comments

Comments
 (0)