Add the LogzMon Log Viewer to freePBX and trixbox
- Introduction
- Download
- Install
- Configure
- Set up expressions for highlighting
- Some logging options
- Hack freePBX to provide LogViewer Link
The log viewing option in freePBX and trixbox is very limited and there has been discussion in the trixbox forum about better ways of extracting information from the asterisk log /var/log/asterisk/full. LogzMon is an open source / GPLV3 licensed log viewing program and it seems to work well. It makes reading log files a lot easier. It can be installed easily on a trixbox server and a simple hack incorporates it into freePBX. Note this hack will be overwritten if you update freePBX. Methodica LogzMon is written by Hans E. Herger
Introduction
This information is taken from the Methodica LogzMon website.
Methodica LogzMon is a log file viewer and a simple log file monitor. The log files are scanned and read from the web server. The results are submitted to the client where a standard browser is needed.
- Main features
- List current log files, archived files, and any ASCII text files that can be read on the same web server machine, where LogzMon is installed.
- Show the contents of selected files or archives.
- Highlight entries matching certain criteria (REGEX(1) patterns).
- Monitor an active log file, auto-refreshing the contents.
- In Auto-refresh mode, send messages to Syslog daemons, via e-mail or SMS when log entries match certain patterns.
- Limit the amount of memory used by the browser by limiting the number of lines interpreted.
- Navigate through pages.
- Select among predefined window sizes, typical for notebook and desktop screens.
- Multi-language support (currently English and German are implemented).
- How it works
- Methodica LogzMon consists of server-side and client-side components.
- The server-side components are PHP(2) scripts, templates, and configuration files.
- The client side component is dynamically generated from a template and updated by the serverside main script. It is an HTML page containing HTML code, style sheets (CSS(3)), and JavaScript code. This page should be correctly processed by modern browsers(4). **Client and server components communicate using AJAX technology. I.e. your browser must be configured to allow for running JavaScript and, when you are using the Internet Explorer browser, the standard AJAX ActiveX component provided by Microsoft.
(1) REGular EXpression. In the Unix/Linux world, standard format for search patterns. (2) PHP: Hypertext Preprocessor (3) CSS: Cascading Style Sheets (4) LogzMon has been tested with IE 6.0/7.0, Mozilla 1.7+, Firefox 1.5/2.0, Opera 8+.
Download
Download the latest version of LogzMon from the LogzMon website.
- Download the .tar version if you are going to install directly on the Centos OS on the trixbox server. You can d/l to your PC and the use winSCP to copy the archive to you trixbox server.
- Download the .zip if you want to unpack the files on a win PC and then copy the individual components to your trixbox server
- The simplest approach is to use ‘wget’ to download directly to the /var/www/html/admin directory. Login to your trixbox server (perhaps using SSH) and then:
cd /var/www/html/admin wget http://tools.methodica.info/logviewer/download/logzmon_1_4.tar
Install
- If you d/l’d the .tar to /var/www/html/admin (or you copied it there), make sure that you are in the admin directory and then untar the file:
cd /var/www/html/admin tar -xvf logzmon_1_4.tar
- This will create a logviewer subdirectory in /var/www/html/admin and decompress the archive there.
Configure
- Download the documentation from the LogzMon website.
- The basic configuration requires that you:
- Edit logviewer_config.inc.php
- The default logviewer_config.inc.php contains the following:
The first line below is commented out with // - You can leave this as you don’t actually need to set a user (as long as you leave the user setting blank in index.html
NOTE: You MUST have valid entries here otherwise the php fails to run and you get a blank page. So rem the lines out with a // or put valid entries in place.
// if ($user=='ADMINISTRATOR.YOURDOMAIN.COM') {
$logfiles = array ( array ('/var/www2/www2.yourdomain.com/logs/speciallogs.txt','(special)'), );
$logdirs = array ( array ('/var/www/www.yourdomain.com/logs',''), array ('/var/www2/www.yourdomain.com/logs',''), );
$archivedirs = array ( array ('/var/www/www.yourdomain.com/logs',''), array ('/var/www/www2.yourdomain.com/logs','(www2)'), );
A typical trixbox config could be to change the lines above as follows:
// if ($user=='ADMINISTRATOR.YOURDOMAIN.COM') {
$logfiles = array ( // array ('/var/www2/www2.yourdomain.com/logs/speciallogs.txt','(special)'), );
$logdirs = array (
array ('/var/log/asterisk',''), array ('/var/log',''), array ('/var/log/asterisk/cdr-csv',''), array ('/etc/asterisk',''),
);
$archivedirs = array ( // array ('/var/www/www.yourdomain.com/logs',''), // array ('/var/www/www2.yourdomain.com/logs','(www2)'), );
- Note three additional lines have been rem’ed out.
- There are three options here that configure arrays in the log viewer
- $logfiles. Here you can indicate specific log files that you want to view. But DON’T include them here if their path is included in the option $logdirs, because the entry will then be duplicated.
- If all you wanted to view was the asterisk logfile ‘full’ you could add an entry to the $logfiles array as follows:
array ('/var/log/asterisk/full','(asterisk log)'),
- $logdirs. Here you can indicate paths that contain log files that are to be viewed. For example
- Add the following to include the log file written by asterisk and freepbx
array ('/var/log/asterisk',''),
- Add the following to look at your CDR records
array ('/var/log/asterisk/cdr-csv',''),
- Add the following if you want to see a list of all all files in /var/log
array ('/var/log',''),
- However NOTE only files that are owned by the user (or part of the group) ‘asterisk’ or are world readable can be viewed by LogzMon. The /var/log option above will list some log files that have permissions that prevent viewing by LogzMon
- Add the following and you can view your asterisk config files. LogzMon will view any text file as long as the file ending is set up in the definitions at the end of logviewer_config.inc.php
array ('/etc/asterisk',''),
- $archivedirs. Add directories here that contain archives that you want to view.
- NOTE: when adding a directory to the array definition DO NOT include a trailing / e.g.
array ('/etc/asterisk',''),
is correct, but,
array ('/etc/asterisk/',''),
is incorrect.
- Finally you need to define some variable that setup your log viewer program. The last block of logviewer_config.inc.php looks something like this
- To view log files that end in .1 or .2 or .log or .csv or .conf or .txt string together _1_2_3_ etc. Include two underscores __ to indicate logfiles that do not have a . suffix such as ‘full’ the main asterisk logfile. So you end up with this.
define('logext','__1_2_log_csv_conf_txt_',true);
- To view archive files add their endings in a similar way
define('arcext','_gz_tar_',true);
- To make the html displayed personal to your server add the hostname here. This option has is just for display purposes
define('host_name','my trixbox host name');
- Enter the IP of your trixbox server here. It is an http link to your server, in the webpage heading.
define('host_name_url','http://192.168.0.100');
- the remaining definitions can be left and are described in the User Guide that you d/l’d
Edit index.html
Two index files are contained in LogzMon use one and delete the other, they only differ in the file ending. The index file contains a line
<meta HTTP-EQUIV=REFRESH CONTENT=“0;URL=logviewer.php?mode=init&user=”>
Just remove the user setting so that it appears as above.
Test
- Point your browser at
http://your_trixbox_ip/admin/logviewer
- Your browser should display a window listing log files that match your condition set in the log file and directory arrays with file endings matching your defines at the end of the configuration file.
- Double click on a log file and the contents should be displayed in the right hand pane. navigate using the forward and back arrows at the top of the webpage.
Set up expressions for highlighting
- The beauty of this log viewer is that you can easily setup expressions that are selectively highlighted in your browser display.
- Look for the $filters section in the php config file. The following is my example:
$filters = array ( array ('/_heartbeat\.htm|/favicon.ico |/img/|/scr/|/css/','hide',''), array ('started','white','green',''), array ('unable','green','red',''), array ('load','white','blue',''), array ('sip','black','orange',''), array ('iax','black','orange',''), array ('zap','black','orange',''), array ('voice','','pink'), array ('eth','','pink'), array ('raid','','pink'), array ('pci','','pink'), );
- the line array (‘unable’,‘green’,‘red’, defines that every time ‘unable’ appears in the log / text file the containing line will displayed as green text on a red background. etc.
Some logging options
- Create a boot log that is readable by asterisk. The boot.log files in Centos are not world readable. If you want to be able to read a boot log through LogzMon then run the following command
dmesg > /var/log/boot.msg
- Make sure that .msg is added to the logext define. If you want to run this every time you reboot the server than add the line to the file /etc/rc.d/rc.local
- The file /etc/asterisk/logger.conf controls the way asterisk logs events. The log file full is defined by
full => notice,warning,error,debug,verbose
If you want just debug messages you can create an additional log file by adding after the entry for ‘full’
asteriskdebug => debug
Hack freePBX to provide LogViewer Link
Here is a simple hack to place a Logviewer link on the freePBX admin page. It works with TB 2.0 and 2.2. It’s just a hack if you update freePBX it will be overwritten.
- In /var/www/html/admin there is a file header.php.
- Before you do any thing else back it up.
- Edit this file and over half way down there is a section
print_sub_tool( _("Management"), "manage.php" , $currentFile=='manage.php' ); print_sub_tool( _("Setup") , "config.php" , $currentFile=='config.php' && isset($_REQUEST['type']) && ($_REQUEST['type']=='setup' || $_REQUEST['type'] == ""), "config.php?type=setup", false ); print_sub_tool( _("Tools") , "config.php" , $currentFile=='config.php' && isset($_REQUEST['type']) && $_REQUEST['type']=='tool' , "config.php?type=tool", false ); print_sub_tool( _("Logviewer") , "./logviewer/index.html",0, NULL, true ); print_sub_tool( _("Reports") , "reports.php", $currentFile=='reports.php' ); print_sub_tool( _("Panel") , "panel.php" , $currentFile=='panel.php' ); print_sub_tool( _("Recordings"), "../recordings/index.php" ,0, NULL, true );
Your version will not contain the line
print_sub_tool( _("Logviewer") , "./logviewer/index.html",0, NULL, true );
- Just add this line as indicated above and it places a link in the freePBX admin options and in this case the link is between ‘Tools’ and ‘Reports’
- It seems to work, and uses the index.html file. If you used the .htm version change this here.
- Getting this edit wrong will BREAK your freePBX, so backup header.php first and if you can’t get this hack to work go back to your original version.
Comments and Criticisms
Please read the User Guide that is provided with this program. There are other ways of using and configuring this program. I have not tried to explore them all, if you find a better way please let me know, via my contact page here or on the trixbox forum.
If you have suggestions about using this with trixbox or freePBX please let me know so that I can update this how-to. If you have suggestions about LogzMon itself you may want to let the author know via the Contact link on the Methodica LogzMon website.