View previous topic :: View next topic |
Author |
Message |
sysadmber
Joined: 08 Dec 2015 Posts: 50
|
Posted: Mon Aug 22, 2016 11:56 pm Post subject: Method "File exists" Reply |
|
|
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. |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
KS-Soft
Joined: 03 Apr 2002 Posts: 12818 Location: USA
|
Posted: Tue Aug 23, 2016 5:10 am Post subject: |
|
|
What exactly reply value do you need?
HostMonitor can show file modification time (%FileTime% variable)
Regards
Alex |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
sysadmber
Joined: 08 Dec 2015 Posts: 50
|
Posted: Tue Aug 23, 2016 10:36 pm Post subject: |
|
|
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. |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
KS-Soft Europe
Joined: 16 May 2006 Posts: 2832
|
Posted: Wed Aug 24, 2016 5:22 am Post subject: |
|
|
You may use Shell Script test for this task: http://www.ks-soft.net/hostmon.eng/mframe.htm#tests.htm#chkShell
Script may look like the following:
Code: | 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 |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
KS-Soft
Joined: 03 Apr 2002 Posts: 12818 Location: USA
|
Posted: Wed Aug 24, 2016 8:45 am Post subject: |
|
|
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 |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
sysadmber
Joined: 08 Dec 2015 Posts: 50
|
Posted: Wed Aug 24, 2016 11:36 pm Post subject: |
|
|
Thanks!
your script works very well. In Combination with "Tune up Reply Value" it is exactly what i wanted. |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
KS-Soft Europe
Joined: 16 May 2006 Posts: 2832
|
Posted: Thu Aug 25, 2016 2:35 am Post subject: |
|
|
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. |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
sysadmber
Joined: 08 Dec 2015 Posts: 50
|
Posted: Thu Aug 25, 2016 5:51 am Post subject: |
|
|
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%) ??? |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
KS-Soft Europe
Joined: 16 May 2006 Posts: 2832
|
Posted: Thu Aug 25, 2016 6:51 am Post subject: |
|
|
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%] |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
sysadmber
Joined: 08 Dec 2015 Posts: 50
|
Posted: Thu Aug 25, 2016 11:07 pm Post subject: |
|
|
Perfect. I change the test to the new logic and everything works as expected.
Thanks |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
|