Confluence禁用HTML宏时嵌入内部站点响应的技术方案咨询
Great question! Since your Confluence instance has HTML macros disabled, there are a few practical approaches to embed your internal sites' /ping responses into table columns—covering both plain text and formatted content like math formulas.
Basic Need: Embed Plain Text /ping Responses
Here are two reliable methods depending on the tools you have available:
1. Use Script Runner Macro (Recommended for Most Enterprise Setups)
If your team uses the Script Runner add-on (common in enterprise Confluence instances), you can create a reusable Groovy script macro to fetch and display the /ping response:
- Go to Confluence Admin > Script Runner > Create Script Macro
- Name it
FetchPingResponse, set it to render inline, and add aurlparameter for the target/pingendpoint - Use this script:
import com.atlassian.sal.api.component.ComponentAccessor def urlParam = getParameter("url") if (!urlParam) return "Missing URL parameter" // Optional: Add caching to reduce repeated API calls def cacheManager = ComponentAccessor.getCacheManager() def cache = cacheManager.getCache("pingResponseCache") def cachedResponse = cache.get(urlParam) if (cachedResponse) { return cachedResponse } // Fetch the /ping response def connection = new URL(urlParam).openConnection() connection.setRequestMethod("GET") connection.setConnectTimeout(5000) // Timeout after 5s to avoid hanging pages def response = connection.inputStream.text // Cache the response for 60 seconds (adjust as needed) cache.put(urlParam, response, 60) return response
- In your table's target cell, call the macro like:
{fetch-ping-response:url=https://your-internal-site/ping}
2. Custom User Macro (No Add-ons Required)
If you can't use Script Runner, create a native Confluence user macro to handle the HTTP request:
- Go to Confluence Admin > User Macros > Create a User Macro
- Set:
- Macro name:
fetchping - Visibility: Visible to all users
- Macro body: None
- Template: Use this Velocity code:
- Macro name:
#set($url = $paramUrl) #if (!$url) Missing 'url' parameter #else #set($httpService = $action.getService("com.atlassian.confluence.plugins.confluence-http-plugin:httpService")) #try #set($response = $httpService.get($url).getEntity().getContent().getText()) $response #catch($e) Failed to fetch response: $e.getMessage() #end #end
- Use it in your table cell with:
{fetchping:url=https://your-internal-site/ping}
Note: Ensure your Confluence instance is allowed to make outbound requests to your internal sites (check your network firewall and Confluence's outbound HTTP whitelist).
Advanced Need: Handle Formatted /ping Responses (Math Formulas, Markdown, etc.)
If your /ping endpoint returns structured content like LaTeX math formulas or Markdown, you'll need to convert that content to Confluence-compatible markup before rendering.
1. LaTeX Math Formulas
If the /ping response is raw LaTeX (e.g., E=mc^2), modify your macro to wrap the response in Confluence's built-in math macro syntax:
Script Runner Script Adjustment:
// ... (keep the caching/fetch logic from before) def latexResponse = connection.inputStream.text // Wrap LaTeX in Confluence's math macro return "{math:$latexResponse}"
Confluence will automatically render this as a properly formatted math formula.
2. Markdown Content
If the /ping response uses Markdown, use Confluence's built-in Markdown parser to convert it to Confluence Wiki markup:
Custom User Macro Adjustment:
#set($url = $paramUrl) #if (!$url) Missing 'url' parameter #else #set($httpService = $action.getService("com.atlassian.confluence.plugins.confluence-http-plugin:httpService")) #try #set($markdownContent = $httpService.get($url).getEntity().getContent().getText()) #set($markdownParser = $action.getService("com.atlassian.confluence.plugins.markdown:markdownParser")) #set($wikiMarkup = $markdownParser.convertToWikiMarkup($markdownContent)) $wikiMarkup #catch($e) Failed to fetch/parse response: $e.getMessage() #end #end
This will convert Markdown headers, lists, and formatting into Confluence's native style.
3. Confluence Wiki Markup
If the /ping response already uses Confluence's own wiki syntax, you can output it directly—Confluence will render it automatically without extra conversion.
内容的提问来源于stack exchange,提问作者Darius X.

