#!/usr/bin/perl
package Newtestlib;
use strict;
use LWP::UserAgent;
use HTML::Form;
use XML::Parser;
use File::Copy;

       	         #########################################################################################
       		 #                                                                                       #
       		 #                               Librairie Newtestlib Version 1                          #
       		 #                                                                                       #
        	 #########################################################################################


##########################################################################################################
my $word_rbt=get_word_for_robot();#the word used for the robots in the file pooler
my $word_sce=get_word_for_scenario();
my $i;
my $j;
my $count = 0;
my $tag = "";
my $data;
my $debug=0;#$v=0;
my $name;
my $ua =LWP::UserAgent->new();
my $userAgent = LWP::UserAgent->new();
my @list_robot;
my $cpt_robot=0;
my $file_r;
my $file_t;
my @liste_sce;
my $cpt_sce;
my $parse1;#$g;#used for the parsing of xml file
my $parse2;#$h;#used for the parsing of xml file
my $parse3;#$q;#used for the parsing of xml file
my $parse4;#$f;#used for the parsing of xml file
my @rbt_sce;
my $parse5;#$r;#used for the parsing of xml file
my $parse6;#$s;#used for the parsing of xml file
#my $az=0;
my $response_children;#t#
my $file_ch;
my $port;
my $url;
my $nmc;
my $passive_file;
my $file_tmp;
my $config_file;
################################################################################

########################
sub get_debug{ #ercuperer la valuer de v pour le debug
my($va)=@_;
$debug=$va;
}
########################
sub get_config_file{
my($cf)=@_;
$config_file=$cf;
}
########################
sub get_param{
#print("il entre");
my $file="$config_file";
open(CONF,"$file") || print("error when opening file $file");
my $t= -s $file;
if($t == 0){print" file $file is empty please wait\n";
            close(CONF);
            }
else{
my $line;
my @words;
my $word;
my @t;
my $i;
while( defined( $line = <CONF> ) )
{ ##si ca commence par "#" sauter la ligne
if(substr($line,0,1) eq "#"){#print("il a trouver # ==> saute la ligne");
goto EXIT;}
else{
#sinon reciperer la ligne
	@words = split( /\=+/, $line );
	$i=0;
	foreach $word (@words)
	   {	#si le premier mot est port recuperer le mot suivant ...
	        #print("word=$word\n");
	         $word=~ s/\n+//;
	        $t[$i]=$word;
	        if(substr($t[$i-1],0,length($t[$i-1])) eq "port") {$port=$word;}
	        if(substr($t[$i-1],0,length($t[$i-1])) eq "url") {$url=$word;}
	        if(substr($t[$i-1],0,length($t[$i-1])) eq "newtest_output_folder") {$file_ch=$word;}
	        if(substr($t[$i-1],0,length($t[$i-1])) eq "passive_file"){$passive_file=$word;  }
	        if(substr($t[$i-1],0,length($t[$i-1])) eq "nmc"){$nmc=$word;}
	        $i++;
	        }
	}

EXIT:
}
}
return($port,$url,$file_ch,$passive_file,$nmc);
}
#############################
sub get_file_rbt_plug{
return $file_r;
}
#############################
sub get_nmc{
my($adrr)=@_;
$nmc=$adrr;
}
#############################
sub get_road{
return $file_ch;
}
############################

             #########################################################

             #######			Robot    	      ########
              										                                        #########################################################

#######################################	debut robot	##########################################################

