home *** CD-ROM | disk | FTP | other *** search
/ Hackers Toolkit v2.0 / Hackers_Toolkit_v2.0.iso / HTML / archive / Unix / logwatch-1_5_1_tar.tar / logwatch-1_5_1_tar / logwatch-1.5.1 / HOWTO-Make-Filter < prev    next >
Text File  |  1998-03-18  |  5KB  |  135 lines

  1. First of all, each filter must process data from one or more "Log-File Group".
  2.  
  3. ***********************************************
  4. * Log-File Groups
  5. ***********************************************
  6.  
  7. Log-File groups are defined by a configuration file in /etc/log.d/conf/logfiles
  8. named <logfile_group_name>.conf.  It is usually easier to copy an existing
  9. logfile-group configuration than it is to create a brand new one.
  10.  
  11. There is only one required line in the logfile-group config file.
  12. This command is called 'LogFile'.
  13.  
  14. # This will be the logfile named 'messages' in the default logfile
  15. # directory (probably /var/log).
  16. LogFile = messages
  17.  
  18. # You can also give this command with an absolute path, like this:
  19. LogFile = /var/log/messages
  20.  
  21. You can have as many LogFile entries as you wish.  All the files
  22. specified will be merged into one input stream for any filters that
  23. use this logfile group.  You can also use standard wildcards when
  24. you specify the filename.
  25.  
  26. Another command that is optional is called 'Archive'.  You can
  27. specify a file to also include in the data stream if the '--archives'
  28. option is used.  If these files do not exist it is okay.  For example:
  29.  
  30. # These 2 'Archive' entries will allow users of most Red Hat Linux
  31. # systems to access their archives of the 'messages' logfile:
  32. Archive = messages.?
  33. # If they configure Compression to be on in /etc/logrotate.conf:
  34. Archive = messages.?.gz
  35. # It is best just to include both of these so that the logfile group
  36. # will work for most systems.
  37.  
  38. Now, the general theory is that the LogFile Group should apply the
  39. date range requested.  If the logfile is in the standard syslog
  40. format, you can use the shared script 'ApplyStdDate'.  The way
  41. to call shared scripts (located in /etc/log.d/scripts/shared) is:
  42.  
  43. *ApplyStdDate = 
  44.  
  45. Anything following the equal sign will be passed to the program as
  46. arguments.  You should look at the current logfile group config files
  47. for examples.
  48.  
  49. Finally, if the directory /etc/log.d/scripts/logfiles/<logfile_group_name>/
  50. exists, any scripts in that directory will be executed.  All of these scripts
  51. take the contents of all the specified logfiles in through STDIN and output
  52. the modified logfile trought STDOUT.  These scripts can be written in any
  53. language that can be executed on your system.
  54.  
  55. ***********************************************
  56. * Service Filter Configuration File
  57. ***********************************************
  58.  
  59. Okay, once you have defined one or more logfile-groups (or decided on one
  60. or more existing logfile-groups), you need to define your service filter.
  61.  
  62. This file needs to be in /etc/log.d/conf/services/ and it needs to be
  63. named <service>.conf.  You should probably copy an existing config for
  64. another service to create a new one.  
  65.  
  66. There is only one required line.  This is the command 'LogFile'.  The
  67. LogFile command allows you to specify one or more *LogFile Groups*
  68. (as described above) that this filter will process.  Remember, any
  69. filter can process any number of LogFile-Groups, and any LogFile-Group
  70. may contain the data from any number of logfiles (and archives). 
  71.  
  72. For a service filter that needs messages from /var/log/messages you 
  73. would add this line:
  74.  
  75. LogFile = messages
  76.  
  77. NOTE:  This is *not* because the name of the logfile is 'messages', but
  78. it is because the name of the LogFile-Group that has been defined is
  79. 'messages'.
  80.  
  81. You can have commands in the form of:
  82.  
  83. *SharedScriptName = Arguments
  84.  
  85. that will execute a script found in the /etc/log.d/scripts/shared/
  86. directory named 'SharedScriptName' with arguments 'Arguments'.
  87. This filter will modify the input to the service's filter.
  88.  
  89. You can also have commands in the form:
  90.  
  91. $EnvironmentVariable = Value
  92.  
  93. This command will set the 'EnvironmentVariable' environment variable
  94. to the value 'Value'.   This environment variable will be accessable
  95. by your filter program.
  96.  
  97. ***********************************************
  98. * Service Filter Executable
  99. ***********************************************
  100.  
  101. Once everything above has been done, you are ready to actually write
  102. your filter.  This can be done in any language as all it does is:
  103. 1) Read logfile entries from STDIN
  104. 2) Access some environment variables
  105. 3) Generate a report on STDOUT
  106.  
  107. Before you try to write a filter, you should create the filter and
  108. make its contents the test script given below.  The filter needs to
  109. be located in /etc/log.d/scripts/services/ and named <service>
  110. (because you named the config file <service>.conf).
  111.  
  112. ###################### Cut Here #########################
  113. #!/bin/bash
  114. # This is as nice script that will show you the lines you will
  115. # be processing and reporting on.  It will first display the
  116. # standard environment variables and then it take STDIN and
  117. # dump it right back out to STDOUT.  
  118.  
  119. # These are the standard environment variables.  You can define
  120. # more in your service config file (see above).
  121. echo "Date Range: $LOGWATCH_DATE_RANGE"
  122. echo "Detail Level: $LOGWATCH_DETAIL_LEVEL"
  123. echo "Temp Dir: $LOGWATCH_TEMP_DIR"
  124. echo "Debug Level: $LOGWATCH_DEBUG"
  125.  
  126. # Now take STDIN and dump it to STDOUT
  127. # Those are back-ticks...
  128. `cat`
  129. ###################### Cut Here #########################
  130.  
  131. If you temorarily replace a script such as 'pam' with the
  132. above, you will notice that much has been cut out of 
  133. /var/log/messages before it gets to this filter.  
  134.  
  135.