jbroy1
Messages postés1Date d'inscriptionmercredi 15 mars 2006StatutMembreDernière intervention10 novembre 2006
-
10 nov. 2006 à 11:05
cs_Bidou
Messages postés5487Date d'inscriptiondimanche 4 août 2002StatutMembreDernière intervention20 juin 2013
-
10 nov. 2006 à 13:56
MON PROBLEME EST LE SUIVANT :
JE DOIS RECUPERER LE TEMPS DE REPONSE D UNE REQUETE PING POUR LE METTRE DANS UNE BASE DE DONNEE RRDTOOL AFIN DE MONITORER LES TEMPS DE REPONSE DE PLUSIEURS ROUTEURS.
Donc j'ai fait un ti .vbs qui me recupere ce temps et qui update la base cependant il me reste un ti probleme quand a la recuperation du temps de reponse quand celui-ci est inférieur à 10ms.
quand je recupere mon ping il peut etre sous 3 formes --> <10; <100; <1000 ms
mon script devra selectionner seulement les chiffres du resultat du ping. J'ai deja reussit a prendre les centaines et dizaines selon une condition IF mais cela ne fonctionne pas si le temps de reponse est <10 car dans ce cas j'obient 1ms au lieu de 1.
SI QUELQU'UN POUVAIT M'AIDER A FINALISER CE PETIT CODE QUI PERMET DE MONITORER LE TEMPS DE LATENCE D'OBJET RESEAU
une fois qu'il sera fini je pourai enfin mettre mes sources en lignes!!! => fonctionne avec PERL et RRDTOOL;;
MERCI ENCORE POUR LES COURAGEUX !!!!!!!!
'Ma boucle de traitement
Set objExec = objShell.Exec("ping " & "192.168.1.1") ' j'exécute le ping
strPingResult = LCase(objExec.StdOut.ReadAll) ' je mets le resultat dans une variable chaine intPos InStr(strPingResult, "moyenne ") ' je cherche la position de "Moyenne = "
strTempsDeReponse = Mid(strPingResult, intPos+10, 3) 'extraction du temps de réponse
if left(strTempsDeReponse, 1) = "m" then ' si temps <100ms je ne prend que la dizaine
strTempsDeReponse = Left(StrTempsDeReponse, 2)
End If
en fait la je veux que quelque soit le resultat du ping il ne retienne que les valeurs numérique du ping je pense qu'il faut rajouter une condition .........
CODE ENTIER
' Mes variables
Dim intPos
Dim strPingResult, strTempsDeReponse, strTempsDeReponseFinal, strPingResult1, strTempsDeReponse1, strTempsDeReponseFinal1, strPingResult2, strTempsDeReponse2, strTempsDeReponseFinal2
Dim fs : Set fs = WScript.CreateObject("Scripting.FileSystemObject")
'Mon objet shell pour exécution commande
Set objShell = CreateObject("WScript.Shell")
Set WshShell = CreateObject("WScript.Shell")
'Création du fichier texte
Set a = fs.CreateTextFile("c:\rrdtool\graphvv" & Year(Date()) & Day(Date()) & Month(Date()) & Hour(Time()) & Minute(Time()) & ".bat")
'Ma boucle de traitement
Set objExec = objShell.Exec("ping " & "192.168.1.1") ' j'exécute le ping
strPingResult = LCase(objExec.StdOut.ReadAll) ' je mets le resultat dans une variable chaine intPos InStr(strPingResult, "moyenne ") ' je cherche la position de "Moyenne ="
strTempsDeReponse = Mid(strPingResult, intPos+10, 3) ' extraction du temps de réponse
if left(strTempsDeReponse, 1) = "m" then ' si temps <100ms je ne prend que la dizaine
strTempsDeReponse = Left(StrTempsDeReponse, 2)
End If
Set objExec = objShell.Exec("ping " & "wanadoo.fr") ' j'exécute le ping
strPingResult1 = LCase(objExec.StdOut.ReadAll) ' je mets le resultat dans une variable chaine intPos InStr(strPingResult1, "moyenne ") ' je cherche la position de "Moyenne ="
strTempsDeReponse1 = Mid(strPingResult1, intPos+10, 3) ' extraction du temps de réponse
if Right(strTempsDeReponse1, 1) = "m" then ' si temps <100ms je ne prend que la dizaine
strTempsDeReponse1 = Left(StrTempsDeReponse1, 2)
End If
Set objExec = objShell.Exec("ping " & "gemini.kicks-ass.net -l 3000") ' j'exécute le ping
strPingResult2 = LCase(objExec.StdOut.ReadAll) ' je mets le resultat dans une variable chaine intPos InStr(strPingResult2, "moyenne ") ' je cherche la position de "Moyenne ="
strTempsDeReponse2 = Mid(strPingResult2, intPos+10, 3) ' extraction du temps de réponse
if Right(strTempsDeReponse2, 1) = "m" then ' si temps <100ms je ne prend que la dizaine
strTempsDeReponse2 = Left(StrTempsDeReponse2, 2)
End If
'recherche du temps unix pour update de la base rrdtool
Set objTimeExec = objShell.Exec("CMD.EXE /C perl -e ""printf time"" ")
strTimeResult = LCase(objTimeExec.StdOut.ReadAll)
'ecriture de fichier bat pour l'update de la base rrdtool
a.writeLine "rrdtool update vv.rrd " & strTimeResult & ":" & strTempsDeReponseFinal & strTimeResult1 & ":" & strTempsDeReponseFinal1 & strTimeResult2 & ":" & strTempsDeReponseFinal2
'update de la base rrdtool
CreateObject("WScript.Shell").Run "c:\rrdtool\rrdtool update vv.rrd " & strTimeResult & ":" & strTempsDeReponseFinal & strTimeResult1 & ":" & strTempsDeReponseFinal1 & strTimeResult2 & ":" & strTempsDeReponseFinal2
'Clear mémoire
set intPos = nothing
set strPingResult = nothing
set strTempsDeReponse = nothing
set arrRouteurs = nothing
set objShell = nothing
Set fs = Nothing
Set a = Nothing
Set objTimeExec = Nothing
dim testvalue
dim testvalue1
dim testvalue2
dim testvalue3
'calcul du temps unix pour soustraction à la date presente
testvalue = strTimeResult - 129600
testvalue1 = strTimeResult - 864000
testvalue2 = strTimeResult - 3628800
testvalue3 = strTimeResult - 47433600