Portainer icon

Portainer

Trabalhe com dados da API do Portainer para gerenciar Docker

Overview

This node integrates with the Portainer API to manage Docker Swarm services, specifically allowing users to retrieve logs from a Docker Swarm service. It is useful for monitoring and debugging running services by fetching their stdout and stderr logs.

Typical use cases include:

  • Debugging issues in a Docker Swarm service by examining its logs.
  • Monitoring service output programmatically within an n8n workflow.
  • Collecting logs for auditing or alerting purposes.

For example, you can configure this node to fetch the last 100 lines of logs including both stdout and stderr with timestamps enabled, helping you quickly identify recent errors or events in your service.

Properties

Name Meaning
Environment ID The ID of the Portainer environment/endpoint where the Docker Swarm service runs.
Service ID The unique identifier of the Docker Swarm service whose logs you want to retrieve.
Include Stdout Whether to include standard output (stdout) logs. Defaults to true.
Include Stderr Whether to include standard error (stderr) logs. Defaults to true.
Tail Lines Number of log lines to retrieve from the end. Can be a number or "all" for all lines.
Timestamps Whether to include timestamps in the logs. Defaults to false.

Output

The node outputs JSON data containing the logs retrieved from the specified Docker Swarm service. The logs are returned as plain text combining stdout and/or stderr streams according to the selected options.

  • The json output field contains the raw log string.
  • No binary data output is produced by this operation.

Example output structure:

{
  "logs": "<log content as a string>"
}

Dependencies

  • Requires a valid connection to a Portainer instance with API access.
  • An API key credential for authenticating requests to the Portainer API must be configured in n8n.
  • The node uses the Portainer API endpoint /endpoints/{environmentId}/docker/services/{serviceId}/logs to fetch logs.

Troubleshooting

  • Common Issues:

    • Invalid or missing Environment ID or Service ID will cause the request to fail.
    • Insufficient permissions or invalid API key may result in authentication errors.
    • Requesting logs for a non-existent or stopped service might return empty results or errors.
  • Error Messages:

    • 401 Unauthorized: Check that the API key credential is correct and has sufficient permissions.
    • 404 Not Found: Verify that the Environment ID and Service ID are correct and the service exists.
    • 400 Bad Request: Ensure that parameters like tailLines are valid (e.g., numeric or "all").
  • Resolution Tips:

    • Double-check input IDs and credentials.
    • Confirm the service is running and accessible via Portainer.
    • Adjust log retrieval options if too many lines cause timeouts or large responses.

Links and References

Discussion