File: Test.pm

package info (click to toggle)
monitoring-plugins-check-logfiles 4.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,812 kB
  • sloc: perl: 19,508; sh: 3,422; makefile: 72; awk: 41
file content (606 lines) | stat: -rwxr-xr-x 20,269 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
package Nagios::CheckLogfiles::Test;

use strict;
use Exporter;
use Nagios::CheckLogfiles;
use File::Basename;
use vars qw(@ISA);

use constant OK => 0;
use constant WARNING => 1;
use constant CRITICAL => 2;
use constant UNKNOWN => 3;

@ISA = qw(Nagios::CheckLogfiles);

sub new {
  my $class = shift;
  my $params = shift;
  my $self = $class->SUPER::new($params);
  foreach my $search (@{$self->{searches}}) {
  	# adds access to the test methods
  	no strict 'refs';
  	my $isa = ref($search).'::ISA';
  	push(@{$isa}, "Nagios::CheckLogfiles::Search::Test");
  }
  return bless $self, $class;
}

sub remove_windows_plugin {
  my $self = shift;
  system("mv ../plugins-scripts/check_logfiles.unix ../plugins-scripts/check_logfiles");
}

sub make_windows_plugin {
  my $self = shift;
  system("mv ../plugins-scripts/check_logfiles ../plugins-scripts/check_logfiles.unix");
  system("cd ..; perl winconfig.pl");
}

sub reset {
  my $self = shift;
  $self->{allerrors} = { OK => 0, WARNING => 0, CRITICAL => 0, UNKNOWN => 0 };
  $self->{matchlines} = { OK => [], WARNING => [], CRITICAL => [], UNKNOWN => [] };
  foreach my $level (qw(OK CRITICAL WARNING UNKNOWN)) {
    $self->{lastmsg}->{$level} = "";
  }  
  foreach my $search (@{$self->{searches}}) {	
    $search->reset();
  }
}

sub reset_run {
  my $self = shift;
  $self->reset();
  $self->run();
}

sub get_search_by_tag {
  my $self = shift;
  my $tag = shift;
  foreach (@{$self->{searches}}) {
    if ($_->{tag} eq $tag) {
      return $_;
    }
  }
  return undef;
}

sub get_search_by_template {
  my $self = shift;
  my $tag = shift;
  foreach (@{$self->{searches}}) {
    if ($_->{template} eq $tag) {
      return $_;
    }
  }
  return undef;
}

sub expect_result {
  my $self = shift;
  my $expect = { 
      OK => shift,
      WARNING => shift,
      CRITICAL => shift,
      UNKNOWN => shift
  };
  my $exp_exit = shift;
  my $as_expected = 1;
  foreach (keys %{$expect}) {
    if (defined $expect->{$_}) {
      if ($expect->{$_} != $self->{allerrors}->{$_}) {
        $as_expected = 0;
      }
    }
  }
  if ($self->{exitcode} != $exp_exit) {
    $as_expected = 0;
  }
  return $as_expected;
}

sub has_result {
  my $self = shift;
  return join(", ", (map { 
      $self->{allerrors}->{$_} 
  } qw(OK WARNING CRITICAL UNKNOWN)), $self->{exitcode});
}

sub create_file {
  my $self = shift;
  my $file = shift;
  my $perms = shift;
  my $contents = shift;
  open CCC, ">$file";
  print CCC $contents;
  close CCC;
  chmod $perms, $file;
}

sub delete_file {
  my $self = shift;
  my $file = shift;
  unlink $file;
}

sub read_file {
  my $self = shift;
  my $file = shift;
  if (-r $file) {
  	local( $/, *FFF ) ;
  	open FFF, "<$file";
  	my $content = <FFF>;
  	close FFF;
  	return $content;
  } else {
    return "";
  }
}

package Nagios::CheckLogfiles::Search::Test;

use strict;
use Exporter;
use File::Basename;
use vars qw(@ISA);

use constant OK => 0;
use constant WARNING => 1;
use constant CRITICAL => 2;
use constant UNKNOWN => 3;

@ISA = qw(Nagios::CheckLogfiles::Search);

sub new {
  my $class = shift;
  my $params = shift;
  my $self = $class->SUPER::new($params);
printf STDERR "i %s new prefilter %s\n", $self->{tag}, $self->{prefilter};
  return bless $self, $class;
}

