Method "File exists" Reply

Need new test, action, option? Post request here.
Post Reply
sysadmber
Posts: 50
Joined: Tue Dec 08, 2015 1:26 am

Method "File exists" Reply

Post by sysadmber »

I added a couple of tests regarding file age.

Unfortuately there is no reply value. Could you please add it? I check if a file is not older that 12 Months. I see if the test is ok or not but i have to calculate the difference by hands which is not comfortable.
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

What exactly reply value do you need?
HostMonitor can show file modification time (%FileTime% variable)

Regards
Alex
sysadmber
Posts: 50
Joined: Tue Dec 08, 2015 1:26 am

Post by sysadmber »

I need the difference between the filedate and the configured value.

Example:

File Date is 01.08.2016. Today is 24.08.2016. The test goes bad if the file is older than 90 days.

Then the Reply should show 67 days left.
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

You may use Shell Script test for this task: http://www.ks-soft.net/hostmon.eng/mfra ... m#chkShell
Script may look like the following:

Code: Select all

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

var objArgs = WScript.Arguments;

if (objArgs.length != 2) {
  WScript.StdOut.Write(statusUnknown + "Required 2 parameters: <file path> <max file age>");
  WScript.Quit;
}

var moddate;
var fname = objArgs(0);
var maxAge = parseInt(objArgs(1));

try {
  var fso = new ActiveXObject("Scripting.FileSystemObject");
  var f = fso.GetFile(fname);
  moddate = f.DateLastModified;
} catch(e) {
  WScript.StdOut.Write(statusUnknown+ e.message+' ['+fname.replace(/\\\\/g,'\\')+']');
  WScript.Quit;
}

var dat = new Date;
var fileAge = parseInt((dat - moddate)/1000/60/60/24); //difference in days
var replyval = maxAge-fileAge;
if (fileAge>maxAge) {
  WScript.StdOut.Write(statusBad+replyval);
} else {
  WScript.StdOut.Write(statusOk+replyval);
}
Start cmd: cmd /c cscript /B /E:JScript %Script% %Params%

Script requires 2 parameters: <file path> <max file age>
Script returns reply with value <max file age> - <file age>

Shell Script params examples:
D:\logs\dataLog.log 90
"D:\old logs\dataLog.log" 180
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

Also we added 3 variables related to Folder/File Availability test method:
%FileAge_Min% - age of the file in minutes
%FileAge_Hour% - age of the file in hours
%FileAge_Day% - age of the file in days
Variables can be used as parameter of some actions, for Optional status processing, reports, etc

If you are using latest version of the software (10.30), you may download update at
www.ks-soft.net/download/hm1031.zip

Regards
Alex
sysadmber
Posts: 50
Joined: Tue Dec 08, 2015 1:26 am

Post by sysadmber »

Thanks!

your script works very well. In Combination with "Tune up Reply Value" it is exactly what i wanted.
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

You are welcome.
Why do you need "Tune up Reply value" option for the script?
Have you tried using update for HostMonitor 10.30 with new variables?
Built-in test methods usually cunsume less resources.
sysadmber
Posts: 50
Joined: Tue Dec 08, 2015 1:26 am

Post by sysadmber »

The tuneup is only for adding a descriptive string to the suggestedReply variable

Yes i tested the new version and the variables. Thanks for your additions.

Your new variable %FileAge_Day% computes the difference between filedate and now, whereas your script computes the difference between now and the future day.
The latter is exactly what i wanted.

To use the new variables one must be able to compute with dates. Maybe something like that:

%Date%-(%FileDate%+%TestTime%) ???
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

With new variable you may use one of the following "Tune Up Reply value" expressions:
Days Left [90-%FileAge_Day%]
[90-%FileAge_Day%] days
[90-%FileAge_Day%]
sysadmber
Posts: 50
Joined: Tue Dec 08, 2015 1:26 am

Post by sysadmber »

Perfect. I change the test to the new logic and everything works as expected.

Thanks
Post Reply