Changeset 9e27991e4a6a9ca92878a7ca39b69d0802d6d734
- Timestamp:
- 03/26/07 21:21:54
(11 years ago)
- Author:
- Theo Schlossnagle <jesus@omniti.com>
- git-committer:
- Theo Schlossnagle <jesus@omniti.com> 1174944114 +0000
- git-parent:
[5c7fb414bc39199cd1989b3f7adba3a0ef1c8f04]
- git-author:
- Theo Schlossnagle <jesus@omniti.com> 1174944114 +0000
- Message:
update the file watcher module
git-svn-id: https://labs.omniti.com/resmon/trunk@36 8c0face9-b7db-6ec6-c4b3-d5f7145c7d55
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
rae5283c |
r9e27991 |
|
118 | 118 | my $file = $arg->{'object'}; |
---|
119 | 119 | my $match = $arg->{'match'}; |
---|
120 | | my $errors; |
---|
121 | | my $errorcount = 0; |
---|
122 | | my $start = 0; |
---|
| 120 | my $max = $arg->{'max'} || 8; |
---|
123 | 121 | my @statinfo = stat($file); |
---|
124 | | if($logfile_stats{$file}) { |
---|
125 | | my($dev, $ino, $size, $errs) = split(/-/, $logfile_stats{$file}); |
---|
126 | | if(($dev == $statinfo[0]) && ($ino == $statinfo[1])) { |
---|
127 | | if($size == $statinfo[7]) { |
---|
128 | | return $arg->set_status("OK($errs)"); |
---|
| 122 | if(exists($arg->{file_dev})) { |
---|
| 123 | if(($arg->{file_dev} == $statinfo[0]) && |
---|
| 124 | ($arg->{file_ino} == $statinfo[1])) { |
---|
| 125 | if($arg->{lastsize} == $statinfo[7]) { |
---|
| 126 | if($arg->{errors}) { |
---|
| 127 | return $arg->set_status("BAD($arg->{nerrs}: $arg->{errors})"); |
---|
| 128 | } |
---|
| 129 | return $arg->set_status("OK(0)"); |
---|
129 | 130 | } |
---|
130 | | $start = $size; |
---|
131 | | $errorcount = $errs; |
---|
132 | | } |
---|
133 | | } |
---|
134 | | $logfile_stats{$file} = "$statinfo[0]-$statinfo[1]-$statinfo[7]-$errorcount"; |
---|
| 131 | } else { |
---|
| 132 | # File is a different file now |
---|
| 133 | $arg->{lastsize} = 0; |
---|
| 134 | $arg->{nerrs} = 0; |
---|
| 135 | $arg->{errors} = ''; |
---|
| 136 | } |
---|
| 137 | } |
---|
135 | 138 | if(!open(LOG, "<$file")) { |
---|
136 | 139 | return $arg->set_status("BAD(ENOFILE)"); |
---|
137 | 140 | } |
---|
138 | | seek(LOG, $statinfo[7], 0); |
---|
| 141 | seek(LOG, $arg->{lastsize}, 0); |
---|
| 142 | |
---|
139 | 143 | while(<LOG>) { |
---|
140 | 144 | chomp; |
---|
141 | 145 | if(/$match/) { |
---|
142 | | $errors .= $_; |
---|
143 | | $errorcount++; |
---|
144 | | } |
---|
145 | | } |
---|
146 | | if($errors) { |
---|
147 | | return $arg->set_status("BAD($errors)"); |
---|
148 | | } |
---|
149 | | return $arg->set_status("OK($errorcount)"); |
---|
| 146 | if($arg->{nerrs} < $max) { |
---|
| 147 | $arg->{errors} .= " " if(length($arg->{errors})); |
---|
| 148 | $arg->{errors} .= $_; |
---|
| 149 | } |
---|
| 150 | $arg->{nerrs}++; |
---|
| 151 | } |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | # Remember where we were |
---|
| 155 | $arg->{file_dev} = $statinfo[0]; |
---|
| 156 | $arg->{file_ino} = $statinfo[1]; |
---|
| 157 | $arg->{lastsize} = $statinfo[7]; |
---|
| 158 | |
---|
| 159 | if($arg->{nerrs}) { |
---|
| 160 | return $arg->set_status("BAD($arg->{nerrs}: $arg->{errors})"); |
---|
| 161 | } |
---|
| 162 | return $arg->set_status("OK(0)"); |
---|
150 | 163 | } |
---|
151 | 164 | |
---|