Search code examples
proxyagentmonit

How to setup M/monit agent behind a proxy?


I've been using mmonit for multiple different hosts to monitor various applications which are working perfectly fine and am very happy with how it is working.

However recently I've run into a wall trying to setup M/monit agent behind a proxy. Not the web interface, but the actual agent.

The host machine has limited connectivity with outside world and only via https proxy (source and destination addresses are limited).

I've tried to export https_proxy and/or http_proxy to no avail.

I've went trough available documentation however everywhere the proxy is mentioned is about setting up web interface behind a proxy and not the actual agent. Am I overlooking something simple? Or should I resort to usage of socat or other similar solutions?

Any help is highly appreciated


Solution

  • I faced the same problem and decided to use tsocks.

    EDIT: tsocks does not work because monit spawns child processes that are not wrapped by tsocks.

    I ended up using socat. Since my m/monit instance is behind SSL with a valid (not self-signed) certificate, I had to jump through one more hoop.

    In /etc/hosts, I pointed my m/monit domain to localhost:

    # /etc/hosts
    127.0.0.1 mmonit.myserver.com
    

    Then I started socat like this:

    socat TCP4-LISTEN:9900,fork SOCKS4:socksproxy.our.corporate.network:123.45.67.89:443,socksport=1080
    

    This does the following:

    • Binds to TCP(4) port 9900
    • Allows multiple connections (fork option)
    • Sends all requests through the SOCKS4 proxy socksproxy.our.corporate.network
    • Forwards all requests to 123.45.67.89 on SSL port 443 (which is my m/monit host)

    In monitrc, configure the m/monit host like this:

    set mmonit https://monit:<yourpassword>@mmonit.myserver.com:9900/collector