New Question
 
 
PRTG Network Monitor

Intuitive to Use.
Easy to manage.

300.000 administrators have chosen PRTG to monitor their network. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free PRTG
Download >>

 

What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general. You are invited to get involved by asking and answering questions!

Learn more

 

Top Tags


View all Tags


File Content Sensor - dynamic filename

Votes:

0

Your Vote:

Up

Down

I am trying to monitor the content of a logfile, using a File Content Sensor.

My problem is that our server creates logfiles with the date encoded as part of the filename, e.g. MyServerLog_dd_mm_yyyy.txt.

Is there anyway of monitoring these logfiles by changing the filename dynamically as the sensor executes ?

filename sensor update

Created on Feb 23, 2015 5:08:50 PM by  davederrick (60) 1



6 Replies

Votes:

0

Your Vote:

Up

Down

Hi,

Thank you for your question. Unfortunately, that is not possible, the File Content Sensor (https://www.paessler.com/manuals/prtg/file_content_sensor) is only able to check one predefined file. But maybe you can use tools like robocopy to copy the recent log version to a "log_temp.txt"? Our sensor could then look into this file.

Created on Feb 24, 2015 9:55:02 AM by  Severin Glaeser [Paessler Support] (0) 1



Votes:

2

Your Vote:

Up

Down

For anyone else looking into this, you can do something similar to what Severin suggested using a batch file and then call that batch file every so often with task manager. The below will scan through all logs in the directory that start with "logfile_" (example logfile_10-24-2017.txt, logfile_11-01-2017.txt) copy the newest one and save it in the same directory as temp_log.txt

Batch file:

rem get latest file:
for /f "tokens=*" %%i in ('dir "c:\logs\logfile_*.txt" /s /od /b') do set a=%%i
rem copy it:
copy "%a%" "c:\logs\temp_log.txt"

Created on May 27, 2017 11:40:29 PM by  pir8radio (170) 2 1

Last change on May 29, 2017 5:35:32 AM by  Luciano Lingnau [Paessler Support]



Votes:

1

Your Vote:

Up

Down

That's a sample how you can do it with powershell. It's a logfile with an dynamic name, it changes every day with the actual date of the day. In the file it will search the last 20 rows for the word "error".

$date = get-date -format "yyyyMMdd"
$file = "servername\d$\staticname_" + $date + ".log"

$string = Get-Content $file | select -Last 20
$last = Get-Content $file | select -Last 1

if ($string -like "*error*")
    {
    write-host "<prtg>"
    write-host "<result>"
    write-host "<channel>Log Alarm</channel>"
    write-host "<value>2</value>"
    write-host "</result>"
    write-host "<text>Error in logfile</text>"
    write-host "</prtg>"
    }
else
    {
    write-host "<prtg>"
    write-host "<result>"
    write-host "<channel>Log Alarm</channel>"
    write-host "<value>0</value>"
    write-host "</result>"
    write-host "<text>Logfile OK - $last</text>"
    write-host "</prtg>"
    }

Created on Oct 16, 2018 6:58:22 AM by  usr_luke (10)

Last change on Oct 16, 2018 7:17:11 AM by  Dariusz Gorka [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Hi there,

Thank you for the addition, will surely come in handy for some customers.

Best regards.

Created on Oct 16, 2018 7:20:55 AM by  Dariusz Gorka [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Can PRTG team modify File-Contrent sensor with third response's suggestion? It is pretty useful.

Created on Sep 25, 2020 4:33:09 PM by  Dakangwu (0) 1



Votes:

0

Your Vote:

Up

Down

Hello,

Thank you for your interest in this sensor.

I shared your request with our developers but such feature is not planned (yet). The PowerShell scripts provided above remain the best options, at least for now.

Kind regards.

Created on Sep 28, 2020 2:50:32 PM by  Florian Lesage [Paessler Support]

Last change on Sep 28, 2020 2:51:03 PM by  Florian Lesage [Paessler Support]



Please log in or register to enter your reply.


Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.