I know that given a Lagrangian, $L(t,x,v)$ you can write the Euler Lagrange equation
$$L_x-\frac{d}{dt}L_v=0, \tag{1}$$
to minimize the functional $$\int_0^TL(t,x,v)dt.\tag{2}$$
I'm interested in the reverse direction - given an ODE say something like
$$y''+f(t)y'+g(t)y+h(t)=0.\tag{3}$$
how can you find $L$?
Denote $y'=p$ for convenience. If you assume that your Lagrangian is $C^2$ and $L_{pp}\neq 0$, then the EL equations can be equivalently written as: $$y''-\frac{1}{L_{pp}}(L_y+L_{px}+L_{py}y')=0$$ So given your ODE, if there exists a $C^2$ Lagrangian, you can obtain it by (hypothetically) comparing terms: $$-\frac{1}{L_{pp}}(L_y+L_{px}+L_{py}y')=f(x)y'+g(x)y+h(x)$$ The specifics depend on your ODE and Lagrangian, and I guess that generally this should not be an easy equation to solve (again, assuming a solution exists).