Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Curl error when leaving webhookurl empty #1931

Open
Jalliuz opened this issue Dec 20, 2024 · 1 comment
Open

Curl error when leaving webhookurl empty #1931

Jalliuz opened this issue Dec 20, 2024 · 1 comment
Labels

Comments

@Jalliuz
Copy link

Jalliuz commented Dec 20, 2024

We have a Monolog/Slack "webhook" implementation in our project. It works fine except when you don't have a webhook url

In my local environment I don't immediately have a Slack webhookurl. These are managed by Slack admins of our company so I can't just create one myself.

But the project requires one in the monolog config.

monolog:
    channels:
        - slack_error
    handlers:
        slack_error:
            type: slackwebhook
            webhook_url: '%env(SLACK_ERROR_WEBHOOK_URL)%'
            channel: '%env(SLACK_ERROR_CHANNEL)%'
            bot_name: '%env(SLACK_BOT_NAME)%'
            icon_emoji: '%env(SLACK_EMOJI)%'
            level: '%env(SLACK_ERROR_LEVEL)%'
            include_extra: true

If I leave it empty, my whole project crashes with a curl error in Handler/SlackWebhookHandler.php line 110

Is there an option to disable it?

What I currently did is setting the level
level: emergency
This is the highest level and I guess it currently never gets thrown.

Solution:
A solution for this bundle can be that if the webhookurl is left empty, no curl will get called

Another solution is adding an option
enabled: false

So te developer can decide if its enabled in his environment or not

@Jalliuz Jalliuz added the Bug label Dec 20, 2024
@davidheunis
Copy link

davidheunis commented Dec 20, 2024

To address your issue, you're correct that the root cause of the crash stems from the fact that the webhook_url is required by the SlackWebhookHandler in Monolog. If it's left empty or not properly configured in your environment, the handler attempts to send a request, leading to a curl error. There are a few potential solutions to make this more flexible and avoid crashes in environments where a valid Slack webhook URL is not available.

Posible Solution:
Use Environment Variable Default Value. If the environment variable is not set or left empty, you could set a default value to prevent Monolog from trying to send data. You could modify the webhook_url in the Monolog configuration file to check if the environment variable exists and fallback to a default empty value or null.

monolog:
    channels:
        - slack_error
    handlers:
        slack_error:
            type: slackwebhook
            webhook_url: '%env(SLACK_ERROR_WEBHOOK_URL)%' # Ensure this is set or falls back to a blank URL.
            channel: '%env(SLACK_ERROR_CHANNEL)%'
            bot_name: '%env(SLACK_BOT_NAME)%'
            icon_emoji: '%env(SLACK_EMOJI)%'
            level: '%env(SLACK_ERROR_LEVEL)%'
            include_extra: true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants