Skip to content

Commit 7e81e91

Browse files
Merge pull request #1782 from atlassian/confluence-apps-count
Confluence apps count
2 parents 2d12640 + 98d10c5 commit 7e81e91

File tree

5 files changed

+61
-6
lines changed

5 files changed

+61
-6
lines changed

app/util/analytics/analytics_utils.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from datetime import datetime, timezone
99
from util.common_util import get_current_version, get_latest_version
10-
from util.analytics.application_info import BITBUCKET, BAMBOO, CROWD, INSIGHT, JSM, CONFLUENCE
10+
from util.analytics.application_info import BITBUCKET, BAMBOO, CROWD, INSIGHT, JSM, CONFLUENCE, JIRA
1111

1212
latest_version = get_latest_version()
1313
current_version = get_current_version()
@@ -106,9 +106,11 @@ 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}')
109+
110+
if collector.app_type in [JIRA, JSM, CONFLUENCE]:
111+
summary_report.append(f'Applications count|{collector.apps_count}')
112+
summary_report.append(f'Custom applications count|{collector.custom_apps_count}')
113+
summary_report.append(f'Custom applications count enabled|{collector.custom_apps_count_enabled}')
112114

113115
if collector.app_type == JSM:
114116
insight = collector.insight

app/util/analytics/application_info.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,36 @@ def java_version(self):
159159
return java_versions_parsed[0].text
160160
return None
161161

162+
@property
163+
def apps_count(self):
164+
return len(self.__get_apps)
165+
166+
@cached_property
167+
def __get_apps(self):
168+
try:
169+
return self.client.get_installed_apps()
170+
except Exception as e:
171+
print(f'ERROR: Could not get the installed applications. Error: {e}')
172+
return []
173+
174+
@cached_property
175+
def __get_custom_apps(self):
176+
all_apps = self.__get_apps
177+
apps_with_vendor_defined = [app for app in all_apps if 'vendor' in app]
178+
non_atlassian_apps = [app for app in apps_with_vendor_defined if 'Atlassian' not in
179+
app['vendor']['name'] and app['userInstalled'] == True]
180+
return non_atlassian_apps
181+
182+
@property
183+
def custom_app_count(self):
184+
return len(self.__get_custom_apps)
185+
186+
@property
187+
def custom_app_count_enabled(self):
188+
non_atlassian_apps = self.__get_custom_apps
189+
non_atlassian_apps_enabled = [app for app in non_atlassian_apps if app['enabled'] == True]
190+
return len(non_atlassian_apps_enabled)
191+
162192

163193
class Bitbucket(BaseApplication):
164194
type = BITBUCKET

app/util/api/confluence_clients.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,13 @@ def get_system_info_page(self):
222222
system_info_html = self.session.post(url=auth_url, data=auth_body, headers={'X-Atlassian-Token': 'no-check'}, verify=self.verify)
223223
return system_info_html.content.decode("utf-8")
224224

225+
def get_installed_apps(self):
226+
plugins_url = f'{self.host}/rest/plugins/1.0/'
227+
r = self.get(plugins_url, error_msg="ERROR: Could not get installed plugins.",
228+
headers={'X-Atlassian-Token': 'no-check'})
229+
return r.json()['plugins']
230+
231+
225232
def get_deployment_type(self):
226233
html_pattern = 'deployment=terraform'
227234
confluence_system_page = self.get_system_info_page()

app/util/data_preparation/confluence_prepare_data.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,20 @@ def __check_license(rest_client):
247247
print(f"The license expiry date: {expiry_date_human}.\n"
248248
f"License available seats: {license_remaining_seats['count']}")
249249

250+
def __check_number_of_custom_app(rest_client):
251+
try:
252+
all_apps = rest_client.get_installed_apps()
253+
apps_with_vendor_defined = [app for app in all_apps if 'vendor' in app]
254+
non_atlassian_apps = [app for app in apps_with_vendor_defined if 'Atlassian' not in
255+
app['vendor']['name'] and app['userInstalled'] == True]
256+
non_atlassian_apps_names = [app['name'] for app in non_atlassian_apps]
257+
print(f"Custom application count: {len(non_atlassian_apps)}")
258+
if non_atlassian_apps:
259+
print(f'Custom app names:')
260+
print(*non_atlassian_apps_names, sep='\n')
261+
except Exception as e:
262+
print(f'ERROR: Could not get the installed applications. Error: {e}')
263+
250264

251265
@print_timing('Confluence data preparation')
252266
def main():
@@ -258,6 +272,7 @@ def main():
258272
rest_client = ConfluenceRestClient(url, CONFLUENCE_SETTINGS.admin_login, CONFLUENCE_SETTINGS.admin_password,
259273
verify=CONFLUENCE_SETTINGS.secure)
260274
rpc_client = ConfluenceRpcClient(url, CONFLUENCE_SETTINGS.admin_login, CONFLUENCE_SETTINGS.admin_password)
275+
__check_number_of_custom_app(rest_client)
261276
__is_remote_api_enabled(rest_client)
262277
__check_license(rest_client)
263278
__check_for_admin_permissions(rest_client)

app/util/data_preparation/jira_prepare_data.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,9 @@ def __check_number_of_custom_app(client):
185185
app['vendor']['name'] and app['userInstalled'] == True]
186186
non_atlassian_apps_names = [app['name'] for app in non_atlassian_apps]
187187
print(f"Custom application count: {len(non_atlassian_apps)}")
188-
print(f'Custom app names:')
189-
print(*non_atlassian_apps_names, sep='\n')
188+
if non_atlassian_apps:
189+
print(f'Custom app names:')
190+
print(*non_atlassian_apps_names, sep='\n')
190191
except Exception as e:
191192
print(f'ERROR: Could not get the installed applications. Error: {e}')
192193

0 commit comments

Comments
 (0)