#################################################################################
sub request_robot{      #requete pour recuperer les informations sur les robots
my($srv)=@_;
 my $x;
# cr�ation de la requ�te
my $req = HTTP::Request->new( GET => "http://$nmc" );#$srv
# ex�cute la requ�te et re�oit la r�ponse
my $res = $userAgent->request($req);
if($debug==1){print("\n\n#####################   ca marche jusque la ################## \n\n");}
 my $message ="<?xml version=\"1.0\" encoding=\"utf-8\"?>
<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">
<soap:Body><ListRobotStatus xmlns=\"http://www.auditec-newtest.com\">
<mode>Location</mode>
<args>
<string>/</string>
</args>
</ListRobotStatus>
</soap:Body>
</soap:Envelope>";
##ENVOI DE LA REQUETE EN MODE "POST" au serveur don l'adresse a etait introduite par l'utilisateur en ligne de commande ###
my $request = HTTP::Request->new(POST => "http://$nmc:$port$url");
#creation de l'entete SOAP + message
$request->header(SOAPAction => '"http://www.auditec-newtest.com/ListRobotStatus"');
$request->content($message);
$request->content_type("text/xml; charset=utf-8");
$request->content_length(length($message)); ###la longeur de la requete en ne comptant pas l'entete SOAP mais en comptant tous les caracteres memes les blancs
#envoi de la requete au serveur
my $response = $userAgent->request($request);
#reponse du serveur
if($response->code == 200) {
                            if($debug==1)  { print($response->content);}
                            $x=$response->content;     ##recuperation de la reponse du serveur(texte xml) dans une variable
                            if($debug==1)
                                     {
                                      print TRACE "the response of the agent is: $response";
                                     }
                            }
else
     {
      print TRACE "the response of the agent is: $response";
      if ($debug==1)
                {print($response->content);
                 die $res->status_line if not $res->is_success;
                }

       $x=$response->content;

     }

 return $x;

}
################################################################################################################################################
sub parser_robot{   #parser de la requete sur les robots
my($x)=@_;
my $parser = new XML::Parser;
$parser->setHandlers(      Start => \&Newtestlib::rbt_startElement,
                           #End => \&endElement,
                           Char => \&Newtestlib::rbt_characterData);
                           #Default => \&default);
 #$parser->parsefile($fichier);
$parser->parse($x);
}
#######recuperer les valeur: Name,Status et LastMessage de chaque robot et les mettre dans une table liste_robot##########
sub rbt_startElement {
                      my($parseinst,$element,%attrs) = @_;
                      SWITCH: {
                               if ($element eq 'Name') {
                                                         $attrs{'Name'} = '';
                                                         $tag = 'Name';

                                                         last SWITCH;
                                                        }
                               elsif ($element eq 'Status') {
                                                             $attrs{'Status'} = '';
                                                             $tag = "Status";
                                                             last SWITCH;
                                                             }
                               elsif ($element eq 'LastMessage') {
                                                                  $attrs{'LastMessage'} = '';
                                                                  $tag = 'LastMessage';
                                                                  last SWITCH;
                                                                  }
                               else {$tag=""};
                              }
                      }

#################################################
sub rbt_characterData {
                       my($parseinst, $data ) = @_;
                       if ($tag eq 'Name'){
                                           $data =~ s/\n|\t//g;
                                           $list_robot[$cpt_robot][0]=$data;
                                           $list_robot[$cpt_robot][0]=uc($list_robot[$cpt_robot][0]);
                                           #if ($debug==1) { print("  $list_robot[$cpt_robot][0] \n");}
                                           }

                       elsif($tag eq 'Status'){
		                 		$data =~ s/\n|\t//g;
				                $list_robot[$cpt_robot][1]=$data;
                                                $list_robot[$cpt_robot][1]=uc($list_robot[$cpt_robot][1]);
                                               # if ($debug==1) { print("  $list_robot[$cpt_robot][1] \n"); }
                                               }
                       elsif($tag eq 'LastMessage'){
                                                    $data =~ s/\n|\t//g;
				                    $list_robot[$cpt_robot][2]=$data;
                                                    $list_robot[$cpt_robot][2]=uc($list_robot[$cpt_robot][2]);
                                                    #if ($debug==1) { print("  $list_robot[$cpt_robot][2] \n\n");}
                                                    $cpt_robot++;
                                                    }
                       }
#############################################################
sub recup_robot{ #recuperation du tableau concernant les informations sur les robots

if ($debug == 1){print ("\n --------------------------------affichage des resultats-------------------------- \n");
           for($i=0;$i<$cpt_robot;$i++) { for($j=0;$j<"3";$j++) {
                                                              print (" \n  $i $j  $list_robot[$i][$j] \n ");
                                                             }
                                       }
             }
  return($cpt_robot,@list_robot);

 }
 #######################################################
