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

[Question] List of events #9

Closed
KaKi87 opened this issue Dec 12, 2024 · 11 comments
Closed

[Question] List of events #9

KaKi87 opened this issue Dec 12, 2024 · 11 comments
Labels
question Further information is requested

Comments

@KaKi87
Copy link

KaKi87 commented Dec 12, 2024

Hello,

The README uses cert_obtained as an example event but what other events are available ?

And specifically, what's the event for an HTTP request ?

Thanks

@mholt
Copy link
Owner

mholt commented Dec 12, 2024

It's hard to give a proper list because each module emits their own events, and modules are pluggable. i.e. we don't control the events that are emitted.

There are some standard ones that are pretty common, especially related to TLS automation -- I'd recommend reading the logs for now, until we figure out a way to document the events.

This PR describes most of them for now, I think: caddyserver/caddy#4912

@mholt mholt added the question Further information is requested label Dec 12, 2024
@mholt mholt closed this as completed Dec 12, 2024
@KaKi87
Copy link
Author

KaKi87 commented Dec 12, 2024

I see no event name in the logs for a request, it's just <date> <hostname> <process>[<pid>]: <json> (and the linked PR doesn't show one either) ?

Thanks

@mholt
Copy link
Owner

mholt commented Dec 12, 2024

There's no event for HTTP requests... there are detailed access logs though. Usually people implement an HTTP handler module for custom HTTP request behavior.

@KaKi87
Copy link
Author

KaKi87 commented Dec 12, 2024

My use case is server-side analytics, so I'd like to run a script every time Caddy receives a request, without proxying or altering that request in any way.
Thanks

@mholt
Copy link
Owner

mholt commented Dec 13, 2024

Definitely write an http handler module instead; it will perform much better!

@KaKi87
Copy link
Author

KaKi87 commented Dec 13, 2024

without proxying or altering that request in any way

@mholt
Copy link
Owner

mholt commented Dec 13, 2024

Yeah. So write a handler. Don't proxy it or alter anything. (I assume you mean alter not alert)

@KaKi87
Copy link
Author

KaKi87 commented Dec 13, 2024

I guess I don't understand what you mean. Could you please explain ? Thanks

@mholt
Copy link
Owner

mholt commented Dec 13, 2024

Sure -- there's an example on the bottom of this page, which explains how to extend Caddy: https://caddyserver.com/docs/extending-caddy

Running a command at every HTTP request will affect requests more than an HTTP handler, which is basically your code that then calls next.ServeHTTP() to pass the request along to the next handler. It's all in process. No proxying, no need to modify the request.

@KaKi87
Copy link
Author

KaKi87 commented Dec 13, 2024

Thanks, but I want to write that script in Bash, not Go 😅

@mholt
Copy link
Owner

mholt commented Dec 13, 2024

Then either read the logs in bash, or write a handler to emit an event on HTTP requests. We don't do this already because running a command on every HTTP request is not very performant and can open the door to DoS.

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

No branches or pull requests

2 participants