Extension for the monit and munin programs(tut from falko)

Discussion in 'Server Operation' started by ColdDoT, Apr 22, 2006.

  1. ColdDoT

    ColdDoT New Member

    hello
    http://www.howtoforge.com/server_monitoring_monit_munin

    i like the programs it is easy to set up and nicly to see but i don't liked it to have 2 diffrent pages and even 1 with a other port. So i tought maybe i can do something cool with it.

    here a SS from my output now
    login:
    [​IMG]

    Overview
    [​IMG]

    requirements
    webserver with php
    followed the tut form falko you can find it here http://www.howtoforge.com/server_monitoring_monit_munin
    monit with ssl installed


    here is the thing i have done (maybe you can call it tut but i don't know)
    first follow the nice tut from falko
    ----------------------------------------------------------
    if you have virtual host you can do this(is not skip this section)
    ----------------------------------------------------------
    edit munin config file
    vi /etc/munin/munin.conf
    set the htmldir to
    htmldir /var/www/stats/monitoring
    then if you have apache with virutal host set this in the httpd.conf file
    if you don't know where it is locate httpd.conf
    vi httpd.conf
    add this below NameVirtualHost *:80
    Code:
    <VirtualHost *:80>
      ServerName stats.example.com:80
      ServerAdmin webmaster@example.com
      ServerAlias stats.example.com *.stats.example.com
      DocumentRoot "/var/www/stats"
    </VirtualHost>
    
    vi /var/www/stats/.htaccess
    Code:
    AuthType Basic
    AuthName "Members Only"
    AuthUserFile /var/www/stats/.htpasswd
    <limit GET PUT POST>
    require valid-user
    </limit>
    
    htpasswd -c /var/www/stats.htpasswd admin
    if you have compiled apache from source first locate htpasswd
    ----------------------------------------------------------
    other wise you can do this
    ----------------------------------------------------------
    example your site is
    www.example.com
    make a map called stats.
    edit munin config file
    vi /etc/munin/munin.conf
    set the htmldir to
    htmldir /var/www/www.example.com/stats/monitoring

    vi /var/www/www.example.com/stats/.htaccess
    Code:
    AuthType Basic
    AuthName "Members Only"
    AuthUserFile /var/www/www.example.com/stats/.htpasswd
    <limit GET PUT POST>
    require valid-user
    </limit>
    
    htpasswd -c /var/www/www.example.com/stats/.htpasswd admin
    if you have compiled apache from source first locate htpasswd
    ----------------------------------------------------------

    now you can add my custom build php script in the stats map.
    index.php
    Code:
    <?
    error_reporting(NULL);
    $monit_port = "2812";
    $monit_user = "admin";
    $monit_pass = "test";
    $server_addres = "www.example.com";
    $full_site = "stats.example.com"; //or if no virtual host "www.example.com/stats/"
    $site_name = "Example";
    $site = file_get_contents("monitoring/index.html");
    $site = str_replace("href=\"","href=\"monitoring/",$site);
    $site = str_replace("src=\"","src=\"monitoring",$site);
    //Copy right remover
    //$site = preg_replace('#<i class="small">(.*?)</i>#',"",$site);
    //$site = preg_replace('#<table cellpadding="2" cellspacing="4" border="0">(.*?)</table>#',"",$site);
    $site = str_replace("server1.example.com</a>",$full_site."</a>",$site);
    $site = str_replace("example.com</a>",$site_name."</a>",$site);
    $site = str_replace('<td><div class="logo">&nbsp;</div></td>',"",$site);
    $site = str_replace('<h1>Overview</h1>',"<span style=\"font-size: 32px;\">Overview</span><br><br>",$site);
    $site = str_replace("<title>Munin :: overview</title>","<title>ColdDoT 1u Server Monitor</title>",$site);
    
    echo $site;
    $fp = fsockopen("ssl://".$full_site, $monit_port, $errno, $errstr);
    if (!$fp) {
       echo "$errstr ($errno)<br />\n";
    } else {
       $out = "GET / HTTP/1.1\r\n";
       $out .= "Host: ".$full_site."\r\n";
       $out .= "Authorization: Basic ".base64_encode($monit_user.":".$monit_pass)."\r\n";
       $out .= "Connection: Close\r\n\r\n";
    
       fwrite($fp, $out);
       while (!feof($fp)) {
           $site2 .= fgets($fp, 128);
       }
       fclose($fp);
    }
    $site2 = preg_replace("#href='(.*?)'#","href='https://".$server_addres.":".$monit_port."$1'",$site2);
    $site2 = preg_replace("#src=\"(.*?)\"#","src=\"https://".$server_addres.":".$monit_port."$1\"",$site2);
    $site2 = preg_replace("#HTTP(.*?)<p>&nbsp;</p>#se","",$site2);
    //Copy right remover
    //$site2 = preg_replace('#<p>&nbsp;</p><p>&nbsp;</p><p><br></p><div align="center">(.*?)</div>#',"<small><center><br><br>Copyright 2000-2006 by ".$site_name."</center></small>",$site2);
    echo $site2;
    ?> 
    
     

    Attached Files:

    Last edited: Apr 22, 2006
  2. ColdDoT

    ColdDoT New Member

    It can be that i have done something wrong don't be mad. It was late you know ;). If there is something wrong post here and i wil solve it.

    greets
     
  3. chrno

    chrno New Member

    Hi ColdDoT,

    I used your index.php (adopting it to my server settings). But it didn't display the monit at all. Any idea how to debug this?

    Thanks

    chrno
     
  4. ColdDoT

    ColdDoT New Member

    Pleaz set to top rule
    error_reporting(NULL);
    to
    error_reporting(E_ALL);

    wat error do you get then ?
     
  5. chrno

    chrno New Member

    Code:
    Warning: fgets(): SSL: fatal protocol error in /var/www/web9/web/index.php on line 37
    
     
  6. ColdDoT

    ColdDoT New Member

    Does the monit programma works well if you see it just trough the normal pages?

    set
    $full_site to your normal addres so you get.
    $full_site = www.yoursite.ext;
    or if you use it as a other virtual host with a subdomain you must set
    $full_site = yoursub.yoursite.ext;

    if this still not works then i must rewrite the whole tut and i can do it tommorow
     
  7. chrno

    chrno New Member

    Emmm ... monit is displaying now but it's still showing that error ...

    I've send you a pm for my website URL. Please have a quick peek ... thanks!
     
  8. ColdDoT

    ColdDoT New Member

    set back
    error_reporting(NULL);

    :D
    The error can't do any harm
     

Share This Page