Fehlercounter in eigenes Fenster legen

  • Hallo Autoitter,

    ich hab gestern für ein Testsystem ein kleines Script gebastelt, welches ein System anpingt und alles in ein Logfile schreibt dazu einen kleinen Logviewer.jetzt fehlt mir eine "progressbar" "kleines Fenster" der mir die Anzahl der Pings und des Fehlercounters ständig aktuallisiert darstellt leider hab ich keine idee wie ich das unterbringen soll.

    eventuell hat von euch ja jemand ne schnelle Lösung so bis Montag morgen 0730 :D

    Script

    Spoiler anzeigen
    [autoit]

    #include <file.au3>
    #include <Date.au3>
    ; Prompt the user to enter the destination IP Adress - no logic verification still now
    $ip = InputBox("Zieladresse", "Please type in the destination address and click OK", "127.0.0.1")
    $i = 1
    $f = 0
    Do
    ping($ip, 150) ; 150 ms timeout for Ping

    [/autoit] [autoit][/autoit] [autoit]

    if @error = 0 Then
    _FileWriteLog(@ScriptDir & "\ping.log"," Works fine " & $ip &" Ping number: " & $i)
    sleep(150)
    ElseIf @error = 1 Then
    _FileWriteLog(@ScriptDir & "\ping.log"," System not reachable " & $ip &" Ping number: " & $i & " Fehlercount " & $f)
    Beep(1250, 150)
    $f = $f + 1
    ElseIf @error = 4 Then
    _FileWriteLog(@ScriptDir & "\ping.log"," System not reachable " & $ip &" Ping number: " & $i& " Fehlercount " & $f)
    Beep(1250, 150)
    $f = $f + 1
    endif

    [/autoit] [autoit][/autoit] [autoit]

    $i = $i + 1
    Until $i = "xXx" ; xXx should never happen

    [/autoit]

    Logviewer

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #Include <File.au3>
    #Include <GuiEdit.au3>
    Opt("GUIOnEventMode", 1)
    Global $iMemo, $new_line
    $width = 1024
    $height = 600
    $hGUI = GUICreate("Log Reader ", $width, $height, -1, -1, Default, $WS_EX_TOPMOST)
    $iMemo = GUICtrlCreateEdit("", 0, 0, $width, $height, $ES_AUTOVSCROLL + $WS_VSCROLL + $WS_HSCROLL + $ES_READONLY)
    GUICtrlSetLimit(-1, 0x7FFFFFFF)
    GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
    GUISetState()
    If $CmdLine[0] > 0 And FileExists($CmdLine[1]) Then
    $file = $CmdLine[1]
    Else
    $file = @ScriptDir & "\ping.log"
    EndIf
    $hFile = FileOpen($file)
    $txt = FileRead($hFile)
    GUICtrlSetData($iMemo, $txt, 1)
    _GUICtrlEdit_LineScroll($iMemo, 1, 0xfffffff)
    $cl = _FileCountLines($file)
    $fs = FileGetSize($file)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
    While Sleep(1000)
    $fs_new = FileGetSize($file)
    If $fs < $fs_new Then
    $cl_new = _FileCountLines($file)
    For $i = $cl + 1 To $cl_new
    $new_line &= FileReadLine($hFile, $i) & @CRLF
    Next
    GUICtrlSetData($iMemo, $new_line, 1)
    $cl = $cl_new
    $fs = $fs_new
    $new_line = ""
    EndIf
    Wend
    Func _Exit()
    FileClose($hFile)
    GUIDelete($hGUI)
    Exit
    EndFunc

    [/autoit]

    Gui für drumrum

    Spoiler anzeigen
    [autoit]

    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    FileInstall("c:\pingtool\pingbox.exe", "c:\temp\pingbox.exe",1)
    FileInstall("c:\Pingtool\Logviewer.exe", "c:\temp\Logviewer.exe",1)
    $Form1 = GUICreate("Pingtester", 195, 211, 488, 336)
    $Start = GUICtrlCreateButton("Start Test", 40, 24, 113, 41)
    $Log = GUICtrlCreateButton("Start Logviewer", 40, 80, 113, 41)
    $Exit = GUICtrlCreateButton("Exit", 40, 136, 113, 41)
    GUISetState(@SW_SHOW)
    While 1
    Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
    ProcessClose ( "pingbox.exe")
    ExitLoop
    Case $Start
    ; When you press Start
    Run("c:\temp\pingbox.exe")
    ;~~
    Case $Log
    ; When you press Log
    Run("c:\temp\Logviewer.exe")

    [/autoit] [autoit][/autoit] [autoit]

    Case $exit
    ProcessClose ( "pingbox.exe")
    ExitLoop
    ;~~
    EndSwitch
    WEnd

    [/autoit]

    das ganze starte ich aus einer kleinen Gui welche auch die Endlosschleife mit exit wegballert. Das ganze war Quick und besonders Dirty also nicht schimpfen. :rolleyes:


    Ich bin für ein bischen hilfe echt dankbar :S

    Einmal editiert, zuletzt von Crashrider (19. Dezember 2010 um 17:38)

  • Hier mal ein Skript, das den Ansatz für die Progressbar zeigt:

    Spoiler anzeigen
    [autoit]

    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <File.au3>

    [/autoit] [autoit][/autoit] [autoit]

    ;FileInstall("c:\pingtool\pingbox.exe", "c:\temp\pingbox.exe", 1)
    ;FileInstall("c:\Pingtool\Logviewer.exe", "c:\temp\Logviewer.exe", 1)

    [/autoit] [autoit][/autoit] [autoit]

    $Form1 = GUICreate("Pingtester", 195, 231, 488, 336)
    $Start = GUICtrlCreateButton("Start Test", 40, 24, 113, 41)
    $Log = GUICtrlCreateButton("Start Logviewer", 40, 80, 113, 41)
    $Exit = GUICtrlCreateButton("Exit", 40, 176, 113, 41)
    DllCall('uxtheme.dll', 'none', 'SetThemeAppProperties', 'int', 0) ; Classic-Style
    $idProgress = GUICtrlCreateProgress(40, 130, 113, 25)
    GUICtrlSetColor(-1, 0xff0000); not working with Windows XP Style
    DllCall('uxtheme.dll', 'none', 'SetThemeAppProperties', 'int', 7) ; Standard-Windows-Style

    [/autoit] [autoit][/autoit] [autoit]

    GUISetState(@SW_SHOW)
    Global $iPingErrors = 0, $iPingAll = 0, $bStopped = True, $ip = "www.autoit.de"

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE, $Exit
    ExitLoop
    Case $Start
    ; When you press Start
    $iPingErrors = 0
    $iPingAll = 0
    $bStopped = Not $bStopped
    If $bStopped Then
    GUICtrlSetData($Start, "&weiter")
    Else
    GUICtrlSetData($Start, "&Stop")
    EndIf
    ; Case $Log
    ; When you press Log
    EndSwitch
    If Not $bStopped Then
    Ping($ip, 150) ; 150 ms timeout for Ping

    [/autoit] [autoit][/autoit] [autoit]

    If @error = 0 Then
    _FileWriteLog(@ScriptDir & "\ping.log", " Works fine " & $ip & " Ping number: " & $iPingAll)
    Sleep(150)
    ElseIf @error = 1 Then
    _FileWriteLog(@ScriptDir & "\ping.log", " System not reachable " & $ip & " Ping number: " & $iPingAll & " Fehlercount " & $iPingErrors)
    Beep(1250, 150)
    $iPingErrors += 1
    ElseIf @error = 4 Then
    _FileWriteLog(@ScriptDir & "\ping.log", " System not reachable " & $ip & " Ping number: " & $iPingAll & " Fehlercount " & $iPingErrors)
    Beep(1250, 150)
    $iPingErrors += 1
    EndIf
    $iPingAll += 1
    GUICtrlSetData($idProgress, $iPingErrors / $iPingAll * 100)
    ConsoleWrite($iPingAll & " Pings, davon Fehler: " & $iPingErrors & " Prozente " & $iPingErrors/$iPingAll*100 & @crlf)
    EndIf
    WEnd

    [/autoit]

    eventuell hat von euch ja jemand ne schnelle Lösung so bis Montag morgen 0730 :D

    na ja wir sind kein machmal Form, die Fleissarbeit musst du schon selbst machen,

    mfg autoBert

  • das ist prima danke

    für den Rest hab ich den ganzen Sonntag wenn ich fertig bin post ichs komplett eventuell kanns ja der ein oder andere gebrauchen

  • So ich denke ich habs soweit fertig :P eigentlich wollte ich noch den Logviewer als childgui integrieren, aber da ich noch nie damit etwas damit gemacht habe brauche ich dafür etwas mehr Zeit :D

    Script

    Spoiler anzeigen
    [autoit]

    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <File.au3>
    DirCreate("C:\RC_apps") ; Erstellen des Programmverzeichnisses
    FileInstall("c:\Pingtool\Logviewer.exe", "c:\RC_apps\Logviewer.exe", 1) ; Logviewer wird ins Programmverzeichniss kopiert
    $Form1 = GUICreate("Ethernet Tester", 215, 231, 488, 336) ; Aufbau der GUI "title" , width , height , left , top
    $Start = GUICtrlCreateButton("Start Test", 40, 24, 133, 41) ; Button Start test erstellen
    $Log = GUICtrlCreateButton("Start Logviewer", 40, 80, 133, 41) ; Button Start Logviewer erstellen
    $Exit = GUICtrlCreateButton("Exit", 40, 176, 133, 41) ; Button Exit erstellen
    DllCall('uxtheme.dll', 'none', 'SetThemeAppProperties', 'int', 0) ; Classic-Style optik für die Gui / Progressbar
    $idProgress = GUICtrlCreateProgress(40, 130, 133, 25) ; Erstellen der Progressbar
    GUICtrlSetColor(-1, 0xff0000) ; Progressbar Inhalt Rot darstellen -> nicht mit Windows XP Style
    DllCall('uxtheme.dll', 'none', 'SetThemeAppProperties', 'int', 7) ; Standard-Windows-Style
    GUISetState(@SW_SHOW) ; Gui einblenden
    Global $iPingErrors = 0, $iPingAll = 0, $bStopped = True,$ip = InputBox("Zieladresse", "Please type in the destination address and click OK", "127.0.0.1") ; Globale Konstanten werden gesetzt - Eingabemaske der Ipadresse als Globalvar
    While 1 ; Endlosschleife der GUI
    Switch GUIGetMsg() ; warten auf Eingabe in der Gui
    Case $GUI_EVENT_CLOSE, $Exit ; Was passiert beim Exit
    ExitLoop ; Sprung aus der Endlosschleife
    Case $Start ; Was passiert beim start klick
    $iPingErrors = 0 ; Fehlercounter auf 0
    $iPingAll = 0 ; Pingcounter auf 0
    $bStopped = Not $bStopped ; Button einstellen start stop weiter
    If $bStopped Then ; Texteinstellung des Start Test Buttons
    GUICtrlSetData($Start, "&weiter") ;
    Else ;
    GUICtrlSetData($Start, "&Stop") ;
    EndIf ;
    Case $Log ; Was passiert beim Log klick
    Run("c:\RC_apps\Logviewer.exe") ; aufruf des logviewers
    EndSwitch ;
    If Not $bStopped Then ; Wenn der Button nicht auf stop steht..
    Ping($ip, 150) ; Ping auf die Zieladresse mit 150 ms timeout
    $Error = @error ; Schreiben des Errorlevels in eine Varriable
    If $error = 0 Then ; Wenn der Errorlevel 0 ist also erfolg
    _FileWriteLog("c:\RC_apps\ping.log", " Works fine " & $ip & " Ping number: " & $iPingAll) ; Logfileeintrag erstellen
    Sleep(150) ; 150 ms Pause wegen der CPU Last ohne geht das Script auf 100%
    Else ; Wenn der Errorlevel nicht 0 ist Fehler
    _FileWriteLog("c:\RC_apps\ping.log", " System not reachable " & $ip & " Ping number: " & $iPingAll & " Fehlercount " & $iPingErrors) ; Logfileeintrag erstellen
    Beep(1250, 100) ; Sound für 100 MS als akkustisches Feedback
    $iPingErrors += 1 ; Fehlercounter hochzählen
    EndIf
    $iPingAll += 1 ; Pingcouter hochzählen
    GUICtrlSetData($idProgress, $iPingErrors / $iPingAll * 100) ; Werte für die Progressbar aufbereiten Fehler im Verhälltnis zu Ping gesammt
    ConsoleWrite($iPingAll & " Pings, davon Fehler: " & $iPingErrors & " Prozente " & $iPingErrors/$iPingAll*100 & @crlf) ; Consoleneintrag fürs Scite
    EndIf
    WEnd

    [/autoit]

    Danke nochmal an Autobert für die Hilfe heute nacht :thumbup:

    mfg

    Crashrider