I do not know where it comes from. The script is a nagios check to monitor the updates.spamassassin.org channel:
#!/usr/bin/perl
use warnings;
use strict;
use Mail::SpamAssassin;
use Net::DNS;
# variables
my ( $sa_version, $rev_sa_version, $SA, $update_dir, $version_on_disk,
$LOCAL_STATE_DIR, $resolver, $query, $version_dns, $sa_channel );
# get the SpamAssassin version from the Perl module
$sa_version = Mail::SpamAssassin::Version();
# reverse this number. We will need it for a txt forware query later
$rev_sa_version = join(".", reverse split(/\./, $sa_version) ) ;
# sa channel we want to monitor
$sa_channel = "updates.spamassassin.org";
# get the local state dir update path
$LOCAL_STATE_DIR = '/var/lib/spamassassin';
$SA = Mail::SpamAssassin->new( {
LOCAL_STATE_DIR => $LOCAL_STATE_DIR,
}
);
$update_dir = $SA->sed_path('__local_state_dir__/__version__');
# inside $update_dir, get the line starting with "# UPDATE "
# save the version in $version_on_disk
if ( -e "$update_dir/updates_spamassassin_org.cf" ) {
open (CF, "$update_dir/updates_spamassassin_org.cf" ) or die "$!\n
+";
while (<CF> ) {
last unless /^# UPDATE\s+[A-Za-z]+\s+(\S+)/;
$version_on_disk = $1;
}
}
print "$sa_channel channel version on disk is: $version_on_disk\n";
$resolver = Net::DNS::Resolver->new;
$query = $resolver->query("$rev_sa_version.$sa_channel", 'txt');
if ( $query ) {
for my $rr ( $query->answer ) {
$version_dns = $rr->rdata;
}
}
print "$sa_channel channel dns txt query version is $version_dns\n";
print "[$version_on_disk]\t version on disk\n";
print "[$version_dns]\t version dns\n";
if ( "$version_on_disk" >= "$version_dns" ) {
print "OK: the $sa_channel version on disk is up to date: $version
+_on_disk\n";
exit 0;
}
else {
print "WARNING: there is a newer version available for SpamAssassi
+n $sa_channel rules (on disk version is $version_on_disk, new version
+ is $version_dns. Run sa-update -D as root to upgrade your SpamAssass
+in channel version.\n";
exit 1;
}
I added the [] chars around $version_on_disk and $version_dns to make sure no strange characters were coming on the variables. They print correctly on the terminal. |