3
# Copyright (c) 2005-2008 Darren Spruell <phatbuckett@gmail.com>
5
# Permission to use, copy, modify, and distribute this software for any
6
# purpose with or without fee is hereby granted, provided that the above
7
# copyright notice and this permission notice appear in all copies.
9
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
################################################################################
18
# This script is used to compare the version and signature level of the
19
# currently running clamd daemon with the latest available versions listed in
20
# the TXT record for current.cvd.clamav.net.
22
# In order to use this script, you might need to make the following adjustments:
23
# - Set the "use lib" path correctly (where utils.pm is located.)
24
# - Set the path to your clamd binary in $clamd_cmd.
26
# This plugin requires the Net::DNS Perl module.
27
################################################################################
29
# Plugin directory / home of utils.pm.
30
use lib "/usr/local/libexec/nagios";
31
use utils qw(%ERRORS &print_revision &support &usage);
32
use Getopt::Long qw(:config no_ignore_case bundling);
38
# Path to installed clamd binary.
39
my $clamd_cmd = "/usr/local/sbin/clamd";
41
# Leave the rest of this alone:
42
my $prog_name = basename $0;
45
my $warn_val = 1; # Default - override with -w arg
46
my $crit_val = 2; # Default - override with -c arg
47
my $help_val = 0; # Off unless -h arg
48
my $verb_val = 0; # Off unless -v arg
49
my $vers_val = 0; # Off unless -V arg
51
my ($msg, $rev_word, $rr, $status, $status_print);
53
# Gives us a way to print out verbose debug information to the screen when user
54
# passes in a -v argument.
55
# print_debug() should receive one parameter: a text string to print out.
59
print "DEBUG: " . $message . "\n";
63
# Looks up and returns the current CVD version information from
65
sub lookup_current() {
66
my $res = Net::DNS::Resolver->new;
67
my $query = $res->search("current.cvd.clamav.net", "TXT");
69
foreach $rr (grep { $_->type eq 'TXT' } $query->answer) {
70
&print_debug("Net::DNS found result: (TXT) " . $rr->txtdata);
74
warn "query failed: ", $res->errorstring, "\n";
78
# comp_sig_ver() should receive three parameters: remote signature database
79
# version, local signature database version, and build date of local
80
# signatures database.
83
my $sig_local = shift;
88
if ($sig_local != $sig_rem) {
89
$diff = $sig_rem - $sig_local;
90
$rev_word = ($diff == 1) ? "revision" : "revisions";
91
if ($diff >= $crit_val) {
92
&print_debug("Installed daily.cvd is behind clamav.net");
93
$status = $ERRORS{'CRITICAL'}; # Will exit with CRITICAL status
94
$status_print = "CRITICAL";
95
} elsif ($diff >= $warn_val) {
96
&print_debug("Installed daily.cvd is behind clamav.net");
97
$status = $ERRORS{'WARNING'}; # Will exit with WARNING status
98
$status_print = "WARNING";
100
&print_debug("Installed daily.cvd is behind clamav.net");
101
$status = $ERRORS{'OK'}; # Will exit with OK status
102
$status_print = "OK";
104
$msg = "ClamAV " . $status_print . ": daily.cvd " . $sig_local .
105
" out of date by " . $diff . " " . $rev_word;
107
&print_debug("Installed daily.cvd matches latest from clamav.net");
108
$status = $ERRORS{'OK'}; # Will exit with OK status
109
$msg = "ClamAV OK: daily.cvd " . $sig_local . " (" . $sig_date .
112
return $msg, $status;
115
# Show usage information
118
$prog_name Nagios plugin $prog_ver (c) 2005-2008 Darren Spruell <phatbuckett\@gmail.com>
120
Perl Check ClamAV daily.cvd plugin for Nagios
122
Usage: $prog_name [-w <warn>] [-c <crit>] [-V] [-v] [-h]
124
-w, --warning=INTEGER
125
Number of revisions behind current daily.cvd to generate a warning state (Default: 1)
126
-c, --critical=INTEGER
127
Number of revisions behind current daily.cvd to generate a critical state (Default: 2)
129
Output version information for the plugin
131
Enable verbose output
138
"w=i" => \$warn_val, "warning=i" => \$warn_val,
139
"c=i" => \$crit_val, "critical=i" => \$crit_val,
140
"h" => \$help_val, "help" => \$help_val,
141
"V" => \$vers_val, "version" => \$vers_val,
142
"v" => \$verb_val, "verbose" => \$verb_val,
145
if ($help_val != 0) {
150
if ($vers_val != 0) {
151
&print_revision($prog_name,$prog_ver);
155
# Make sure the binary exists.
157
&print_debug("Found clamd at $clamd_cmd");
159
&print_debug("Can't execute clamd at $clamd_cmd");
160
die("FATAL: Unable to execute $clamd_cmd");
163
&print_debug("Threshhold values: warning=$warn_val, critical=$crit_val");
165
# Should return something like: ClamAV 0.87.1/1205/Wed Dec 7 07:00:48 2005
166
chomp(my $clamd_ver = `$clamd_cmd -V`);
168
# Should return something like: 0.87.1:34:1206:1134072033:1
169
chomp(my $dnstxt_ver = &lookup_current());
171
# Parse what we get from clamd -V and our DNS query
172
my @clamdresults = split(/\//,$clamd_ver);
173
my @txtresults = split(/:/,$dnstxt_ver);
175
# Get the currently running ClamAV sig level and cvd date out of this
176
my $local_latest_daily = $clamdresults[1];
177
my $local_latest_date = $clamdresults[2];
179
&print_debug("Local daily.cvd dated $local_latest_date");
180
&print_debug("Local daily.cvd version = $local_latest_daily");
182
# Get the latest ClamAV daily signatures version out of this
183
my $clamav_latest_daily = $txtresults[2];
184
&print_debug("Latest daily.cvd version = $clamav_latest_daily");
186
my @prog_sig_res = &comp_sig_ver($clamav_latest_daily, $local_latest_daily,
189
print $prog_sig_res[0] . "\n";
190
exit $prog_sig_res[1];