#!/usr/bin/perl -w # # Copyright (c) 2012 Ralf Schiffers # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # ################################################################################ # This script is used to compare the database version of F-Prot command-line- # scanner fpscan with the current date. # # In order to use this script, you might need to make the following # adjustments: # - Set the path to your fpscan binary in $fpscan. # - set the string to search for to get the Database version (it should be # correct for the current version, but maybe F-Prot will change this in future # version, so just run "fpscan --version" from commandline to find out what # is the appropriate value for your F-Prot fpscan. # # This scripts needs the following perl modules (available via CPAN) # - Date::Calc # - Getopt::Long # ################################################################################ use strict; use Date::Calc qw(Delta_Days); use Getopt::Long; use vars qw ($opt_h $opt_w $opt_c); # Path to fsav binary. my $fpscan = "/opt/f-prot/fpscan"; # String to search for in output of "fpscan --version" to get the Database date my $search_string = 'Virus signatures: '; # Default warning and critical age of virus-database in days my $warn_level = 1; my $crit_level = 2; ######################## Nothing to change below this ########################## my $script = "check_fprot"; my $script_version = "1.0.0"; # Check fsav exists and is executable for us if (!-x $fpscan) { die("ERROR: Unable to execute $fpscan"); } # Get the Options Getopt::Long::Configure('bundling'); GetOptions ("h" => \$opt_h, "help" => \$opt_h, "w=i" => \$opt_w, "warning=i" => \$opt_w, "c=i" => \$opt_c, "critical=i" => \$opt_c, ); if ($opt_h) { usage(); } $warn_level = $opt_w if defined $opt_w; $crit_level = $opt_c if defined $opt_c; if ($warn_level >= $crit_level) { die ("ERROR: Warning must not be greater or equal than Critical"); } # Get the current date to compare it with fpscan Database version my $current_year = (localtime)[5] + 1900; my $current_month = (localtime)[4] + 1; my $current_days = (localtime)[3]; # Get the date of current database chomp(my $fpscan_version = `$fpscan --version 2>/dev/null`); my $fpscan_dbdate = substr($fpscan_version,index($fpscan_version,$search_string)+length($search_string), 12); my $fpscan_dbyear = substr($fpscan_dbdate,0,4); my $fpscan_dbmonth = substr($fpscan_dbdate,4,2); my $fpscan_dbdays = substr($fpscan_dbdate,6,2); my $fpscan_dbhours = substr($fpscan_dbdate,8,2); my $fpscan_dbminutes = substr($fpscan_dbdate,10,2); # Compare the dates and set exit code for Nagios my $difference_days = Delta_Days ($fpscan_dbyear, $fpscan_dbmonth, $fpscan_dbdays, $current_year, $current_month, $current_days); my $fpscan_status = "F-Prot OK - virus database is $difference_days days old (from $fpscan_dbdays.$fpscan_dbmonth.$fpscan_dbyear $fpscan_dbhours:$fpscan_dbminutes)\n"; my $plugin_status = 0; if ($difference_days >= $crit_level) { $plugin_status = 2; $fpscan_status = "F-Prot critical - virus database is $difference_days days old (from $fpscan_dbdays.$fpscan_dbmonth.$fpscan_dbyear $fpscan_dbhours:$fpscan_dbminutes)\n"; } elsif ($difference_days >= $warn_level) { $plugin_status = 1; $fpscan_status = "F-Prot warning - virus database is $difference_days days old (from $fpscan_dbdays.$fpscan_dbmonth.$fpscan_dbyear $fpscan_dbhours:$fpscan_dbminutes)\n"; } print $fpscan_status; exit $plugin_status; ################################################################################ # help and usage information # ################################################################################ sub usage { print << "USAGE"; ----------------------------------------------------------------- $script v$script_version Nagios plugin to check if F-Prot fpscan database is up-to-date Usage: $script -w -c Options: -h show this help -w generate a warning state if F-Prot database is older than days (default is 1) -c generate a critical state if F-Prot database is older than days (default is 2) ----------------------------------------------------------------- Copyright (C) 2012 Ralf Schiffers. All rights reserved This program is free software; you can redistribute it or modify it under the terms of the GNU General Public License ----------------------------------------------------------------- USAGE exit 0; }