#!/usr/bin/perl
use strict;
use POSIX;
#use lib "/usr/local/nagios/libexec/";
use Newtestlib;



                 #########################################################################################
       		 #                                                                                       #
       		 #                               Plugin Scenario Version 1                               #
       		 #                                                                                       #
        	 #########################################################################################


##########################################################################################################
our %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
my $i=0;
my $cpt;#$c;
my @recup_word;#@b;
my $bool1=0;
my $cpt1;#$x=0;#-1
my @tab_split_separator;#@p;
my $j=0;
my $now;
my @tab_recup_sce;#@v;
my $config_file;
my $case;#$cas;
my $rbt;#$z;
my $sce_or_host;
my @param;
my $nmc;   #@nmc
my $log;
my $file_pooler;#$file_r;####le chemin du fichier file_rbt_sce
my $file_command_nagios;#$file_e;#ex:/usr/local/nagios/var/rw/nagios.cmd"
my $t;#for the timestamp(time)
my $sec;
my $min;
my $hour;
my $day;
my $month;
my $year;
my @Month_name;
my $s;#for the timestamp(second)
my $m;#for the timestamp(minute)
my $h;#for the timestamp(our)
my $mday;#for the timestamp(day)
my $mon;# @Month_name->[$month];  #for the timestamp(month)
my $y;
my $wday;#for the timestamp
my $timestamp;
my($line,@words,$word,%total);
my $cpt2=1;#$n=1;
my $perfdata;
my @tab_split_id_name;#recuperer le champ nom scenario qui est de la forme nom_sce=id
my @name_sce;#recuperer uniquement le nom_sce
my @state;#the nagios state of the scenario
my $param_ok;
my $passif_arg;
my $word_for_sce;
my @suffix_preffix_file_pooler;
my @trace_log;
my $size_file_pooler;
my $split_perf;#used only in the actif case
#######################################################################################################################################
#print("sdfsdfq ok");
if (@ARGV != 5)
	{
        print "missing argument\n";
	print "usage : program config_file_path pooling_mode( p or a) nmc_addr probe_name scenario_name \n";
	$param_ok=Newtestlib::more_param_sce($ARGV[0],$ARGV[1],$ARGV[2],$ARGV[3],$ARGV[4]);
        }
$param_ok=Newtestlib::more_param_sce($ARGV[0],$ARGV[1],$ARGV[2],$ARGV[3],$ARGV[4]);
if(!($param_ok eq "")){ exit;}