sub get_file_rbtsce{ #recuperer le nom complet du fichier file_rbt_sce
my ($file)=@_;
if($debug==1){print("\n ici file=$file");}
$file_r="$file.txt";
my $sec;
my $min;
my $hour;
my $day;
my $month;
my $year;
my @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 ];
my $t= "%02d:%02d:%02d %02d %s %04d";
my $s = $sec;
my $m = $min;
my $h = $hour;
my $mday = $day;
my $mon =$month;# @Month_name->[$month];
my $y = $year+1900;
my $wday = 3;
$t=time();
$file_tmp="$file_r\_tmp.$t";
open(FILE_R,">$file_tmp") || print("impossible d'ouvrir tmp_$file_r.$t");
}
############################
sub get_file_tmp{
return $file_tmp;
}
############################
sub get_file_trace{ #recuperer le nom complet du fichier trace
my ($file)=@_;
if($debug==1){print("\n ici file_trace=$file");}
$file_t=$file;
open(TRACE,">>$file_t");
}
############################
 sub writing_robot{     #ecriture des infrmations sur les robots dans le ficheir file_rbt_sce
my($base,$cpt_rbt,@list_rbt)=@_;
 @list_robot= @list_rbt;
 $cpt_robot=$cpt_rbt;
 $base=$base;
my $now = localtime;
print TRACE "***** start :OPEN file_rbt_sce_$base at : $now *****\n";
for($i=0;$i<$cpt_robot;$i++)
                           {
                            print FILE_R ("$word_rbt\|\|$list_robot[$i][0]\|\|$list_robot[$i][1]\|\|$list_robot[$i][2]\n");
                            if($debug==1){ print("$word_rbt\|\|$list_robot[$i][0]\|\|$list_robot[$i][1]\|\|$list_robot[$i][2]\n");}                                                          }
if($debug==1) { print("\n remplissage du fichier $file_r \n");}
  }
##############################			fin robot			##########################

              #########################################################

              #######			Robot    	      ########
              										                                         #########################################################