sub reset {
  my $self = shift;
#printf STDERR "i %s renew prefilter %s with tag %s\n", $self->{tag}, $self->{prefilter}, $self->{macros}->{CL_TAG};
  $self->{matchlines} = { OK => [], WARNING => [], CRITICAL => [], UNKNOWN => [] };
  $self->{lastmsg} = { OK => "", WARNING => "", CRITICAL => "", UNKNOWN => "" };
  $self->{negpatterncnt} = { OK => [], WARNING => [], CRITICAL => [], UNKNOWN => [] };  
  $self->{thresholdcnt} = { OK => 0, WARNING => 0, CRITICAL => 0, UNKNOWN => 0 };
  #$self->{preliminaryfilter} = { SKIP => [], NEED => [] };
  $self->{perfdata} = "";
  foreach my $level (qw(CRITICAL WARNING UNKNOWN)) {
    foreach my $pat (@{$self->{negpatterns}->{$level}}) {
      push(@{$self->{negpatterncnt}->{$level}}, 0);
    }
  }
  if (exists $self->{template} && exists $self->{dynamictag}) {
    $self->{macros}->{CL_TAG} = $self->{dynamictag};
    $self->{macros}->{CL_TEMPLATE} = $self->{template};
  } else {
    #$self->resolve_macros(\$self->{tag});
    $self->{macros}->{CL_TAG} = $self->{tag};
  }
  delete $self->{lastlogoffset};
  delete $self->{lastlogtime};
  delete $self->{lastlogoffset};
  delete $self->{lastlogfile};
  delete $self->{newlogoffset};
  delete $self->{newlogtime};
  delete $self->{newdevino};
  delete $self->{newlogfile};
  delete $self->{tracebuffer};
  delete $self->{laststate};
  delete $self->{matchlines};
  $self->{relevantfiles} = [];
  $self->{logrotated} = 0;
  $self->{logmodified} = 0;
  $self->{linesread} = 0;
  $self->{relevantfiles} = [];
  if (exists $self->{options}->{sticky}) {
    $self->{options}->{sticky} = 1 if ($self->{options}->{sticky} > 1);
  }
  return $self;
}

sub dump_trace {
  my $self = shift;
  foreach (@{$self->{tracebuffer}}) {
    printf STDERR "%s\n", $_;
  }
}

sub delete_logfile {
  my $self = shift;
  my $rndfile;
  $self->{oldrandomfile} = $self->{randomfile};
  if (-e $self->{logfile}) {
    $self->trace(sprintf "D1 logfile %s %d", $self->{logfile},
        (stat $self->{logfile})[1]);
    unlink $self->{logfile};
    # reuse the inode immediately
    $self->{randomfile} = sprintf "%s/this_is_random.%d",
        dirname($self->{logfile}), int(rand 1000);
    $rndfile = IO::File->new();
    $rndfile->open(">$self->{randomfile}");
    $rndfile->printf("\n");
    $rndfile->close();
    sleep 1;
    #system("touch $self->{randomfile}");
    $self->trace(sprintf "D2 rndfile %d", (stat $self->{randomfile})[1]);
    if ($self->{oldrandomfile} && -f $self->{oldrandomfile}) {
      $self->trace(sprintf "D3 rndfile %d", (stat $self->{oldrandomfile})[1]);
      unlink $self->{oldrandomfile};
    }
    delete $self->{oldrandomfile};
  }
  if ($self->{rotation}) {
    $self->delete_archives();
  }
}

sub delete_seekfile {
  my $self = shift;
  if (-e $self->{seekfile}) {
    $self->trace(sprintf "D1 seekfile %s %d", $self->{seekfile},
        (stat $self->{seekfile})[1]);
    unlink $self->{seekfile};
  } else {
    $self->trace(sprintf "D2 seekfile %s", $self->{seekfile});
  }
}

sub delete_archives {
  my $self = shift;
  foreach my $archive (glob $self->{archivedir}.'/*') {
    if ($archive ne $self->{logfile}) {
      unlink $archive;
    }
  }
}

sub touch_logfile {
  my $self = shift;
  my $logfh = IO::File->new();
  $logfh->autoflush(1);
  $logfh->open($self->{logfile}, "a");
  $logfh->close();
}

