#!/usr/bin/perl

use Sys::Hostname;
$host = hostname;


#Lizenz pruefen
system ("/opt/kav/bin/licenseviewer -s > /var/log/kav/expire.log");

#Logfile ueberpruefen
$datfile="/var/log/kav/expire.log";
open(INDEX,"$datfile") or die "Konnte datei nicht öffenen";
@index = <INDEX>;
close(INDEX);
foreach (@index){
	$zeile =$_;
	#chomp($zeile); 
	if ( $zeile =~ m/Expiration date:/o ) { 
	
	($info1, $info2, $expire_date, $expire, $in, $expire_days, $days) = split(/ /, $zeile);
			
			
			if (($expire_days <= 31) && ($expire_days > 7)) {
				print "WARNING: Expire in $expire_days days";
			}
			elsif (($expire_days <= 7) && ($expire_days > 1)) {
				print "WARNING: Expire in $expire_days days";
                                
                        }
			elsif ($expire_days == 1) {
				print "WARNING: Expire in $expire_days days";
                        }                                                                	
			else {
				print "OK: License is valid for $expire_days days";
			}
	}
	if ( $zeile =~ m/No license keys found/o ) {
		print "CRITICAL: No License !!\n";
	}
	
	if ( $zeile =~ m/key was expired/o ) {
                print "CRITICAL: Key has expired !!\n";
	}

}
