Forum des Objets Communicants et Solutions pour les Libérer...
Vous souhaitez réagir à ce message ? Créez un compte en quelques clics ou connectez-vous pour continuer.

Forum des Objets Communicants et Solutions pour les Libérer...


 
AccueilAccueil  GalerieGalerie  RechercherRechercher  Dernières imagesDernières images  S'enregistrerS'enregistrer  Connexion  
-24%
Le deal à ne pas rater :
PC Portable Gaming 15.6″ Medion Erazer Deputy P40 (FHD 144Hz, RTX ...
759.99 € 999.99 €
Voir le deal

 

 [Karotz] Comment ça aucune commande ?

Aller en bas 
2 participants
AuteurMessage
Mephisto
Silver Nabz
Silver Nabz
Mephisto


Age : 43
Localisation : Golbey (88)
Nabaztag : Aiko [Tag²] & Océane de Rigosa Rives [Karotz]
Nbr de messages : 311
Carottes : 5532

[Karotz] Comment ça aucune commande ? Empty
MessageSujet: [Karotz] Comment ça aucune commande ?   [Karotz] Comment ça aucune commande ? Icon_minitimeMer 14 Déc 2011 - 17:46

Bonjour à toutes et à tous,

Je suis en train d'écrire un script en PHP pour m'avertir via le Karotz si l'un des serveurs de mon boulot ne répond plus (les serveurs ne sont pas accessible depuis l'extérieur)

Voilà le script, dans l'état actuel, donc encore en test

Code:
<?php

class Karotz {

   private $Kz_Nom      = null;
   private $Kz_Token      = null;
   private $Kz_Voix      = "voice=fr";
   private $Kz_Type_Voix   = 1;
   private $Kz_Msg      = null;
   
   private $Msg_Liste_Srv    = null;

   private $Tmp_Serveur    = null;

   function __contruct() {}

   function Lapin($Son_Nom,$Son_Token = null)
   {
      $this->Kz_Nom = "sn=".$Son_Nom;                           // Le nom du Karotz
      if(isset($Son_Token)) {$this->Kz_Token = "token=".$Son_Token;   }      // Le token du Karotz
   }

   function Voix($Type_Voix,$La_Voix)
   {
      
      $this->Kz_Type_Voix = $Type_Voix;

      $La_Voix--;
      
      switch($Type_Voix) {
         case 1:
            $voix = array("fr","en","de","es");
            $this->Kz_Voix = "voice=".$voix[$La_Voix];
            break;
         case 2:
            $voix = array("bicool","chuchotement","darkvadoor","electra",
                  "guy_vieux","guy_voix_basse","guy_fort","guy_grave",
                  "helium","jose","juliexp","julieEnfant","loic","mamie",
                  "manuella","matteo","narbe","nono","papanoel","philippe","ramboo","samy","sidoo");
            $this->Kz_Voix = "ws_kajedo=".$voix[$La_Voix];
            break;
         default:
            break;
      }
   }

   function PrepareURL()
   {
      if(sizeof($this->Tmp_Serveur) == 0) { exit("Tout va bien, pourquoi envoyer un message ?"); }
      if(sizeof($this->Tmp_Serveur) == 1)
      {
         $this->Kz_Msg = "tts=Attention,+le,+serveur,+" . $this->Tmp_Serveur[0] .",+a,+un,+probleme";
      }
      else
      {
         for($x=0;$x<sizeof($this->Tmp_Serveur);$x++)
         {
            $this->Msg_Liste_Srv  .= "+" . $this->Tmp_Serveur[$x] . ",";
         }
         $this->Kz_Msg = "tts=Attention,+les,+serveurs," . $this->Msg_Liste_Srv  ."+ont,+un,+probleme";
      }

      if($this->Kz_Type_Voix == 2) { $this->Kz_Msg .= ",+Fin."; } else { $this->Kz_Msg .="."; }

      $url = "http://api.wizz.cc/?";
      $url .= $this->Kz_Nom;
      if(isset($this->Kz_Token))
      {      
         $url .= "&" . $this->Kz_Token;
      }
      $url .= "&" . $this->Kz_Msg;
      $url .= "&" . $this->Kz_Voix;
      return $url;
   }

   function Liste_Serveur($Serveur)
   {
      $this->Tmp_Serveur = $Serveur;
   }

   function EnvoiMsg()
   {
      $curl = curl_init();
      curl_setopt($curl, CURLOPT_URL,$this->PrepareURL() );
      curl_setopt($curl, CURLINFO_HEADER_OUT, true);
      curl_setopt($curl, CURLOPT_HEADER, false);
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($curl, CURLOPT_BINARYTRANSFER, true);
      $result = curl_exec($curl);
      if(!$curl)
      {
         echo "ERREUR : ". curl_error($curl);
         curl_close($curl);
         exit();
      }
      $curl_info = curl_getinfo($curl);
      $retour = print_r($curl_info);      
      curl_close($curl);
      echo "<br>Retour  : " . $result;
   }
}
?>

