Show /var/log/messages in server_stats

Discussion in 'Tips/Tricks/Mods' started by goldstift, Jan 18, 2008.

  1. goldstift

    goldstift ISPConfig Developer ISPConfig Developer

    Hi there,

    I just wrote a little plugin that does a "sudo cat /var/log/messages" and display the result in a tab in server status dialog.

    First I had to create the php script in "/home/admispconfig/ispconfig/lib/plugins/check_messagelog.plugin.php":
    PHP:
    <?php
    /*
    Copyright (c) 2008 Alexander Heusingfeld, http://www.goldstift.de
    */

     #############################################################
     #
     # ISPConfig Plugin
     # Version 1.0
     #
     # Plugin Name: check_messagelog
     # Version:     1.0
     # Datum:       17.01.2008
     #
     #############################################################

     
    if(CONFIG_LOADED != 1) die('Direct access not permitted.');

    class 
    check_messagelog_plugin {

        function 
    show ($doc_id$doctype_id$groupid 0)
        {
        global 
    $go_info$go_api;


        if(
    $go_info["server"]["os"] != "linux"$go_api->errorMessage("Dieses Plugin ist nur für Linux verfügbar.");

            
    $buffer '';
    // for this to work you need to add the following to "visudo" at [sudoers]
        
    $fd popen ("sudo cat /var/log/messages""r");
        if(
    $fd == false){ 
            
    $buffer 'ERROR: For this to work you need to add the following line to "visudo" at the [sudoers] section 
                    admispconfig ALL=(ALL) NOPASSWD: /bin/cat /var/log/messages

            For additional hints on visudo and ispconfig look here: http://www.howtoforge.com/forums/showpost.php?p=102225&postcount=6'
    ;
        } else {
            while (!
    feof($fd)) {
                
    $buffer .= fgets($fd4096);
            }
        }
        
    pclose($fd);

        
    $html_out .= '<div align="center"><table width="90%" border="0" cellspacing="1" cellpadding="4" bgcolor="#CCCCCC">
         <tr>
           <td width="100%" bgcolor="#FFFFFF"><h3>'
    .$go_api->lng('var_log_messages').':</h3></td>
         </tr><tr>
           <td width="100%" bgcolor="#FFFFFF"><pre>'
    .$buffer.'</pre></td>
         </tr></table></div>'
    ;

        return 
    $html_out;
        }

        function 
    insert($doc_id$doctype_id$groupid 0) { return true; }
        function 
    update($doc_id$doctype_id$groupid 0) { return true; }
        function 
    delete($doc_id$doctype_id$groupid 0) { return true; }
        function 
    undelete($doc_id$doctype_id$groupid 0) { return true; }
    }
    ?>

    Then I added the new tab to the configuration in the ispconfig mysql database table:
    Code:
    UPDATE `doctype` SET `doctype_def` = 'O:3:"doc":28:{s:6:"userid";s:1:"1";s:7:"groupid";s:1:"1";s:14:"group_required";s:1:"0";s:5:"modul";s:3:"sys";s:4:"tree";s:1:"0";s:7:"buttons";s:1:"0";s:4:"name";s:12:"serverstatus";s:4:"type";s:9:"text/html";s:13:"template_type";s:4:"file";s:13:"template_path";N;s:12:"storage_type";s:2:"db";s:12:"storage_path";s:16:"isp_serverstatus";s:10:"form_width";s:3:"450";s:4:"deck";a:5:{i:0;O:4:"deck":5:{s:8:"elements";a:2:{i:0;O:11:"pluginField":13:{s:9:"css_class";N;s:7:"options";N;s:4:"name";s:12:"check_uptime";s:4:"type";s:11:"pluginField";s:5:"title";N;s:8:"language";s:2:"de";s:11:"description";N;s:6:"length";i:30;s:7:"visible";i:1;s:8:"required";i:1;s:14:"reg_expression";N;s:10:"reg_fehler";N;s:6:"search";N;}i:1;O:11:"pluginField":13:{s:9:"css_class";s:0:"";s:7:"options";N;s:4:"name";s:10:"check_disk";s:4:"type";s:11:"pluginField";s:5:"title";N;s:8:"language";s:2:"de";s:11:"description";N;s:6:"length";i:30;s:7:"visible";i:1;s:8:"required";i:1;s:14:"reg_expression";N;s:10:"reg_fehler";N;s:6:"search";N;}}s:5:"title";s:6:"Status";s:7:"visible";s:1:"1";s:9:"perm_read";s:1:"r";s:10:"perm_write";s:1:"r";}i:1;O:4:"deck":5:{s:8:"elements";a:1:{i:0;O:11:"pluginField":13:{s:9:"css_class";N;s:7:"options";N;s:4:"name";s:13:"check_meminfo";s:4:"type";s:11:"pluginField";s:5:"title";N;s:8:"language";s:2:"de";s:11:"description";N;s:6:"length";i:30;s:7:"visible";i:1;s:8:"required";i:1;s:14:"reg_expression";N;s:10:"reg_fehler";N;s:6:"search";N;}}s:5:"title";s:15:"Arbeitsspeicher";s:7:"visible";s:1:"1";s:9:"perm_read";s:1:"r";s:10:"perm_write";s:1:"r";}i:2;O:4:"deck":5:{s:8:"elements";a:1:{i:0;O:11:"pluginField":13:{s:9:"css_class";N;s:7:"options";N;s:4:"name";s:13:"check_cpuinfo";s:4:"type";s:11:"pluginField";s:5:"title";N;s:8:"language";s:2:"de";s:11:"description";N;s:6:"length";i:30;s:7:"visible";i:1;s:8:"required";i:1;s:14:"reg_expression";N;s:10:"reg_fehler";N;s:6:"search";N;}}s:5:"title";s:3:"CPU";s:7:"visible";s:1:"1";s:9:"perm_read";s:1:"r";s:10:"perm_write";s:1:"r";}i:3;O:4:"deck":5:{s:8:"elements";a:1:{i:0;O:11:"pluginField":13:{s:9:"css_class";s:0:"";s:7:"options";N;s:4:"name";s:14:"check_services";s:4:"type";s:11:"pluginField";s:5:"title";N;s:8:"language";s:2:"de";s:11:"description";N;s:6:"length";i:30;s:7:"visible";i:1;s:8:"required";i:1;s:14:"reg_expression";N;s:10:"reg_fehler";N;s:6:"search";N;}}s:5:"title";s:7:"Dienste";s:7:"visible";s:1:"1";s:9:"perm_read";s:1:"r";s:10:"perm_write";s:1:"r";}i:4;O:4:"deck":5:{s:8:"elements";a:1:{i:0;O:11:"pluginField":13:{s:9:"css_class";s:0:"";s:7:"options";N;s:4:"name";s:16:"check_messagelog";s:4:"type";s:11:"pluginField";s:5:"title";N;s:8:"language";s:2:"de";s:11:"description";N;s:6:"length";i:30;s:7:"visible";i:1;s:8:"required";i:1;s:14:"reg_expression";N;s:10:"reg_fehler";N;s:6:"search";N;}}s:5:"title";s:10:"MessageLog";s:7:"visible";s:1:"1";s:9:"perm_read";s:1:"r";s:10:"perm_write";s:1:"r";}}s:5:"title";s:17:"ISP Server Status";s:8:"keywords";N;s:11:"description";s:0:"";s:4:"path";N;s:4:"icon";s:10:"status.gif";s:5:"cache";s:1:"0";s:8:"permtype";N;s:7:"version";d:1.100000000000000088817841970012523233890533447265625;s:11:"event_class";s:0:"";s:12:"event_insert";s:0:"";s:12:"event_update";s:0:"";s:12:"event_delete";s:0:"";s:10:"event_show";N;s:11:"wysiwyg_lib";i:0;}' WHERE doctype_id=1021
    
    For this to work I needed to modify the sudo-config. Type "visudo" and add the following at the sudoers section:
    Code:
            admispconfig ALL=(ALL) NOPASSWD: /bin/cat /var/log/messages
    
    For additional hints on visudo and ispconfig look here: http://www.howtoforge.com/forums/showpost.php?p=102225&postcount=6

    That's it, a preformatted output of your /var/log/messages.
    BTW: I afterwards also changed ISPConfig configuration to log to the SYSTEM.

    @Falko and Till: is there any easy way to edit the serialized objects in the "doctype" table?? The way I added my new tab was really weird!!!

    Greets,
    Alex
     
  2. falko

    falko Super Moderator ISPConfig Developer

    You can use the Form Editor under Management.
     

Share This Page