log file processing

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
avery_larry
Posts: 25
Joined: Thu Sep 11, 2008 11:06 am

log file processing

Post by avery_larry »

After reading about the log file processing, I decided to do the following:

Log all events to both the primary and backup log files.
Every month move the primary log file to a backup location and rename the backup log file as the primary log file using a custom .cmd file.

This should give me a primary log file that always has the previous and current month's events. The backup log file then just has the current month's events.

I setup the log file special processing like this:

if common log(s) was created 1 month(s) ago execute command:
cmd /c "c:\program files\hostmonitor\logs\changelog.cmd"

I can post the .cmd file if you want, but I'm certain it's working correctly.

I realized that it should be 2 month(s) ago instead of 1, so I've changed that already. However, the command has been executing every day--sometimes more than once per day--at least as far as I can tell because there's no long term record since my command file expects to be called once per month--it effectively overwrites the previous backup with the new backup if it's executed more than 1 time in any given month.

So my first question--how specifically does hostmonitor determine when the log file was created? (creation date of file, opens the file and looks at oldest event, etc.)

My second question -- why would the program execute more than one time per day, or even more than one time per month?
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

So my first question--how specifically does hostmonitor determine when the log file was created?
HostMonitor checks file creation time
My second question -- why would the program execute more than one time per day, or even more than one time per month?
Because logical condition returns "true" result.
Every month move the primary log file to a backup location and rename the backup log file as the primary log file using a custom .cmd file.
May I see changelog.cmd?

Regards
Alex
avery_larry
Posts: 25
Joined: Thu Sep 11, 2008 11:06 am

Post by avery_larry »

KS-Soft wrote:
So my first question--how specifically does hostmonitor determine when the log file was created?
HostMonitor checks file creation time
My second question -- why would the program execute more than one time per day, or even more than one time per month?
Because logical condition returns "true" result.
Well, uhh, sure--but I don't understand how it would be true every day, plus the documentation says it only checks once per day . . .
Every month move the primary log file to a backup location and rename the backup log file as the primary log file using a custom .cmd file.
May I see changelog.cmd?

Regards
Alex
changelog.cmd:
@echo off
for /f "tokens=2,4 delims=/ " %%a in ("%date%") do (
set mnth=%%a
set yr=%%b
)
cd /d "c:\program files\hostmonitor\logs"
if not exist %yr% md %yr%
move log.htm %yr%\%mnth%log.htm
move syslog.htm %yr%\%mnth%syslog.htm
ren log2.htm log.htm
Does it check the file creation date of any/all of the files in the logs directory? the changelog.cmd file is located in the same directory as the log files . . . (as well as the backup subdirectories)
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

Well, uhh, sure--but I don't understand how it would be true every day
If file cannot be moved for some reason, condition will be "true" everyday...
Could you please check creation date of the log file(s)?

Have you used some other log file except "log.htm"?
Regarding script: I think its better to use %logname% variable instead of constant "log.htm".
In such case your script will work even if you change name of the log file. Or may be you have changed it a while ago? That's why HostMonitor checks that old log and starts script.
Does it check the file creation date of any/all of the files in the logs directory?
No. HostMonitor keeps history of log files, so it checks only log files that were is use.

Regards
Alex
User avatar
greyhat64
Posts: 246
Joined: Fri Mar 14, 2008 9:10 am
Location: USA

Post by greyhat64 »

avery_larry,
It looks like you're using text or html for logging, which makes for easy log file manipulation, but automating it is a challenge isn't it?

It probably depends on how you would like to manage logging and reporting, but couldn't you use the "Change log file every month" option and simply run a (Windows Scheduler/AT) scheduled task once a month to copy/move those that are older than xx (59) days to the backup location?

Dubolomov has a pretty good script on this forum to do something like that (his backs up HM configs, but could be easily modified), and I've got a pretty clever date manipulation batch script (subtract x days from today - it's even leapyear aware!) that I've been intending to use to further automate and dress up his script. I've also been toying with the idea of writing a VBScript or PowerShell script to do the whole enchillada.

If that sounds like a good idea let me know. I'd be glad to show you what I have thus far and let you play with it to suit your needs. There are just so many ways to attack this - none of them are wrong, but of course mine's the most right :lol:

