<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Parser Support Variable Filename]]></title><description><![CDATA[<p dir="auto">How can I setup a logmonitor parser for a variable filename?</p>
<p dir="auto">log_20100920.txt</p>
<p dir="auto">The filename is not reset daily it is reset each time the server is restarted, so what I want is to monitor the most recent created filename in the folder starting with log_</p>
<p dir="auto">Is this accomplished using a macro? If so what the best way to approach this?</p>
<p dir="auto">Thanks for any input</p>
]]></description><link>https://forum.netxms.org/topic/991/parser-support-variable-filename</link><generator>RSS for Node</generator><lastBuildDate>Fri, 13 Nov 2026 10:33:04 GMT</lastBuildDate><atom:link href="https://forum.netxms.org/topic/991.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 01 Oct 2010 17:06:28 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Parser Support Variable Filename on Thu, 07 Oct 2010 04:18:11 GMT]]></title><description><![CDATA[<p dir="auto">Thanks,</p>
<p dir="auto">In the meantime here is the solution I implemented based on your suggestion. I just call this from a batch file and run it on reboot and on a daily schedule then restart the service. If you redefine the filter and/or the path it should work for most people who would need it (on windows systems).</p>
<p dir="auto">Also the log parser def in this sample was used to parse errors from a JBOSS-TOMCAT 4.2 bundle stdout log.</p>
<p dir="auto">This code should generate this sort of output,</p>
<pre><code>&lt;parser processAll="1"&gt;
	&lt;file&gt;C:\Program Files\ApplicationName\logs\stdout_20091207.log&lt;/file&gt;
	&lt;macros&gt;
		&lt;macro name="timestamp"&gt;[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2},[0-9]{3}&lt;/macro&gt;
	&lt;/macros&gt;
	&lt;rules&gt;
		&lt;rule break="1"&gt;
			&lt;match&gt;@{timestamp}.ERROR (.*)&lt;/match&gt;
			&lt;event params="1"&gt;100002&lt;/event&gt;
		&lt;/rule&gt;
	&lt;/rules&gt;
&lt;/parser&gt;
</code></pre>
<p dir="auto">LogConfig.vbs</p>
<pre><code>Dim defaultLogFileName
Dim netXMSAgentCFGFileName
Dim quoteChar
Dim Filter

Dim dynamicLogLocation

dynamicLogLocation = "C:\Program Files\ApplicationName\logs\"

' Define the filter used (if desired) to find a specific log file in a folder
Filter = "out*.log"

' Used if unable to find a log file in the folder
defaultLogFileName = "out.log"

' Location and name of log file definition
netXMSAgentCFGFileName = "C:\NetXMS\var\dynamic_log.xml"

quoteChar = CHR(34)


Const OverwriteFile = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")

logFileName = GetNewestFile(dynamicLogLocation)
If logFileName = "" Then
   logFileName = defaultLogFileName
End If

Set objTextFile = objFSO.OpenTextFile(netXMSAgentCFGFileName, OverwriteFile, True)

objTextFile.WriteLine("&lt;parser processAll=" + quoteChar + "1" + quoteChar + "&gt;")
objTextFile.WriteLine(vbTab + "&lt;file&gt;" + logFileName + "&lt;/file&gt;")
objTextFile.WriteLine(vbTab + "&lt;macros&gt;")
objTextFile.WriteLine(vbTab + vbTab + "&lt;macro name=" + quoteChar + "timestamp" + quoteChar + "&gt;[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2},[0-9]{3}&lt;/macro&gt;")
objTextFile.WriteLine(vbTab + "&lt;/macros&gt;")
objTextFile.WriteLine(vbTab + "&lt;rules&gt;")
objTextFile.WriteLine(vbTab + vbTab + "&lt;rule break=" + quoteChar + "1" + quoteChar + "&gt;")
objTextFile.WriteLine(vbTab + vbTab + vbTab + "&lt;match&gt;@{timestamp}.ERROR (.*)&lt;/match&gt;")
objTextFile.WriteLine(vbTab + vbTab + vbTab + "&lt;event params=" + quoteChar + "1" + quoteChar + "&gt;100002&lt;/event&gt;")
objTextFile.WriteLine(vbTab + vbTab + "&lt;/rule&gt;")
objTextFile.WriteLine(vbTab + "&lt;/rules&gt;")
objTextFile.WriteLine("&lt;/parser&gt;")
objTextFile.Close

'Then ...  net stop NetXMSAgentdW32 and net start NetXMSAgentdW32

