wavecamper

Logfile Analyse

Hi,

ich suche ein Tool welches frei konfigurierbar/programmierbar ist, in dem ich verschiedene logfiles automatisch analysieren kann.
Dies soll so funktionieren, dass ich eine Zeile aus dem Logfile herauskopiere und mir dieses so übersetzt wird, wie ich es vorgebe.
Es handelt sich dabei um PLC & FSC Logfiles. Dies sind Controller im Bereich Warehouse, welche immer die gleiche Struktur an Logfiles aufweisen jedoch muss ich diese immer mühsam mit Tabellen usw manuell übersetzen.

Beispiel:

Code: 154365427674878 - 5 - 1 -
Übersetzung: Barcode - Info Punkt 24078 -ausgeschleust auf rutsche 24 -

usw. Hoffe es wird damit deutlich.

Meine Netzsuche war bisher leider erfolglos aber ich gehe stark davon aus das ich nicht der erste bin der diese Idee hat.

Mein erster Versuch war es dies mit Excel und Trennzeichen zu machen jedoch sind die Text Strings nicht immer gleich lang und da stoße ich bei Excel an seine Grenzen.
Bei Bedarf kann ich natürlich auch echte Beispiele liefern.
Auf Facebook teilen
Auf X (Twitter) teilen
Auf Reddit teilen
Auf Linkedin teilen

Content-ID: 1219842163

Url: https://administrator.de/forum/logfile-analyse-1219842163.html

Ausgedruckt am: 21.05.2025 um 06:05 Uhr

Lochkartenstanzer
Lochkartenstanzer 02.09.2021 um 10:25:10 Uhr
Goto Top
Moin,

Ich vermute mal, ein einfaches bash- oder powershell-script würde das gewünschte tun, sofern man eine Tabelle hat, wie was zu übersetzen ist.

Aber hne echte Beispiele wird das nichts.

lks
wavecamper
wavecamper 02.09.2021 um 10:48:21 Uhr
Goto Top
[0x02]4110668 202957952455029156090155030102_________________________________________[0x03]

So sieht das Telegram aus das ich auswerten möchte. Ich kann leider die dazu gehörigen Tabellen nicht veröffentlichen aber es gibt dann halt ca. 20 verschiedene Tabellen anhand derer man diesen Textstring entschlüsseln kann.
em-pie
em-pie 02.09.2021 um 11:58:56 Uhr
Goto Top
Moin,

  • baue eine PS-GUI
  • baue dort ein Eingabefeld ein
  • Scanne dort den Code
  • Lasse eine Funktion aufrufen
  • Die Funktion zerhackstückel dir den Code, wie du ihn brauchst (wir können das ja nicht; kennen wir ja keine Daten)
  • suche mit dem "dechiffrierten Code" deine Zeile aus den verschiedenen Tabellen zusammen
  • Schreibe das Ergebnis in einen String
  • geben den String in der GUI in einem Label aus

Fertig ist der Lack.

Gruß
em-pie
Lochkartenstanzer
Lochkartenstanzer 02.09.2021 aktualisiert um 12:04:14 Uhr
Goto Top
Zitat von @em-pie:

Moin,

  • baue eine PS-GUI

Ich würde da einfach ein bash- oder powershell-Skript machen, das ohne Parameter (oder mit den Parametern Eingabe- und Ausgabedatei) aufgerufen wird und einfach das gesamte Logfile konvertiert.

Ansonsten wäre die vorgehensweise gleich:

  • zerpflücke den Code in einzelteile
  • schaue in den Tabellen nach
  • baue daraus die Ausgabe zusammen.

lks
wavecamper
wavecamper 02.09.2021 um 14:22:25 Uhr
Goto Top
Danke für die Rückmeldungen. Ich schaue mal ob ich das so umgesetzt bekomme.
colinardo
Lösung colinardo 02.09.2021, aktualisiert am 03.09.2021 um 09:48:42 Uhr
Goto Top
Servus,
für die GUI Fanatiker bspw. so etwas mal schnell mit Powershell skizziert mit der sich die Einstellungen zusammenklicken lassen und das Ergebnis dann auch wieder als CSV exportieren lässt

screenshot