#######################################			debut sceanrio			##########################################################
sub req_sce{  #requete n�1 sur les scenario(listscenariostatus)
my($name)=@_;
if($debug==1){print("name=$name");}
  my $msg ="<?xml version=\"1.0\" encoding=\"utf-8\"?>
                              <soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">
                              <soap:Body>
                              <ListScenarioStatus xmlns=\"http://www.auditec-newtest.com\">
                              <mode>Robot</mode>
                              <range>0</range>
                              <args>
                              <string>$name</string>
                              </args>
                              </ListScenarioStatus>
                              </soap:Body>
                              </soap:Envelope>";
     ######ENVOI DE LA REQUETE EN MODE "POST" au serveur dont l'adresse a etait introduite par l'utilisateur en ligne de commande ########
                              my $rq = HTTP::Request->new(POST => "http://$nmc:$port$url");
                              #creation de l'entete SOAP + message
                              $rq->header(SOAPAction => '"http://www.auditec-newtest.com/ListScenarioStatus"');
                              $rq->content($msg);
                              $rq->content_type("text/xml; charset=utf-8");
                              $rq->content_length(length($msg)); ###la longeur de la requete en ne comptant pas l'entete SOAP mais en comptant tous les caracteres memes les blancs
                              my $rs = $userAgent->request($rq);
                              ##############################################
                              my $y;
                              $y=$rs->content;
                              print TRACE "\nthe result of the second request is:\n $y\n";
                              if($debug==1) {print("\n recuperation de la requete scenario r�ussite \n");}
                              print TRACE "end of the second request\n";
return $y;
}
#################################################################################################
sub get_name{#recuperer le nom du robot en cours
my ($nam)=@_;
if($debug==1){print("\n name=$nam");}
$name=$nam;
}
#############################################################################################################

 #############################################################################################################################
 sub request_sce{#requete n�2 sur les scanrio(listresult)
 my ($name)=@_;
 my $msgc ="<?xml version=\"1.0\" encoding=\"utf-8\"?>
 <soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">
                                                                               <soap:Body>
                                                                               <ListResults xmlns=\"http://www.auditec-newtest.com\">
                                                                               <mode>Robot</mode>
                                                                               <range>30</range>
                                                                               <args>
                                                                               <string>$name</string>
                                                                               </args>
                                                                               </ListResults>
                                                                               </soap:Body>
                                                                               </soap:Envelope>";
                                                                               my $reqc = HTTP::Request->new(POST => "http://$nmc:$port$url");
                                                                               $reqc->header(SOAPAction => '"http://www.auditec-newtest.com/ListResults"');
                                                                               $reqc->content($msgc);
                                                                               $reqc->content_type("text/xml; charset=utf-8");
                                                                               $reqc->content_length(length($msgc));
                                                                                my $resc = $userAgent->request($reqc);
                                                                               my $z;
                                                                               if($debug==1) { print($resc->content);}
                                                                               $z= $resc->content;

 return $z;
  }
  #################################################################################################################
 sub sce_parser{#parser de la requete n�1 sur scanrio
 my ($y)=@_;
  my $parser1 = new XML::Parser;

                              $parser1->setHandlers(Start =>\&Newtestlib::sce_startElement,
                                                       #  End => \&endElement,
                                                    Char =>\&Newtestlib::sce_characterData);
                                                        #  Default => \&default);
                              $parser1->parse($y);
#print FILE_R ("\|\|");###
      }
  #########################################################################################################
                               ###recuperer les valeur: Name,Status et LastMessage pour les scenarios de chaque robot + ecriture dans le meme fichier que celui des robots file_rbt_sce_nomserveur +remplir une table contenant les scenario liste_sce ##############
 sub sce_startElement {
 my( $parseinst, $element, %attrs ) = @_;
                 SWITCH: {
                           if ($element eq 'MeasureName') {
                                                            if ($debug==1) { print "MeasureName: ";}
                                                                                             $attrs{'MeasureName'} = '';
                                                                                             $tag = "MeasureName";
                                                                                             last SWITCH;
                                                                                            }
                                                             elsif ($element eq 'Status') {
                                                                                           if ($debug==1) { print 'Status: '; }
                                                                                           $attrs{'Status'} = '';
                                                                                           $tag = 'Status';
                                                                                           last SWITCH;
                                                                                           }
                                                             elsif ($element eq 'LastMessage') {
                                                                                                $attrs{'LastMessage'} = '';
                                                                                                $tag = 'LastMessage';
                                                                                                last SWITCH;
                                                                                               }
                                                             else {$tag=""};
                            }
                       }

 sub sce_characterData {
                                #modifier en nomrobot,nomscenario,status,lastmessage
 my( $parseinst, $data ) = @_;
if($tag eq 'Status'){
$data =~ s/\n|\t//g;
$liste_sce[0][1]=$data;  #
                }
if($tag eq 'LastMessage'){
$data =~ s/\n|\t//g;
$liste_sce[0][2]=$data;
$liste_sce[0][2]=uc($liste_sce[0][2]);
                         }
if($tag eq 'MeasureName'){
$data =~ s/\n|\t//g;
$liste_sce[0][0]=$data;
$liste_sce[0][0]=uc($liste_sce[0][0]); #noms des scenarios du robot $name
print FILE_R ("\n$word_sce\|\|$name\|\|$liste_sce[0][0]");
$liste_sce[0][4]=0;
                                                                              ####################################

print TRACE "third request\n";
my $z=Newtestlib::request_sce($name);
print TRACE "\nthe result of the third request is:\n $z\n";
my $parser2 = new XML::Parser;
$parser2->setHandlers(     Start => \&sce_c_startElement,
                            Char => \&sce_c_characterData);
 $parser2->parse($z);
 if($debug==1) { print("\n il est au niveau du deuxieme parseur xml \"$parser2->parse($z); \"n ");}
 sub sce_c_startElement {
 my( $parseinst, $element, %attrs ) = @_;
 SWITCH: {
 if  ($element eq 'MeasureName'){
   $attrs{'MeasureName'} = '';
   $tag = 'MeasureName';                                                                                                                                  last SWITCH;
                }
   elsif  ($element eq 'Id') {
            $attrs{'Id'} = '';
            $tag = 'Id';
            last SWITCH;
                  }
   elsif ($element eq 'ExecutionDate') {
          $attrs{'ExecutionDate'} = '';
          $tag = 'ExecutionDate';
          last SWITCH;
           }
   else {$tag=""};
       }
   }
sub sce_c_characterData {
  my( $parseinst, $data ) = @_;
  if($tag eq 'Id'){
  $data=~ s/\n|\t//g;
  $parse1=$data;
 $parse1=uc($parse1);   #$parse1 contient l'id d'un scenario
      }
 elsif($tag eq 'ExecutionDate'){
   $data =~ s/\n|\t//g;
   $parse2=$data;
   $parse2=uc($parse2);
      }
 elsif($tag eq 'MeasureName'){
     $data=~ s/\n|\t//g;                                                                                                                                                     $parse4=$data;
     $parse4=uc($parse4);
if(($liste_sce[0][0] eq $parse4)&&($liste_sce[0][4]==0 )){#verification que la l'identifiant recuper� correspond bien a la mesure recuper�e ulterieurement
  #verifier que le nom du scanrio dans mes 2 tableau scanrio(lsitscanariostatus et listresult) est le meme afin d'ajouter l'id dans le premier tableau
    $rbt_sce[0][0]=$name;                                                                                                                                 $rbt_sce[0][1]=uc($parse4);
    $rbt_sce[0][2]=uc($parse1);
    $rbt_sce[0][3]=uc($parse2);
    $liste_sce[0][4]=1;
if($debug==1) {print("\n $name $liste_sce[0][0],$liste_sce[0][1],$liste_sce[0][2] !!!! $rbt_sce[0][0],$rbt_sce[0][1],$rbt_sce[0][2],$rbt_sce[0][3]\n");}
print FILE_R ("=$rbt_sce[0][2]\|\|$liste_sce[0][1]\|\|$liste_sce[0][2]\|\|");
print TRACE ("\"if($tag eq 'MeasureName'){\" of the \"sub sce_c_characterData {\" of the result of third request\n");
children_request();
children_parser();
print FILE_R ("\|\|");
}
else{if($debug==1) {print("\n saut pour:$name $liste_sce[$i][0]\n");}}
                                                                                                                                                                                     }
        if($debug==1) { print("\n nouveau scenario\n");}
                                  }
               }

  }

 #################################################################################################################


               ################################################################

               ########			Mesures filles  	      #########
              										                                          ################################################################

 sub children_request{
  print TRACE "fourth request\n";
  my $msgch ="<?xml version=\"1.0\" encoding=\"utf-8\"?>
 <soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">
  <soap:Body>
  <ListResultChildren xmlns=\"http://www.auditec-newtest.com\">
  <resultId>$parse1</resultId>
  </ListResultChildren>
 </soap:Body>
  </soap:Envelope>";
  my $reqch = HTTP::Request->new(POST => "http://$nmc:$port$url");
  $reqch->content($msgch);
  $reqch->content_type("text/xml; charset=utf-8");
  $reqch->content_length(length($msgch));
  my $resch = $userAgent->request($reqch);

  if($debug==1) {print("\n resultat de la requete children\n");}
  if($debug==1) { print($resch->content);}
  print TRACE ("\nthe result of the fourth request is :\n$resch->content\n");
  $response_children= $resch->content;
 if($debug==1){ print ("\n t= $response_children\n");}
  print TRACE "the result of the fourth request is:\n  $response_children\n";
  }

  ######################################################################################
  sub children_parser{
  my $parser3 = new XML::Parser;
 $parser3->setHandlers(     Start => \&ch_startElement,
 Char => \&ch_characterData);
 $parser3->parse( $response_children);
 sub ch_startElement {
 my( $parseinst, $element, %attrs ) = @_;
 SWITCH: {
 if  ($element eq 'MeasureName'){
 $attrs{'MeasureName'} = '';
 $tag = 'MeasureName';
 last SWITCH;
  }
 elsif  ($element eq 'ExecutionValue') {
  $attrs{'ExecutionValue'} = '';
  $tag = 'ExecutionValue';
  last SWITCH;
    }
 elsif ($element eq 'MeasureThreshold') {
     $attrs{'MeasureThreshold'} = '';
     $tag = 'MeasureThreshold';
     last SWITCH;
     }
   else {$tag=""};
   }
   }
   sub ch_characterData {
      my( $parseinst, $data ) = @_;
            if($tag eq 'MeasureName'){
         $data=~ s/\n|\t//g;
              $parse3=$data;
            }
    if($tag eq 'ExecutionValue'){
         $data=~ s/\n|\t//g;
         $parse5=$data;
         }
 if($tag eq 'MeasureThreshold'){
$data=~ s/\n|\t//g;
 $parse6=$data;
if($parse6 == -79228162514264337593543950335){$parse6 = -1;}
       print FILE_R ("$parse3=$parse5;$parse6!!");
		}
    }
}
############################
sub end{
my $now1 = localtime;
my $now2 = localtime; ##pour afficher le moment ou le fichier trace fini de se remplir
print TRACE ("\n end of the \"file file_rbt_sce_...\" : $now1\n***** $now2 *****\n ");
close (TRACE);
my $now4 = localtime;
#print "\n end : $now4 \n";##pour afficher le moment ou le program
close(FILE_R);
FILE:
#my $t= -s $file_r;
if(!(-e $file_r)){
  	          #if($t == 0){
	          copy("$file_tmp","$file_r") or print "File cannot be copied.";
                  chmod '777',"$file_r";
                  unlink("$file_tmp");
	          goto QUIT;
        	}
else{
 unlink("$file_r");
 goto FILE
   }
QUIT:
}

