To access the HTTP-API your client must first login to M/Monit. The form based authentication process used by M/Monit is the same as the one specified in the Java Servlet Specification.

authentication

1. Upon access to a protected area the M/Monit server determines if the client has been previously authenticated, if this is the case, the requested page is sent back to the client.

2. If the client has not been authenticated, the M/Monit server stores the original request URL and displays a login page. The client posts a login form back to the M/Monit server and the server attempts to authenticate the user credentials embedded in the form. If authentication fails the server returns an error page. If authentication succeeds, the server checks if the authenticated user belongs to a security role that is authorized to access the requested page. If the user is authorized the server redirects the request to the original stored request URL. If the user is not authorized to access the requested page the M/Monit server will send a 403 Forbidden response back to the client.

Form Based Authentication utilizes HTTP session and clients must support cookies and send the session cookie, zsessionid, with every request.

If the session timed out or is invalidated, the user is logged out and any subsequent request requires the user to re-authenticate.

CSRF-Protection

M/Monit protects against Cross-Site Request Forgery (CSRF) with the headers in which browsers say where a request comes from. A request other than GET, HEAD or OPTIONS is refused with HTTP 403 when its Sec-Fetch-Site header says it comes from another origin or, from browsers that do not send that header, when its Origin header names another host or port than the one the request was sent to.

A program that uses the HTTP-API sends neither header and needs nothing for CSRF. If it sends Origin, that must name the M/Monit server it connects to. The z_csrf_protection login parameter and the CSRFToken header or parameter, which M/Monit used before 4.4.0, are accepted and ignored.

Examples

See the cURL example for more details