Subversion Repositories DevTools

Rev

Rev 5399 | Rev 5405 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5399 Rev 5404
Line 91... Line 91...
91
    filtered => 0,                      # Packages filtered out
91
    filtered => 0,                      # Packages filtered out
92
    missing  => 0,                      # Packages missing
92
    missing  => 0,                      # Packages missing
93
    transfer => 0,                      # Packages to transfer
93
    transfer => 0,                      # Packages to transfer
94
    writable => 0,                      # Packages still writable - thus not transferred
94
    writable => 0,                      # Packages still writable - thus not transferred
95
    tagCount => 0,                      # Packages tagged to be transferred
95
    tagCount => 0,                      # Packages tagged to be transferred
-
 
96
                                        #
-
 
97
                                        # Expected from the Target 
-
 
98
#   Target.Hostname => '',              # Target Hostname
-
 
99
#   Target.avail    => 0,               # Information from 'df' 1Kblocks 
-
 
100
#   Target.pcent    => 0,
-
 
101
#   Target.size     => 0,
-
 
102
#   Target.used     => 0,
-
 
103
#   Target.iavail   => 0,               # Inode information from 'df'
-
 
104
#   Target.ipcent   => 0,
-
 
105
#   Target.isize    => 0,
-
 
106
#   Target.iused    => 0,
-
 
107
#   Target.Total    => 0,               # Number of Package Versions in the archive
-
 
108
#   Target.Damaged  => 0,               # Number that are damaged
-
 
109
#   Target.Delete   => 0,               # Number marked for future deletion
-
 
110
#   Target.Missing  => 0,               # Number missing
96
);
111
);
97
 
112
 
98
#
113
#
99
#   Describe configuration parameters
114
#   Describe configuration parameters
100
#
115
#
Line 137... Line 152...
137
#       Set up a logger
152
#       Set up a logger
138
#       Write a pidfile - thats not used
153
#       Write a pidfile - thats not used
139
readConfig();
154
readConfig();
140
Utils::writepid($conf);
155
Utils::writepid($conf);
141
$logger->logmsg("Starting...");
156
$logger->logmsg("Starting...");
-
 
157
readStatistics();
142
sighandlers($conf);
158
sighandlers($conf);
143
$startTime = time();
159
$startTime = time();
144
 
160
 
145
#
161
#
146
#   Main processing loop
162
#   Main processing loop
Line 326... Line 342...
326
    #   Returned data looks like:
342
    #   Returned data looks like:
327
    #   1141792602 GMT(Wed Mar  8 04:36:42 2006) [DL] ishieldmodules/11.5.0.cots
343
    #   1141792602 GMT(Wed Mar  8 04:36:42 2006) [DL] ishieldmodules/11.5.0.cots
328
    #   
344
    #   
329
    #
345
    #
330
    my $remotePkgList;
346
    my $remotePkgList;
-
 
347
    my $remotePackageVersionCount = 0;
-
 
348
    my $remoteData;
331
    my $ph;
349
    my $ph;
332
    my $tgt_cmd = "$conf->{'bindir'}/get_plist.pl";
350
    my $tgt_cmd = "$conf->{'bindir'}/get_plist.pl";
333
    my $ssh_cmd = sshCmd($tgt_cmd);
351
    my $ssh_cmd = sshCmd($tgt_cmd);
334
 
352
 
335
    $logger->verbose2("processReleaseList:ssh_cmd:$ssh_cmd");
353
    $logger->verbose2("processReleaseList:ssh_cmd:$ssh_cmd");
336
    open ($ph, "$ssh_cmd |");
354
    open ($ph, "$ssh_cmd |");
337
    while ( <$ph> )
355
    while ( <$ph> )
338
    {
356
    {
339
        chomp;
357
        chomp;
340
        if ( parsePkgList($_, \%{$remotePkgList} ) )
358
        if ($_ =~ m~^Metadata\s+~)
341
        {
359
        {
342
            $logger->verbose2("processReleaseList:Data: $_");
360
            parsePkgMetaData($_, \%{$remoteData})
343
        }
361
        }
344
        else
362
        else
345
        {
363
        {
-
 
364
            if ( parsePkgList($_, \%{$remotePkgList} ) )
-
 
365
            {
-
 
366
                $logger->verbose2("processReleaseList:Data: $_");
-
 
367
                $remotePackageVersionCount++;
-
 
368
            }
-
 
369
            else
-
 
370
            {
346
            $logger->warn("processReleaseList:Bad Data: $_");
371
                $logger->warn("processReleaseList:Bad Data: $_");
-
 
372
            }
347
        }
373
        }
348
    }
374
    }
349
    close ($ph);
375
    close ($ph);
350
    $logger->verbose("processReleaseList:End: $?");
376
    $logger->verbose("processReleaseList:End: $?");