else{
$config_file=$ARGV[0];  #chemin du ficheir newtest_config
$case=$ARGV[1];#si =p =>passif   sinon actif
$nmc=$ARGV[2];   #@nmc
$rbt=$ARGV[3];# "berlin";le nom du robot
if ( not -e ($config_file) )
	{
        print " config file  needed ".$config_file." doesn t exist \n";
        exit;
        }

#$aze n'a pas a exister####################"$aze=$ARGV[3];# scenario ou hostla valeur du booleen
$sce_or_host=$ARGV[4];#  scenarion(actif case) or hostname(passif case)
Newtestlib::get_config_file($ARGV[0]);
@param=Newtestlib::get_param();
@trace_log=Newtestlib::get_suffix_preffix_trace_plug_sce();
$log=$param[2].$trace_log[0].$nmc.$trace_log[1];
open(LOG,">>$log") || print " error when opening the file $log\n";
print LOG "		*****$ARGV[3]:plugin_rbt_sce.cgi*****\n";
$rbt= uc($rbt);
$nmc=~ s/\./_/g;
@suffix_preffix_file_pooler=Newtestlib::get_suffix_preffix_file_pooler();
$file_pooler=$param[2].$suffix_preffix_file_pooler[0].$nmc.$suffix_preffix_file_pooler[1];####le chemin du fichier file_rbt_sce
$file_command_nagios="$param[3]";#ex:/usr/local/nagios/var/rw/nagios.cmd"
START:open(FILE,"$file_pooler") || print " error when opening the file $file_pooler\n";
$size_file_pooler= -s $file_pooler;
if($size_file_pooler == 0 || !(-e $file_pooler)){
                             $now = localtime;
                             print LOG "now:$ARGV[3]:UNKNOWN:file is empty please wait";
                             close(FILE);
                             goto START;
                           }
else{

###########recruperation du timestamp###########

@Month_name = ( "January", "February", "March", "April", "May", "June",  "July", "August", "September", "October", "November", "December" );
( $sec, $min, $hour, $day, $month, $year ) = ( localtime ) [ 0, 1, 2, 3, 4, 5 ];
$t= "%02d:%02d:%02d %02d %s %04d";
$s = $sec;
$m = $min;
$h = $hour;
$mday = $day;
$mon =$month;# @Month_name->[$month];
$y = $year+1900;
$wday = 3;
$timestamp = mktime($sec,$min,$hour,$mday,$mon,$year,$wday,0,-1);
$t=time();
###########fin de recruperation du timestamp###########

############################################################################################################
$passif_arg=Newtestlib::get_passif_arg();
$word_for_sce=Newtestlib::get_word_for_scenario();
if( $ARGV[1] eq "$passif_arg" ){#######"#CAS PASSIF

	###################################### 		CAS PASSIF  (PASSIF CASE)	##################################################

$now = localtime;
print LOG ("$now:$ARGV[3]:passif case\n");
while( defined( $line = <FILE> ) )
{
   @words = split( /\|\|+/, $line );  #recuperer une ligne
        foreach $word (@words)
                         {
      	                 $recup_word[$i]=$word;
	                 if($bool1 == 1){
	                 $tab_recup_sce[$cpt1][$j]=$word;
	                 $j++;
                         }
   if($recup_word[$i-1] eq "$word_for_sce" && $word eq "$rbt"){
	                                  $bool1=1;
                                          $j=0;
	                                  $cpt1++;
	                                  $tab_recup_sce[$cpt1][$j]=$word;
	                                  $j++;
	                                  }
                          $i++;
     }
 }

if ($bool1==0){print("no scenario for the robot $rbt\n");
$now = localtime;
print LOG ("$now:$ARGV[3]:no scenario for the robot $rbt \n");}
open(RECUP,"+>$file_command_nagios") || print LOG " error when opening the file $file_command_nagios\n";
for($cpt=0;$cpt<=$cpt1;$cpt++)
{###format des perf(il doit y avoir 4 ";"
   	@tab_split_id_name = split( /\=+/, $tab_recup_sce[$cpt][1]);
	$name_sce[$cpt][0]=$tab_split_id_name[0];
	$name_sce[$cpt][0]=~ s/\n+//;
	if(defined($tab_recup_sce[$cpt][4]))
        		{$j=0;
                       	 @words = split( /\!\!+/, $tab_recup_sce[$cpt][4]);
                         foreach $word (@words)
                                               { $tab_split_separator[$cpt][$j]=$word;
                                                 $tab_split_separator[$cpt][$j]=~ s/\n+/ /;
                                                 $tab_split_separator[$cpt][$j]=$tab_split_separator[$cpt][$j].";;;";
                                                 $j++;
                                               }
                       }
}
for($cpt=1;$cpt<=$cpt1;$cpt++)
                    {
	             @state= Newtestlib::get_nagios_sce_state($tab_recup_sce[$cpt][2]);
                    passif();
                     }
}


             ###############################  FIN CAS PASSIF (END OF ACTIF CASE) ###########################################

#####################################################################################################################################################


             ###############################   CAS ACTIF  ###########################################

else {#### CAS ACTIF
$sce_or_host=uc($sce_or_host);
if(defined($ARGV[0]) && defined($ARGV[1]) && defined($ARGV[2]) && defined($ARGV[3]))
 {
	$now = localtime;
	print LOG ("$now:actif case\n");
	open(FILE,"<$file_pooler") or die"open: $!";
       	while( defined( $line = <FILE> ) )
                                          {
  	                                     @words = split( /\|\|+/, $line );  #recuperer une ligne
	                                     $bool1=0;
                                             $j=0;
	                                     foreach $word (@words)
	                                                  {
	                                                   $recup_word[$i]=$word;
	                                                   if($bool1 == 1){
	                                                   $tab_recup_sce[$j]=$word;
	                                                   $j++;
                                                           }
                                             if($recup_word[$i-2] eq "$word_for_sce" &&  $recup_word[$i-1] eq "$rbt" && substr($recup_word[$i],0,length($sce_or_host)) eq "$sce_or_host")
                                                     {$bool1=1;
                                                      $tab_recup_sce[$j]=$word;
                                                      $j++;
	                                              }
                                             $i++;
	                                  }
  }

if($tab_recup_sce[0] eq ""){print("the couple robot:$rbt scenario:$sce_or_host does not exist\n");
                $now = localtime;
                print LOG ("$now:$ARGV[3]:the couple robot:$rbt scenario:$sce_or_host does not exist\n");
                }

if(defined($tab_recup_sce[3])){$j=0;
                   @words = split( /\!\!+/, $tab_recup_sce[3]);
                   foreach $word (@words)
                                         { $tab_split_separator[$j]=$word;
                                           $tab_split_separator[$j]=~ s/\n+/ /;
  		       		           $perfdata=$perfdata.$tab_split_separator[$j].";;; ";
                                         }
                       }

#decoupage selon "!!"
if(defined($tab_recup_sce[3])){
                   @words = split( /\!\!+/, $tab_recup_sce[3]);
                   $split_perf=@words;
                   $split_perf=~ s/\n+/ /;
                  }
$cpt2=1;
actif(); #
  }
 }
}
close(FILE);
close(RECUP);
close(LOG);
}

