| 1 | ############################################################################# | ||
| 2 | # | ||
| 3 | # NOTE: This file under revision control using RCS | ||
| 4 | # Any changes made without RCS will be lost | ||
| 5 | # | ||
| 6 | # $Source: /usr/local/cvsroot/vbtk/VBTK/Log.pm,v $ | ||
| 7 | # $Revision: 1.7 $ | ||
| 8 | # $Date: 2002/03/04 20:53:07 $ | ||
| 9 | # $Author: bhenry $ | ||
| 10 | # $Locker: $ | ||
| 11 | # $State: Exp $ | ||
| 12 | # | ||
| 13 | # Purpose: An extension of VBTK::Wrapper for use in monitoring | ||
| 14 | # log files | ||
| 15 | # | ||
| 16 | # Depends on: VBTK::Common, VBTK::Wrapper | ||
| 17 | # | ||
| 18 | # Copyright (C) 1996 - 2002 Brent Henry | ||
| 19 | # | ||
| 20 | # This program is free software; you can redistribute it and/or | ||
| 21 | # modify it under the terms of version 2 of the GNU General Public | ||
| 22 | # License as published by the Free Software Foundation available at: | ||
| 23 | # http://www.gnu.org/copyleft/gpl.html | ||
| 24 | # | ||
| 25 | # This program is distributed in the hope that it will be useful, | ||
| 26 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 27 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 28 | # GNU General Public License for more details. | ||
| 29 | # | ||
| 30 | ############################################################################# | ||
| 31 | # | ||
| 32 | # | ||
| 33 | # REVISION HISTORY: | ||
| 34 | # | ||
| 35 | # $Log: Log.pm,v $ | ||
| 36 | # Revision 1.7 2002/03/04 20:53:07 bhenry | ||
| 37 | # *** empty log message *** | ||
| 38 | # | ||
| 39 | # Revision 1.6 2002/03/04 16:49:09 bhenry | ||
| 40 | # Changed requirement back to perl 5.6.0 | ||
| 41 | # | ||
| 42 | # Revision 1.5 2002/03/02 00:53:54 bhenry | ||
| 43 | # Documentation updates | ||
| 44 | # | ||
| 45 | # Revision 1.4 2002/02/13 07:38:52 bhenry | ||
| 46 | # Disabled RrdLogRecovery and removed use of @log | ||
| 47 | # | ||
| 48 | # Revision 1.3 2002/01/25 07:16:51 bhenry | ||
| 49 | # Changed to inherit from Wrapper | ||
| 50 | # | ||
| 51 | |||
| 52 | package VBTK::Log; | ||
| 53 | |||
| 54 | use 5.6.0; | ||
| 55 | use strict; | ||
| 56 | use warnings; | ||
| 57 | # I like using undef as a value so I'm turning off the uninitialized warnings | ||
| 58 | no warnings qw(uninitialized); | ||
| 59 | |||
| 60 | use VBTK::Common; | ||
| 61 | use VBTK::Wrapper; | ||
| 62 | |||
| 63 | # Inherit methods from VBTK::Wrapper; | ||
| 64 | our @ISA=qw(VBTK::Wrapper); | ||
| 65 | |||
| 66 | our $VERBOSE = $ENV{VERBOSE}; | ||
| 67 | |||
| 68 | #------------------------------------------------------------------------------- | ||
| 69 | # Function: new | ||
| 70 | # Description: Object constructor. Allocates memory for all class members | ||
| 71 | # Input Parms: | ||
| 72 | # Output Parms: Pointer to class | ||
| 73 | #------------------------------------------------------------------------------- | ||
| 74 | sub new | ||
| 75 | { | ||
| 76 | my $type = shift; | ||
| 77 | my $self = {}; | ||
| 78 | bless $self, $type; | ||
| 79 | |||
| 80 | # Store all passed input name pairs in the object | ||
| 81 | $self->set(@_); | ||
| 82 | |||
| 83 | # Setup a default interval | ||
| 84 | my $interval = 60; | ||
| 85 | |||
| 86 | # Setup a hash of default parameters | ||
| 87 | my $defaultParms = { | ||
| 88 | Interval => $interval, | ||
| 89 | SourceList => $::REQUIRED, | ||
| 90 | VBServerURI => $::VBURI, | ||
| 91 | VBHeader => undef, | ||
| 92 | VBDetail => [ '$data' ], | ||
| 93 | LogFile => undef, | ||
| 94 | LogHeader => undef, | ||
| 95 | LogDetail => undef, | ||
| 96 | RotateLogAt => undef, | ||
| 97 | RotateLogOnEOF => undef, | ||
| 98 | Split => undef, | ||
| 99 | Filter => undef, | ||
| 100 | Ignore => undef, | ||
| 101 | # This makes it jump to the end of the log file and start | ||
| 102 | # monitoring from there. That way we don't reprocess the whole | ||
| 103 | # log file any time we re-start. | ||
| 104 | SkipLines => '-0', | ||
| 105 | Timeout => undef, | ||
| 106 | TimeoutStatus => undef, | ||
| 107 | Follow => 1, | ||
| 108 | FollowTimeout => undef, | ||
| 109 | FollowHeartbeat => 1, | ||
| 110 | DebugHeader => undef, | ||
| 111 | }; | ||
| 112 | |||
| 113 | # Run the validation, setting defaults if values are not already set | ||
| 114 | $self->validateParms($defaultParms) || &fatal("Exiting"); | ||
| 115 | |||
| 116 | # Initialize a wrapper object. | ||
| 117 | $self->SUPER::new() || return undef; | ||
| 118 | |||
| 119 | # Store the default parms | ||
| 120 | $self->{defaultParms} = $defaultParms; | ||
| 121 | |||
| 122 | ($self); | ||
| 123 | } | ||
| 124 | |||
| 125 | #------------------------------------------------------------------------------- | ||
| 126 | # Function: addVBObj | ||
| 127 | # Description: Add a vb object to the wrapper object. | ||
| 128 | # Input Parms: | ||
| 129 | # Output Parms: None | ||
| 130 | #------------------------------------------------------------------------------- | ||
| 131 | sub addVBObj | ||
| 132 | { | ||
| 133 | my $self = shift; | ||
| 134 | my $Interval = $self->{Interval}; | ||
| 135 | my %args = @_; | ||
| 136 | |||
| 137 | # Setup some reasonable thresholds | ||
| 138 | my $expireAfterSec = int($Interval * 3); | ||
| 139 | my $description = qq( | ||
| 140 | This object follows the output of the specified log file watching for | ||
| 141 | warnings or errors. | ||
| 142 | ); | ||
| 143 | |||
| 144 | # Setup a hash of rules to be returned | ||
| 145 | my $defaultRules = { | ||
| 146 | VBObjName => ".$::HOST.log.generic", | ||
| 147 | TextHistoryLimit => 200, | ||
| 148 | ReverseText => 1, | ||
| 149 | Rules => { | ||
| 150 | '($data =~ /error|fail/i)' => 'Fail', | ||
| 151 | '($data =~ /warn/i)' => 'Warn' }, | ||
| 152 | Requirements => undef, | ||
| 153 | StatusHistoryLimit => 30, | ||
| 154 | StatusChangeActions => undef, | ||
| 155 | StatusUpgradeRules => undef, | ||
| 156 | ExpireAfter => "$expireAfterSec seconds", | ||
| 157 | Description => $description, | ||
| 158 | RrdTimeCol => undef, | ||
| 159 | RrdColumns => undef, | ||
| 160 | RrdFilter => undef, | ||
| 161 | RrdMin => undef, | ||
| 162 | RrdMax => undef, | ||
| 163 | RrdXFF => undef, | ||
| 164 | RrdCF => undef, | ||
| 165 | RrdDST => undef, | ||
| 166 | }; | ||
| 167 | |||
| 168 | # Run the validation | ||
| 169 | &validateParms(\%args,$defaultRules) || &fatal("Exiting"); | ||
| 170 | |||
| 171 | # Add the rule | ||
| 172 | my $vbObj = $self->SUPER::addVBObj(%args); | ||
| 173 | |||
| 174 | ($vbObj); | ||
| 175 | } | ||
| 176 | |||
| 177 | 1; | ||
| 178 | __END__ |