sub truncate_logfile {
  my $self = shift;
  truncate($self->{logfile}, 0);
}

sub restrict_logfile {
  my $self = shift;
  if ($^O =~ /MSWin/) {
    my $winlogfile = $self->{logfile};
    $winlogfile =~ s/\//\\/g;
    my $cmd = sprintf "CACLS %s /D %s /E", $winlogfile, $self->{macros}->{CL_USERNAME};
    $self->trace("%s", $cmd);
    system($cmd);
  } else {
    chmod 0000, $self->{logfile};
  }
}

sub unrestrict_logfile {
  my $self = shift;
  if ($^O =~ /MSWin/) {
    my $winlogfile = $self->{logfile};
    $winlogfile =~ s/\//\\/g;
    my $cmd = sprintf "CACLS %s /G %s:F /E", $winlogfile, $self->{macros}->{CL_USERNAME};
    $self->trace("%s", $cmd);
    system($cmd);
  } else {
    chmod 0644, $self->{logfile};
  } 
} 

sub dump_seekfile {
  my $self = shift;
  my $seekfh = IO::File->new();
  if ($seekfh->open($self->{seekfile}, "r")) {
    while (my $line = $seekfh->getline()) {
      printf "%s", $line;
    }
    $seekfh->close();
  }
}

sub rotate {
  my $self = shift;
  my $method = shift || $self->{rotation};
  if ($method eq "SOLARIS") {
  	my $oldest = 0;
  	foreach my $archive (glob $self->{archivedir}.'/messages.*') {
  	  if ($archive =~ /messages.(\d+)/) {
  	  	if ($1 > $oldest) {
  	  	  $oldest = $1;
  	  	}
  	  }
  	}
  	foreach (reverse (0 .. $oldest)) {
  	  if (-f $self->{archivedir}.'/messages.'.$_) {
        rename $self->{archivedir}.'/messages.'.$_,
            $self->{archivedir}.'/messages.'.($_ + 1); 
            $self->trace(sprintf "i move %s to %s", $self->{archivedir}.'/messages.'.$_,
            $self->{archivedir}.'/messages.'.($_ + 1));
  	  } else {
  	    $self->trace(sprintf "i cannot find %s", $self->{archivedir}.'/messages.'.$_);
  	  }
  	}
  	$self->trace(sprintf "i move %s to %s", $self->{logfile}, $self->{archivedir}.'/messages.0');
    rename $self->{logfile}, $self->{archivedir}.'/messages.0';
  } elsif ($method eq "loglog0log1") {
    my $oldest = 0;
    my $globfiles = $self->{archivedir}.'/'.$self->{logbasename}.'.*';
    if ($globfiles =~ /[^\\][ ]/) {
      # because Core::glob splits the argument on whitespace
      $globfiles =~ s/( )/\\$1/g;
    }
    foreach my $archive (glob "$globfiles") {
      $archive = basename($archive);
      if ($archive !~ /^$self->{logbasename}\.(\d+)$/) {
        next;
      } else {
  	if ($1 > $oldest) {
  	  $oldest = $1;
  	}
      }
    }
    foreach (reverse (0 .. $oldest)) {
      if (-f $self->{archivedir}.'/'.$self->{logbasename}.'.'.$_) {
        rename $self->{archivedir}.'/'.$self->{logbasename}.'.'.$_,
        $self->{archivedir}.'/'.$self->{logbasename}.'.'.($_ + 1);
        $self->trace(sprintf "i move %s to %s", 
            $self->{archivedir}.'/'.$self->{logbasename}.'.'.$_,
            $self->{archivedir}.'/'.$self->{logbasename}.'.'.($_ + 1));
      } else {
        $self->trace(sprintf "i cannot find %s", 
            $self->{archivedir}.'/'.$self->{logbasename}.'.'.$_);
      }
    }
    $self->trace(sprintf "i move %s to %s", $self->{logfile}, $self->{archivedir}.'/'.$self->{logbasename}.'.0');
    rename $self->{logfile}, $self->{archivedir}.'/'.$self->{logbasename}.'.0';
  }
  sleep 2;
}

sub rotate_compress {
  my $self = shift;
  my $method = shift || $self->{rotation};
  if ($method eq "SOLARIS") {
    my $oldest = 0;
    $self->trace(sprintf "compressing and rotation like solaris");
    foreach my $archive (glob $self->{archivedir}.'/messages.*') {
      if ($archive =~ /messages.(\d+)/) {
        if ($1 > $oldest) {
          $oldest = $1;
        }
      }
    }
    $self->trace(sprintf "oldest archive is messages.%d", $oldest);
    foreach (reverse (0 .. $oldest)) {
      if (-f $self->{archivedir}.'/messages.'.$_) {
        $self->trace(sprintf "i found %s",
            $self->{archivedir}.'/messages.'.$_);
        rename $self->{archivedir}.'/messages.'.$_,
            $self->{archivedir}.'/messages.'.($_ + 1);
        $self->trace(sprintf "i move %s to %s modified %d,  accessed %d,  inode %d",
            $self->{archivedir}.'/messages.'.$_,
            $self->{archivedir}.'/messages.'.($_ + 1),
            (stat $self->{archivedir}.'/messages.'.($_ + 1))[9],
            (stat $self->{archivedir}.'/messages.'.($_ + 1))[8],
            (stat $self->{archivedir}.'/messages.'.($_ + 1))[10]);
        system("gzip", "-f", $self->{archivedir}.'/messages.'.($_ + 1));
        sleep 2;
        $self->trace(sprintf "i compress %s modified %d,  accessed %d,  inode %d",
            $self->{archivedir}.'/messages.'.($_ + 1),
            (stat $self->{archivedir}.'/messages.'.($_ + 1).'.gz')[9],
            (stat $self->{archivedir}.'/messages.'.($_ + 1).'.gz')[8],
            (stat $self->{archivedir}.'/messages.'.($_ + 1).'.gz')[10]);
      } elsif (-f $self->{archivedir}.'/messages.'.$_.'.gz') {
        $self->trace(sprintf "i found %s",
            $self->{archivedir}.'/messages.'.$_.'.gz');
        rename $self->{archivedir}.'/messages.'.$_.'.gz',
            $self->{archivedir}.'/messages.'.($_ + 1).'.gz';
        $self->trace(sprintf "i move %s to %s modified %d,  accessed %d,  inode %d",
            $self->{archivedir}.'/messages.'.$_.'.gz',
            $self->{archivedir}.'/messages.'.($_ + 1).'.gz',
            (stat $self->{archivedir}.'/messages.'.($_ + 1).'.gz')[9],
            (stat $self->{archivedir}.'/messages.'.($_ + 1).'.gz')[8],
            (stat $self->{archivedir}.'/messages.'.($_ + 1).'.gz')[10]);
        sleep 2;
      } else {
        $self->trace(sprintf "i cannot find %s",
            $self->{archivedir}.'/messages.'.$_);
      }
    }
    rename $self->{logfile}, $self->{archivedir}.'/messages.0';
    $self->trace(sprintf "i move %s to %s modified %d,  accessed %d,  inode %d", 
        $self->{logfile}, $self->{archivedir}.'/messages.0',
        (stat $self->{archivedir}.'/messages.0')[9],
        (stat $self->{archivedir}.'/messages.0')[8],
        (stat $self->{archivedir}.'/messages.0')[10]);

    $self->trace(sprintf "done compressing and rotation like solaris");
  }
  sleep 2;
}


sub dump_protocol {
  my $self = shift;
  foreach my $level (qw (OK WARNING CRITICAL UNKNOWN)) {
    if ($self->getmatches($level)) {
      printf STDERR "%s errors in %s\n", $level, $self->{logbasename};
      foreach ($self->getmatchmessages($level)) {
        printf STDERR "%s\n", $_;
      }
    }
  }
}