####################################################################################################################################################


sub passif{
if(!defined($tab_recup_sce[$cpt][4]) || $tab_recup_sce[$cpt][4] eq "" || $tab_recup_sce[$cpt][4] eq " "){
	             print RECUP "[$t] PROCESS_SERVICE_CHECK_RESULT;$sce_or_host;$rbt\_$name_sce[$cpt][0];3;no information for the couple ($rbt,$name_sce[$cpt][0])\n";
	             $now = localtime;
	             print  LOG "$now:$ARGV[3]:[$t] PROCESS_SERVICE_CHECK_RESULT;$sce_or_host;$rbt\_$name_sce[$cpt][0];3;no information for the couple ($rbt,$name_sce[$cpt][0])\n";
	            }
if(defined($tab_recup_sce[$cpt][3]) && defined($tab_recup_sce[$cpt][4]))
{ $cpt2=1;
$perfdata="";
while(defined($tab_split_separator[$cpt][$cpt2])){ $perfdata=$perfdata." ".$tab_split_separator[$cpt][$cpt2];
                            $cpt2++;
                           }
if (length($perfdata)>2){ #il existe des perf
                         if($tab_recup_sce[$cpt][2] eq "Available"){
                         print RECUP "[$t] PROCESS_SERVICE_CHECK_RESULT;$sce_or_host;$rbt\_$name_sce[$cpt][0];$state[1];newtest state is $tab_recup_sce[$cpt][2] for the couple ($rbt ,$name_sce[$cpt][0]) which send last message at $tab_recup_sce[$cpt][3] | $perfdata\n";
	                 $now = localtime;
	                  print LOG "$now:$ARGV[3]:[$t] PROCESS_SERVICE_CHECK_RESULT;$sce_or_host;$rbt\_$name_sce[$cpt][0];$state[1];newtest state is $tab_recup_sce[$cpt][2] for the couple ($rbt ,$name_sce[$cpt][0]) which send last message at $tab_recup_sce[$cpt][3] | $perfdata\n";
	                                              }

                          elsif($tab_recup_sce[$cpt][2] eq "Warning"){
                          print RECUP "[$t] PROCESS_SERVICE_CHECK_RESULT;$sce_or_host;$rbt\_$name_sce[$cpt][0];$state[1];newtest state is $tab_recup_sce[$cpt][2] for the couple ($rbt ,$name_sce[$cpt][0]) which send last message at $tab_recup_sce[$cpt][3] | $perfdata\n";
                          $now = localtime;
                          print LOG "$now:$ARGV[3]:[$t] PROCESS_SERVICE_CHECK_RESULT;$sce_or_host;$rbt\_$name_sce[$cpt][0];$state[1];newtest state is $tab_recup_sce[$cpt][2] for the couple ($rbt ,$name_sce[$cpt][0]) which send last message at $tab_recup_sce[$cpt][3] | $perfdata\n";
                                                        }

                         elsif($tab_recup_sce[$cpt][2] eq "Failed"){#$stat="OK";
                         print RECUP "[$t] PROCESS_SERVICE_CHECK_RESULT;$sce_or_host;$rbt\_$name_sce[$cpt][0];$state[1];newtest state is $tab_recup_sce[$cpt][2] for the couple ($rbt ,$name_sce[$cpt][0]) which send last message at $tab_recup_sce[$cpt][3] | $perfdata\n";
                         $now = localtime;
                         print  LOG "$now:$ARGV[3]:[$t] PROCESS_SERVICE_CHECK_RESULT;$sce_or_host;$rbt\_$name_sce[$cpt][0];$state[1];newtest state is $tab_recup_sce[$cpt][2] for the couple ($rbt ,$name_sce[$cpt][0]) which send last message at $tab_recup_sce[$cpt][3] | $perfdata\n";
                                                         }

                         elsif($tab_recup_sce[$cpt][2] eq "Canceled"){
                         print RECUP "[$t] PROCESS_SERVICE_CHECK_RESULT;$sce_or_host;$rbt\_$name_sce[$cpt][0];$state[1];newtest state is $tab_recup_sce[$cpt][2] for the couple ($rbt ,$name_sce[$cpt][0]) which send last message at $tab_recup_sce[$cpt][3] | $perfdata\n";
                         $now = localtime;
                         print LOG "$now:$ARGV[3]:[$t] PROCESS_SERVICE_CHECK_RESULT;$sce_or_host;$rbt\_$name_sce[$cpt][0];$state[1];newtest state is $tab_recup_sce[$cpt][2] for the couple ($rbt ,$name_sce[$cpt][0]) which send last message at $tab_recup_sce[$cpt][3] | $perfdata\n";
                                                        }

                         elsif($tab_recup_sce[$cpt][2] eq "OutOfRange"){ }

                         elsif($tab_recup_sce[$cpt][2] eq "Unknown"){
                         print RECUP "[$t] PROCESS_SERVICE_CHECK_RESULT;$sce_or_host;$rbt\_$name_sce[$cpt][0];$state[1];newtest state is $tab_recup_sce[$cpt][2] for the couple ($rbt ,$name_sce[$cpt][0]) which send last message at $tab_recup_sce[$cpt][3] | $perfdata\n";
                         $now = localtime;
                         print LOG "$now:$ARGV[3]:[$t] PROCESS_SERVICE_CHECK_RESULT;$sce_or_host;$rbt\_$name_sce[$cpt][0];$state[1];newtest state is $tab_recup_sce[$cpt][2] for the couple ($rbt ,$name_sce[$cpt][0]) which send last message at $tab_recup_sce[$cpt][3] | $perfdata\n";
                                                       }

                         else{print RECUP "[$t] PROCESS_SERVICE_CHECK_RESULT;$sce_or_host;$rbt\_$name_sce[$cpt][0];3;sdgsdno information for the couple ($rbt,$name_sce[$cpt][0])\n";
	             $now = localtime;
	             print  LOG "$now:$ARGV[3]:[$t] PROCESS_SERVICE_CHECK_RESULT;$sce_or_host;$rbt\_$name_sce[$cpt][0];3;qsfqno information for the couple ($rbt,$name_sce[$cpt][0])\n";


}
}
#!define($perfdate)
else{#pas de perf

     if($tab_recup_sce[$cpt][2] eq "Available"){#il n'existe pas de perf
                                  print RECUP "[$t] PROCESS_SERVICE_CHECK_RESULT;$sce_or_host;$rbt\_$name_sce[$cpt][0];$state[1];newtest state is $tab_recup_sce[$cpt][2] for the couple ($rbt ,$name_sce[$cpt][0]) which send last message at $tab_recup_sce[$cpt][3] \n";
                                  $now = localtime;
                                  print LOG "$now:$ARGV[3]:[$t] PROCESS_SERVICE_CHECK_RESULT;$sce_or_host;$rbt\_$name_sce[$cpt][0];$state[1];newtest state is $tab_recup_sce[$cpt][2] for the couple ($rbt ,$name_sce[$cpt][0]) which send last message at $tab_recup_sce[$cpt][3] \n";
                                  }

      elsif($tab_recup_sce[$cpt][2] eq "Warning"){
                                    print RECUP "[$t] PROCESS_SERVICE_CHECK_RESULT;$sce_or_host;$rbt\_$name_sce[$cpt][0];$state[1];newtest state is $tab_recup_sce[$cpt][2] for the couple ($rbt ,$name_sce[$cpt][0]) which send last message at $tab_recup_sce[$cpt][3]\n";
                                    $now = localtime;
                                    print LOG "$now:$ARGV[3]:[$t] PROCESS_SERVICE_CHECK_RESULT;$sce_or_host;$rbt\_$name_sce[$cpt][0];$state[1];newtest state is $tab_recup_sce[$cpt][2] for the couple ($rbt ,$name_sce[$cpt][0]) which send last message at $tab_recup_sce[$cpt][3]\n";
                                    }

      elsif($tab_recup_sce[$cpt][2] eq "Failed"){#$stat="OK";
                                   print RECUP "[$t] PROCESS_SERVICE_CHECK_RESULT;$sce_or_host;$rbt\_$name_sce[$cpt][0];$state[1];anewtest state is $tab_recup_sce[$cpt][2] for the couple ($rbt ,$name_sce[$cpt][0]) which send last message at $tab_recup_sce[$cpt][3]\n";
                                   $now = localtime;
                                   print LOG "$now:$ARGV[3]:[$t] PROCESS_SERVICE_CHECK_RESULT;$sce_or_host;$rbt\_$name_sce[$cpt][0];$state[1];newtest state is $tab_recup_sce[$cpt][2] for the couple ($rbt ,$name_sce[$cpt][0]) which send last message at $tab_recup_sce[$cpt][3]\n";
                                   }

      elsif($tab_recup_sce[$cpt][2] eq "Canceled"){
                                     print RECUP "[$t] PROCESS_SERVICE_CHECK_RESULT;$sce_or_host;$rbt\_$name_sce[$cpt][0];$state[1];anewtest state is $tab_recup_sce[$cpt][2] for the couple ($rbt ,$name_sce[$cpt][0]) which send last message at $tab_recup_sce[$cpt][3]\n";
                                     $now = localtime;
                                     print LOG "$now:$ARGV[3]:[$t] PROCESS_SERVICE_CHECK_RESULT;$sce_or_host;$rbt\_$name_sce[$cpt][0];$state[1];newtest state is $tab_recup_sce[$cpt][2] for the couple ($rbt ,$name_sce[$cpt][0]) which send last message at $tab_recup_sce[$cpt][3]\n";
                                   }

      elsif($tab_recup_sce[$cpt][2] eq "OutOfRange"){ }

        elsif($tab_recup_sce[$cpt][2] eq "Unknown"){
                                      print RECUP "[$t] PROCESS_SERVICE_CHECK_RESULT;$sce_or_host;$rbt\_$name_sce[$cpt][0];$state[1];anewtest state is $tab_recup_sce[$cpt][2] for the couple ($rbt ,$name_sce[$cpt][0]) which send last message at $tab_recup_sce[$cpt][3] \n";
                                      $now = localtime;
                                      print LOG "$now:$ARGV[3]:[$t] PROCESS_SERVICE_CHECK_RESULT;$sce_or_host;$rbt\_$name_sce[$cpt][0];$state[1];newtest state is $tab_recup_sce[$cpt][2] for the couple ($rbt ,$name_sce[$cpt][0]) which send last message at $tab_recup_sce[$cpt][3] \n";
                                      }
#}

         elsif(!defined($tab_recup_sce[$cpt][4]) || $tab_recup_sce[$cpt][4] eq "" || $tab_recup_sce[$cpt][4] eq " "){
print RECUP "[$t] PROCESS_SERVICE_CHECK_RESULT;$sce_or_host;$rbt\_$name_sce[$cpt][0];3;no information for the couple ($rbt,$name_sce[$cpt][0])\n";
$now = localtime;
print  LOG "$now:$ARGV[3]:[$t] PROCESS_SERVICE_CHECK_RESULT;$sce_or_host;$rbt\_$name_sce[$cpt][0];3;no information for the couple ($rbt,$name_sce[$cpt][0])\n";
}

else{  print RECUP "[$t] PROCESS_SERVICE_CHECK_RESULT;$sce_or_host;$rbt\_$name_sce[$cpt][0];3;AZNo information for the couple ($rbt,$name_sce[$cpt][0])\n";
$now = localtime;
print  LOG "$now:$ARGV[3]:[$t] PROCESS_SERVICE_CHECK_RESULT;$sce_or_host;$rbt\_$name_sce[$cpt][0];3;AZEno information for the couple ($rbt,$name_sce[$cpt][0])\n";
     }
   }
}

}