351
    LogTxError ($?);
377
    LogTxError ($?);
Line 525... Line 551...
525
    my $needPkgListCount = 0;
551
    my $needPkgListCount = 0;
526
    my $filteredCount = 0;
552
    my $filteredCount = 0;
527
    my $missingCount = 0;
553
    my $missingCount = 0;
528
    my $writableCount = 0;
554
    my $writableCount = 0;
529
    my $excludeCount = 0;
555
    my $excludeCount = 0;
-
 
556
    my $packageVersionCount = 0;
530
    while ( (my ($pname, $pvers)) = each %{$pkgList} )
557
    while ( (my ($pname, $pvers)) = each %{$pkgList} )
531
    {
558
    {
532
        #
559
        #
533
        #   Ignore excluded packages
560
        #   Ignore excluded packages
534
        #
561
        #
Line 552... Line 579...
552
        }
579
        }
553
 
580
 
554
        while ( (my ($pver, $pdata) ) = each %{$pvers} )
581
        while ( (my ($pver, $pdata) ) = each %{$pvers} )
555
        {
582
        {
556
            my $tmtime = $remotePkgList->{$pname}{$pver}{time} || 0;
583
            my $tmtime = $remotePkgList->{$pname}{$pver}{time} || 0;
-
 
584
            $packageVersionCount++;
557
 
585
 
558
            # Package is present in both list
586
            # Package is present in both list
559
            my ($mtime, $mode) = Utils::mtime( catfile( $conf->{'dpkg_archive'} , $pname, $pver, 'descpkg' ));
587
            my ($mtime, $mode) = Utils::mtime( catfile( $conf->{'dpkg_archive'} , $pname, $pver, 'descpkg' ));
560
            if ( $mtime == 0 )
588
            if ( $mtime == 0 )
561
            {
589
            {
Line 620... Line 648...
620
    #
648
    #
621
    #   Update stats
649
    #   Update stats
622
    #   At this point we are looking pretty good
650
    #   At this point we are looking pretty good
623
    #   
651
    #   
624
    $statistics{state} = 'OK';
652
    $statistics{state} = 'OK';
625
    $statistics{total} = scalar keys(%{$pkgList});
653
    $statistics{total} = $packageVersionCount;
626
    $statistics{remoteTotal} = scalar keys(%{$remotePkgList});
654
    $statistics{remoteTotal} = $remotePackageVersionCount;
627
    $statistics{transfer} = $needPkgListCount;
655
    $statistics{transfer} = $needPkgListCount;
628
    $statistics{delete} = $excessPkgListCount;
656
    $statistics{delete} = $excessPkgListCount;
629
    $statistics{filtered} = $filteredCount;
657
    $statistics{filtered} = $filteredCount;
630
    $statistics{missing} = $missingCount;
658
    $statistics{missing} = $missingCount;
631
    $statistics{writable} = $writableCount;
659
    $statistics{writable} = $writableCount;
Line 1356... Line 1384...
1356
    $hashp->{$pname}{$pver} = $rv;
1384
    $hashp->{$pname}{$pver} = $rv;
1357
    return $hashp;
1385
    return $hashp;
1358
}
1386
}
1359
 
1387
 
1360
#-------------------------------------------------------------------------------
1388
#-------------------------------------------------------------------------------
-
 
1389
# Function        : parsePkgMetaData
-
 
1390
#
-
 
1391
# Description     : Parse one line of meta data from a pkgList
-
 
1392
#                   Lines are multiple item="data" items
-
 
1393
#
-
 
1394
# Inputs          : $line                   - Line of data
-
 
1395
#                   $hashp                  - Ref to hash to populate
-
 
1396
#
-
 
1397
# Returns         : Nothing
-
 
1398
#
-
 
1399
sub parsePkgMetaData
-
 
1400
{
-
 
1401
    my ($line, $hashp) = @_;
-
 
1402
 
-
 
1403
    if ( $line =~ m~\s+(.+?)="(.+?)"~ )
-
 
1404
    {
-
 
1405
        $hashp->{$1} = $2;
-
 
1406
        $statistics{'Target.' . $1} = $2;
-
 
1407
        $line = $';
-
 
1408
 
-
 
1409
        $logger->verbose2("parsePkgMetaData: $1 = $2");
-
 
1410
    }
-
 
1411
}
-
 
1412
 
-
 
1413
 
-
 
1414
#-------------------------------------------------------------------------------
1361
# Function        : resetDailyStatistics 
1415
# Function        : resetDailyStatistics 
1362
#
1416
#
1363
# Description     : Called periodically to reset the daily statistics
1417
# Description     : Called periodically to reset the daily statistics
1364
#
1418
#
1365
# Inputs          : $time       - Current time
1419
# Inputs          : $time       - Current time
Line 1377... Line 1431...
1377
    if ($yday != $today)
1431
    if ($yday != $today)
1378
    {
1432
    {
1379
        $yday = $today;
1433
        $yday = $today;
1380
        $logger->logmsg('Resetting daily statistics' );
1434
        $logger->logmsg('Resetting daily statistics' );
1381
 
1435
 
-
 
1436
        # Note: Must match @recoverTags in readStatistics
1382
        $statistics{dayStart} = $time;
1437
        $statistics{dayStart} = $time;
1383
        $statistics{txCount} = 0;
1438
        $statistics{txCount} = 0;
1384
        $statistics{delCount} = 0;
1439
        $statistics{delCount} = 0;
1385
        $statistics{staleTags} = 0;
1440
        $statistics{staleTags} = 0;
1386
        $statistics{linkErrors} = 0;
1441
        $statistics{linkErrors} = 0;
1387
    }
1442
    }
1388
}
1443
}
1389
 