##### eventcreate
sub logger {
  my $self = shift;
  my $hostname = shift;
  my $process = shift;
  my $count = shift || 1;
  my $message = shift;
  my $raw = shift || 0;
  my $details = shift || {};
  $| = 1;
  if (($self->{type} eq "psloglist") || ($self->{type} eq "eventlog") || ($self->{type} eq "wevtutil")) {
    my $cmd;
    my $type = exists $details->{EventType} ? uc $details->{EventType} : "INFORMATION";
    my $source = exists $details->{Source} ? $details->{Source} : "check_logfiles";
    my $id = exists $details->{EventID} ? $details->{EventID} : 1;
    while ($count--) {
      if ($^O =~ /cygwin/) {
        #$cmd = sprintf '/cygdrive/c/WINDOWS/system32/eventcreate /L Application /SO %s /T %s /ID %s /D "%s" >/dev/null 2>&1',
        $cmd = sprintf '/cygdrive/c/WINDOWS/system32/eventcreate /L Application /T %s /ID %s /D "%s" >/dev/null 2>&1',
            $type, $id, $message;
      } else { # MSWin or other native windows perls
        $cmd = sprintf 'C:\WINDOWS\system32\eventcreate /L Application /SO %s /T %s /ID %s /D "%s" 1>NUL 2>&1',
            $source, $type, $id, $message;
      }
printf "exec %s\n", $cmd;
      system($cmd);
    }
  } else {
    $hostname ||= "localhost";
    $process ||= "check_logfiles";
    my $logfh = IO::File->new();
    $logfh->autoflush(1);
    if ($logfh->open($self->{logfile}, "a")) {
      while ($count--) {
        if (! $raw) {
    	  my($sec, $min, $hour, $mday, $mon, $year) = 
              (localtime)[0, 1, 2, 3, 4, 5];
          my $timestamp = sprintf "%3s %2d %02d:%02d:%02d",
              ("Jan", "Feb", "Mar", "Apr", "May", "Jun",
              "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")[$mon],
              $mday, $hour, $min, $sec;
          if ($process ne 'check_logfiles') {
            # z.b. $tivtest->logger('dellsrv', 'Server Administrator:', 1, "Storage Service EventID: 1004 on PE 1850");
            # Jun 19 10:57:58 dellsrv Server Administrator: Storage Service EventID: 1004 on PE 1850
  	    $logfh->printf("%s %s %s %s\n",
  	        $timestamp, $hostname, $process, $message);
          } else {
  	    $logfh->printf("%s %s %s[%d] %s\n",
  	        $timestamp, $hostname, $process, $$, $message);
          }
        } else {
  	  $logfh->printf("%s\n", $message);
        }
      }
    }
    $logfh->close();
  }
}