Dans un premier temps, je déclare ma class

Code:
$kz = new Karotz();

Puis j'envoie les paramètres du lapin (Nom et Token si il y a lieu)

Code:
$kz->Lapin("O2RR");

Je choisis le type de voix , puis la voix en elle même

Code:
$kz->Voix(2,12);

J'injecte la liste du ou des serveurs.

Code:
$kz->Liste_Serveur(array("symphonie","sauvegarde","fichier"));

Ici je lui envoi un tableau mais en production, ce sera remplacé par une variable contenant un tableau.

Et j'envoie le message au karotz

Code:
$kz->EnvoiMsg();

Enfin je devrais envoyer comme retour, je le message suivant

Citation :
Retour : [Karotz] Aucune commande

Si j'affiche les infos venant de curl, j'ai ceci

Citation :
Array (
[url] => http://api.wizz.cc/?sn=O2RR&tts=Attention,+les,+serveurs,+symphonie,+sauvegarde,+fichier,+ont,+un,+probleme,+Fin.&ws_kajedo=julieEnfant
[content_type] => text/html
[http_code] => 200
[header_size] => 463
[request_size] => 174
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 1.836027
[namelookup_time] => 0.000637
[connect_time] => 0.765778
[pretransfer_time] => 0.765786
[size_upload] => 0
[size_download] => 24
[speed_download] => 13
[speed_upload] => 0
[download_content_length] => -1
[upload_content_length] => 0
[starttransfer_time] => 1.835992
[redirect_time] => 0
[certinfo] => Array ( )
[request_header] => GET /?sn=O2RR&tts=Attention,+les,+serveurs,+symphonie,+sauvegarde,+fichier,+ont,+un,+probleme,+Fin.&ws_kajedo=julieEnfant HTTP/1.1 Host: api.wizz.cc Accept: */*
)

Si je prend l'url et que je la colle directement dans le navigateur, ça fonctionne. nabzcry

Je pense que c'est dans la fonction EnvoiMsg que j'ai un problème mais où précisément, c'est un grand mystère.

Je me tourne donc vers vous, afin de voir si l'une ou l'un d'entre vous aurait une idée.

Merci d'avance pour votre aide.
Revenir en haut Aller en bas
wizz.cc
Special Nabz
Special Nabz
wizz.cc


Localisation : Paris - France
Nabaztag : Wizz.cc
Nbr de messages : 729
Carottes : 5415

[Karotz] Comment ça aucune commande ? Empty
MessageSujet: Re: [Karotz] Comment ça aucune commande ?   [Karotz] Comment ça aucune commande ? Icon_minitimeMer 14 Déc 2011 - 18:12

Salut Mephisto,
Si tu obtiens la réponse [Karotz] Aucune commande c'est que le param &tts n'est pas détecté (non présent ou mal orthographié ou transcodé etc...)

et comme ça fonctionne en copiant l'url dans un nav... mets un wireshark et intercepte le get de ton prg pour vérifier.

Citation :
Je suis en train d'écrire un script en PHP pour m'avertir via le Karotz si l'un des serveurs de mon boulot ne répond plus (les serveurs ne sont pas accessible depuis l'extérieur)

sinon t'inquiète pas, y'en aura tjs un pour te prévenir (et t'incendier) au tél... nabzsteam

Cdt,
Wizz.cc
Revenir en haut Aller en bas
http://wizz.cc
Mephisto
Silver Nabz
Silver Nabz
Mephisto


Age : 43
Localisation : Golbey (88)
Nabaztag : Aiko [Tag²] & Océane de Rigosa Rives [Karotz]
Nbr de messages : 311
Carottes : 5532

[Karotz] Comment ça aucune commande ? Empty
MessageSujet: Re: [Karotz] Comment ça aucune commande ?   [Karotz] Comment ça aucune commande ? Icon_minitimeMer 14 Déc 2011 - 19:43

Salut Wizz,

ça fonctionne, j'ai simplement changé les & amp; par &.

Je confirme si un serveur tombe, tu es le dernier au courant.
Revenir en haut Aller en bas
Contenu sponsorisé





[Karotz] Comment ça aucune commande ? Empty
MessageSujet: Re: [Karotz] Comment ça aucune commande ?   [Karotz] Comment ça aucune commande ? Icon_minitime

Revenir en haut Aller en bas
 
[Karotz] Comment ça aucune commande ?
Revenir en haut 
Page 1 sur 1
 Sujets similaires
-
» suivis de commande karotz?
» Problème pré-commande Karotz
» Comment mettre une commande vocale à une application?
» Comment avoir un karotz
» Assistant Open Karotz. Libérez votre lapin sans passer par le site officiel !

Permission de ce forum:Vous ne pouvez pas répondre aux sujets dans ce forum
Forum des Objets Communicants et Solutions pour les Libérer... :: II. Nabaztag, Karotz, mir:ror, Dal:Dal (Violet Object Operating System) :: L'univers de Nabaztag :: Archives :: API-
Sauter vers: