#!/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-secure with the # current date. # # In order to use this script, you might need to make the following # adjustments: # - Set the path to your fsav binary in $fsav. # - set the string to search for to get the Database version (it should be # correct for the German version, but maybe F-Secure will change this in future # version, so just run "fsav --version" from commandline to find out what # is the appropraite value for your F-Secure fsav # # This scripts needs the following perl modules (available via CPAN) # - Date::Calc # - Getopt::Long # - POSIX # ################################################################################ # # Changes: # # V 1.0.0 (12.06.2012) # - initial version # # V 1.0.1 (05.09.2012) # - fixed some typos in comments # - Database version is printed in status # ################################################################################ use strict; use Date::Calc qw(Delta_Days); use Getopt::Long; use vars qw ($opt_h $opt_w $opt_c); use POSIX; # Path to fsav binary. my $fsav = "/usr/bin/fsav"; # String to search for in output of "fsav --version" to get the Database date my $search_string = 'Database version: '; # 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_fsecure"; my $script_version = "1.0.1"; # Check fsav exists and is executable for us if (!-x $fsav) { die("ERROR: Unable to execute $fsav"); } # 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 fsav 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 $fsav_version = `$fsav --version`); my $fsav_virdef = substr($fsav_version,index($fsav_version,$search_string)+length($search_string), 13); my @fsav_dbdate = split('-',substr($fsav_version,index($fsav_version,$search_string)+length($search_string), 10)); my $fsav_dbyear = $fsav_dbdate[0]; my $fsav_dbmonth = $fsav_dbdate[1]; my $fsav_dbdays = $fsav_dbdate[2]; # Compare the dates and set exit code for Nagios my $difference_days = Delta_Days ($fsav_dbyear, $fsav_dbmonth, $fsav_dbdays, $current_year, $current_month, $current_days); my $fsecure_status = "F-Secure OK - virus database is $difference_days days old (version: $fsav_virdef)\n"; my $plugin_status = 0; if ($difference_days >= $crit_level) { $plugin_status = 2; $fsecure_status = "F-Secure critical - virus database is $difference_days days old (version: $fsav_virdef)\n"; } elsif ($difference_days >= $warn_level) { $plugin_status = 1; $fsecure_status = "F-Secure warning - virus database is $difference_days days old (version: $fsav_virdef)\n"; } print $fsecure_status; exit $plugin_status; ################################################################################ # help and usage information # ################################################################################ sub usage { print << "USAGE"; ----------------------------------------------------------------- $script v$script_version Nagios plugin to check if F-Secure database is up-to-date Usage: $script -w -c Options: -h show this help -w generate a warning state if F-Secure database is older than days (default is 1) -c generate a critical state if F-Secure 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; }