Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,368,495
Community Members
 
Community Events
168
Community Groups

How to detect unknown-attachments error in your Confluence instance

Hi!

In this article, we will write a small tool to detect unknown attachments errors in rendered Confluence pages.

These symptoms appeared from irrelevant reference to attachments, lost files on file system level, corrupted data in attachments tables in Confluence DB, or the result of migrated/imported data.

Maybe you can meet with this error many times, like this  

unknown-attachments.PNG

Let's find these easy errors in your confluence. 

1. You need to install python

2. and then

 pip install atlassian-python-api

The Source code of library located is here.

3. An algorithm is easy:

3.1. Get all space keys

3.2.  Get all page ids

3.3. A check has an error or not. The method you can find here

4. Raise the Jira issue for your documentation team :) 

 

Let's see it in python code:

3.1. 

def check_unknown_attachment_in_space(confluence, space_key):
"""
Detect errors in space
:param confluence:
:param space_key:
:return:
"""
page_ids = get_all_pages_ids(confluence, space_key)
print("Start review pages {} in {}".format(len(page_ids), space_key))
for page_id in page_ids:
link = confluence.has_unknown_attachment_error(page_id)
if len(link) > 0:
print(link)

if
__name__ == '__main__':
space_list = confluence.get_all_spaces()
for space in space_list:
print("Start review {} space".format(space['key']))
check_unknown_attachment_in_space(confluence, space['key'])

 

 3.2. Get all page ids

def get_all_pages_ids(conf, space_key):
page_ids = []

limit = 50
flag = True
step = 0
while flag:
values = conf.get_all_pages_from_space(space=space_key, start=step * limit, limit=limit)
step += 1

if len(values) == 0:
flag = False
print("Extracted all pages excluding restricts")
else:
for value in values:
page_ids.append(value.get('id'))

return page_ids

3.3 And last one step is to check the error it is already in the atlassian-python-api library:

link = confluence.has_unknown_attachment_error(page_id)
if len(link) > 0:
print(link)

 

4. If the script will detect some errors then in the output you will find tiny URL links to the page with errors. 

 

Hope it helps detect the problems. 

 

My motivation was a lot of Confluence instances and of course, migrations.

P.S. Full example is here

 

 

Cheers,

Gonchik Tsymzhitov

 

 

0 comments

Comment

Log in or Sign up to comment
TAGS

Atlassian Community Events