############################
sub get_nagios_rbt_state{
my($stat)=@_;
my @tab;
$tab[0][0]="OK";#etat nmc
$tab[0][1]="OK";#etat nagios
$tab[0][2]="0";#exit nagios
$tab[0][3]="10";#perf

$tab[1][0]="SUSPENDED";#etat nmc
$tab[1][1]="WARNING";#etat nagios
$tab[1][2]="1";#exit nagios
$tab[1][3]="5";#perf

$tab[2][0]="STOPPED";#etat nmc
$tab[2][1]="WARNING";#etat nagios
$tab[2][2]="1";#exit nagios
$tab[2][3]="5";#perf

$tab[3][0]="UNKNOWN";#etat nmc
$tab[3][1]="CRITICAL";#etat nagios
$tab[3][2]="2";#exit nagios
$tab[3][3]="0";#perf

$tab[4][0]="UNINSTALLED";#etat nmc
$tab[4][1]="CRITICAL";#etat nagios
$tab[4][2]="2";#exit nagios
$tab[4][3]="0";#perf

$tab[5][0]="INOPERATIVE";#etat nmc
$tab[5][1]="CRITICAL";#etat nagios
$tab[5][2]="2";#exit nagios
$tab[5][3]="0";#perf

$tab[6][0]="RESUME";#etat nmc
$tab[6][1]="WARNING";#etat nagios
$tab[6][2]="1";#exit nagios
$tab[6][3]="5";#perf

if($stat eq "OK"){return ($tab[0][1],$tab[0][2],$tab[0][3]);}
if($stat eq "SUSPENDED"){return ($tab[1][1],$tab[1][2],$tab[1][3]);}
if($stat eq "STOPPED"){return ($tab[2][1],$tab[2][2],$tab[2][3]);}
if($stat eq "UNKNOWN"){return ($tab[3][1],$tab[3][2],$tab[3][3]);}
if($stat eq "UNINSTALLED"){return ($tab[4][1],$tab[4][2],$tab[4][3]);}
if($stat eq "INOPERATIVE"){return ($tab[5][1],$tab[5][2],$tab[5][3]);}
if($stat eq "RESUME"){return ($tab[6][1],$tab[6][2],$tab[6][3]);}
}
############################

