You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
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
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
Gonchik Tsymzhitov
Solution architect | DevOps
:)
Cyprus, Limassol
170 accepted answers
0 comments