1444
 
1390
#-------------------------------------------------------------------------------
1445
#-------------------------------------------------------------------------------
-
 
1446
# Function        : readStatistics 
-
 
1447
#
-
 
1448
# Description     : Read in the last set of stats
-
 
1449
#                   Used after a restart to recover daily statistics
-
 
1450
#
-
 
1451
# Inputs          : 
-
 
1452
#
-
 
1453
# Returns         : 
-
 
1454
#
-
 
1455
sub readStatistics
-
 
1456
{
-
 
1457
    my @recoverTags = qw(dayStart txCount delCount staleTags linkErrors);
-
 
1458
 
-
 
1459
    if ($conf->{'statsfile'} and -f $conf->{'statsfile'})
-
 
1460
    {
-
 
1461
        if (open my $fh, $conf->{'statsfile'})
-
 
1462
        {
-
 
1463
            while (<$fh>)
-
 
1464
            {
-
 
1465
                m~(.*):(.*)~;
-
 
1466
                if ( grep( /^$1$/, @recoverTags ) ) 
-
 
1467
                {
-
 
1468
                    $statistics{$1} = $2;
-
 
1469
                    $logger->verbose("readStatistics $1, $2\n");
-
 
1470
                }
-
 
1471
            }
-
 
1472
            close $fh;
-
 
1473
            $yday = (localtime($statistics{dayStart}))[7];
-
 
1474
        }
-
 
1475
    }
-
 
1476
}
-
 
1477
 
-
 
1478
 
-
 
1479
#-------------------------------------------------------------------------------
1391
# Function        : periodicStatistics 
1480
# Function        : periodicStatistics 
1392
#
1481
#
1393
# Description     : Called on a regular basis to write out statistics
1482
# Description     : Called on a regular basis to write out statistics
1394
#                   Used to feed information into Nagios
1483
#                   Used to feed information into Nagios
1395
#                   
1484
#                   
Line 1426... Line 1515...
1426
            $fh = undef;
1515
            $fh = undef;
1427
            $logger->warn("Cannot create temp stats file: $!");
1516
            $logger->warn("Cannot create temp stats file: $!");
1428
        }
1517
        }
1429
        else
1518
        else
1430
        {
1519
        {
1431
            foreach my $key ( keys %statistics)
1520
            foreach my $key ( sort { lc($a) cmp lc($b) } keys %statistics)
1432
            {
1521
            {
1433
                print $fh $key . ':' . $statistics{$key} . "\n";
1522
                print $fh $key . ':' . $statistics{$key} . "\n";
1434
                $logger->verbose2('Statistics:'. $key . ':' . $statistics{$key});
1523
                $logger->verbose2('Statistics:'. $key . ':' . $statistics{$key});
1435
            }
1524
            }
1436
            close $fh;
1525
            close $fh;
Line 1457... Line 1546...
1457
 
1546
 
1458
    $SIG{TERM} = sub {
1547
    $SIG{TERM} = sub {
1459
        # On shutdown
1548
        # On shutdown
1460
        $logger->logmsg('Received SIGTERM. Shutting down....' );
1549
        $logger->logmsg('Received SIGTERM. Shutting down....' );
1461
        unlink $conf->{'pidfile'} if (-f $conf->{'pidfile'});
1550
        unlink $conf->{'pidfile'} if (-f $conf->{'pidfile'});
1462
        unlink $conf->{'statsfile'} if (-f $conf->{'statsfile'});
-
 
1463
        unlink $conf->{'statsfiletmp'} if (-f $conf->{'statsfiletmp'});
-
 
1464
        exit 0;
1551
        exit 0;
1465
    };
1552
    };
1466
 
1553
 
1467
    $SIG{HUP} = sub {
1554
    $SIG{HUP} = sub {
1468
        # On logrotate
1555
        # On logrotate