Function GetNewestFile(ByVal sPath)

   sNewestFile = Null   ' init value


   Set oFSO = CreateObject("Scripting.FileSystemObject")
   Set oFolder = oFSO.GetFolder(sPath)
   Set oFiles = oFolder.Files

   ' enumerate the files in the folder, finding the newest file
   For Each oFile In oFiles
     On Error Resume Next
     If CompareFileName(oFile.Name,Filter) Then
        If IsNull(sNewestFile) Then
          sNewestFile = oFile.Path
          dPrevDate = oFile.DateLastModified
        Elseif dPrevDate &lt; oFile.DateLastModified Then
          sNewestFile = oFile.Path
        End If
     End If
     On Error Goto 0
   Next

   If IsNull(sNewestFile) Then sNewestFile = ""

   GetNewestFile = sNewestFile

End Function


Private Function CompareFileName (ByVal Name, ByVal Filter) ' (recursive)
   CompareFileName = False
   Dim np, fp: np = 1: fp = 1
   Do
      If fp &gt; Len(Filter) Then CompareFileName = np &gt; len(name): Exit Function
      If Mid(Filter,fp) = ".*" Then    ' special case: ".*" at end of filter
         If np &gt; Len(Name) Then CompareFileName = True: Exit Function
         End If
      If Mid(Filter,fp) = "." Then     ' special case: "." at end of filter
         CompareFileName = np &gt; Len(Name): Exit Function
         End If
      Dim fc: fc = Mid(Filter,fp,1): fp = fp + 1
      Select Case fc
         Case "*"
            CompareFileName = CompareFileName2(name,np,filter,fp)
            Exit Function
         Case "?"
            If np &lt;= Len(Name) And Mid(Name,np,1) &lt;&gt; "." Then np = np + 1
         Case Else
            If np &gt; Len(Name) Then Exit Function
            Dim nc: nc = Mid(Name,np,1): np = np + 1
            If Strcomp(fc,nc,vbTextCompare)&lt;&gt;0 Then Exit Function
         End Select
   Loop
End Function

Private Function CompareFileName2 (ByVal Name, ByVal np0, ByVal Filter, ByVal fp0)
   Dim fp: fp = fp0
   Dim fc2
   Do                                  ' skip over "*" and "?" characters in filter
      If fp &gt; Len(Filter) Then CompareFileName2 = True: Exit Function
      fc2 = Mid(Filter,fp,1): fp = fp + 1
      If fc2 &lt;&gt; "*" And fc2 &lt;&gt; "?" Then Exit Do
      Loop
   If fc2 = "." Then
      If Mid(Filter,fp) = "*" Then     ' special case: ".*" at end of filter
         CompareFileName2 = True: Exit Function
         End If
      If fp &gt; Len(Filter) Then         ' special case: "." at end of filter
         CompareFileName2 = InStr(np0,Name,".") = 0: Exit Function
         End If
      End If
   Dim np
   For np = np0 To Len(Name)
      Dim nc: nc = Mid(Name,np,1)
      If StrComp(fc2,nc,vbTextCompare)=0 Then
         If CompareFileName(Mid(Name,np+1),Mid(Filter,fp)) Then
            CompareFileName2 = True: Exit Function
            End If
         End If
   Next
   CompareFileName2 = False
End Function
</code></pre>
]]></description><link>https://forum.netxms.org/post/4511</link><guid isPermaLink="true">https://forum.netxms.org/post/4511</guid><dc:creator><![CDATA[Netvoid]]></dc:creator><pubDate>Thu, 07 Oct 2010 04:18:11 GMT</pubDate></item><item><title><![CDATA[Reply to Parser Support Variable Filename on Tue, 05 Oct 2010 18:53:41 GMT]]></title><description><![CDATA[<p dir="auto">Hi!</p>
<p dir="auto">It's not possible to take most recent file in directory for log parsing. The only workaround I see is to update &lt;file&gt; section in parser's XML with some external script on server start. I have created feature request (<a href="https://www.netxms.org/bugtrack/view.php?id=306" rel="nofollow ugc">https://www.netxms.org/bugtrack/view.php?id=306</a>) to improve this in the future.</p>
<p dir="auto">Best regards,<br />
Victor</p>
]]></description><link>https://forum.netxms.org/post/4508</link><guid isPermaLink="true">https://forum.netxms.org/post/4508</guid><dc:creator><![CDATA[victor]]></dc:creator><pubDate>Tue, 05 Oct 2010 18:53:41 GMT</pubDate></item></channel></rss>