sub loggercrap {
  my $self = shift;
  my $hostname = shift || "localhost";
  my $process = shift || "check_logfiles";
  my $count = shift || 1;
  my $maxmsg = rand($count) + 1;
  my $messages = [
      ["", 
          "-- MARK --",
          "last message repeated 1 time",
          "last message repeated 100 times"],
      ["in.fingerd", 
          "connect from xxx1\@umbc9.umbc.edu"],
      ["inetd", 
          "registrar/tcp: Connection from hpcae30 (160.21.33.43) at Wed Nov 29 11:10:17 2006",
          "shell/tcp: Connection from svxbs28 (160.21.33.209) at Wed Nov 29 11:15:01 2006",
          "auth/tcp: Connection from lldsm43 (160.21.33.146) at Wed Nov 29 10:24:55 2006"],
      ["sam-arcopy", 
          "[ID 287109 local7.info] info OS call error: open(/net/spams/fs02/share/PAK/aw_06/1000/E61/R-V515229N47D20OL6HP19T\334/08.06.2006_18.35_3_LB_3_A/DATA/MeasSetup/ChanPos): File is offline",
          "[ID 475690 local7.info] info OS call error: open failed: sa.912518",
          "[ID 821104 local7.info] info OS call error: open(/net/spams/fs02/share/EWE-ARCH/aw_30/E60/_Datenkorb/_G01_E060-07-03-450/_41_FV_2_iO/CCA060/FV_CCA060_CHIKOR-HO_E89x-07-03-450_E89x-07-06-400/SB_041028_DF_CCA060_E89x-07-03-450_E89x-07-06-400__E060_E070-07-09-350_E060-07-09-350.xml"
      ],
      ["devfsadm",
          "[ID 518500 daemon.error] readlink failed for /dev/vx/dsk/rootdg: Invalid argument"
      ],
      ["sshd", 
          "Invalid user delta from 194.44.247.243 ",
          "Invalid user tester from 194.44.247.243 ",
          "Failed none for hiasl from 192.168.9.11 port 4250 ssh2",
          "[ID 800047 auth.info] Connection closed by 160.21.33.116",
          "[ID 800047 auth.info] Found matching RSA key: 46:8f:0b:18:a6:ed:2a:89:b0:f7:79:9e:e5:5f:65:8d",
          "[ID 800047 auth.info] Accepted publickey for qqdda from 160.21.33.116 port 44436 ssh2",
          "[ID 800047 auth.info] Failed none for qqdda from 160.21.33.116 port 44398 ssh2",
          "[ID 800047 auth.info] subsystem request for sftp",
          "[ID 800047 auth.info] Generating new 768 bit RSA key.",
          "[ID 800047 auth.info] RSA key generation complete."],
      ["scsi",
          "[ID 799468 kern.info] ssd112 at scsi_vhci0: name g600c0ff000000000007c026394436200, bus address g600c0ff000000000007c026394436200",
          "[ID 243001 kern.info]      Target 0x2305ef: Device type not supported: Device type=0x3 Peripheral qual=0x0"],
      ["mpxio",
          "[ID 669396 kern.info] /scsi_vhci/ssd\@g600c0ff000000000007c02288cc3ff00 (ssd114) multipath status: failed, path /pci\@1d,700000/SUNW,qlc\@2/fp\@0,0 (fp4) to target address: 226000c0ffa07c02,3 is offline. Load balancing: none",
          "[ID 669396 kern.info] /scsi_vhci/ssd\@g600c0ff000000000007c02288cc3ff00 (ssd114) multipath status: degraded, path /pci\@1d,700000/SUNW,qlc\@2/fp\@0,0 (fp4) to target address: 226000c0ffa07c02,3 is online. Load balancing: none"]
  ];
  for (1..$maxmsg) {
  	my $procnum = int rand(scalar(@{$messages}));
  	my $msgnum = int rand(scalar(@{$messages->[$procnum]}) - 1) + 1;
    $self->logger(undef, $messages->[$procnum]->[0], 1, $messages->[$procnum]->[$msgnum]);
  }
  $self->trace(sprintf "%s logs %d random messages to %s", 
      $self->{tag}, $maxmsg, $self->{logfile});
  return $maxmsg;
}

sub revert_seekfile {
  my $self = shift;
  my $tmp = {};
  our $state = {};
  if (-f $self->{seekfile}) {
    $self->trace(sprintf "seekfile to revert %s found", $self->{seekfile});
    eval {
      do $self->{seekfile};
    };
    if ($@) {
      # found a seekfile with the old syntax
      $self->trace(sprintf "seekfile to revert has old format %s", $@);
      my $seekfh = new IO::File;
      $seekfh->open($self->{seekfile}, "r");
      $tmp->{lastlogoffset} = $seekfh->getline() || 0;
      $tmp->{lastlogtime} = $seekfh->getline() || 0;
      $tmp->{lastdevino} = $seekfh->getline();
      chomp $tmp->{lastlogoffset};
      chomp $tmp->{lastlogtime};
      chomp $tmp->{lastdevino};
      $seekfh->close();
      if (! $self->{lastdevino}) {
        # upgrade vom < 1.4 on the fly
        $self->{lastdevino} = (-e $self->{logfile}) ?
            sprintf ("%d:%d", (stat $self->{logfile})[0],
              (stat $self->{logfile})[1]) : "0:0";
      }
      $self->{lastlogfile} = $self->{logfile};
    } else {
      $self->trace(sprintf "seekfile to revert has new format %s", $@);
      $tmp->{lastlogoffset} = $state->{logoffset};
      $tmp->{lastlogtime} = $state->{logtime};
      $tmp->{lastdevino} = $state->{devino};
      $tmp->{lastlogfile} = $state->{logfile};
    }
    my $seekfh = new IO::File;
    if ($seekfh->open($self->{pre2seekfile}, "w")) {
      $self->trace(sprintf "writing seekfile %s in old format as %s",
          $self->{seekfile}, $self->{pre2seekfile});
      $seekfh->printf("%d\n", $tmp->{lastlogoffset});
      $seekfh->printf("%d\n", $tmp->{lastlogtime});
      $seekfh->printf("%s\n", $tmp->{lastdevino});
      $seekfh->close();
      unlink $self->{seekfile};
    }
  }
}

1;