Skip to content

Commit 2d12640

Browse files
Merge pull request #1780 from atlassian/apps-count-for-jira
added apps count to analytics
2 parents 7d4e177 + ce08f23 commit 2d12640

File tree

5 files changed

+74
-0
lines changed

5 files changed

+74
-0
lines changed

app/util/analytics/analytics.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ 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
57+
self.custom_apps_count_enabled = application.custom_app_count_enabled
5558
if self.app_type != CROWD:
5659
self.processors = application.processors
5760
self.deployment = application.deployment

app/util/analytics/analytics_utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ 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}')
111+
summary_report.append(f'Custom applications count enabled|{collector.custom_apps_count_enabled}')
109112

110113
if collector.app_type == JSM:
111114
insight = collector.insight

app/util/analytics/application_info.py

Lines changed: 34 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,9 @@ class BaseApplication:
3132
version = None
3233
nodes_count = None
3334
dataset_information = None
35+
apps_count = None
36+
custom_app_count = None
37+
custom_app_count_enabled = None
3438

3539
def __init__(self, api_client, config_yml):
3640
self.client = api_client(host=config_yml.server_url,
@@ -99,6 +103,36 @@ def __issues_count(self):
99103
def dataset_information(self):
100104
return f"{self.__issues_count()} issues"
101105

106+
@property
107+
def apps_count(self):
108+
return len(self.__get_apps)
109+
110+
@cached_property
111+
def __get_apps(self):
112+
try:
113+
return self.client.get_installed_apps()
114+
except Exception as e:
115+
print(f'ERROR: Could not get the installed applications. Error: {e}')
116+
return []
117+
118+
@cached_property
119+
def __get_custom_apps(self):
120+
all_apps = self.__get_apps
121+
apps_with_vendor_defined = [app for app in all_apps if 'vendor' in app]
122+
non_atlassian_apps = [app for app in apps_with_vendor_defined if 'Atlassian' not in
123+
app['vendor']['name'] and app['userInstalled'] == True]
124+
return non_atlassian_apps
125+
126+
@property
127+
def custom_app_count(self):
128+
return len(self.__get_custom_apps)
129+
130+
@property
131+
def custom_app_count_enabled(self):
132+
non_atlassian_apps = self.__get_custom_apps
133+
non_atlassian_apps_enabled = [app for app in non_atlassian_apps if app['enabled'] == True]
134+
return len(non_atlassian_apps_enabled)
135+
102136

103137
class Confluence(BaseApplication):
104138
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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,21 @@ 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+
try:
182+
all_apps = client.get_installed_apps()
183+
apps_with_vendor_defined = [app for app in all_apps if 'vendor' in app]
184+
non_atlassian_apps = [app for app in apps_with_vendor_defined if 'Atlassian' not in
185+
app['vendor']['name'] and app['userInstalled'] == True]
186+
non_atlassian_apps_names = [app['name'] for app in non_atlassian_apps]
187+
print(f"Custom application count: {len(non_atlassian_apps)}")
188+
print(f'Custom app names:')
189+
print(*non_atlassian_apps_names, sep='\n')
190+
except Exception as e:
191+
print(f'ERROR: Could not get the installed applications. Error: {e}')
192+
193+
194+
180195
def main():
181196
print("Started preparing data")
182197

@@ -188,6 +203,7 @@ def main():
188203
__check_for_admin_permissions(client)
189204
__check_current_language(client)
190205
__check_license(client)
206+
__check_number_of_custom_app(client)
191207
dataset = __create_data_set(client)
192208
write_test_data_to_files(dataset)
193209

0 commit comments

Comments
 (0)