####################################################################################################################################################

sub actif{
open(RECUP,"+>$file_command_nagios") || print " error when opening the file $file_command_nagios\n";
$bool1=length($tab_recup_sce[1]);
@state= Newtestlib::get_nagios_sce_state($tab_recup_sce[1]);
  if(length($tab_recup_sce[1]) == 1 ){ print "UNKNOWN:newtest state is UNKNOWN for the couple ($rbt,$sce_or_host) ";
                          $now = localtime;
                          print LOG "$now:UNKNOWN:newtest state is UNKNOWN for the couple ($rbt,$sce_or_host) ";
                          exit $ERRORS{"UNKNOWN"};
                          }
  if (length($tab_recup_sce[3]) == 1)
        {
        if($tab_recup_sce[1] eq "Available"){#$stat=0;
	                        print "$state[0]:newtest state is $tab_recup_sce[1]  for the couple ($rbt,$sce_or_host) which send last message at $tab_recup_sce[2] \n";
	                        print LOG "$state[0]:newtest state is $tab_recup_sce[1] for the couple ($rbt,$sce_or_host)  which send last message at $tab_recup_sce[2] \n";
	                        exit $ERRORS{"$state[0]"};
                                }

	if($tab_recup_sce[1] eq "OutOfRange"){ }

	if($tab_recup_sce[1] eq "Warning"){
                               print  "$state[0]:newtest state is $tab_recup_sce[1] for the couple ($rbt,$sce_or_host) which send last message at $tab_recup_sce[2]\n";
                               $now = localtime;
                               print LOG "$now:$state[0]:newtest state is $tab_recup_sce[1] for the couple ($rbt,$sce_or_host) which send last message at $tab_recup_sce[2]\n";
                               exit $ERRORS{"$state[0]"};
                               }

        if($tab_recup_sce[1] eq "Failed"){#$stat="OK";
				print "$state[0]:newtest state is $tab_recup_sce[1] for the couple ($rbt,$sce_or_host) which send last message at $tab_recup_sce[2]\n";
			        $now = localtime;
				print LOG "$now:$state[0]:newtest state is $tab_recup_sce[1] for the couple ($rbt,$sce_or_host) which send last message at $tab_recup_sce[2]\n";
				exit $ERRORS{"$state[0]"};
                              }

        if($tab_recup_sce[1] eq "Canceled"){
				print  "$state[0]:newtest state is $tab_recup_sce[1] for the couple ($rbt,$sce_or_host) which send last message at $tab_recup_sce[2]\n";
				$now = localtime;
				print LOG "$now:$state[0]:newtest state is $tab_recup_sce[1] for the couple ($rbt,$sce_or_host) which send last message at $tab_recup_sce[2]\n";
				exit $ERRORS{"$state[0]"};
                                }


        if($tab_recup_sce[1] eq "Unknown"){
				print "$state[0]:newtest state is $tab_recup_sce[1] for the couple ($rbt,$sce_or_host) which send last message at $tab_recup_sce[2]\n";
			        $now = localtime;
				print LOG "$now:$state[0]:newtest state is $tab_recup_sce[1] for the couple ($rbt,$sce_or_host) which send last message at $tab_recup_sce[2]\n";
				exit $ERRORS{"$state[0]"};
                                }

           }
#pas de perf
if(length($tab_recup_sce[3]) > 1)
      {
      if($tab_recup_sce[1] eq "Available"){#$stat=0;
           			 print "$state[0]:newtest state is $tab_recup_sce[1] for the couple ($rbt,$sce_or_host) which send last message at $tab_recup_sce[2]|$perfdata \n";
            			 $now = localtime;
            			 print LOG "$now:$state[0]:newtest state is $tab_recup_sce[1] for the couple ($rbt,$sce_or_host) which send last message at $tab_recup_sce[2]|$perfdata \n";
				 exit $ERRORS{"$state[0]"};
                                 }

       if($tab_recup_sce[1] eq "OutOfRange"){ }

        elsif($tab_recup_sce[1] eq "Warning"){
        	                  print "$state[0]:newteste stat is $tab_recup_sce[1] for the couple ($rbt,$sce_or_host) which send last message at $tab_recup_sce[2] |$perfdata \n";
        			  $now = localtime;
       				  print LOG "$now:$state[0]:newteste stat is $tab_recup_sce[1] for the couple ($rbt,$sce_or_host) which send last message at $tab_recup_sce[2] |$perfdata \n";
				  exit $ERRORS{"$state[0]"};
                                  }


        elsif($tab_recup_sce[1] eq "Failed"){
				print "$state[0]:newtest state is $tab_recup_sce[1] for the couple ($rbt,$sce_or_host) which send last message at $tab_recup_sce[2] |$perfdata\n";
 				$now = localtime;
				print LOG "$now:$state[0]:newtest state is $tab_recup_sce[1] for the couple ($rbt,$sce_or_host) which send last message at $tab_recup_sce[2] |$perfdata\n";
				exit $ERRORS{"$state[0]"};
                                }

        elsif($tab_recup_sce[1] eq "Canceled"){
		                   print  "$state[0]:newtest state is $tab_recup_sce[1] for the couple ($rbt,$sce_or_host) which send last message at $tab_recup_sce[2] |$perfdata\n";
 				   $now = localtime;
				   print LOG "$now:$state[0]:newtest state is $tab_recup_sce[1] for the couple ($rbt,$sce_or_host) which send last message at $tab_recup_sce[2] |$perfdata\n";
				   exit $ERRORS{"$state[0]"};
                                   }


        elsif($tab_recup_sce[1] eq "Unknown"){
		                  print "$state[0]:newtest state is $tab_recup_sce[1] for the couple ($rbt,$sce_or_host) which send last message at $tab_recup_sce[2] |$perfdata\n";
 				  $now = localtime;
				  print LOG "$now:$state[0]:newtest state is $tab_recup_sce[1] for the couple ($rbt,$sce_or_host) which send last message at $tab_recup_sce[2] |$perfdata\n";
				  exit $ERRORS{"$state[0]"};
                                  }

    }

}