screenshot

screenshot

screenshot

Die möglichen Optionen sind natürlich noch alle nicht ausgereizt, wie z.B. das Anbieten unterschiedlicher Suchdatei-Formate etc. das lässt sich dann nach eigenem Gusto anpassen, war halt auf die Schnelle zusammengeschrotet.

# hide powershell console window
Add-Type –MemberDefinition '[DllImport("user32.dll")]public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);' -name Window -namespace W32  
[void][W32.Window]::ShowWindow((Get-Process -id $pid).MainWindowHandle, 0) 

# function which generates the form
function GenerateForm {

    #region Import the Assemblies
    [reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null  
    [reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null  
    #endregion

    $form1 = New-Object System.Windows.Forms.Form -Property @{
      Name = 'form1'  
      Text = "Logfile Translator"  
      ClientSize = '846,558'  
    }
    $tabs = New-Object System.Windows.Forms.TabControl -Property @{
      Name = "tabs"  
      Anchor = 15
      Location = '12,12'  
      Size = '822,534'  
      SelectedIndex = 0
      add_SelectedIndexChanged = {
        if ($tabs.SelectedIndex -eq 2){
            $transtables = New-Object System.Collections.ArrayList
            $dgvTable.Rows | %{
                $transtables.Add((Import-CSV -LiteralPath $_.Cells[1].Value.toString() -Delimiter $comboDelimiter.Text))
            }
        
            $transresult = $global:matches | %{
                $obj = [ordered]@{}
                $cnt = 1
                foreach($grp in ($_.Groups | select -skip 1)){
                    $obj.($dgvTable.Rows[$cnt-1].Cells.Value) = $transtables[($cnt-1)] | ?{$_.($txtSearchColumn.Text) -eq $grp.Value} | select -Firs 1 -Expand $txtReplaceColumn.Text
                    $cnt++
                }
                [pscustomobject]$obj
            }

            $data = New-Object System.Collections.ArrayList
            $data.AddRange(@($transresult))
            $dgvResult.DataSource = $data
        }
      }
      add_Selecting = {
        if($_.TabPageIndex -eq 2 -and $dgvTable.Rows.Count -lt 1){
            [System.Windows.Forms.MessageBox]::Show("Please fill translation table first!","Info",0,48)  
            $_.Cancel = $true
        }
      }
    }
    $form1.Controls.Add($tabs)
    
    $tabLogfile = New-Object System.Windows.Forms.TabPage -Property @{
      Name = "tabLogfile"  
      Text = "Logfile"  
      Size =  '814,508'  
      Location = '22,4'  
      Padding = 10
      UseVisualStyleBackColor = $True
    }
    $tabs.Controls.Add($tabLogfile)
    
    $label1 = New-Object System.Windows.Forms.Label -Property @{
      Name = "label1"  
      Anchor = 9
      Location = '701,18'  
      Size = '100,23'  
      Text = "Preview"  
      TextAlign = 64
    }
    $tabLogfile.Controls.Add($label1)
    
    $txtLogfile = New-Object System.Windows.Forms.TextBox -Property @{
      Name = 'txtLogfile'  
      Location = '13,44'  
      Size = '788,451'  
      Anchor = 15
      Multiline = $True
      ReadOnly = $True
      ScrollBars = "Both"  
    }
    $tabLogfile.Controls.Add($txtLogfile)
    
    $btnLoadLogfile = New-Object System.Windows.Forms.Button -Property @{
      Name = 'btnLoadLogfile'  
      Location = '13,13'  
      Size = '91,23'  
      Text = "Load logfile ..."  
      add_Click = {
        $dlg = New-Object System.Windows.Forms.OpenFileDialog -Property @{Multiselect = $false}
        if($dlg.ShowDialog() -eq 'OK'){  
            $txtLogfile.Text = Get-Content $dlg.FileName -raw
            $global:logfile = $dlg.FileName
        }

      }
    }
    $tabLogfile.Controls.Add($btnLoadLogfile)
    
    $tabTranslation = New-Object System.Windows.Forms.TabPage -Property @{
      Name = "tabTranslation"  
      Location = '22,4'  
      Size = '814,508'  
      Padding = 10
      Text = "Translation"  
    }
    $tabs.Controls.Add($tabTranslation)
    
    $btnUpdateRegex = New-Object System.Windows.Forms.Button -Property @{
      Name = "btnUpdateRegex"  
      Text = "Update"  
      Location = '707,10'  
      Size = '94,23'  
      Anchor = "Top,Right"  
      Enabled = $false
      add_Click = {
        try{
            $global:regex = [regex]::new($txtParserRegex.Text)
            if ($global:regex.GetGroupNumbers().Count -le 1){
                throw "Please define at least 1 submatch definition!"  
            }
            $dgvTable.Rows.Clear()
            $global:matches = $global:regex.Matches((Get-Content $global:logfile -raw))
        
            1..($global:regex.GetGroupNumbers().Count - 1) | %{
                $dgvTable.Rows.Add(@($_,''))  
            }
        }catch{
            [System.Windows.Forms.MessageBox]::Show("Invalid regular expression!`n`n $($_.Exception.Message)","Regular expression syntax error",0,48)  
        }
      }
    }
    $tabTranslation.Controls.Add($btnUpdateRegex)
    
    $csvPanel = New-Object System.Windows.Forms.Panel -Property @{
      Name = "csvPanel"  
      Location =  '300,282'  
      Size = '315,120'  
      Padding = 10
      
    }
    $tabTranslation.Controls.Add($csvPanel)
    
    $txtReplaceColumn = New-Object System.Windows.Forms.TextBox -Property @{
      Anchor = 13
      Name = "txtReplaceColumn"  
      Size = '183,20'  
      Location = '119,60'  
        TabIndex = 2
    }
    $csvPanel.Controls.Add($txtReplaceColumn)
    
    $label7 = New-Object System.Windows.Forms.Label -Property @{
      Name = "label7"  
      Text = "Replace with column"  
      Size = '109,23'  
      Location = '13,63'  
    }
    $csvPanel.Controls.Add($label7)
    
    $txtSearchColumn = New-Object System.Windows.Forms.TextBox -Property @{
      Name = "txtSearchColumn"  
      Size = '183,20'  
      Location = '119,34'  
      Anchor = 13
        TabIndex = 1
    }
    $csvPanel.Controls.Add($txtSearchColumn)
    
    $label6 = New-Object System.Windows.Forms.Label -Property @{
      Name = "label6"  
      Text = "Search in column"  
      Size = '100,23'  
      Location = '13,37'  
    }
    $csvPanel.Controls.Add($label6)
    
    $comboDelimiter = New-Object System.Windows.Forms.ComboBox -Property @{
      Name = "comboDelimiter"  
    Size = '75,21'  
      Location = '119,7'  
      Text = ";"  
        TabIndex = 0
    }
    [void]$comboDelimiter.Items.Add(",")  
    [void]$comboDelimiter.Items.Add(";")  
    $csvPanel.Controls.Add($comboDelimiter)
    
    $label5 = New-Object System.Windows.Forms.Label -Property @{
      Name = "label5"  
      Size = '64,23'  
      Location = '13,10'  
      Text = "Delimiter"  
    }
    $csvPanel.Controls.Add($label5)

    $comboLookupFormat = New-Object System.Windows.Forms.ComboBox -Property @{
      Name = "comboLookupFormat"  
      Size = '121,21'  
      Location = '154,282'  
      DropDownStyle = 2
      add_SelectedIndexChanged = {
        switch($comboLookupFormat.Text){
            "CSV" {$csvPanel.Visible = $true}  
        }
      }
    }
    [void]$comboLookupFormat.Items.Add("CSV")  
    $comboLookupFormat.SelectedIndex = 0
    $tabTranslation.Controls.Add($comboLookupFormat)
       
    $label4 = New-Object System.Windows.Forms.Label -Property @{
      Name = "label4"  
      Size = '135,23'  
      Location = '13,285'  
      Text = "Lookup table format"  
    }
    $tabTranslation.Controls.Add($label4)
    
    $label3 = New-Object System.Windows.Forms.Label -Property @{
      Name = "label3"  
      Size = '135,40'  
      Location = '13,53'  
      Text = "Translation Table assignments"  
    }
    $tabTranslation.Controls.Add($label3)
    
    $dgvTable = New-Object System.Windows.Forms.DataGridView -Property @{
      Name = "dgvTable"  
      Size = '647,216'  
      Location = '154,53'  
      Anchor = 13
      AllowUserToAddRows = $false
      add_CellDoubleClick = {
        if ($_.ColumnIndex -eq 1){
            $dlg = New-Object System.Windows.Forms.OpenFileDialog -Property @{Multiselect = $false}
            switch($comboLookupFormat.Text){
                'CSV' {$dlg.Filter = "CSV Files | *.csv"}  
                default {$dlg.Filter = "All files | *.*"}  
            }
            if($dlg.ShowDialog() -eq 'OK'){  
                $dgvTable.Rows[$_.RowIndex].Cells[1].Value = $dlg.FileName
            }
        }
      }
    }
    $dgvTable.Columns.Add((New-Object System.Windows.Forms.DataGridViewTextBoxColumn -Property @{
        FillWeight = 50
        HeaderText = "Regex Submatch"  
        Name = ""  
        Width = 100
    }))
    $dgvTable.Columns.Add((New-Object System.Windows.Forms.DataGridViewTextBoxColumn -Property @{
        AutoSizeMode = 16
        FillWeight = 200
        HeaderText = "Lookup in file"  
        Name = ""  
        Width = 504
    }))
    $tabTranslation.Controls.Add($dgvTable)
    
    $txtParserRegex = New-Object System.Windows.Forms.TextBox  -Property @{
      Name = "txtParserRegex"  
      Size = '547,20'  
      Location = '154,12'  
      Anchor = 13
      add_TextChanged = {
        $btnUpdateRegex.Enabled = $txtParserRegex.Text -ne ''  
      }
    }
    $tabTranslation.Controls.Add($txtParserRegex)
    
    $label2 = New-Object System.Windows.Forms.Label  -Property @{
      Name = "label2"  
      Size = '135,23'  
      Location = '13,10'  
      Text = "Parser Regular Expression"  
      TextAlign = 16
    }
    $tabTranslation.Controls.Add($label2)
    
    $tabResults = New-Object System.Windows.Forms.TabPage  -Property @{
      Name = "tabResults"  
      Size = '814,508'  
      Location = '4,22'  
      Text = "Result"  
      Padding = 10
      UseVisualStyleBackColor = $True
    }
    $tabs.Controls.Add($tabResults)
    
    $btnExport = New-Object System.Windows.Forms.Button  -Property @{
      Name = "btnExport"  
      Size = '75,23'  
      Location = '726,472'  
      Text = "Export"  
      Anchor = 'Bottom,Right'  
      add_Click = {
        $dlg = New-Object System.Windows.Forms.SaveFileDialog
        $dlg.Filter = "CSV Files | *.csv"  
        if($dlg.ShowDialog() -eq 'OK'){  
            $dgvResult.DataSource | Export-CSV -LiteralPath $dlg.FileName -Delimiter ";" -NoType -Encoding Default  
        }

      }
    }
    $tabResults.Controls.Add($btnExport)
    
    $dgvResult = New-Object System.Windows.Forms.DataGridView  -Property @{
      Name = "dgvResult"  
      Size = '788,453'  
      Location = '13,13'  
      Anchor = 15
    }
    $tabResults.Controls.Add($dgvResult)
    
    $InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
    
    #Save the initial state of the form
    $InitialFormWindowState = $form1.WindowState
    #Init the OnLoad event to correct the initial state of the form
    $form1.add_Load({
      #Correct the initial state of the form to prevent the .Net maximized form issue
      $form1.WindowState = $InitialFormWindowState
    })
    #Show the Form
    [void]$form1.ShowDialog()
}

# call form function
GenerateForm

Grüße Uwe

p.s. ich bin kein eigentlich kein GUI Designer, das machen andere sicher besser face-wink
wavecamper
wavecamper 03.09.2021 aktualisiert um 09:57:47 Uhr
Goto Top
Hi Uwe,

wow super, vielen Dank! Das ist viel mehr als ich erwartet habe, das von Dir Umgesetzte werde ich mal weiterverfolgen.