Is it possible to search the Confluence Databases for instances of a specific macros?

We are looking to remove/disable a macros on our instance of confluence, but we need to run a check to see if any pages are using the plugin to preclude their media from breaking? Can one query the Confluence DB for occurrences of a macros on any pages within Confluence?

2 answers

You can use the search to find out if a macro was inserted on one or more pages. An example: If you like to know if the multiexcerpt or multiexcerpt-include macro has been used in your Confluence, type macroName:multi* in the Search field, and hit Enter.

So if I'm looking for Widget Connector, can I search "macroName:'Widget Connector'"?

Yes, I tried macroName:widget* and it worked.

Hey, Ian.

You can do this via the XMLRPC

Here is a example written in python finding all pages with a instance of the thumbnail macro (ac:thumbnail)

Once complete all links containing said macro are written to a errors.json file.

#!/usr/bin/env python
import xmlrpclib
import json

class bcolors:
    HEADER = '\033[95m'
    OKBLUE = '\033[94m'
    OKGREEN = '\033[92m'
    WARNING = '\033[93m'
    FAIL = '\033[91m'
    ENDC = '\033[0m'

    def disable(self):
        self.HEADER = ''
        self.OKBLUE = ''
        self.OKGREEN = ''
        self.WARNING = ''
        self.FAIL = ''
        self.ENDC = ''

#Confluence XML-RPC info
url 		= 'http://localhost:1990/rpc/xmlrpc'
client 		= xmlrpclib.Server(url, verbose=0);
authToken	= client.confluence2.login("admin", "admin");
spaces 		= client.confluence2.getSpaces(authToken);
# Error stack
errors 		= []
# Macro definition we're looking for
macro = "ac:thumbnail"

for space in spaces:
  print ("Parsing space: " + space['name']);
  spacePages = client.confluence2.getPages(authToken,space['key'])
  for spacePage in spacePages:
      print ("- Parsing page: " + spacePage['title']);
      # get the page in question with content
      page = client.confluence2.getPage(authToken, spacePage["id"])
      # did we find the macro definition?
      if(page["content"].find(macro) > 0):
        print ("{0}Found {1} macro!{2}".format(bcolors.WARNING, macro, bcolors.ENDC))

# print the errors
for error in errors:
	print error["url"]

#store the errors
with open('errors.json', 'w') as outfile:
  json.dump([errors], outfile)


For this line of code -
# Macro definition we're looking for
macro = "ac:thumbnail"
where do we find macro = "sometext" in Confluence?

To view the macro handle, go to a page containing the macro and click Tools->View Storage format

You should now see something like this:

<ac:structured-macro ac:name="tip">

where tip is the macro handle. Try this with the answer by Evelin
Or simply update the lines

# Macro definition we're looking for
macro = 'ac:structured-macro ac:name="tip"'

The macro handle for Widget Connector is simply :)

ac:structured-macro ac:name="widget"

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Feb 06, 2019 in Confluence

Try out the new editing experience

Hi team, I’m Avinoam, a product manager on Confluence Cloud, and today I’m really excited to let the Community know that all customers can now try out the new editing experience and see some of the ...

1,312 views 93 8
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you