Check last modify time of growing log files

All questions related to installations, configurations and maintenance of Advanced Host Monitor (including additional tools such as RMA for Windows, RMA Manager, Web Servie, RCC).
Post Reply
Stefan
Posts: 22
Joined: Fri Feb 11, 2011 3:01 am

Check last modify time of growing log files

Post by Stefan »

Hello KS-support team,

I have a problem to identify several log files.
I want to check the age (last modify time) of the newest file with "Folder/File Availability"-test.

In the following I want to show you the structure of log files which are
located !!!only in one!!! directory.

---------------------------------------------------------------
"Control_3_PROD20150313.0" (50MB - old log file)
"Control_3_PROD20150313.1" (newest log file)

"Control_5_PROD20150313.0" (50MB - old log file)
"Control_5_PROD20150313.1" (newest log file)

"Control_13_PROD20150313.0" (50MB - old log file)
"Control_13_PROD20150313.1" (newest log file)
---------------------------------------------------------------

Unfortunately, the system, which generate log files, will create new log-file by reaching size of 50 MegaBytes and increase ending number of filename.
So, if I use the path-string "\\[SERVER-IP]\[DIRECTORY-NAME]\Control_3_PROD%yyyy%%mm%%dd%.*" with enabled macro translation,
HostMonitor can not identify the newest log-file.

Can you help me to find the way to identify always the growing log-files?

Regards,
Stefan
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

Use another variable: %NewestFile% - Name of the newest file in specified folder
\\SERVER-IP\DIRECTORY-NAME\%NewestFile%

Regards
Alex
Stefan
Posts: 22
Joined: Fri Feb 11, 2011 3:01 am

Post by Stefan »

Hi Alex,

my problem is, that into the same directory, there are more than one log-files which grows continuely.
So I can not use %NewestFile% variable because HostMonitor will check always one of all growing log-files?

Regards,
Stefan
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

Sorry, I do not understand.
You said you want to check newest file (using modification timestamp). Then you need to use %newestfile% variable.

Regards
Alex
Stefan
Posts: 22
Joined: Fri Feb 11, 2011 3:01 am

Post by Stefan »

Hi Alex,

sorry for my bad description.

I want to check newest file of each log-file.
But unfortunately, there are all three log-files into same directory! (see following example)

---------------------------------------------------------------
"Control_3_PROD20150313.0" (50MB - old log file)
"Control_3_PROD20150313.1" (newest log file)

"Control_5_PROD20150313.0" (50MB - old log file)
"Control_5_PROD20150313.1" (newest log file)

"Control_13_PROD20150313.0" (50MB - old log file)
"Control_13_PROD20150313.1" (newest log file)
---------------------------------------------------------------

Which file will HostMonitor check by using %NewestFile% Variable? (Always the newest one ???)

Regards,
Stefan
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

Oh, I see - application records 3 log files at the same time and there is no fixed name for each log file?
Then I do not see solution.
Unless you can change application settings so it will use different folders for these log files.

Regards
Alex
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

Actually this can be done using custom script with Shell Script test method.
What is expected Reply (e.g. file age in minutes, or just time string)
What threshold condition should look like? (e.g. set Bad status if file is older than 30 min.)
Stefan
Posts: 22
Joined: Fri Feb 11, 2011 3:01 am

Post by Stefan »

Hello KS-Soft Europe team,

it would be great if you can show me an example of using a custom script with shell script test method!
As reply I expect the file age in minutes and threshold condition to set bad status should be file age is older than 15 minutes.

Regards,
Stefan
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

JScript for Shell Script test method may look like the following:

Code: Select all

statusUnknown     = "ScriptRes:Unknown:"
statusOk          = "ScriptRes:Ok:"
statusBad = "ScriptRes:Bad:"

objArgs = WScript.Arguments;

if (objArgs.length<3) {
  WScript.StdOut.Write(statusUnknown + 'Required 3 parameters: <folder path> <partial file name e.g.: TEST03> <age in minutes>');
  WScript.Quit();
}

  var oFS = new ActiveXObject('Scripting.FileSystemObject');
  var ff1 = oFS.GetFolder(objArgs(0));
  var fc = new Enumerator(ff1.files);
  var newestFile = false;
  var newestTime = false;

  for (; !fc.atEnd(); fc.moveNext())
    {
     if (newestFile === false&&fc.item().name.indexOf(objArgs(1))>-1) {
        newestTime = fc.item().DateLastModified;
        newestFile = fc.item();
        }

     if (fc.item().DateLastModified > newestTime&&fc.item().name.indexOf(objArgs(1))>-1) {
        newestTime = fc.item().DateLastModified;
        newestFile = fc.item();
        }
    }

    if (newestFile === false) {
      WScript.StdOut.Write(statusUnknown + 'No files found with name like ('+objArgs(1)+')');
       WScript.Quit();
      }
    
     var dat = new Date;
     var fileAge = parseInt((dat - newestTime)/1000/60);

     if (fileAge > parseInt(objArgs(2))) {
       WScript.StdOut.Write(statusBad+fileAge+' ('+newestFile.name+')');
       WScript.Quit();
     }

   WScript.StdOut.Write(statusOk+fileAge);
Start cmd: cmd /c cscript /B /E:JScript %Script% %Params%
Script requires 3 parameters: <folder path> <partial file name e.g.: Control_6_PROD> <age in minutes>
E.g.:
"\\SERVER-IP\DIRECTORY-NAME\" Control_13_ 15
Stefan
Posts: 22
Joined: Fri Feb 11, 2011 3:01 am

Post by Stefan »

Hello KS-Soft Europe team,

thank you very much for your Jscript-code!!!
It is working very well :D

Great support!!! Thanks!!!

Regards,
Stefan
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

You are welcome!
Post Reply