Oh and depending on how extensive the number of hosts/tests you might want to consider DBF or SQL logging. But that would change things drastically now, wouldn't it? :wink:
Last edited by greyhat64 on Tue Oct 07, 2008 12:15 pm, edited 1 time in total.
avery_larry
Posts: 25
Joined: Thu Sep 11, 2008 11:06 am

Post by avery_larry »

This must be some bizarre Windows problem. The log.htm file (primary log) has a creation date of 8/28/2008. log2.htm (the backup log) and syslog.htm both have creation dates of today. If I shutdown HM and start it back up, then the script file I created will run -- which makes sense as the creation date of log.htm is 8/28/2008. However, the script file is successful. The log.htm file is MOVED to the 2008 directory and the log2.htm file is subsequently RENAMED. However, the log.htm file (which was JUST renamed from log2.htm with a creation date of today) now shows a file creation date of 8/28/2008. Based on the contents of the files, I can absolutely confirm that the script file runs and does what I've described. The new log.htm file is in fact renamed from the log2.htm file and HM creates a brand new log2.htm and syslog.htm file (both with current creation dates). In the 2008 directory, the 10log.htm file shows a creation date of 8/28 and the 10syslog.htm file shows a creation date of today.
avery_larry
Posts: 25
Joined: Thu Sep 11, 2008 11:06 am

Post by avery_larry »

greyhat64 wrote:avery_larry,
It looks like you're using text or html for logging, which makes for easy log file manipulation, but automating it is a challenge isn't it?

It probably depends on how you would like to manage logging and reporting, but couldn't you use the "Change log file every month" option and simply run a (Windows Scheduler/AT) scheduled task once a month to copy/move those that are older than xx (59) days to the backup location?

Dubolomov has a pretty good script on this forum to do something like that (his backs up HM configs, but could be easily modified), and I've got a pretty clever date manipulation batch script (subtract x days from today - it's even leapyear aware!) that I've been intending to use to further automate and dress up his script. I've also been toying with the idea of writing a VBScript or PowerShell script to do the whole enchillada.

If that sounds like a good idea let me know. I'd be glad to show you what I have thus far and let you play with it to suit your needs. There are just so many ways to attack this - none of them are wrong, but of course mine's the most right :lol:

Oh and depending on how extensive the number of hosts/tests you might want to consider DBF or SQL logging. But that would change things drastically now, wouldn't it? :wink:
The problem is that I don't want the log to start over. I always want to have at least a full month of data in the current log file (for use with the log analyzer). With the "Change log file every month" option the current viewable history starts over (or do I misunderstand that option?).

Frankly, it's quite simple to add the necessary code to my script file (if there's already a backup file from the current month, then don't do another backup). I just jumped to the conclusion that HM was messing up instead of Windows.
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

However, the script file is successful. The log.htm file is MOVED to the 2008 directory and the log2.htm file is subsequently RENAMED. However, the log.htm file (which was JUST renamed from log2.htm with a creation date of today) now shows a file creation date of 8/28/2008.
Yes, I recall such Windows bug (or particularity?)...
If you remove some file and create new one with the same name, Windows can use creation time of that removed (non-existing anomore!) file!! Why Microsoft did this? I have no idea :roll:
That's why HostMonitor forcibly sets correct time for all new logs.

Regards
Alex
User avatar
greyhat64
Posts: 246
Joined: Fri Mar 14, 2008 9:10 am
Location: USA

Post by greyhat64 »

The problem is that I don't want the log to start over. . . (or do I misunderstand that option?).
Which is exactly why I don't use that option either, I just thought I'd bring it up in case it works for you.
Frankly, it's quite simple to add the necessary code to my script file (if there's already a backup file from the current month, then don't do another backup). I just jumped to the conclusion that HM was messing up instead of Windows.
As stated before, you just ran into a common Windows bug.

I'm sure you could figure out how to manipulate the existing files in order to maintain the file date you want with a series of copies and renames, but you might consider using xcopy or robocopy to preserve attributes. And then there are the command line utilites to manipulate create/accessed/modified dates as well.

Good luck!
Post Reply