sub get_nagios_sce_state{
my($stat)=@_;
my @tab;
$tab[0][0]="Available";#etat nmc
$tab[0][1]="OK";#etat nagios
$tab[0][2]="0";#exit nagios

$tab[1][0]="Warning";#etat nmc
$tab[1][1]="WARNING";#etat nagios
$tab[1][2]="1";#exit nagios

$tab[2][0]="Failed";#etat nmc
$tab[2][1]="CRITICAL";#etat nagios
$tab[2][2]="2";#exit nagios

$tab[3][0]="Canceled";#etat nmc
$tab[3][1]="OK";#etat nagios
$tab[3][2]="0";#exit nagios

$tab[4][0]="Unknown";#etat nmc
$tab[4][1]="UNKNOWN";#etat nagios
$tab[4][2]="3";#exit nagios

$tab[5][0]="OutOfRange";#etat nmc
$tab[5][1]="UNKNOWN";#etat nagios
$tab[5][2]="3";#exit nagios


if($stat eq "Available"){return ($tab[0][1],$tab[0][2]);}
if($stat eq "Warning"){return ($tab[1][1],$tab[1][2]);}
if($stat eq "Failed"){return ($tab[2][1],$tab[2][2]);}
if($stat eq "Canceled"){return ($tab[3][1],$tab[3][2]);}
if($stat eq "Unknown"){return ($tab[4][1],$tab[4][2]);}
if($stat eq "OutOfRange"){return ($tab[5][1],$tab[5][2]);}
}

sub get_plug_rbt_name{
my $name_plug_rbt="Newtest_plugin_rbt.pl";
return $name_plug_rbt;
}

sub get_plug_sce_name{
my $name_plug_sce="Newtest_plugin_rbt_sce.pl";
return $name_plug_sce;
}

