Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

List broken macros in Confluence

m.w March 2, 2015

Hi,

I'd like to clean up our instance of Confluence, removing some of the plugins we don't need. I want to remove the plugins in the test environment, then try and get a list of pages with broken macros..

 

Is there any plugins / user macros that can obtain such a list?

 

Thanks,

m.w

 

3 answers

1 vote
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 2, 2015

You can use macroName: in the search to find pages using a specific macro.

Listing pages with broken macros is a bit harder though.

Andy January 9, 2017

Thank you - that was enough for me to find what I needed.

0 votes
Stephen Deutsch
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 3, 2015

Hi Mark,

I thought something like this would be useful, so I whipped up a short python script:

import xmlrpclib
import codecs

confluenceUrl = "https://<your-server>"
server = xmlrpclib.ServerProxy(confluenceUrl + '/rpc/xmlrpc')
username = 'username'
password = 'password'
token = server.confluence2.login(username, password)
spaceSummary = server.confluence2.getSpaces(token)
for space in spaceSummary:
    log = ""
    log += "<hr>\n"
    log += "<p>Searching in space " + space["name"] + " - " + space["key"] + "</p>\n"
    log += "<hr>\n"
    print log
    
    with codecs.open('logfile.html', 'a', encoding='utf-8') as f: 
        f.write(log)
        f.close()
    
    spacePages = server.confluence2.getPages(token, space["key"])
    for page in spacePages:
        pageContent = server.confluence2.renderContent(token, "", page["id"], "", {'style': 'clean'})
        
        if '<span class="error">Unknown macro:' in pageContent:
            log = ""
            log += "<p>Page " + page["title"] + " has broken macros!</p>\n"
            log += "<p>Page ID: " + page["id"] + "</p>\n"
            log += '<p>Page URL: <a href="' + page["url"] + '">' + page["url"] + '</a></p><p> </p>\n'
            log += "<p>----</p>\n"
            print log
            
            with codecs.open('logfile.html', 'a', encoding='utf-8') as f: 
                f.write(log)
                f.close()

It will go through every page on your site and see whether it has broken macros on it and outputs the results with links to the pages in an HTML file.  I would run it off-hours (or on your test instance) since it hits the server pretty hard, but we have a fairly good size instance and it only took about 5-10 minutes to run.  I only tested it with plain Python 2.7.8 and Confluence 5.5, but it should work fine on other versions.

Zayne Halsall April 26, 2016

Doesn't work in Cloud.

Traceback (most recent call last):
File "./pythonConfluenceBrokenMacros.py", line 10, in <module>
token = server.confluence2.login(username, password)
File "/usr/lib64/python2.7/xmlrpclib.py", line 1240, in __call__
return self.__send(self.__name, args)
File "/usr/lib64/python2.7/xmlrpclib.py", line 1599, in __request
verbose=self.__verbose
File "/usr/lib64/python2.7/xmlrpclib.py", line 1280, in request
return self.single_request(host, handler, request_body, verbose)
File "/usr/lib64/python2.7/xmlrpclib.py", line 1328, in single_request
response.msg,
xmlrpclib.ProtocolError: <ProtocolError for XXXXXX.atlassian.net/rpc/xmlrpc: 404 Not Found>
Stephen Deutsch
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 26, 2016

It seems like you might be missing the full context Path.  Usually Cloud instances are XXXXXX.atlassian.net/wiki

Try updating your URL to that and hopefully it should work.

Zayne Halsall April 26, 2016

@Stephen Deutsch, spot on. Correcting the URL got it to run. Although I now get a 504 time out after a few minutes.

Ulf Glaeser June 5, 2017

@Stephen Deutsch: Nice example.

Does anyone know whether something like this is possible through the REST API as well, since XML-RPC is now a deprecated API?

Nils Leger September 18, 2019

For python 3.x you need to replace 

import xmlrpclib
server = xmlrpclib.ServerProxy(confluenceUrl + '/rpc/xmlrpc')

with 

from xmlrpc import client
server = client.ServerProxy(confluenceUrl + '/rpc/xmlrpc')
0 votes
Lukas Knoch -Rumpelcoders-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 2, 2015

There is a plugin that can remove a macro from every page in your confluence instance. You can even replace it with a different string/macro.  You might want to check that out. It also lists the occurences of that macro. 

https://marketplace.atlassian.com/plugins/at.rumpelcoder.confluence.search-and-replace

 

It doesn't list broken macros. I don't think there is a possibility fot that.

 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events