sub more_param{
my (@arg)=@_;
my $passif;
$passif=get_passif_arg();
if ($arg[0] eq "" || $arg[1] eq "" || $arg[2] eq "" || $arg[3] eq "" ){
print("the file needs more parameters\nthe parameters are:\nthe name of the config file Newtest ex:/tmp/newtest_config.cfg\nthe case of execution ex:for the passif case 'p' and for the actif 'a'\nthe adress of the NMC ex:192.168.1.2\nthe name of the robot ex:berlin\nfor the passif case :the name of the host (only for the file concerning the plugin scenario) ex:\n host_berlin  \n ex: perl Newtest_plugin_rbt.pl c:\newtest_config.cfg a 192.168.8.121 berlin ---> actif case\nex: perl Newtest_plugin_rbt.pl c:\newtest_config.cfg p 192.168.8.121 berlin host_berlin --> passif case");
return "no-ok";
}
if($arg[1] eq "$passif" && $arg[4] eq "") {
print("the file needs an other parameter which is the name of the host\nex: host_berlin ");
return "no-ok";
}
}


sub name_plugin_rbt{
my $plug_rbt= "Newtest_plugin_rbt.pl";
return $plug_rbt;
}
sub name_plugin_rbt_sce{
my $plug_rbt_sce= "Newtest_plugin_rbt_sce.pl";
return $plug_rbt_sce;
}
sub get_suffix_preffix_file_pooler{
my $suffix_file_pooler="Newtest_file_rbt_sce_";
my $preffix_file_pooler='.txt';
return  ($suffix_file_pooler,$preffix_file_pooler);
}

sub get_suffix_preffix_trace_plug_rbt{
my $suffix_trace_plug_rbt="trace_Newtest_plugin_rbt_";
my $preffix_trace_plug_rbt='.log';
return  ($suffix_trace_plug_rbt,$preffix_trace_plug_rbt);
}

sub get_suffix_preffix_trace_plug_sce{
my $suffix_trace_plug_sce="trace_Newtest_plugin_rbt_sce_";
my $preffix_trace_plug_sce='.log';
return  ($suffix_trace_plug_sce,$preffix_trace_plug_sce);
}

sub get_passif_arg(){
my $passif_arg="p";
return $passif_arg;
}
sub robot_values{
my @tab;

}
sub get_word_for_robot{
  $word_rbt="RBT";
 return $word_rbt;
}

sub get_word_for_scenario{
  $word_sce="SCE";
 return $word_sce;
}

sub get_rbt_state {
my @tab;
$tab[0]="OK";
$tab[1]="SUSPENDED";
$tab[2]="STOPPED";
$tab[3]="UNKNOWN";
$tab[4]="UNINSTALLED";
$tab[5]="INOPERATIVE";
$tab[6]="RESUME";

return @tab;

}

sub exec_plug_sce_passif{

my ($current_dir)=@_;
my $name_plug_rbt=Newtestlib::get_plug_rbt_name();
my $name_plug_rbt_sce=Newtestlib::get_plug_sce_name();
$current_dir= substr($current_dir,0, index($current_dir,$name_plug_rbt));
 my $road_sce=$current_dir.$name_plug_rbt_sce;
 return $road_sce;
}

sub more_param_sce{
my (@arg)=@_;
my $passif;
$passif=get_passif_arg();
if ($arg[0] eq "" || $arg[1] eq "" || $arg[2] eq "" || $arg[3] eq "" || $arg[4] eq ""){
print("the file needs more parameters\nthe parametrs are:\nthe name of the config file Newtest ex:/tmp/newtest_config.cfg\nthe case of execution ex:for the passif case 'p' and for the actif case 'a'\nthe adress of the NMC ex:192.168.1.2\nthe name of the robot ex:berlin\nthe name of the host for the passif case or the name of the scenario the actif case(only for the file concerning the plugin scenario) ex:\n host_berlin (passif case) or dns_test(actif case for the file concerning the plugin scenario)\nex: perl Newtest_plugin_rbt_sce.pl c:\\newtest_config.cfg a 192.168.8.121 berlin dns_test ---> actif case\nex: perl Newtest_plugin_rbt_sce.pl c:\\newtest_config.cfg p 192.168.8.121 berlin host_berlin ---> passif case");
return "no-ok";
}
}

1;